Skip to content

Add GetCapability/Compile infrastructure for EP ABI #24887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 91 commits into from
Jun 19, 2025
Merged

Conversation

adrianlizarraga
Copy link
Contributor

@adrianlizarraga adrianlizarraga commented May 28, 2025

Description

This PRs sets the foundation for the EP ABI, which allows plugin-EPs to interface with ORT using a binary stable interface. A plugin-EP can be built separately from ORT and is not tied to a specific commit of ORT.

Currently, this PR adds basic APIs necessary to allow an example plugin-EP to compile and run a simple model with a single Mul node.

Motivation and Context

Based on #21450

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR lays the groundwork for a binary-stable plugin EP ABI in ORT, adds a sample plugin EP that runs a single Mul operator, and extends the core/session stack and C APIs to load and invoke plugin EPs.

  • Introduce example_plugin_ep.cc showing how a plugin-EP implements OrtEp and node compute callbacks.
  • Extend the C API (onnxruntime_c_api.h, ep_api.h/cc) and internal types (abi_ep_types.h, ep_plugin_provider_interfaces.*) to support graph/node enumeration and OrtNodeComputeInfo.
  • Update session creation and partitioner code (utils.cc, provider_policy_context.cc, graph_partitioner.cc, etc.) to recognize and wrap plugin EPs.

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/autoep/library/example_plugin_ep.cc Sample EP implementation with MulKernel and EP API usage.
include/onnxruntime/core/session/onnxruntime_c_api.h Add OrtNodeComputeInfo and NodeComputeContext_NodeName.
core/session/ep_api.h / ep_api.cc Implement Graph_Get*, Node_Get*, and EpGraphSupportInfo_AddSupportedNodes.
core/session/ep_plugin_provider_interfaces.* Define PluginExecutionProviderFactory and PluginExecutionProvider.
core/session/utils.cc Construct plugin vs. internal EP factory based on devices.
core/session/provider_policy_context.cc Invoke CreateEp instead of ORT_NOT_IMPLEMENTED.
core/session/ep_factory_internal.* Change constructor signatures to use gsl::span.
core/graph/model_editor_api_types.* / model_editor_c_api.cc Add internal/external conversion and null checks.
core/graph/graph.cc Adapt LoadFromModelEditorApiModel to new ModelEditorGraph.
core/framework/graph_partitioner.cc Update PlaceNode to accept ComputeCapability and handle subgraphs.
core/framework/compute_capability.h Add use_subgraph_name_as_fused_node_name flag.
Comments suppressed due to low confidence (2)

onnxruntime/test/autoep/library/example_plugin_ep.cc:115

  • [nitpick] The variable name type_shape0 is ambiguous. Consider renaming to type_shape_info_input0 (and similarly for type_shape1) for clarity.
OrtTensorTypeAndShapeInfo* type_shape0 = nullptr;

onnxruntime/core/framework/graph_partitioner.cc:366

  • The code now takes a ComputeCapability but still refers to capability.sub_graph, which no longer exists on that type. You need to either restore the IndexedSubGraph parameter or update the logic to use the correct subgraph member from ComputeCapability.
