Skip to content

Commit fd2e6cd

Browse files
authored
[Docs] Update Plugin EP docs (#27132)
### Description <!-- Describe your changes. --> Update plugin EP docs. Add a page on testing and move existing pages around. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> Update documentation.
1 parent 33092ab commit fd2e6cd

File tree

5 files changed

+117
-88
lines changed

5 files changed

+117
-88
lines changed

docs/execution-providers/EP-Context-Design.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ return the `external_info` argument from the `output_model_onnx_initializer_hand
479479
- [C API functions](https://github.com/microsoft/onnxruntime/blob/879ec0392ad5128968440a4e5b5a0bb742494ae5/include/onnxruntime/core/session/onnxruntime_c_api.h#L7751-L7774)
480480

481481
### Usage example: cross-compilation with a plugin EP
482-
By default, ONNX Runtime only allows the use of [plugin EPs](./plugin-ep-libraries.md) that are compatible with real hardware devices discovered by ONNX Runtime.
482+
By default, ONNX Runtime only allows the use of [plugin EPs](./plugin-ep-libraries/) that are compatible with real hardware devices discovered by ONNX Runtime.
483483
To support the creation of compiled models targeted for hardware devices not present on the compiling machine (i.e., cross-compiling), a plugin EP may be allowed
484484
to create virtual hardware devices that an application can use to compile models.
485485

@@ -645,7 +645,7 @@ OrtStatus* ORT_API_CALL EpFactoryVirtualGpu::GetSupportedDevicesImpl(OrtEpFactor
645645
- [Reference example plugin EP with virtual GPU](https://github.com/microsoft/onnxruntime/tree/main/onnxruntime/test/autoep/library/example_plugin_ep_virt_gpu)
646646
- [OrtEpApi::GetEnvConfigEntries C API function](https://github.com/microsoft/onnxruntime/blob/990ba5f0c3e0c8735fec8bf89dd11953224a9c03/include/onnxruntime/core/session/onnxruntime_ep_c_api.h#L1431-L1446)
647647
- [Ort::GetEnvConfigEntries C++ API function](https://github.com/microsoft/onnxruntime/blob/990ba5f0c3e0c8735fec8bf89dd11953224a9c03/include/onnxruntime/core/session/onnxruntime_cxx_api.h#L3531-L3532)
648-
- [Plugin EP library documentation](./plugin-ep-libraries.md)
648+
- [Plugin EP library documentation](./plugin-ep-libraries/)
649649
- [Additional Python usage examples in unit tests](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/test/python/onnxruntime_test_python_compile_api.py)
650650
- [Python ModelCompiler class](https://github.com/microsoft/onnxruntime/blob/a5ba2ba3998820dd8da111c90c420479aac7a11e/onnxruntime/python/onnxruntime_inference_collection.py#L680-L709)
651651

@@ -694,6 +694,6 @@ ort.unregister_execution_provider_library(ep_lib_registration_name)
694694
```
695695

696696
#### References
697-
- [Plugin EP library documentation](./plugin-ep-libraries.md)
697+
- [Plugin EP library documentation](./plugin-ep-libraries/)
698698
- [Additional Python usage examples in unit tests](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/test/python/onnxruntime_test_python_compile_api.py)
699699
- [Python ModelCompiler class](https://github.com/microsoft/onnxruntime/blob/a5ba2ba3998820dd8da111c90c420479aac7a11e/onnxruntime/python/onnxruntime_inference_collection.py#L680-L709)

docs/execution-providers/plugin-ep-libraries.md renamed to docs/execution-providers/plugin-ep-libraries/development-and-usage.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
---
2-
title: Plugin EP libraries
3-
description: Plugin EP libraries
4-
parent: Execution Providers
5-
nav_order: 17
2+
title: Development and Usage
3+
description: Development and Usage
4+
grand_parent: Execution Providers
5+
parent: Plugin Execution Provider Libraries
6+
nav_order: 1
67
redirect_from: /docs/reference/execution-providers/Plugin-EP-Libraries
78
---
89

9-
# Plugin Execution Provider Libraries
10+
# Plugin Execution Provider Library Development and Usage
1011
{: .no_toc }
1112

13+
This page provides a reference for the APIs necessary to develop and use plugin EP libraries with ONNX Runtime.
14+
1215
## Contents
1316
{: .no_toc }
1417

1518
* TOC placeholder
1619
{:toc}
1720

18-
## Background
19-
An ONNX Runtime Execution Provider (EP) executes model operations on one or more hardware accelerators (e.g., GPU, NPU, etc.). ONNX Runtime provides a variety of built-in EPs, such as the default CPU EP. To enable further extensibility, ONNX Runtime supports user-defined plugin EP libraries that an application can register with ONNX Runtime for use in an ONNX Runtime inference session.<br/>
20-
21-
This page provides a reference for the APIs necessary to develop and use plugin EP libraries with ONNX Runtime.
22-
2321
## Creating a plugin EP library
2422
A plugin EP is built as a dynamic/shared library that exports the functions `CreateEpFactories()` and `ReleaseEpFactory()`. ONNX Runtime calls `CreateEpFactories()` to obtain one or more instances of `OrtEpFactory`. An `OrtEpFactory` creates `OrtEp` instances and specifies the hardware devices supported by the EPs it creates.
2523

@@ -45,7 +43,7 @@ The following table lists the **required** variables and functions that an imple
4543

4644
<tr>
4745
<td>GetName</td>
48-
<td>Get the execution provider name.<br/><br/>The recommended convention for a plugin execution provider name is to have the name end with the suffix "PluginExecutionProvider". E.g., "ContosoAiPluginExecutionProvider".</td>
46+
<td>Get the execution provider name.<br/><br/>The recommended convention for an execution provider name is to have the name end with the suffix "ExecutionProvider". E.g., "ContosoAiExecutionProvider".</td>
4947
<td><a href="https://github.com/microsoft/onnxruntime/blob/16ae99ede405d3d6c59d7cce80c53f5f7055aeed/onnxruntime/test/autoep/library/ep.cc#L181">ExampleEp::GetNameImpl()</a></td>
5048
</tr>
5149

@@ -330,7 +328,7 @@ For example, if a single factory instance supports both CPU and NPU, then the ca
330328
- ep_device_1: (factory_0, NPU)
331329

332330
<br/>
333-
<p align="center"><img width="100%" src="../../images/plugin_ep_sd_lib_reg.png" alt="Sequence diagram showing registration and unregistration of a plugin EP library"/></p>
331+
<p align="center"><img width="100%" src="../../../images/plugin_ep_sd_lib_reg.png" alt="Sequence diagram showing registration and unregistration of a plugin EP library"/></p>
334332

335333
### Session creation with explicit OrtEpDevice(s)
336334
The application code below uses the API function [SessionOptionsAppendExecutionProvider_V2](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a285a5da8c9a63eff55dc48e4cf3b56f6) to add an EP from a library to an ONNX Runtime session.
@@ -374,7 +372,7 @@ env.UnregisterExecutionProviderLibrary(/*...*/);
374372
As shown in the following sequence diagram, ONNX Runtime calls `OrtEpFactory::CreateEp()` during session creation in order to create an instance of the plugin EP.
375373

376374
<br/>
377-
<p align="center"><img width="100%" src="../../images/plugin_ep_sd_appendv2.png" alt="Sequence diagram showing session creation with explicit ep devices"/></p>
375+
<p align="center"><img width="100%" src="../../../images/plugin_ep_sd_appendv2.png" alt="Sequence diagram showing session creation with explicit ep devices"/></p>
378376

379377
### Session creation with automatic EP selection
380378
The application code below uses the API function [SessionOptionsSetEpSelectionPolicy](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a2ae116df2c6293e4094a6742a6c46f7e) to have ONNX Runtime automatically select an EP based on the user's policy (e.g., PREFER_NPU).
@@ -397,7 +395,7 @@ env.UnregisterExecutionProviderLibrary(/*...*/);
397395
```
398396

399397
<br/>
400-
<p align="center"><img width="100%" src="../../images/plugin_ep_sd_autoep.png" alt="Sequence diagram showing session creation with automatic EP selection"/></p>
398+
<p align="center"><img width="100%" src="../../../images/plugin_ep_sd_autoep.png" alt="Sequence diagram showing session creation with automatic EP selection"/></p>
401399

402400
## API reference
403401
API header files:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Plugin Execution Provider Libraries
3+
parent: Execution Providers
4+
has_children: true
5+
nav_order: 17
6+
---
7+
8+
# Plugin Execution Provider Libraries
9+
An ONNX Runtime Execution Provider (EP) executes model operations on one or more hardware accelerators (e.g., GPU, NPU, etc.). ONNX Runtime provides a variety of built-in EPs, such as the default CPU EP. To enable further extensibility, ONNX Runtime supports user-defined plugin EP libraries that an application can register with ONNX Runtime for use in an ONNX Runtime inference session.
10+
11+
This section provides a reference for plugin EP libraries.
Lines changed: 23 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
---
2-
title: Plugin Execution Provider Packaging Guidance
3-
description: Packaging guidance for plugin EP packages
4-
parent: Execution Providers
5-
nav_order: 18
6-
redirect_from: /docs/reference/execution-providers/Plugin-EP-Packaging
2+
title: Packaging Guidance
3+
description: Packaging Guidance
4+
grand_parent: Execution Providers
5+
parent: Plugin Execution Provider Libraries
6+
nav_order: 3
77
---
88

9-
# ONNX Runtime Plugin Execution Provider Packaging Guidance
9+
# Plugin Execution Provider Library Packaging Guidance
1010
{: .no_toc }
1111

12+
This page provides guidance for ONNX Runtime plugin EP implementers to consider with regards to packaging for a plugin EP.
13+
1214
## Contents
1315
{: .no_toc }
1416

1517
* TOC placeholder
1618
{:toc}
1719

18-
## Overview
19-
20-
This document aims to provide guidance for ONNX Runtime (ORT) plugin Execution Provider (EP) implementers to consider with regards to packaging for a plugin EP.
21-
2220
## General Guidance
2321

2422
### Usage
25-
2623
Note: Generally, when referring to the ORT API, we will refer to the C API functions. Equivalents should exist for other language bindings that support plugin EP usage.
2724

2825
#### Manual EP Library Registration
29-
3026
Users are expected to call [`OrtApi::RegisterExecutionProviderLibrary()`](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a7c8ea74a2ee54d03052f3d7cd1e1335d) to register the plugin EP library. Then, they may either choose to use the auto EP selection mechanism or manually call [`OrtApi::SessionOptionsAppendExecutionProvider_V2()`](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a285a5da8c9a63eff55dc48e4cf3b56f6) to explicitly use the plugin EP.
3127

3228
### Structure
3329

3430
#### Contents
35-
3631
A plugin EP package should contain the plugin EP shared library file and any other files that need to be distributed with it.
3732

3833
A plugin EP package should NOT contain the ORT shared library or other core ORT libraries (e.g., onnxruntime.dll or libonnxruntime.so). Users should obtain the ORT library separately, most likely via installing the separate ONNX Runtime package.
@@ -42,18 +37,16 @@ A plugin EP package should have no need to depend on the separate ONNX Runtime p
4237
#### Additional Information to Provide
4338

4439
##### Library Path
45-
4640
There should be a way to get the package's plugin EP library path. The user will need the plugin EP library path to call `OrtApi::RegisterExecutionProviderLibrary()`.
4741

4842
For example, the package may provide a helper function that returns the path to the plugin EP library. The recommended name for this helper function is "get library path".
4943

5044
##### EP name(s)
5145
There should be a way to get the plugin EP name(s) provided by the package. The user may require the plugin EP name(s) to select the appropriate `OrtEpDevice` instances to provide to `OrtApi::SessionOptionsAppendExecutionProvider_V2()`.
5246

53-
For example, the plugin EP name(s) may be well-documented or made available with a helper function provided by the package. The recommended name for this helper function is "get EP name", or "get EP names" if there are multiple names.
47+
For example, the plugin EP name(s) may be well-documented or made available with a helper function provided by the package. The recommended name for a helper function returning all EP names is "get EP names". Additionally, if there is only one EP name, a helper function returning the single value named "get EP name" may be provided for convenience.
5448

5549
#### Package Naming
56-
5750
The name of the package should indicate that the package contains a plugin EP and be distinguishable from other ORT packages.
5851

5952
For example, this may be done by using a special prefix or suffix.
@@ -63,79 +56,38 @@ For example, this may be done by using a special prefix or suffix.
6356
### PyPI
6457

6558
#### Package Naming
66-
6759
The prefix "onnxruntime-ep" can be used to identify a plugin EP.
6860

6961
The suggested package naming convention is "onnxruntime-ep-\<EP identifier\>".
7062

7163
For example, "onnxruntime-ep-contoso-ai".
7264

7365
#### Helper Functions
66+
The package should provide helper function `get_library_path()` to get the EP library path.
7467

75-
As mentioned in the general guidance section, the package should provide helper function `get_library_path()` to get the EP library path. The package may provide helper function `get_ep_name()` or `get_ep_names()` to get the EP name(s).
76-
77-
#### Usage example
78-
79-
```python
80-
import onnxruntime as ort
81-
import onnxruntime_ep_contoso_ai as contoso_ep
82-
83-
# Path to the plugin EP library
84-
ep_lib_path = contoso_ep.get_library_path()
85-
# Registration name can be anything the application chooses
86-
ep_registration_name = "contoso_ep_registration"
87-
88-
# Register plugin EP library with ONNX Runtime
89-
ort.register_execution_provider_library(ep_registration_name, ep_lib_path)
68+
The package should provide helper function `get_ep_names()` to get the EP name(s).
9069

91-
# Create ORT session with explicit OrtEpDevice(s)
70+
The package may provide helper function `get_ep_name()` to get the single EP name if there is just one.
9271

93-
# Get EP name(s) from the plugin EP library
94-
ep_names = contoso_ep.get_ep_names()
95-
# For this example we'll use the first one
96-
ep_name = ep_names[0]
72+
#### Example
73+
Refer to the [example Python package setup](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/plugin_execution_providers/basic/python) and its [example usage](https://github.com/microsoft/onnxruntime-inference-examples/blob/main/plugin_execution_providers/basic/python/example_usage/example_usage.py).
9774

98-
# Select an OrtEpDevice
99-
# For this example, we'll use any OrtEpDevices matching our EP name
100-
all_ep_devices = ort.get_ep_devices()
101-
selected_ep_devices = [ep_device for ep_device in all_ep_devices if ep_device.ep_name == ep_name]
102-
103-
assert len(selected_ep_devices) > 0
104-
105-
sess_options = ort.SessionOptions()
106-
107-
# EP-specific options
108-
ep_options = {}
109-
110-
# Equivalent to the C API's SessionOptionsAppendExecutionProvider_V2 that appends the plugin EP to the session options
111-
sess_options.add_provider_for_devices(selected_ep_devices, ep_options)
112-
113-
assert sess_options.has_providers() == True
114-
115-
# Create ORT session with the plugin EP
116-
model_path = "/path/to/model.onnx"
117-
sess = ort.InferenceSession(model_path, sess_options=sess_options)
118-
119-
# Use `sess`
120-
# ...
121-
122-
del sess
123-
124-
# Unregister the library using the same registration name specified earlier
125-
# Must only unregister a library after all sessions that use the library have been released
126-
ort.unregister_execution_provider_library(ep_registration_name)
127-
```
12875

12976
### NuGet
13077

13178
#### Package Naming
132-
13379
NuGet packages may use a reserved ID prefix.
13480

135-
The suggested package naming convention is "\<Vendor prefix\>.ML.OnnxRuntime.\<EP identifier\>.EP".
81+
The suggested package naming convention is "\<Vendor prefix\>.ML.OnnxRuntime.EP.\<EP identifier\>".
13682

137-
For example, "Contoso.ML.OnnxRuntime.ContosoAI.EP".
83+
For example, "Contoso.ML.OnnxRuntime.EP.ContosoAI".
13884

13985
#### Helper Functions
86+
The package should provide helper function `GetLibraryPath()` to get the EP library path.
87+
88+
The package should provide helper function `GetEpNames()` to get the EP name(s).
89+
90+
The package may provide helper function `GetEpName()` to get the single EP name if there is just one.
14091

141-
As mentioned in the general guidance section, the package should provide helper function `GetLibraryPath()` to get the EP library path. The package may provide helper function `GetEpName()` or `GetEpNames()` to get the EP name(s).
92+
#### Example
93+
Refer to the [example NuGet package setup](https://github.com/microsoft/onnxruntime-inference-examples/tree/main/plugin_execution_providers/basic/csharp) and its [example usage](https://github.com/microsoft/onnxruntime-inference-examples/blob/main/plugin_execution_providers/basic/csharp/SampleApp/Program.cs).
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: Testing Guidance
3+
description: Testing Guidance
4+
grand_parent: Execution Providers
5+
parent: Plugin Execution Provider Libraries
6+
nav_order: 2
7+
---
8+
9+
# Plugin Execution Provider Library Testing Guidance
10+
{: .no_toc }
11+
12+
A plugin EP is responsible for ensuring that its implementation behaves correctly. This includes interacting with ONNX Runtime in the expected way as documented by the plugin EP API. It also includes the operator-level behavior as specified by the operator specification, e.g., from the ONNX standard.
13+
14+
## Contents
15+
{: .no_toc }
16+
17+
* TOC placeholder
18+
{:toc}
19+
20+
## EP unit testing
21+
Plugin EP implementations are expected to have their own unit tests.
22+
23+
### Operator-level testing utility provided by ONNX Runtime
24+
ONNX Runtime has existing unit tests that validate an EP's op implementation. These tests are located in the unit test program `onnxruntime_provider_test`. This program supports usage with a dynamically specified plugin EP.
25+
26+
In particular, unit tests utilizing the `onnxruntime::test::OpTester` or `onnxruntime::test::ModelTester` classes can also be run with a plugin EP.
27+
28+
Plugin EP implementers may use this test program to help test their plugin EP if desired. The rest of this section explains how to do this.
29+
30+
#### Building
31+
Build the onnxruntime shared library and the `onnxruntime_provider_test` target from source.
32+
```
33+
cd <onnxruntime repo>
34+
# Note: On Windows, use build.bat instead of build.sh
35+
./build.sh --build_shared_lib --update --build --parallel --target onnxruntime_provider_test
36+
```
37+
38+
The onnxruntime shared library and `onnxruntime_provider_test` will be available in the binary output directory.
39+
40+
#### Running
41+
`onnxruntime_provider_test` supports the standard GoogleTest arguments. E.g., `--gtest_filter` can be used to run particular tests of interest.
42+
43+
Importantly, it supports configuration of a dynamically specified plugin EP through the environment variable `ORT_UNIT_TEST_MAIN_DYNAMIC_PLUGIN_EP_CONFIG_JSON`. The configuration value should be specified as a JSON string.
44+
45+
Here is an example value for `ORT_UNIT_TEST_MAIN_DYNAMIC_PLUGIN_EP_CONFIG_JSON`:
46+
```json
47+
{
48+
"ep_library_registration_name": "example_plugin_ep",
49+
"ep_library_path": "/path/to/libexample_plugin_ep.so",
50+
"selected_ep_name": "example_plugin_ep",
51+
"default_ep_options": { "ep_option_key": "ep_option_value" }
52+
}
53+
```
54+
55+
`ep_library_registration_name` and `ep_library_path` are the same as the `registration_name` and `path` parameters passed in to [`OrtApi::RegisterExecutionProviderLibrary()`](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a7c8ea74a2ee54d03052f3d7cd1e1335d), respectively.
56+
57+
`selected_ep_name` should be set to the plugin EP's name. All available `OrtEpDevice`s (returned by [`OrtApi::GetEpDevices()`](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a52107386ff1be870f55a0140e6add8dd)) matching that EP name will be used.
58+
59+
As an alternative to `selected_ep_name`, `selected_ep_device_indices` may be set to a list of integers representing the indices into the available `OrtEpDevice`s list. This requires knowing what `OrtEpDevice`s are available.
60+
The available `OrtEpDevices` can be obtained with [`OrtApi::GetEpDevices()`](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a52107386ff1be870f55a0140e6add8dd).
61+
The `onnxruntime_perf_test` tool also provides the [`--list_ep_devices`](https://github.com/microsoft/onnxruntime/blob/f83d4d06e4283d53a10c54ce84da3455cfb4e21d/onnxruntime/test/perftest/command_args_parser.cc#L195) option, which may be used in conjunction with the [`--plugin_ep_libs`](https://github.com/microsoft/onnxruntime/blob/f83d4d06e4283d53a10c54ce84da3455cfb4e21d/onnxruntime/test/perftest/command_args_parser.cc#L186-L188) option to display them.
62+
63+
Optionally, `default_ep_options` may be set to specify EP-specific options as string key value pairs.
64+
65+
## EP integration testing and model testing
66+
There are a number of APIs that a plugin EP will implement to interact with ONNX Runtime. Although conformance tests at the EP API level were considered, they were not deemed to be that useful yet. Currently, it is expected that the integration with ONNX Runtime can be meaningfully tested using high level tests that run an entire model.
67+
68+
Plugin EPs may vary significantly from one to another in terms of capability, whether it is optional feature support or operator support. Therefore, it is expected that plugin EPs will have a set of models that are most relevant to them and that these models can be used for testing.

0 commit comments

Comments
 (0)