microsoft / microsoft/onnxruntime

When developing an ONNX Runtime execution provider, how to get the current `InferenceSession` instance which the execution provider registers with?

Open
#18,046 10 comments 0 reactions 1 assignee View on GitHub

@pranavsharma is already working on this.

Since Oct 24, 2023.

core runtime platform:windows
Dominant language
C++
Stars
21.9k
Forks
4.2k
Avg merge
4d 11h
Merged PRs (30d)
184

Description

### Describe the issue

When developing an ONNX Runtime execution provider, how to get the current `InferenceSession` instance which the execution provider registers with?

Seems like there is no approach to that so far?

Can we make a few changes to the class `InferenceSession` of ONNXRuntime core?

- Opiton 1
1. In the base class `IExecutionProvider`, add a new protected memeber variable `std::shared_ptr curr_sess_` and related public getter method and setter method. Then every child class of IExecutionProvider will inherit this attribute and related getter method and setter method.
2. In the method `InferenceSession::RegisterExecutionProvider()`, assign the `this` pointer to `curr_sess_` of an instance of a child class of `IExecutionProvider` using the corresponding setter method of the child class.
- Option 2
1. In a child class `MyCostumExecutionProvider`, add a new private memeber variable `std::shared_ptr curr_sess_` and related public getter method and setter method.
2. In the method `InferenceSession::RegisterExecutionProvider()` OR `InferenceSession::Initialize()`, specially handle `MyCustomExecutionProvider` to assign the `this` pointer to `MyCustomExecutionProvider::curr_sess_` using the corresponding setter method of `MyCustomExecutionProvider`. An example of specially handling a specific execution provider in `InferenceSession` class is `DmlExecutionProvider`.

### To reproduce

N/A.

### Urgency

_No response_

### Platform

All

### OS Version

All

### ONNX Runtime Installation

Other / Unknown

### ONNX Runtime Version or Commit ID

All

### ONNX Runtime API

C++

### Architecture

X64

### Execution Provider

Other / Unknown

### Execution Provider Library Version

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.