if (nullptr == capability.sub_graph->GetMetaDef()) {

@jywu-msft jywu-msft requested a review from HectorSVC May 31, 2025 20:20
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@adrianlizarraga adrianlizarraga requested a review from Copilot May 31, 2025 20:43
Copy link
Contributor

@edgchen1 edgchen1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

started reviewing

edgchen1
edgchen1 previously approved these changes Jun 18, 2025
@adrianlizarraga adrianlizarraga merged commit 0ef8213 into main Jun 19, 2025
89 of 90 checks passed
@adrianlizarraga adrianlizarraga deleted the adrianl/ep-abi branch June 19, 2025 04:19
adrianlizarraga added a commit that referenced this pull request Jun 19, 2025
### Description
Missed a few documentation errors in the [previous
PR](#24887). This PR fixes
the C/C++ API documentation generation action:
https://github.com/microsoft/onnxruntime/actions/runs/15749541590



### Motivation and Context
Fix the C/C++ API documentation generation GitHub action.
chilo-ms added a commit that referenced this pull request Jun 28, 2025
This PRs adds additional Node_GetAttributes C API for EP ABI use.
It's based on #24887
wcy123 added a commit to wcy123/onnxruntime that referenced this pull request Jul 7, 2025
Runtime C API.

PR microsoft#24887 allows plugin-EPs to interface with ORT using a binary stable
interface.

It is an important feature for a plugin EP to generate an EP context
model as specified by
https://onnxruntime.ai/docs/execution-providers/EP-Context-Design.html

The EP needs to read and write the `ep_cache_context` attribute of type
`ORT_OP_ATTR_STRING` as specified by
https://github.com/microsoft/onnxruntime/blob/5fdd4e4f2a2b6705a9a49a378a3b3496805067ee/onnxruntime/core/graph/contrib_ops/contrib_defs.cc#L3301-L3305

The current implemention of `ReadOpAttr` regards an attribute of type
`ORT_OP_ATTR_STRING` as a null terminated string.
https://github.com/microsoft/onnxruntime/blob/5fdd4e4f2a2b6705a9a49a378a3b3496805067ee/onnxruntime/core/session/custom_ops.cc#L437

It is very common that `ep_cache_context` is a sequence of bytes, as
specificed by ONNX
https://github.com/ankane/onnxruntime-1/blob/95843a5dbc3100062be88bcb0d06fd36877f3f77/onnxruntime/core/protobuf/onnx-ml.proto#L148

This commit adds a new operator attribute type `ORT_OP_ATTR_BYTES` to
the ONNX Runtime C API, which allows plugin EPs to read and write
`ep_cache_context` as a sequence of bytes.
HectorSVC pushed a commit that referenced this pull request Jul 7, 2025
### Description

Add a new ORT API `GetSessionOptionConfigEntries`.

### Motivation and Context

#24887 allows plugin-EPs to interface with ORT using a binary stable interface. #24445 allows an EP to handle the extraction of EP options from the session option configurations. For an EP like VitisAI EP to comply with the requirements,

it is necessary for a plugin-EPs to access all config entries in a session option.

```c++
    OrtKeyValuePairs * kvps = nullptr;
    auto status = GetSessionOptionConfigEntries(session_option, &kvps);
    if(status) {
        throw status;
    }
    std::unique_ptr<OrtKeyValuePairs, void (*)(OrtKeyValuePairs*)>
        config_entries(kvps,
                       ort_api.ReleaseKeyValuePairs);
    const char* const* keys = nullptr;
    const char* const* values = nullptr;
    size_t num_keys = 0;
    // Get keys and values from the config entries
    Ort::GetApi().GetKeyValuePairs(config_entries.get(), &keys, &values, &num_keys);

    for (size_t i = 0; i < num_keys; ++i) {
        // process keys[i] and values[i]
    }
```
wcy123 added a commit to wcy123/onnxruntime that referenced this pull request Jul 8, 2025
Runtime C API.

PR microsoft#24887 allows plugin-EPs to interface with ORT using a binary stable
interface.

It is an important feature for a plugin EP to generate an EP context
model as specified by
https://onnxruntime.ai/docs/execution-providers/EP-Context-Design.html

The EP needs to read and write the `ep_cache_context` attribute of type
`ORT_OP_ATTR_STRING` as specified by
https://github.com/microsoft/onnxruntime/blob/5fdd4e4f2a2b6705a9a49a378a3b3496805067ee/onnxruntime/core/graph/contrib_ops/contrib_defs.cc#L3301-L3305

The current implemention of `ReadOpAttr` regards an attribute of type
`ORT_OP_ATTR_STRING` as a null terminated string.
https://github.com/microsoft/onnxruntime/blob/5fdd4e4f2a2b6705a9a49a378a3b3496805067ee/onnxruntime/core/session/custom_ops.cc#L437

It is very common that `ep_cache_context` is a sequence of bytes, as
specificed by ONNX
https://github.com/ankane/onnxruntime-1/blob/95843a5dbc3100062be88bcb0d06fd36877f3f77/onnxruntime/core/protobuf/onnx-ml.proto#L148

This commit adds a new operator attribute type `ORT_OP_ATTR_BYTES` to
the ONNX Runtime C API, which allows plugin EPs to read and write
`ep_cache_context` as a sequence of bytes.
daijh pushed a commit to daijh/onnxruntime that referenced this pull request Jul 10, 2025
### Description

Add a new ORT API `GetSessionOptionConfigEntries`.

### Motivation and Context

microsoft#24887 allows plugin-EPs to interface with ORT using a binary stable interface. microsoft#24445 allows an EP to handle the extraction of EP options from the session option configurations. For an EP like VitisAI EP to comply with the requirements,

it is necessary for a plugin-EPs to access all config entries in a session option.

```c++
    OrtKeyValuePairs * kvps = nullptr;
    auto status = GetSessionOptionConfigEntries(session_option, &kvps);
    if(status) {
        throw status;
    }
    std::unique_ptr<OrtKeyValuePairs, void (*)(OrtKeyValuePairs*)>
        config_entries(kvps,
                       ort_api.ReleaseKeyValuePairs);
    const char* const* keys = nullptr;
    const char* const* values = nullptr;
    size_t num_keys = 0;
    // Get keys and values from the config entries
    Ort::GetApi().GetKeyValuePairs(config_entries.get(), &keys, &values, &num_keys);

    for (size_t i = 0; i < num_keys; ++i) {
        // process keys[i] and values[i]
    }
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants