Skip to content

Commit b7bc71b

Browse files
authored
[Plugin EP docs] Split development and usage docs into separate pages, document some 1.24 API additions (#27196)
### Description <!-- Describe your changes. --> Split development-and-usage.md into development.md and usage.md. Add some initial documentation for plugin EP APIs introduced in 1.24. Preview: https://edgchen1.github.io/onnxruntime/docs/execution-providers/plugin-ep-libraries/ ### 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. --> More reorganizing. Start documenting 1.24 additions.
1 parent fd2e6cd commit b7bc71b

File tree

5 files changed

+290
-194
lines changed

5 files changed

+290
-194
lines changed

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

Lines changed: 90 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
2-
title: Development and Usage
3-
description: Development and Usage
2+
title: Development
3+
description: Development
44
grand_parent: Execution Providers
55
parent: Plugin Execution Provider Libraries
6-
nav_order: 1
7-
redirect_from: /docs/reference/execution-providers/Plugin-EP-Libraries
6+
nav_order: 2
87
---
98

10-
# Plugin Execution Provider Library Development and Usage
9+
# Developing a Plugin Execution Provider Library
1110
{: .no_toc }
1211

13-
This page provides a reference for the APIs necessary to develop and use plugin EP libraries with ONNX Runtime.
12+
This page provides a reference for how to develop plugin EP libraries with ONNX Runtime.
1413

1514
## Contents
1615
{: .no_toc }
@@ -19,13 +18,15 @@ This page provides a reference for the APIs necessary to develop and use plugin
1918
{:toc}
2019

2120
## Creating a plugin EP library
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.
21+
A plugin EP is built as a dynamic/shared library that exports the C 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.
2322

24-
The ONNX Runtime repository includes a [sample plugin EP library](https://github.com/microsoft/onnxruntime/tree/main/onnxruntime/test/autoep/library), which is referenced in the following sections.
23+
The ONNX Runtime repository includes a few [sample plugin EP libraries](https://github.com/microsoft/onnxruntime/tree/main/onnxruntime/test/autoep/library), which are referenced in the following sections.
2524

2625
### Defining an OrtEp
2726
An `OrtEp` represents an instance of an EP that is used by an ONNX Runtime session to identify and execute the model operations supported by the EP.
2827

28+
The [`OrtEp`](https://onnxruntime.ai/docs/api/c/struct_ort_ep.html) API struct is defined in [`onnxruntime_ep_c_api.h`](https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_ep_c_api.h).
29+
2930
The following table lists the **required** variables and functions that an implementer must define for an `OrtEp`.
3031

3132
<table>
@@ -53,6 +54,18 @@ The following table lists the **required** variables and functions that an imple
5354
<td><a href="https://github.com/microsoft/onnxruntime/blob/16ae99ede405d3d6c59d7cce80c53f5f7055aeed/onnxruntime/test/autoep/library/ep.cc#L231">ExampleEp::GetCapabilityImpl()</a></td>
5455
</tr>
5556

57+
</table>
58+
59+
The following table lists the **required** functions that an implementer must define for an `OrtEp` that compiles nodes.
60+
In ORT 1.23, these were required functions because only compiling EPs were supported.
61+
62+
<table>
63+
<tr>
64+
<th>Field</th>
65+
<th>Summary</th>
66+
<th>Example implementation</th>
67+
</tr>
68+
5669
<tr>
5770
<td>Compile</td>
5871
<td>
@@ -72,7 +85,29 @@ Release <code>OrtNodeComputeInfo</code> instances.
7285

7386
</table>
7487

75-
The following table lists the **optional** functions that an implementor may define for an `OrtEp`. If an optional `OrtEp` function is not defined, ONNX Runtime uses a default implementation.
88+
The following table lists the **required** functions that an implementer must define for an `OrtEp` that provides operator kernels with a kernel registry.
89+
90+
<table>
91+
<tr>
92+
<th>Field</th>
93+
<th>Summary</th>
94+
<th>Example implementation</th>
95+
</tr>
96+
97+
<tr>
98+
<td>GetKernelRegistry</td>
99+
<td>
100+
101+
Gets the execution provider's kernel registry, if any.<br/><br/>
102+
A kernel registry contains kernel creation information for operator kernels supported by an EP.
103+
104+
</td>
105+
<td><a href="https://github.com/microsoft/onnxruntime/blob/592bcb4a84f1463752a335705bae1565a0abc2b5/onnxruntime/test/autoep/library/example_plugin_ep_kernel_registry/ep.cc#L110">ExampleKernelEp::GetKernelRegistryImpl()</a></td>
106+
</tr>
107+
108+
</table>
109+
110+
The following table lists the **optional** functions that an implementer may define for an `OrtEp`. If an optional `OrtEp` function is not defined, ONNX Runtime uses a default implementation.
76111

77112
<table>
78113
<tr>
@@ -153,11 +188,22 @@ The compatibility information string can be used with <code>OrtEpFactory::Valida
153188
<td></td>
154189
</tr>
155190

191+
<tr>
192+
<td>IsConcurrentRunSupported</td>
193+
<td>
194+
Gets whether the execution provider supports concurrent run calls made on the session.<br/><br/>
195+
If not implemented, ORT assumes that concurrent runs are supported.
196+
</td>
197+
<td></td>
198+
</tr>
199+
156200
</table>
157201

158202
### Defining an OrtEpFactory
159203
An `OrtEpFactory` represents an instance of an EP factory that is used by an ONNX Runtime session to query device support, create allocators, create data transfer objects, and create instances of an EP (i.e., an `OrtEp`).
160204

205+
The [`OrtEpFactory`](https://onnxruntime.ai/docs/api/c/struct_ort_ep_factory.html) API struct is defined in [`onnxruntime_ep_c_api.h`](https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_ep_c_api.h).
206+
161207
The following table lists the **required** variables and functions that an implementer must define for an `OrtEpFactory`.
162208

163209
<table>
@@ -261,6 +307,41 @@ This is use to create a synchronization stream for the <code>OrtMemoryDevice</co
261307
<td><a href="https://github.com/microsoft/onnxruntime/blob/3cadbdb495761a6a54845b178f9bdb811a2c8bde/onnxruntime/test/autoep/library/ep_factory.cc#L300">ExampleEpFactory::CreateSyncStreamForDeviceImpl()</a></td>
262308
</tr>
263309

310+
<tr>
311+
<td>GetHardwareDeviceIncompatibilityDetails</td>
312+
<td>
313+
Check for known incompatibility reasons between a hardware device and this execution provider.<br/><br/>
314+
This function allows an execution provider to check if a specific hardware device is compatible with the execution provider. The EP can set specific incompatibility reasons via the <code>OrtDeviceEpIncompatibilityDetails</code> parameter using <code><a href="https://onnxruntime.ai/docs/api/c/struct_ort_ep_api.html#a6f089e88e76dc58c9bf1e7f5102fb6d7">OrtEpApi::DeviceEpIncompatibilityDetails_SetDetails</a></code>.
315+
</td>
316+
<td><a href="https://github.com/microsoft/onnxruntime/blob/0b9e85feea12aca69d5ba3ddaf46e0bd2f058647/onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc#L377">ExampleEpFactory::GetHardwareDeviceIncompatibilityDetailsImpl()</a></td>
317+
</tr>
318+
319+
<tr>
320+
<td>CreateExternalResourceImporterForDevice</td>
321+
<td>
322+
Create an <code>OrtExternalResourceImporterImpl</code> for external resource import.<br/><br/>
323+
This is used to create an external resource importer that enables zero-copy import of external GPU memory (e.g., D3D12 shared resources) and synchronization primitives (e.g., D3D12 timeline fences).<br/><br/>
324+
EPs that support external resource import (via CUDA, HIP, Vulkan, or D3D12 APIs) can implement this to allow applications to share GPU resources without copies.
325+
</td>
326+
<td><a href="https://github.com/microsoft/onnxruntime/blob/0b9e85feea12aca69d5ba3ddaf46e0bd2f058647/onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc#L400">ExampleEpFactory::CreateExternalResourceImporterForDeviceImpl()</a></td>
327+
</tr>
328+
329+
<tr>
330+
<td>GetNumCustomOpDomains</td>
331+
<td>
332+
Gets the number of EP-specific <code>OrtCustomOpDomain</code>s provided by the factory.
333+
</td>
334+
<td><a href="https://github.com/microsoft/onnxruntime/blob/0b9e85feea12aca69d5ba3ddaf46e0bd2f058647/onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc#L335">ExampleEpFactory::GetNumCustomOpDomainsImpl()</a></td>
335+
</tr>
336+
337+
<tr>
338+
<td>GetCustomOpDomains</td>
339+
<td>
340+
Gets the EP-specific <code>OrtCustomOpDomain</code>s provided by the factory.
341+
</td>
342+
<td><a href="https://github.com/microsoft/onnxruntime/blob/0b9e85feea12aca69d5ba3ddaf46e0bd2f058647/onnxruntime/test/autoep/library/example_plugin_ep/ep_factory.cc#L344">ExampleEpFactory::GetCustomOpDomainsImpl()</a></td>
343+
</tr>
344+
264345
</table>
265346

266347

@@ -289,114 +370,6 @@ The following table lists the functions that have to be exported from the plugin
289370

290371
</table>
291372

292-
293-
## Using a plugin EP library
294-
### Plugin EP library registration
295-
The sample application code below uses the following API functions to register and unregister a plugin EP library.
296-
- [RegisterExecutionProviderLibrary](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a7c8ea74a2ee54d03052f3d7cd1e1335d)
297-
- [UnregisterExecutionProviderLibrary](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#acd4d148e149af2f2304a45b65891543f)
298-
299-
```cpp
300-
const char* lib_registration_name = "ep_lib_name";
301-
Ort::Env env;
302-
303-
// Register plugin EP library with ONNX Runtime.
304-
env.RegisterExecutionProviderLibrary(
305-
lib_registration_name, // Registration name can be anything the application chooses.
306-
ORT_TSTR("ep_path.dll") // Path to the plugin EP library.
307-
);
308-
309-
{
310-
Ort::Session session(env, /*...*/);
311-
// Run a model ...
312-
}
313-
314-
// Unregister the library using the application-specified registration name.
315-
// Must only unregister a library after all sessions that use the library have been released.
316-
env.UnregisterExecutionProviderLibrary(lib_registration_name);
317-
```
318-
319-
As shown in the following sequence diagram, registering a plugin EP library causes ONNX Runtime to load the library and
320-
call the library's `CreateEpFactories()` function. During the call to `CreateEpFactories()`, ONNX Runtime determines the subset
321-
of hardware devices supported by each factory by calling `OrtEpFactory::GetSupportedDevices()` with all hardware devices that
322-
ONNX Runtime discovered during initialization.
323-
324-
The factory returns `OrtEpDevice` instances from `OrtEpFactory::GetSupportedDevices()`.
325-
Each `OrtEpDevice` instance pairs a factory with a hardware device that the factory supports.
326-
For example, if a single factory instance supports both CPU and NPU, then the call to `OrtEpFactory::GetSupportedDevices()` returns two `OrtEpDevice` instances:
327-
- ep_device_0: (factory_0, CPU)
328-
- ep_device_1: (factory_0, NPU)
329-
330-
<br/>
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>
332-
333-
### Session creation with explicit OrtEpDevice(s)
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.
335-
336-
The application first calls [GetEpDevices](https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a52107386ff1be870f55a0140e6add8dd) to get a list of `OrtEpDevices`
337-
available to the application. Each `OrtEpDevice` represents a hardware device supported by an `OrtEpFactory`.
338-
The `SessionOptionsAppendExecutionProvider_V2` function takes an array of `OrtEpDevice` instances as input, where all `OrtEpDevice` instances refer to the same `OrtEpFactory`.
339-
340-
```cpp
341-
Ort::Env env;
342-
env.RegisterExecutionProviderLibrary(/*...*/);
343-
344-
{
345-
std::vector<Ort::ConstEpDevice> ep_devices = env.GetEpDevices();
346-
347-
// Find the Ort::EpDevice for "my_ep".
348-
std::array<Ort::ConstEpDevice, 1> selected_ep_devices = { nullptr };
349-
for (Ort::ConstEpDevice ep_device : ep_devices) {
350-
if (std::strcmp(ep_device.GetName(), "my_ep") == 0) {
351-
selected_ep_devices[0] = ep_device;
352-
break;
353-
}
354-
}
355-
356-
if (selected_ep_devices[0] == nullptr) {
357-
// Did not find EP. Report application error ...
358-
}
359-
360-
Ort::KeyValuePairs ep_options(/*...*/); // Optional EP options.
361-
Ort::SessionOptions session_options;
362-
session_options.AppendExecutionProvider_V2(env, selected_ep_devices, ep_options);
363-
364-
Ort::Session session(env, ORT_TSTR("model.onnx"), session_options);
365-
366-
// Run model ...
367-
}
368-
369-
env.UnregisterExecutionProviderLibrary(/*...*/);
370-
```
371-
372-
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.
373-
374-
<br/>
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>
376-
377-
### Session creation with automatic EP selection
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).
379-
If the plugin EP library registered with ONNX Runtime has a factory that supports NPU, then ONNX Runtime may select an EP from that factory to run the model.
380-
381-
```cpp
382-
Ort::Env env;
383-
env.RegisterExecutionProviderLibrary(/*...*/);
384-
385-
{
386-
Ort::SessionOptions session_options;
387-
session_options.SetEpSelectionPolicy(OrtExecutionProviderDevicePolicy::PREFER_NPU);
388-
389-
Ort::Session session(env, ORT_TSTR("model.onnx"), session_options);
390-
391-
// Run model ...
392-
}
393-
394-
env.UnregisterExecutionProviderLibrary(/*...*/);
395-
```
396-
397-
<br/>
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>
399-
400373
## API reference
401374
API header files:
402375
- [onnxruntime_ep_c_api.h](https://github.com/microsoft/onnxruntime/blob/main/include/onnxruntime/core/session/onnxruntime_ep_c_api.h)
@@ -647,78 +620,3 @@ Opaque type that represents an ONNX operator attribute.
647620
</tr>
648621

649622
</table>
650-
651-
652-
### Plugin EP Library Registration APIs
653-
The following table lists the API functions used for registration of a plugin EP library.
654-
655-
<table>
656-
<tr>
657-
<th>
658-
Function
659-
</th>
660-
<th>
661-
Description
662-
</th>
663-
</tr>
664-
665-
<tr>
666-
<td>
667-
<a href="https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a7c8ea74a2ee54d03052f3d7cd1e1335d">RegisterExecutionProviderLibrary</a>
668-
</td>
669-
<td>
670-
Register an EP library with ORT. The library must export the <code>CreateEpFactories</code> and <code>ReleaseEpFactory</code> functions.
671-
</td>
672-
</tr>
673-
674-
<tr>
675-
<td>
676-
<a href="https://onnxruntime.ai/docs/api/c/struct_ort_api.html#acd4d148e149af2f2304a45b65891543f">UnregisterExecutionProviderLibrary</a>
677-
</td>
678-
<td>
679-
Unregister an EP library with ORT. Caller <b>MUST</b> ensure there are no <code>OrtSession</code> instances using the EPs created by the library before calling this function.
680-
</td>
681-
</tr>
682-
683-
<tr>
684-
<td>
685-
<a href="https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a52107386ff1be870f55a0140e6add8dd">GetEpDevices</a>
686-
</td>
687-
<td>
688-
Get the list of available OrtEpDevice instances.<br/><br/>
689-
Each <code>OrtEpDevice</code> instance contains details of the execution provider and the device it will use.
690-
</td>
691-
</tr>
692-
693-
<tr>
694-
<td>
695-
<a href="https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a285a5da8c9a63eff55dc48e4cf3b56f6">SessionOptionsAppendExecutionProvider_V2</a>
696-
</td>
697-
<td>
698-
Append the execution provider that is responsible for the provided <code>OrtEpDevice</code> instances to the session options.
699-
</td>
700-
</tr>
701-
702-
<tr>
703-
<td>
704-
<a href="https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a2ae116df2c6293e4094a6742a6c46f7e">SessionOptionsSetEpSelectionPolicy</a>
705-
</td>
706-
<td>
707-
Set the execution provider selection policy for the session.<br/><br/>
708-
Allows users to specify a device selection policy for automatic EP selection. If custom selection is required please use
709-
<code>SessionOptionsSetEpSelectionPolicyDelegate</code> instead.
710-
</td>
711-
</tr>
712-
713-
<tr>
714-
<td>
715-
<a href="https://onnxruntime.ai/docs/api/c/struct_ort_api.html#a29c026bc7aa6672f93b7f9e31fd3e4a7">SessionOptionsSetEpSelectionPolicyDelegate</a>
716-
</td>
717-
<td>
718-
Set the execution provider selection policy delegate for the session.<br/><br/>
719-
Allows users to provide a custom device selection policy for automatic EP selection.
720-
</td>
721-
</tr>
722-
723-
</table>
724-

docs/execution-providers/plugin-ep-libraries/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ title: Plugin Execution Provider Libraries
33
parent: Execution Providers
44
has_children: true
55
nav_order: 17
6+
redirect_from: /docs/reference/execution-providers/Plugin-EP-Libraries
67
---
78

89
# Plugin Execution Provider Libraries

docs/execution-providers/plugin-ep-libraries/packaging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Packaging Guidance
33
description: Packaging Guidance
44
grand_parent: Execution Providers
55
parent: Plugin Execution Provider Libraries
6-
nav_order: 3
6+
nav_order: 4
77
---
88

99
# Plugin Execution Provider Library Packaging Guidance

docs/execution-providers/plugin-ep-libraries/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Testing Guidance
33
description: Testing Guidance
44
grand_parent: Execution Providers
55
parent: Plugin Execution Provider Libraries
6-
nav_order: 2
6+
nav_order: 3
77
---
88

99
# Plugin Execution Provider Library Testing Guidance

0 commit comments

Comments
 (0)