![]() |
ONNX Runtime
|
The OrtEpFactory provides functions to create and manage execution providers. More...
#include <onnxruntime_ep_c_api.h>
Public Member Functions | |
| OrtStatus * | GetSupportedDevices (OrtEpFactory *this_ptr, const OrtHardwareDevice *const *devices, size_t num_devices, OrtEpDevice **ep_devices, size_t max_ep_devices, size_t *num_ep_devices) |
| Get information from the execution provider about OrtHardwareDevice support. | |
| OrtStatus * | CreateEp (OrtEpFactory *this_ptr, const OrtHardwareDevice *const *devices, const OrtKeyValuePairs *const *ep_metadata_pairs, size_t num_devices, const OrtSessionOptions *session_options, const OrtLogger *logger, OrtEp **ep) |
| Function to create an OrtEp instance for use in a Session. | |
| OrtStatus * | ValidateCompiledModelCompatibilityInfo (OrtEpFactory *this_ptr, const OrtHardwareDevice *const *devices, size_t num_devices, const char *compatibility_info, OrtCompiledModelCompatibility *model_compatibility) |
| Validate a compiled model against an ordered execution provider device configuration. | |
| OrtStatus * | CreateAllocator (OrtEpFactory *this_ptr, const OrtMemoryInfo *memory_info, const OrtKeyValuePairs *allocator_options, OrtAllocator **allocator) |
| Create an OrtAllocator that can be shared across sessions for the given OrtMemoryInfo. | |
| OrtStatus * | CreateDataTransfer (OrtEpFactory *this_ptr, OrtDataTransferImpl **data_transfer) |
| Create an OrtDataTransferImpl instance for the factory. | |
| OrtStatus * | CreateSyncStreamForDevice (OrtEpFactory *this_ptr, const OrtMemoryDevice *memory_device, const OrtKeyValuePairs *stream_options, OrtSyncStreamImpl **stream) |
| Create a synchronization stream for the given memory device. | |
| OrtStatus * | GetHardwareDeviceIncompatibilityDetails (OrtEpFactory *this_ptr, const OrtHardwareDevice *hw, OrtDeviceEpIncompatibilityDetails *details) |
| Check for known incompatibility reasons between a hardware device and this execution provider. | |
| OrtStatus * | CreateExternalResourceImporterForDevice (OrtEpFactory *this_ptr, const OrtEpDevice *ep_device, OrtExternalResourceImporterImpl **out_importer) |
| Create an OrtExternalResourceImporterImpl for external resource import. | |
| OrtStatus * | GetNumCustomOpDomains (OrtEpFactory *this_ptr, size_t *num_domains) |
| Returns the number of OrtCustomOpDomains that this factory provides. | |
| OrtStatus * | GetCustomOpDomains (OrtEpFactory *this_ptr, OrtCustomOpDomain **domains, size_t num_domains) |
| Gets the EP-specific OrtCustomOpDomains. | |
| OrtStatus * | InitGraphicsInterop (OrtEpFactory *this_ptr, const OrtEpDevice *ep_device, const OrtGraphicsInteropConfig *config) |
| Initialize graphics interop for the EP factory. | |
| OrtStatus * | DeinitGraphicsInterop (OrtEpFactory *this_ptr, const OrtEpDevice *ep_device) |
| Deinitialize graphics interop for the EP factory. | |
| OrtStatus * | SelectBestModelCandidate (OrtEpFactory *this_ptr, const OrtHardwareDevice *device, const OrtKeyValuePairs *const *candidates, size_t num_candidates, const OrtSessionOptions *session_options, size_t *selected_index) |
| Select the best model variant candidate from metadata. | |
Public Attributes | |
| uint32_t | ort_version_supported |
| The ONNX Runtime version the execution provider was compiled with. | |
| const char *(* | GetName )(const OrtEpFactory *this_ptr) |
| Get the name of the execution provider that the factory creates. | |
| const char *(* | GetVendor )(const OrtEpFactory *this_ptr) |
| Get the name of vendor who owns the execution provider that the factory creates. | |
| void(* | ReleaseEp )(OrtEpFactory *this_ptr, struct OrtEp *ep) |
| Release the OrtEp instance. | |
| uint32_t(* | GetVendorId )(const OrtEpFactory *this_ptr) |
| Get the vendor id who owns the execution provider that the factory creates. | |
| const char *(* | GetVersion )(const OrtEpFactory *this_ptr) |
| Get the version of the execution provider that the factory creates. | |
| void(* | ReleaseAllocator )(OrtEpFactory *this_ptr, OrtAllocator *allocator) |
| Release an OrtAllocator created by the factory. | |
| bool(* | IsStreamAware )(const OrtEpFactory *this_ptr) |
| Check if execution providers created by the factory are stream aware. | |
The OrtEpFactory provides functions to create and manage execution providers.
| OrtStatus * OrtEpFactory::CreateAllocator | ( | OrtEpFactory * | this_ptr, |
| const OrtMemoryInfo * | memory_info, | ||
| const OrtKeyValuePairs * | allocator_options, | ||
| OrtAllocator ** | allocator | ||
| ) |
Create an OrtAllocator that can be shared across sessions for the given OrtMemoryInfo.
The factory that creates the EP is responsible for providing the allocators required by the EP. The OrtMemoryInfo instance will match one of the values set in the OrtEpDevice using EpDevice_AddAllocatorInfo.
Implementation of this function is optional. It is required if ORT needs to create a shared allocator for an OrtMemoryInfo advertised by the EP.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | memory_info | The OrtMemoryInfo to create the allocator for. May be nullptr. |
| [in] | allocator_options | Optional key-value pairs for allocator options, can be nullptr. |
| [out] | allocator | The created OrtAllocator instance. When called to create an allocator for a session, this may be set to nullptr if the EP does not provide a preferred allocator for the memory location. When called to create a shared allocator, this must be set to a non-null value. |
| OrtStatus * OrtEpFactory::CreateDataTransfer | ( | OrtEpFactory * | this_ptr, |
| OrtDataTransferImpl ** | data_transfer | ||
| ) |
Create an OrtDataTransferImpl instance for the factory.
This is used to create an IDataTransfer implementation that can be used to copy data between devices that the execution provider supports.
| [in] | this_ptr | The OrtEpFactory instance. |
| [out] | data_transfer | The created OrtDataTransferImpl instance. Set to nullptr if not required. |
| OrtStatus * OrtEpFactory::CreateEp | ( | OrtEpFactory * | this_ptr, |
| const OrtHardwareDevice *const * | devices, | ||
| const OrtKeyValuePairs *const * | ep_metadata_pairs, | ||
| size_t | num_devices, | ||
| const OrtSessionOptions * | session_options, | ||
| const OrtLogger * | logger, | ||
| OrtEp ** | ep | ||
| ) |
Function to create an OrtEp instance for use in a Session.
ORT will call ReleaseEp to release the instance when it is no longer needed.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | devices | The OrtHardwareDevice instances that the execution provider was selected to use. May be a subset of the OrtHardwareDevice instances that the execution provider's factory set as supported in the call to OrtEpFactory::GetSupportedDevices. |
| [in] | ep_metadata_pairs | Execution provider metadata that was provided to OrtEpApi::CreateEpDevice, for each device. |
| [in] | num_devices | The number of devices the execution provider was selected for. |
| [in] | session_options | The OrtSessionOptions instance that contains the configuration options for the session. This will include ep_options from GetSupportedDevices as well as any user provided overrides. Execution provider options will have been added with a prefix of 'ep.[ep name].'. The OrtSessionOptions instance will NOT be valid after this call and should not be stored for later use. |
| [in] | logger | The OrtLogger instance for the session that the execution provider should use for logging. |
| [out] | ep | The OrtEp instance created by the factory. |
| OrtStatus * OrtEpFactory::CreateExternalResourceImporterForDevice | ( | OrtEpFactory * | this_ptr, |
| const OrtEpDevice * | ep_device, | ||
| OrtExternalResourceImporterImpl ** | out_importer | ||
| ) |
Create an OrtExternalResourceImporterImpl for external resource import.
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).
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.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | ep_device | The OrtEpDevice to create the external resource importer for. |
| [out] | out_importer | The created OrtExternalResourceImporterImpl instance. Set to nullptr if external resource import is not supported. |
| OrtStatus * OrtEpFactory::CreateSyncStreamForDevice | ( | OrtEpFactory * | this_ptr, |
| const OrtMemoryDevice * | memory_device, | ||
| const OrtKeyValuePairs * | stream_options, | ||
| OrtSyncStreamImpl ** | stream | ||
| ) |
Create a synchronization stream for the given memory device.
This is used to create a synchronization stream for the memory device that can be used for operations outside of a session.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | memory_device | The OrtMemoryDevice to create the synchronization stream for. |
| [in] | stream_options | Options for stream creation. May be nullptr. |
| [out] | stream | The created OrtSyncStreamImpl instance. nullptr if the execution provider is not stream aware. |
| OrtStatus * OrtEpFactory::DeinitGraphicsInterop | ( | OrtEpFactory * | this_ptr, |
| const OrtEpDevice * | ep_device | ||
| ) |
Deinitialize graphics interop for the EP factory.
This function cleans up any graphics interop context that was set up by InitGraphicsInterop. Should be called when graphics interop is no longer needed.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | ep_device | The OrtEpDevice to deinitialize graphics interop for. |
| OrtStatus * OrtEpFactory::GetCustomOpDomains | ( | OrtEpFactory * | this_ptr, |
| OrtCustomOpDomain ** | domains, | ||
| size_t | num_domains | ||
| ) |
Gets the EP-specific OrtCustomOpDomains.
This function is used when running inference on a model that contains EP-specific custom operations.
Workflow:
As a result, any session created from these session options will have these custom op domains registered in ORT, ensuring that the custom ops are properly recognized and validated when the model is loaded.
Plugin EPs can provide two types of custom ops:
Note: The OrtCustomOpDomain instances must be valid while any session is using them. EP factory has the responsibility to release OrtCustomOpDomain instances it creates. It happens automatically if using the C++ Ort::CustomOpDomain class.
| [in] | this_ptr | The OrtEpFactory instance. |
| [out] | domains | Array of num_domains elements pre-allocated by ORT that should be filled with OrtCustomOpDomain instances created by the EP. The num_domains is the value returned by GetNumCustomOpDomains(). |
| [in] | num_domains | The size of the domains array pre-allocated by ORT. |
| OrtStatus * OrtEpFactory::GetHardwareDeviceIncompatibilityDetails | ( | OrtEpFactory * | this_ptr, |
| const OrtHardwareDevice * | hw, | ||
| OrtDeviceEpIncompatibilityDetails * | details | ||
| ) |
Check for known incompatibility reasons between a hardware device and this execution provider.
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 OrtDeviceEpIncompatibilityDetails parameter using OrtEpApi::DeviceEpIncompatibilityDetails_SetDetails.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | hw | The hardware device to check for incompatibility. |
| [in,out] | details | Pre-allocated incompatibility details object created and initialized by ORT. The EP can use OrtEpApi::DeviceEpIncompatibilityDetails_SetDetails to set incompatibility information. If the device is compatible, the EP can leave the object unchanged (it defaults to no incompatibility). |
| OrtStatus * OrtEpFactory::GetNumCustomOpDomains | ( | OrtEpFactory * | this_ptr, |
| size_t * | num_domains | ||
| ) |
Returns the number of OrtCustomOpDomains that this factory provides.
| [in] | this_ptr | The OrtEpFactory instance. |
| [out] | num_domains | Output parameter set to the number of provided OrtCustomOpDomain instances. |
| OrtStatus * OrtEpFactory::GetSupportedDevices | ( | OrtEpFactory * | this_ptr, |
| const OrtHardwareDevice *const * | devices, | ||
| size_t | num_devices, | ||
| OrtEpDevice ** | ep_devices, | ||
| size_t | max_ep_devices, | ||
| size_t * | num_ep_devices | ||
| ) |
Get information from the execution provider about OrtHardwareDevice support.
| [in] | this_ptr | The OrtEpFactory instance. Non-const as the factory is passed through to the CreateEp call via the OrtEpDevice. |
| [in] | devices | The OrtHardwareDevice instances that are available. |
| [in] | num_devices | The number of OrtHardwareDevice instances. |
| [out] | ep_devices | OrtEpDevice instances for each OrtHardwareDevice that the EP can use. The implementation should call OrtEpApi::CreateEpDevice to create, and add the OrtEpDevice instances to this pre-allocated array. ORT will take ownership of the values returned. i.e. usage is ep_devices[0] = <ptr to OrtEpDevice created with OrtEpApi::CreateEpDevice>; |
| [in] | max_ep_devices | The maximum number of OrtEpDevices that can be added to ep_devices. Current default is 8. This can be increased if needed. |
| [out] | num_ep_devices | The number of EP devices added to ep_devices. |
Environment configuration entries are populated before any library is registered, so OrtEpApi::GetEnvConfigEntries may be called from this function, but it must be called synchronously on the thread invoking GetSupportedDevices. The implementation must not wait for another thread that calls OrtEpApi::GetEnvConfigEntries.
| OrtStatus * OrtEpFactory::InitGraphicsInterop | ( | OrtEpFactory * | this_ptr, |
| const OrtEpDevice * | ep_device, | ||
| const OrtGraphicsInteropConfig * | config | ||
| ) |
Initialize graphics interop for the EP factory.
This function sets up graphics interop context that enables synchronization between external graphics API workloads (D3D12, Vulkan) and ONNX Runtime inference.
The factory stores the graphics context configuration and uses it when creating synchronization streams via CreateSyncStreamForDevice. This approach is more graceful than passing the command queue directly during stream creation.
The implementation is EP-specific. EPs may create a specialized interop context using platform-specific APIs to enable GPU-GPU synchronization.
Key design points:
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | ep_device | The OrtEpDevice to initialize graphics interop for. |
| [in] | config | Configuration specifying the graphics API and required handles. |
| OrtStatus * OrtEpFactory::SelectBestModelCandidate | ( | OrtEpFactory * | this_ptr, |
| const OrtHardwareDevice * | device, | ||
| const OrtKeyValuePairs *const * | candidates, | ||
| size_t | num_candidates, | ||
| const OrtSessionOptions * | session_options, | ||
| size_t * | selected_index | ||
| ) |
Select the best model variant candidate from metadata.
Evaluates each candidate's metadata against the given hardware device and optional session options, and returns the index of the best match.
Each candidate is an OrtKeyValuePairs representing one model variant. The KVP uses indexed keys so that the EP can inspect each model's metadata independently. A variant always has num_models >= 1.
Required and optional keys:
where <i> is a zero-based index (e.g., "0.ep_compatibility_info", "1.ep_compatibility_info").
The implementer should loop from 0 to num_models - 1 and validate each "\<i\>.ep_compatibility_info" entry. An advanced implementation may additionally consider "role" or other metadata when ranking candidates.
Why this function exists:
The existing ValidateCompiledModelCompatibilityInfo() alone is not sufficient for some EPs to determine the best compatible model when there are multiple candidates. For example, an EP may support multiple compilation modes (e.g., "speed optimized" vs "memory optimized") that produce different compatibility strings. The EP can implement this function to evaluate the candidate metadata and select the best compatible variant based on its own criteria, the target device, and the session options.
If all candidates are unsupported, this function succeeds and sets selected_index to SIZE_MAX.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | device | The target hardware device that the EP would run on. Must map to this EP. |
| [in] | candidates | Array of OrtKeyValuePairs pointers (one per model variant). |
| [in] | num_candidates | Number of candidates (i.e., number of model variants to evaluate). |
| [in] | session_options | Optional session options to consider when selecting the best candidate. May be nullptr if no session-level preferences are relevant. |
| [out] | selected_index | Selected candidate index, or SIZE_MAX if all unsupported. |
| OrtStatus * OrtEpFactory::ValidateCompiledModelCompatibilityInfo | ( | OrtEpFactory * | this_ptr, |
| const OrtHardwareDevice *const * | devices, | ||
| size_t | num_devices, | ||
| const char * | compatibility_info, | ||
| OrtCompiledModelCompatibility * | model_compatibility | ||
| ) |
Validate a compiled model against an ordered execution provider device configuration.
Given a compatibility info string produced during model compilation, the EP factory determines whether the compiled model can run when the EP is created with the provided hardware devices. The string is opaque to ORT and the caller; the caller is not expected to know which devices were used to compile the model.
devices is the non-empty, ordered device configuration that the caller intends to use. The caller should pass the corresponding OrtEpDevice values, in the same order, to OrtApi::SessionOptionsAppendExecutionProvider_V2 if it subsequently creates a session for the compiled model. Device order may be significant.
The implementation must interpret the configuration using the same device selection, fallback, and participation rules as OrtEpFactory::CreateEp:
Do not unconditionally validate each device independently and return the worst result. The meaning of a multi-device configuration is EP-defined. For example, an artifact compiled for one device can be optimal for an ordered configuration in which that device is selected and later entries are ignored. Conversely, an artifact partitioned across two devices is unsupported if either required device is absent.
A supported result must mean that creating the EP and loading the compiled model with the equivalent device configuration will not fail due to compiled-model incompatibility. OrtCompiledModelCompatibility_EP_NOT_APPLICABLE is an overall "no compatibility determination" result; it is not a required identity value for combining per-device results.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | devices | Ordered array of OrtHardwareDevice pointers for the intended EP configuration. |
| [in] | num_devices | Number of entries in devices. Must be greater than zero. |
| [in] | compatibility_info | The compatibility information string produced when the model was compiled. |
| [out] | model_compatibility | Compatibility of the model with the intended EP device configuration. |
| const char *( * OrtEpFactory::GetName) (const OrtEpFactory *this_ptr) |
Get the name of the execution provider that the factory creates.
The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
| [in] | this_ptr | The OrtEpFactory instance. |
| const char *( * OrtEpFactory::GetVendor) (const OrtEpFactory *this_ptr) |
Get the name of vendor who owns the execution provider that the factory creates.
The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
| [in] | this_ptr | The OrtEpFactory instance. |
| uint32_t( * OrtEpFactory::GetVendorId) (const OrtEpFactory *this_ptr) |
Get the vendor id who owns the execution provider that the factory creates.
This is typically the PCI vendor ID. See https://pcisig.com/membership/member-companies
| [in] | this_ptr | The OrtEpFactory instance. |
| const char *( * OrtEpFactory::GetVersion) (const OrtEpFactory *this_ptr) |
Get the version of the execution provider that the factory creates.
The version string should adhere to the Semantic Versioning 2.0 specification (https://github.com/semver/semver/blob/v2.0.0/semver.md).
The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
| [in] | this_ptr | The OrtEpFactory instance. |
| bool( * OrtEpFactory::IsStreamAware) (const OrtEpFactory *this_ptr) |
Check if execution providers created by the factory are stream aware.
| [in] | this_ptr | The OrtEpFactory instance. |
| uint32_t OrtEpFactory::ort_version_supported |
The ONNX Runtime version the execution provider was compiled with.
Implementation should set to ORT_API_VERSION. ORT will use this to ensure it does not call functions that were not available when the library was compiled.
| void( * OrtEpFactory::ReleaseAllocator) (OrtEpFactory *this_ptr, OrtAllocator *allocator) |
Release an OrtAllocator created by the factory.
Implementation of this function is required if OrtEpFactory::CreateAllocator or OrtEp::CreateAllocator is implemented.
| void( * OrtEpFactory::ReleaseEp) (OrtEpFactory *this_ptr, struct OrtEp *ep) |
Release the OrtEp instance.
| [in] | this_ptr | The OrtEpFactory instance. |
| [in] | ep | The OrtEp instance to release. |