-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[DRAFT] Allow EP to provide additional HW devices #26234
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
base: main
Are you sure you want to change the base?
Changes from all commits
283bd5b
bc4df99
fb7441c
5dafb50
d23bd3a
f86a4e9
f711df7
02ced24
7d30fa7
f9514a3
b553858
24316d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,6 +465,33 @@ struct OrtEpApi { | |
*/ | ||
ORT_API_T(uint64_t, GetSyncIdForLastWaitOnSyncStream, | ||
_In_ const OrtSyncStream* producer_stream, _In_ const OrtSyncStream* consumer_stream); | ||
|
||
/** \brief Create an OrtHardwareDevice. | ||
* | ||
* \note Called within OrtEpFactory::GetAdditionalHardwareDevices to augment the list of devices discovered by ORT. | ||
* | ||
* \param[in] type The hardware device type. | ||
* \param[in] vendor_id The hardware device's vendor identifier. | ||
* \param[in] device_id The hardware device's identifier. | ||
* \param[in] vendor_name The hardware device's vendor name as a null-terminated string. Copied by ORT. | ||
* \param[in] metadata Optional OrtKeyValuePairs instance for hardware device metadata that may be queried by | ||
* applications via OrtApi::GetEpDevices() or the EP factory that receives this hardware device | ||
* instance as input to OrtEpFactory::GetSupportedDevices(). | ||
* Refer to onnxruntime_ep_device_ep_metadata_keys.h for common OrtHardwareDevice metadata keys. | ||
* \param[out] hardware_device Output parameter set to the new OrtHardwareDevice instance that is created. | ||
* | ||
* \snippet{doc} snippets.dox OrtStatus Return Value | ||
* | ||
* \since Version 1.24. | ||
*/ | ||
ORT_API2_STATUS(CreateHardwareDevice, _In_ OrtHardwareDeviceType type, | ||
_In_ uint32_t vendor_id, | ||
_In_ uint32_t device_id, | ||
_In_ const char* vendor_name, | ||
_In_opt_ const OrtKeyValuePairs* metadata, | ||
_Out_ OrtHardwareDevice** hardware_device); | ||
|
||
ORT_CLASS_RELEASE(HardwareDevice); | ||
}; | ||
|
||
/** | ||
|
@@ -981,6 +1008,39 @@ struct OrtEpFactory { | |
_In_ const OrtMemoryDevice* memory_device, | ||
_In_opt_ const OrtKeyValuePairs* stream_options, | ||
_Outptr_ OrtSyncStreamImpl** stream); | ||
|
||
/** \brief Get additional hardware devices from the execution provider to augment the devices discovered by ORT. | ||
* | ||
* \note Any returned devices that have already been found by ORT are ignored. | ||
* | ||
* \note New additional devices created by this EP factory are not provided to other EP factories. Only this | ||
* EP factory receives the new additional hardware devices via OrtEpFactory::GetSupportedDevices(). | ||
* Any OrtEpDevice instances that this EP factory creates with an additional hardware device are visible to | ||
* applications that call OrtApi::GetEpDevices(). | ||
Comment on lines
+1016
to
+1019
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this complexity? Alternatively, if we're only going to show the OrtEpDevice to the EP that created it, can the EP create it inside of GetSupportedDevices? e.g. inside GetSupportedDevices
EP could register the OrtHardwareDevice with ORT so we can release it when the EP is unregistered, or EP could own it if we provided a ReleaseHardwareDevice function. Only place the OrtHardwareDevice shows up is indirectly in the OrtEpDevice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that helps with complexity, but it lacks a signal for the EP to know it should create a virtual device.
Or do we expect it creates all possible virtual devices by default? |
||
* | ||
* \param[in] this_ptr The OrtEpFactory instance. | ||
* \param[in] found_devices Array of hardware devices that have already been found by ORT during device discovery. | ||
* \param[in] num_found_devices Number of hardware devices that have already been found by ORT. | ||
* \param[out] additional_devices Additional OrtHardwareDevice instances that the EP can use. | ||
* The implementation should call OrtEpApi::CreateHardwareDevice to create the devices, | ||
* and then add the new OrtHardwareDevice instances to this pre-allocated array. | ||
* ORT will take ownership of the values returned. i.e. usage is: | ||
* `additional_devices[0] = <OrtHardwareDevice created via CreateHardwareDevice>;` | ||
* \param[in] max_additional_devices The maximum number of OrtHardwareDevice instances that can be added to | ||
* `additional_devices`. Current default is 8. This can be increased if needed. | ||
* \param[out] num_additional_devices The number of additional hardware devices actually added | ||
* to `additional_devices`. | ||
* | ||
* \snippet{doc} snippets.dox OrtStatus Return Value | ||
* | ||
* \since Version 1.24. | ||
*/ | ||
ORT_API2_STATUS(GetAdditionalHardwareDevices, _In_ OrtEpFactory* this_ptr, | ||
_In_reads_(num_found_devices) const OrtHardwareDevice* const* found_devices, | ||
_In_ size_t num_found_devices, | ||
_Inout_ OrtHardwareDevice** additional_devices, | ||
_In_ size_t max_additional_devices, | ||
_Out_ size_t* num_additional_devices); | ||
}; | ||
|
||
#ifdef __cplusplus | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
#include "core/common/cpuid_info.h" | ||
#include "core/common/logging/logging.h" | ||
#include "core/session/onnxruntime_ep_device_ep_metadata_keys.h" | ||
|
||
namespace onnxruntime { | ||
|
||
|
@@ -48,6 +49,8 @@ OrtHardwareDevice DeviceDiscovery::GetCpuDeviceFromCPUIDInfo() { | |
cpu_device.vendor_id = cpuid_info.GetCPUVendorId(); | ||
cpu_device.device_id = 0; | ||
cpu_device.type = OrtHardwareDeviceType_CPU; | ||
cpu_device.metadata.Add(kOrtHardwareDevice_MetadataKey_DiscoveredBy, "ONNX Runtime"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this as well as IsVirtual? Wary of having too much stuff in metadata, and possibly the IsVirtual implies it was not discovered by ORT unless there's some other feature that will rely on an explicit 'discovered by' value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My thought is that:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we only show the virtual device to the EP that created it, is there value in DiscoveredBy? |
||
cpu_device.metadata.Add(kOrtHardwareDevice_MetadataKey_IsVirtual, "0"); | ||
|
||
return cpu_device; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: does ORT take ownership and EP does not need to release metadata KVP instance if provided?