You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 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.
Copy file name to clipboardExpand all lines: docs/execution-providers/EP-Context-Design.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -479,7 +479,7 @@ return the `external_info` argument from the `output_model_onnx_initializer_hand
479
479
-[C API functions](https://github.com/microsoft/onnxruntime/blob/879ec0392ad5128968440a4e5b5a0bb742494ae5/include/onnxruntime/core/session/onnxruntime_c_api.h#L7751-L7774)
480
480
481
481
### 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.
483
483
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
484
484
to create virtual hardware devices that an application can use to compile models.
-[Reference example plugin EP with virtual GPU](https://github.com/microsoft/onnxruntime/tree/main/onnxruntime/test/autoep/library/example_plugin_ep_virt_gpu)
646
646
-[OrtEpApi::GetEnvConfigEntries C API function](https://github.com/microsoft/onnxruntime/blob/990ba5f0c3e0c8735fec8bf89dd11953224a9c03/include/onnxruntime/core/session/onnxruntime_ep_c_api.h#L1431-L1446)
647
647
-[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/)
649
649
-[Additional Python usage examples in unit tests](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/test/python/onnxruntime_test_python_compile_api.py)
-[Plugin EP library documentation](./plugin-ep-libraries.md)
697
+
-[Plugin EP library documentation](./plugin-ep-libraries/)
698
698
-[Additional Python usage examples in unit tests](https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/test/python/onnxruntime_test_python_compile_api.py)
# Plugin Execution Provider Library Development and Usage
10
11
{: .no_toc }
11
12
13
+
This page provides a reference for the APIs necessary to develop and use plugin EP libraries with ONNX Runtime.
14
+
12
15
## Contents
13
16
{: .no_toc }
14
17
15
18
* TOC placeholder
16
19
{:toc}
17
20
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
-
23
21
## Creating a plugin EP library
24
22
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.
25
23
@@ -45,7 +43,7 @@ The following table lists the **required** variables and functions that an imple
45
43
46
44
<tr>
47
45
<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>
@@ -330,7 +328,7 @@ For example, if a single factory instance supports both CPU and NPU, then the ca
330
328
- ep_device_1: (factory_0, NPU)
331
329
332
330
<br/>
333
-
<palign="center"><imgwidth="100%"src="../../images/plugin_ep_sd_lib_reg.png"alt="Sequence diagram showing registration and unregistration of a plugin EP library"/></p>
331
+
<palign="center"><imgwidth="100%"src="../../../images/plugin_ep_sd_lib_reg.png"alt="Sequence diagram showing registration and unregistration of a plugin EP library"/></p>
334
332
335
333
### Session creation with explicit OrtEpDevice(s)
336
334
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.
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.
375
373
376
374
<br/>
377
-
<palign="center"><imgwidth="100%"src="../../images/plugin_ep_sd_appendv2.png"alt="Sequence diagram showing session creation with explicit ep devices"/></p>
375
+
<palign="center"><imgwidth="100%"src="../../../images/plugin_ep_sd_appendv2.png"alt="Sequence diagram showing session creation with explicit ep devices"/></p>
378
376
379
377
### Session creation with automatic EP selection
380
378
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).
<palign="center"><imgwidth="100%"src="../../images/plugin_ep_sd_autoep.png"alt="Sequence diagram showing session creation with automatic EP selection"/></p>
398
+
<palign="center"><imgwidth="100%"src="../../../images/plugin_ep_sd_autoep.png"alt="Sequence diagram showing session creation with automatic EP selection"/></p>
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.
This page provides guidance for ONNX Runtime plugin EP implementers to consider with regards to packaging for a plugin EP.
13
+
12
14
## Contents
13
15
{: .no_toc }
14
16
15
17
* TOC placeholder
16
18
{:toc}
17
19
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
-
22
20
## General Guidance
23
21
24
22
### Usage
25
-
26
23
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.
27
24
28
25
#### Manual EP Library Registration
29
-
30
26
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.
31
27
32
28
### Structure
33
29
34
30
#### Contents
35
-
36
31
A plugin EP package should contain the plugin EP shared library file and any other files that need to be distributed with it.
37
32
38
33
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
42
37
#### Additional Information to Provide
43
38
44
39
##### Library Path
45
-
46
40
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()`.
47
41
48
42
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".
49
43
50
44
##### EP name(s)
51
45
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()`.
52
46
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.
54
48
55
49
#### Package Naming
56
-
57
50
The name of the package should indicate that the package contains a plugin EP and be distinguishable from other ORT packages.
58
51
59
52
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.
63
56
### PyPI
64
57
65
58
#### Package Naming
66
-
67
59
The prefix "onnxruntime-ep" can be used to identify a plugin EP.
68
60
69
61
The suggested package naming convention is "onnxruntime-ep-\<EP identifier\>".
70
62
71
63
For example, "onnxruntime-ep-contoso-ai".
72
64
73
65
#### Helper Functions
66
+
The package should provide helper function `get_library_path()` to get the EP library path.
74
67
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
The package should provide helper function `get_ep_names()` to get the EP name(s).
90
69
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.
92
71
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).
97
74
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
-
assertlen(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
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\>".
136
82
137
-
For example, "Contoso.ML.OnnxRuntime.ContosoAI.EP".
83
+
For example, "Contoso.ML.OnnxRuntime.EP.ContosoAI".
138
84
139
85
#### 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.
140
91
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).
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
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`:
`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