onnxruntime_ep_c_api.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Licensed under the MIT License.
  3. // Do not include this file directly. Please include "onnxruntime_c_api.h" instead.
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. ORT_RUNTIME_CLASS(Ep);
  8. ORT_RUNTIME_CLASS(EpFactory);
  9. ORT_RUNTIME_CLASS(EpGraphSupportInfo);
  10. ORT_RUNTIME_CLASS(MemoryDevice); // opaque class to wrap onnxruntime::OrtDevice
  11. ORT_RUNTIME_CLASS(NodeComputeContext);
  12. ORT_RUNTIME_CLASS(DataTransferImpl);
  13. ORT_RUNTIME_CLASS(SyncNotificationImpl);
  14. ORT_RUNTIME_CLASS(SyncStreamImpl);
  15. // struct that an EP implements for IDataTransfer to copy between devices it uses and CPU
  16. struct OrtDataTransferImpl {
  17. uint32_t ort_version_supported; ///< Must be initialized to ORT_API_VERSION
  18. /** \brief Release the OrtDataTransferImpl instance.
  19. *
  20. * This is called by ORT when the OrtDataTransferImpl instance is no longer needed.
  21. * The implementation should release any resources held by the instance.
  22. *
  23. * \param[in] this_ptr Pointer to the OrtDataTransferImpl instance.
  24. *
  25. * \since Version 1.23.
  26. */
  27. ORT_API_T(void, Release, _In_ OrtDataTransferImpl* this_ptr);
  28. /** \brief Check if the implementation can copy between the source and destination memory devices.
  29. *
  30. * \param[in] this_ptr Pointer to the OrtDataTransferImpl instance.
  31. * \param[in] src_memory_device Source OrtMemoryDevice to copy from.
  32. * \param[in] dst_memory_device Destination OrtMemoryDevice to copy to.
  33. * \return True if the implementation can copy between the devices.
  34. *
  35. * \since Version 1.23.
  36. */
  37. ORT_API_T(bool, CanCopy, _In_ const OrtDataTransferImpl* this_ptr,
  38. _In_ const OrtMemoryDevice* src_memory_device, _In_ const OrtMemoryDevice* dst_memory_device);
  39. /** \brief Copy tensors from src_tensors to dst_tensors using the provided streams.
  40. *
  41. * The implementation can use the provided streams to perform asynchronous copies if supported.
  42. * If a stream is not available, the copy is performed synchronously.
  43. *
  44. * \param[in] this_ptr Pointer to the OrtDataTransferImpl instance.
  45. * \param[in] src_tensors Array of source OrtValue pointers to copy from.
  46. * \param[in] dst_tensors Array of destination OrtValue pointers to copy to.
  47. * \param[in] streams Array of OrtSyncStream pointers for the copy operations, if the execution provider is stream
  48. * aware. nullptr if it is not.
  49. * \param[in] num_tensors Number of tensors to copy.
  50. *
  51. * \snippet{doc} snippets.dox OrtStatus Return Value
  52. *
  53. * \since Version 1.23.
  54. */
  55. ORT_API2_STATUS(CopyTensors, _In_ OrtDataTransferImpl* this_ptr,
  56. _In_reads_(num_tensors) const OrtValue** src_tensors,
  57. _In_reads_(num_tensors) OrtValue** dst_tensors,
  58. _In_reads_(num_tensors) OrtSyncStream** streams,
  59. _In_ size_t num_tensors);
  60. };
  61. /** \brief Struct that an EP implements for Stream Notifications.
  62. *
  63. * \since Version 1.23.
  64. */
  65. struct OrtSyncNotificationImpl {
  66. uint32_t ort_version_supported; ///< Must be initialized to ORT_API_VERSION
  67. /** \brief Release the OrtSyncNotificationImpl instance.
  68. *
  69. * This is called by ORT when the OrtSyncNotificationImpl instance is no longer needed.
  70. * The implementation should release any resources held by the instance.
  71. *
  72. * \param[in] this_ptr Pointer to the OrtSyncNotificationImpl instance.
  73. *
  74. * \since Version 1.23.
  75. */
  76. ORT_API_T(void, Release, _In_ OrtSyncNotificationImpl* this_ptr);
  77. /** \brief Called by ORT to activate the notification.
  78. *
  79. * \param[in] this_ptr Pointer to the OrtSyncNotificationImpl instance.
  80. *
  81. * \since Version 1.23.
  82. */
  83. ORT_API2_STATUS(Activate, _In_ OrtSyncNotificationImpl* this_ptr);
  84. /** \brief Wait for a device to device operation to complete.
  85. *
  86. * \param[in] this_ptr Pointer to the OrtSyncNotificationImpl instance.
  87. * \param[in] stream The OrtSyncStream instance that will wait on this notification to be activated.
  88. *
  89. * \since Version 1.23.
  90. */
  91. ORT_API2_STATUS(WaitOnDevice, _In_ OrtSyncNotificationImpl* this_ptr, _In_ OrtSyncStream* consumer_stream);
  92. /** \brief Wait for a device to host operation to complete.
  93. *
  94. * \param[in] this_ptr Pointer to the OrtSyncNotificationImpl instance.
  95. *
  96. * \since Version 1.23.
  97. */
  98. ORT_API2_STATUS(WaitOnHost, _In_ OrtSyncNotificationImpl* this_ptr);
  99. };
  100. /** \brief Struct that an EP implements if it wishes to implement Stream support.
  101. *
  102. * This struct provides the overrides for onnxruntime::Stream's virtual methods.
  103. *
  104. * \since Version 1.23.
  105. */
  106. struct OrtSyncStreamImpl {
  107. uint32_t ort_version_supported; ///< Must be initialized to ORT_API_VERSION
  108. /** \brief Release the OrtSyncStreamImpl instance.
  109. *
  110. * This is called by ORT when the OrtSyncStreamImpl instance is no longer needed.
  111. * The implementation should release any resources held by the instance.
  112. *
  113. * \param[in] this_ptr Pointer to the OrtSyncStreamImpl instance.
  114. *
  115. * \since Version 1.23.
  116. */
  117. ORT_API_T(void, Release, _In_ OrtSyncStreamImpl* this_ptr);
  118. /** \brief Get the handle of the stream.
  119. *
  120. * This returns the native handle for the stream. e.g. cudaStream_t for CUDA streams.
  121. *
  122. * \param[in] this_ptr Pointer to the OrtSyncStreamImpl instance.
  123. * \return The handle of the stream.
  124. *
  125. * \since Version 1.23.
  126. */
  127. ORT_API_T(void*, GetHandle, _In_ OrtSyncStreamImpl* this_ptr);
  128. /** \brief Create an OrtSyncNotificationImpl for the OrtSyncStreamImpl instance.
  129. *
  130. * \param[in] this_ptr Pointer to the OrtSyncStreamImpl instance
  131. * \param[out] notification The new OrtSyncNotificationImpl instance.
  132. *
  133. * \since Version 1.23.
  134. */
  135. ORT_API2_STATUS(CreateNotification, _In_ OrtSyncStreamImpl* this_ptr,
  136. _Outptr_ OrtSyncNotificationImpl** notification);
  137. /** \brief Flush the stream.
  138. *
  139. * This is called by ORT to flush the stream, ensuring that all operations submitted to the stream are completed.
  140. *
  141. * \param[in] this_ptr Pointer to the OrtSyncStreamImpl instance.
  142. *
  143. * \since Version 1.23.
  144. */
  145. ORT_API2_STATUS(Flush, _In_ OrtSyncStreamImpl* this_ptr);
  146. /** \brief Notify the stream that a session run has ended.
  147. *
  148. * This is called by ORT to notify the stream that a session run has ended, allowing the stream to perform any
  149. * necessary cleanup or finalization.
  150. *
  151. * \param[in] this_ptr Pointer to the OrtSyncStreamImpl instance.
  152. *
  153. * \since Version 1.23.
  154. */
  155. ORT_API2_STATUS(OnSessionRunEnd, _In_ OrtSyncStreamImpl* this_ptr);
  156. };
  157. struct OrtNodeFusionOptions;
  158. typedef struct OrtNodeFusionOptions OrtNodeFusionOptions;
  159. struct OrtNodeComputeInfo;
  160. typedef struct OrtNodeComputeInfo OrtNodeComputeInfo;
  161. /**
  162. * \brief The OrtNodeFusionOptions struct specifies options for fusing nodes supported by an execution provider.
  163. *
  164. * Refer to OrtEpApi::EpGraphSupportInfo_AddNodesToFuse.
  165. *
  166. * \since Version 1.23.
  167. */
  168. struct OrtNodeFusionOptions {
  169. /** \brief The ONNX Runtime version the OrtNodeFusionOptions was compiled with.
  170. *
  171. * Implementation should set to ORT_API_VERSION.
  172. * ORT will use this to ensure it does not use members that were not available when the EP library was compiled.
  173. *
  174. * \since Version 1.23.
  175. */
  176. uint32_t ort_version_supported;
  177. /** \brief If set to true, specify that the execution provider does not require ONNX Runtime to provide constant
  178. * initializers as inputs to the fused node during model inference. This is used when the execution
  179. * provider saves a copy of constant initializers, and allows ONNX Runtime to release constant initializers that
  180. * are not used by any execution provider.
  181. *
  182. * If not specified, defaults to false. That is, ONNX Runtime provides constant initializers as inputs to
  183. * the fused node by default.
  184. *
  185. * \since Version 1.23.
  186. */
  187. bool drop_constant_initializers;
  188. // const OrtNode* fused_node_schema;
  189. };
  190. /**
  191. * \brief The OrtNodeComputeInfo struct provides functions that an OrtEp implements to specify the compute
  192. * function for a compiled OrtGraph instance.
  193. * \since Version 1.23.
  194. */
  195. struct OrtNodeComputeInfo {
  196. /** \brief The ONNX Runtime version the OrtNodeComputeInfo was compiled with.
  197. *
  198. * Implementation should set to ORT_API_VERSION.
  199. * ORT will use this to ensure it does not call functions that were not available when the EP library was compiled.
  200. *
  201. * \since Version 1.23.
  202. */
  203. uint32_t ort_version_supported;
  204. /** \brief Creates an opaque compute state object that is then passed to the Compute() function during inference.
  205. * \param[in] this_ptr The OrtNodeComputeInfo instance.
  206. * \param[in] compute_context OrtNodeComputeContext instance that contains compiled/fused node's name and host
  207. * memory allocation functions. Can optionally be used to build the compute state.
  208. * \param[out] compute_state Output parameter that is assigned the opaque computation state. ONNX Runtime calls
  209. * ReleaseState() (after calling Compute()) to allow the implementer to release the
  210. * compute state.
  211. *
  212. * \snippet{doc} snippets.dox OrtStatus Return Value
  213. *
  214. * \since Version 1.23.
  215. */
  216. OrtStatus*(ORT_API_CALL* CreateState)(_In_ OrtNodeComputeInfo* this_ptr,
  217. _In_ OrtNodeComputeContext* compute_context,
  218. _Outptr_ void** compute_state);
  219. /** \brief Computation function called to execute the fused node compiled by an OrtEp instance.
  220. * \param[in] this_ptr The OrtNodeComputeInfo instance.
  221. * \param[in] compute_state The opaque computation state returned by CreateState().
  222. * \param[in] kernel_context The OrtKernelContext instance used to access inputs/outputs.
  223. *
  224. * \snippet{doc} snippets.dox OrtStatus Return Value
  225. *
  226. * \since Version 1.23.
  227. */
  228. OrtStatus*(ORT_API_CALL* Compute)(_In_ OrtNodeComputeInfo* this_ptr, _In_ void* compute_state,
  229. _In_ OrtKernelContext* kernel_context);
  230. /** \brief Releases the compute state returned by CreateState().
  231. * \param[in] this_ptr The OrtNodeComputeInfo instance.
  232. * \param[inout] compute_state The opaque compute state returned by CreateState().
  233. *
  234. * \since Version 1.23.
  235. */
  236. void(ORT_API_CALL* ReleaseState)(_In_ OrtNodeComputeInfo* this_ptr, _Frees_ptr_opt_ void* compute_state);
  237. };
  238. struct OrtEpApi {
  239. /** \brief Create an OrtEpDevice for the EP and an OrtHardwareDevice.
  240. * \param[in] ep_factory Execution provider factory that is creating the instance.
  241. * \param[in] hardware_device Hardware device that the EP can utilize.
  242. * \param[in] ep_metadata Optional OrtKeyValuePairs instance for execution provider metadata that may be used
  243. * during execution provider selection and passed to CreateEp.
  244. * ep_device will copy this instance and the user should call ReleaseKeyValuePairs.
  245. * \param[in] ep_options Optional OrtKeyValuePairs instance for execution provider options that will be added
  246. * to the Session configuration options if the execution provider is selected.
  247. * ep_device will copy this instance and the user should call ReleaseKeyValuePairs.
  248. * \param ep_device OrtExecutionDevice that is created.
  249. *
  250. * \since Version 1.22.
  251. */
  252. ORT_API2_STATUS(CreateEpDevice, _In_ OrtEpFactory* ep_factory,
  253. _In_ const OrtHardwareDevice* hardware_device,
  254. _In_opt_ const OrtKeyValuePairs* ep_metadata,
  255. _In_opt_ const OrtKeyValuePairs* ep_options,
  256. _Out_ OrtEpDevice** ep_device);
  257. ORT_CLASS_RELEASE(EpDevice);
  258. /** \brief Specify nodes that are supported by an OrtEp and should be fused into one node.
  259. *
  260. * Because the nodes will be fused into one "fused node", there must not exist an unsupported node in
  261. * a path between two of the provided nodes. Otherwise, the graph will become invalid.
  262. *
  263. * This function can be called multiple times. A subsequent call to this function will force the next set of
  264. * nodes to be fused into a different node.
  265. *
  266. * \param[in] graph_support_info OrtEpGraphSupportInfo instance to which to add the supported nodes.
  267. * \param[in] nodes Array of nodes supported by the EP that should be fused/compiled.
  268. * \param[in] num_nodes The number of supported nodes.
  269. * \param[in] node_fusion_options Optional node fusion options. Ignored if set to NULL.
  270. *
  271. * \snippet{doc} snippets.dox OrtStatus Return Value
  272. *
  273. * \since Version 1.23.
  274. */
  275. ORT_API2_STATUS(EpGraphSupportInfo_AddNodesToFuse, _In_ OrtEpGraphSupportInfo* graph_support_info,
  276. _In_reads_(num_nodes) const OrtNode* const* nodes, _In_ size_t num_nodes,
  277. _In_opt_ const OrtNodeFusionOptions* node_fusion_options);
  278. /** \brief Specify a node that is supported by an OrtEp and should be run with a registered EP kernel.
  279. *
  280. * \param[in] graph_support_info OrtEpGraphSupportInfo instance to which to add the supported node.
  281. * \param[in] node The supported OrtNode instance.
  282. *
  283. * \snippet{doc} snippets.dox OrtStatus Return Value
  284. *
  285. * \since Version 1.23.
  286. */
  287. ORT_API2_STATUS(EpGraphSupportInfo_AddSingleNode, _In_ OrtEpGraphSupportInfo* graph_support_info,
  288. _In_ const OrtNode* node);
  289. /** \brief Query a OrtNodeComputeContext for the name of the node that encapsulates the compiled/fused node.
  290. *
  291. * Used in OrtNodeComputeInfo::CreateComputeState().
  292. *
  293. * \param[in] context The OrtNodeComputeContext instance to query.
  294. * \return The node's name.
  295. *
  296. * \note Returned string is owned by ORT and valid only while OrtNodeComputeInfo::CreateComputeState() is called.
  297. *
  298. * \since Version 1.23.
  299. */
  300. ORT_API_T(const char*, NodeComputeContext_NodeName, _In_ const OrtNodeComputeContext* context);
  301. /** \brief Register an allocator with the OrtEpDevice.
  302. *
  303. * This allows an EP to provide OrtMemoryInfo for DEFAULT and HOST_ACCESSIBLE memory type as needed.
  304. * The registered values will be used in calls to OrtEpFactory::CreateAllocator to ensure the required allocator/s
  305. * are available for EP usage.
  306. *
  307. * Multiple calls for the same entry type will replace a previous entry.
  308. *
  309. * Available entries:
  310. * - OrtDeviceAllocator with type of OrtDeviceMemoryType_DEFAULT
  311. * - OrtDeviceAllocator with type of OrtDeviceMemoryType_HOST_ACCESSIBLE
  312. * - OrtReadOnlyAllocator with type of OrtDeviceMemoryType_DEFAULT
  313. * - if provided this allocator will only be used to copy initializers to the device the EP uses.
  314. * ORT will use the OrtDeviceAllocator if not provided.
  315. *
  316. * \param[in] ep_device The OrtEpDevice instance to register the OrtMemoryInfo with.
  317. * \param[in] allocator_memory_info The OrtMemoryInfo information for the allocator.
  318. *
  319. * \snippet{doc} snippets.dox OrtStatus Return Value
  320. *
  321. * \since Version 1.23.
  322. */
  323. ORT_API2_STATUS(EpDevice_AddAllocatorInfo, _In_ OrtEpDevice* ep_device,
  324. _In_ const OrtMemoryInfo* allocator_memory_info);
  325. /** \brief Get the OrtMemoryDevice from an OrtMemoryInfo instance.
  326. *
  327. * This is required for OrtDataTransferImpl (which implements onnxruntime::IDataTransfer) where the OrtMemoryDevice
  328. * is used in the CanCopy and CopyTensors functions.
  329. *
  330. * \param[in] memory_info The OrtMemoryInfo instance to get the memory device from.
  331. * \return The OrtMemoryDevice associated with the OrtMemoryInfo instance.
  332. *
  333. * \since Version 1.23.
  334. */
  335. ORT_API_T(const OrtMemoryDevice*, MemoryInfo_GetMemoryDevice, _In_ const OrtMemoryInfo* memory_info);
  336. /** \brief Get the OrtMemoryDevice from an OrtValue instance if it contains a Tensor.
  337. *
  338. * \param[in] value The OrtValue instance to get the memory device from.
  339. * \return Memory device if OrtValue contains a Tensor, nullptr otherwise.
  340. *
  341. * \since Version 1.23.
  342. */
  343. ORT_API_T(const OrtMemoryDevice*, Value_GetMemoryDevice, _In_ const OrtValue* value);
  344. /** \brief Compare two OrtMemoryDevice instances for equality.
  345. *
  346. * This is used to check if two memory devices are the same.
  347. * Used to implement DataTransferImpl::CanCopy.
  348. *
  349. * \param[in] a The first OrtMemoryDevice instance to compare.
  350. * \param[in] b The second OrtMemoryDevice instance to compare.
  351. * \return True if the two OrtMemoryDevice instances are equal, false otherwise.
  352. *
  353. * \since Version 1.23.
  354. */
  355. ORT_API_T(bool, MemoryDevice_AreEqual, _In_ const OrtMemoryDevice* a, _In_ const OrtMemoryDevice* b);
  356. /** \brief Get the OrtMemoryInfoDeviceType value from an OrtMemoryDevice instance.
  357. *
  358. * \param[in] memory_device OrtMemoryDevice instance.
  359. * \return The OrtMemoryInfoDeviceType value.
  360. *
  361. * \since Version 1.23.
  362. */
  363. ORT_API_T(OrtMemoryInfoDeviceType, MemoryDevice_GetDeviceType, _In_ const OrtMemoryDevice* memory_device);
  364. /** \brief Get the OrtDeviceMemoryType value from an OrtMemoryDevice instance.
  365. *
  366. * \param[in] memory_device OrtMemoryDevice instance.
  367. * \return The OrtDeviceMemoryType value.
  368. *
  369. * \since Version 1.23.
  370. */
  371. ORT_API_T(OrtDeviceMemoryType, MemoryDevice_GetMemoryType, _In_ const OrtMemoryDevice* memory_device);
  372. /** \brief Get the vendor ID from an OrtMemoryDevice instance.
  373. *
  374. * The vendor ID is used to identify the vendor of the device, and is typically set to the PCI vendor ID.
  375. *
  376. * If the device is not vendor specific (e.g. CPU memory) the vendor ID is set to 0.
  377. *
  378. * \param[in] memory_device OrtMemoryDevice instance.
  379. * \return The vendor ID value.
  380. *
  381. * \since Version 1.23.
  382. */
  383. ORT_API_T(uint32_t, MemoryDevice_GetVendorId, _In_ const OrtMemoryDevice* memory_device);
  384. /** \brief Get the device ID from an OrtMemoryDevice instance.
  385. *
  386. * \param[in] memory_device OrtMemoryDevice instance.
  387. * \return The device ID.
  388. *
  389. * \since Version 1.23.
  390. */
  391. ORT_API_T(uint32_t, MemoryDevice_GetDeviceId, _In_ const OrtMemoryDevice* memory_device);
  392. /** \brief Get the OrtSyncStreamImpl associated with an OrtSyncStream instance.
  393. *
  394. * This allows an the plugin library to connect its OrtSyncStreamImpl instance with an OrtSyncStream if needed.
  395. *
  396. * \param[in] stream The OrtSyncStream instance to find an OrtSyncStreamImpl for.
  397. * \return The associated OrtSyncStreamImpl if found. nullptr otherwise.
  398. *
  399. * \since Version 1.23.
  400. *
  401. * \remarks There should always be an OrtSyncStreamImpl associated with an OrtSyncStream instance that the EP gets.
  402. */
  403. ORT_API_T(const OrtSyncStreamImpl*, SyncStream_GetImpl, _In_ const OrtSyncStream* stream);
  404. /** \brief Get the current sync ID for a stream.
  405. *
  406. * \param[in] stream The OrtSyncStream to get the sync ID for.
  407. * \return Current sync ID.
  408. *
  409. * \since Version 1.23.
  410. */
  411. ORT_API_T(uint64_t, SyncStream_GetSyncId, _In_ const OrtSyncStream* stream);
  412. /** \brief Get the sync ID for the last time the consumer_stream waited on the producer_stream.
  413. *
  414. * When two streams are synchronized, the sync id represents the event used in that synchronization.
  415. *
  416. * \param[in] producer_stream The OrtSyncStream that produced the data.
  417. * \param[in] consumer_stream The OrtSyncStream that waited on the producer_stream.
  418. * \return ID for last sync. 0 if no sync has occurred between the two streams.
  419. *
  420. * \since Version 1.23.
  421. */
  422. ORT_API_T(uint64_t, GetSyncIdForLastWaitOnSyncStream,
  423. _In_ const OrtSyncStream* producer_stream, _In_ const OrtSyncStream* consumer_stream);
  424. };
  425. /**
  426. * \brief The data layout type.
  427. *
  428. * EPs may specify a preferred data layout type. ORT's default layout type is OrtEpDataLayout_NCHW, or
  429. * OrtEpDataLayout_Default.
  430. *
  431. * \since Version 1.23.
  432. */
  433. typedef enum OrtEpDataLayout {
  434. OrtEpDataLayout_NCHW = 0,
  435. OrtEpDataLayout_NHWC,
  436. OrtEpDataLayout_Default = OrtEpDataLayout_NCHW,
  437. } OrtEpDataLayout;
  438. /**
  439. * \brief The OrtEp struct provides functions to implement for an execution provider.
  440. * \since Version 1.22.
  441. */
  442. struct OrtEp {
  443. /** \brief The ONNX Runtime version the execution provider was compiled with.
  444. *
  445. * Implementation should set to ORT_API_VERSION.
  446. * ORT will use this to ensure it does not call functions that were not available when the library was compiled.
  447. *
  448. * \since Version 1.22.
  449. */
  450. uint32_t ort_version_supported;
  451. /** \brief Get the execution provider name.
  452. *
  453. * The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
  454. *
  455. * \param[in] this_ptr The OrtEp instance.
  456. * \return The execution provider name.
  457. *
  458. * \since Version 1.22.
  459. */
  460. ORT_API_T(const char*, GetName, _In_ const OrtEp* this_ptr);
  461. /** \brief Get information about the nodes supported by the OrtEp instance.
  462. *
  463. * IMPORTANT: This is not the final version of this API function. This is currently experimental but will
  464. * be stabilized by the ONNX Runtime 1.23 release.
  465. *
  466. * \param[in] this_ptr The OrtEp instance.
  467. * \param[in] graph The OrtGraph instance for which to populate node support. The OrtGraph could be a nested subgraph
  468. * contained by a node (e.g., an If or Loop node). ONNX Runtime calls this function separately
  469. * for each nested subgraph.
  470. * \param[inout] graph_support_info OrtEpGraphSupportInfo instance that the implementer must fill out in order to
  471. * specify the supported nodes.
  472. *
  473. * \snippet{doc} snippets.dox OrtStatus Return Value
  474. *
  475. * \since Version 1.23.
  476. */
  477. ORT_API2_STATUS(GetCapability, _In_ OrtEp* this_ptr, _In_ const OrtGraph* graph,
  478. _Inout_ OrtEpGraphSupportInfo* graph_support_info);
  479. /** \brief Compile OrtGraph instances assigned to the OrtEp. Implementer must set a OrtNodeComputeInfo instance
  480. * for each OrtGraph in order to define its computation function.
  481. *
  482. * If the session is configured to generate a pre-compiled model, the execution provider must return EPContext nodes,
  483. * as OrtNode instances, that ONNX Runtime uses to create a pre-compiled model, known as an "EPContext model".
  484. * An EPContext model contains EPContext nodes. Each EPContext node encapsulates the pre-compiled binary data for a
  485. * OrtGraph compiled for a specific execution provider. For more details about the EPContext design, refer to:
  486. * \htmlonly
  487. * <a href="https://onnxruntime.ai/docs/execution-providers/EP-Context-Design.html">EPContext design document.</a>
  488. * \endhtmlonly
  489. *
  490. * \param[in] this_ptr The OrtEp instance.
  491. * \param[in] graphs Array of `count` OrtGraph instances to compile. Each graph contains only the nodes for
  492. * which the execution provider indicated support. Nested subgraphs contained by a
  493. * node, such as an If or Loop, have separate OrtGraph instances.
  494. * \param[in] fused_nodes Array of `count` fused nodes that will replace the compiled graphs.
  495. * Each fused node is an OrtNode initialized with the intended fused node name and
  496. * input/output information.
  497. * \param[in] count The number of OrtGraph instances to compile.
  498. * \param[out] node_compute_infos Array of `count` OrtNodeComputeInfo instances that define each OrtGraph instance's
  499. * computation function. The implementer allocates the OrtNodeComputeInfo instances.
  500. * ORT calls ReleaseNodeComputeInfos() to release multiple instances in a batch.
  501. * \param[out] ep_context_nodes Output array of `count` OrtNode instances, each representing an EPContext
  502. * node for a compiled OrtGraph. The execution provider must use
  503. * OrtModelEditorApi::CreateNode to create the OrtNode instances. ONNX Runtime takes
  504. * ownership of the OrtNode instances, so the execution provider must NOT call
  505. * OrtApi::ReleaseNode. Should be ignored if the session is not configured to generate an
  506. * EPContext model.
  507. *
  508. * \snippet{doc} snippets.dox OrtStatus Return Value
  509. *
  510. * \note Do NOT cache the provided OrtGraph instances in any of the OrtNodeComputeInfo functions because the
  511. * graphs are only valid for the duration of the call to Compile. Any graph/node/input/output
  512. * names that are needed by the OrtNodeComputeInfo functions must be copied and stored by the OrtEp.
  513. *
  514. * \since Version 1.23.
  515. */
  516. ORT_API2_STATUS(Compile, _In_ OrtEp* this_ptr, _In_ const OrtGraph** graphs,
  517. _In_ const OrtNode** fused_nodes, _In_ size_t count,
  518. _Out_writes_all_(count) OrtNodeComputeInfo** node_compute_infos,
  519. _Out_writes_(count) OrtNode** ep_context_nodes);
  520. /** \brief Release OrtNodeComputeInfo instances.
  521. *
  522. * \param[in] this_ptr The OrtEp instance.
  523. * \param[inout] node_compute_infos The OrtNodeComputeInfo instances to release.
  524. * \param[in] num_node_compute_infos The number of OrtNodeComputeInfo instances.
  525. *
  526. * \since Version 1.23.
  527. */
  528. ORT_API_T(void, ReleaseNodeComputeInfos, _In_ OrtEp* this_ptr,
  529. OrtNodeComputeInfo** node_compute_infos,
  530. _In_ size_t num_node_compute_infos);
  531. /** \brief Get the EP's preferred data layout.
  532. *
  533. * \note Implementation of this function is optional.
  534. * If not implemented, ORT will assume that this EP prefers the data layout `OrtEpDataLayout::NCHW`.
  535. *
  536. * \param[in] this_ptr The OrtEp instance.
  537. * \param[out] preferred_data_layout The EP's preferred data layout.
  538. *
  539. * \snippet{doc} snippets.dox OrtStatus Return Value
  540. *
  541. * \since Version 1.23.
  542. */
  543. ORT_API2_STATUS(GetPreferredDataLayout, _In_ OrtEp* this_ptr, _Out_ OrtEpDataLayout* preferred_data_layout);
  544. /** \brief Given an op with domain `domain` and type `op_type`, determine whether an associated node's data layout
  545. * should be converted to `target_data_layout`.
  546. * If the EP prefers a non-default data layout (see `GetPreferredDataLayout()`), this function will be called
  547. * during layout transformation with `target_data_layout` set to the EP's preferred data layout.
  548. *
  549. * \note Implementation of this function is optional.
  550. * If an EP prefers a non-default data layout, it may implement this to customize the specific op data layout
  551. * preferences at a finer granularity.
  552. *
  553. * \param[in] this_ptr The OrtEp instance.
  554. * \param[in] domain The op domain. An empty string means the ONNX domain.
  555. * \param[in] op_type The op type.
  556. * \param[in] target_data_layout The target data layout.
  557. * \param[out] should_convert Whether the associated node's data layout should be converted to `target_data_layout`.
  558. * If greater than 0, convert.
  559. * If 0, don't convert.
  560. * Otherwise, if less than 0, leave the decision to ORT.
  561. *
  562. * \snippet{doc} snippets.dox OrtStatus Return Value
  563. *
  564. * \since Version 1.23.
  565. */
  566. ORT_API2_STATUS(ShouldConvertDataLayoutForOp, _In_ OrtEp* this_ptr,
  567. _In_z_ const char* domain, _In_z_ const char* op_type,
  568. _In_ OrtEpDataLayout target_data_layout,
  569. _Outptr_ int* should_convert);
  570. /** \brief Set dynamic options on this EP.
  571. *
  572. * Dynamic options can be set by the user at any time after session creation with `OrtApi::SetEpDynamicOptions()`.
  573. *
  574. * \param[in] this_ptr The OrtEp instance.
  575. * \param[in] option_keys The dynamic option keys.
  576. * \param[in] option_values The dynamic option values.
  577. * \param[in] num_options The number of dynamic options.
  578. *
  579. * \note Implementation of this function is optional.
  580. * An EP should only implement this if it needs to handle any dynamic options.
  581. *
  582. * \snippet{doc} snippets.dox OrtStatus Return Value
  583. *
  584. * \since Version 1.23.
  585. */
  586. ORT_API2_STATUS(SetDynamicOptions, _In_ OrtEp* this_ptr,
  587. _In_reads_(num_options) const char* const* option_keys,
  588. _In_reads_(num_options) const char* const* option_values,
  589. _In_ size_t num_options);
  590. /** \brief Called by ORT to notify the EP of the start of a run.
  591. *
  592. * \param[in] this_ptr The OrtEp instance.
  593. * \param[in] run_options The run options for this run.
  594. *
  595. * \note Implementation of this function is optional.
  596. *
  597. * \snippet{doc} snippets.dox OrtStatus Return Value
  598. *
  599. * \since Version 1.23.
  600. */
  601. ORT_API2_STATUS(OnRunStart, _In_ OrtEp* this_ptr, _In_ const OrtRunOptions* run_options);
  602. /** \brief Called by ORT to notify the EP of the end of a run.
  603. *
  604. * \param[in] this_ptr The OrtEp instance.
  605. * \param[in] run_options The run options for this run.
  606. * \param[in] sync_stream Whether any associated stream should be synchronized during this call.
  607. * Only applicable if there is such a stream.
  608. *
  609. * \note Implementation of this function is optional.
  610. *
  611. * \snippet{doc} snippets.dox OrtStatus Return Value
  612. *
  613. * \since Version 1.23.
  614. */
  615. ORT_API2_STATUS(OnRunEnd, _In_ OrtEp* this_ptr, _In_ const OrtRunOptions* run_options, _In_ bool sync_stream);
  616. /** \brief Create an OrtAllocator for the given OrtMemoryInfo for an OrtSession.
  617. *
  618. * The OrtMemoryInfo instance will match one of the values set in the OrtEpDevice using EpDevice_AddAllocatorInfo.
  619. * Any allocator specific options should be read from the session options.
  620. *
  621. * If nullptr OrtEpFactory::CreateAllocator will be used.
  622. *
  623. * \param[in] this_ptr The OrtEpFactory instance.
  624. * \param[in] memory_info The OrtMemoryInfo to create the allocator for. May be nullptr.
  625. * \param[out] allocator The created OrtAllocator instance. Set to nullptr if the default CPU allocator is used.
  626. *
  627. * \snippet{doc} snippets.dox OrtStatus Return Value
  628. *
  629. * \since Version 1.23.
  630. */
  631. ORT_API2_STATUS(CreateAllocator, _In_ OrtEp* this_ptr,
  632. _In_ const OrtMemoryInfo* memory_info,
  633. _Outptr_result_maybenull_ OrtAllocator** allocator);
  634. /** \brief Create a synchronization stream for the given memory device for an OrtSession.
  635. *
  636. * This is used to create a synchronization stream for the execution provider and is used to synchronize
  637. * operations on the device during model execution.
  638. * Any stream specific options should be read from the session options.
  639. *
  640. * If nullptr OrtEpFactory::CreateSyncStreamForDevice will be used.
  641. *
  642. * \param[in] this_ptr The OrtEpFactory instance.
  643. * \param[in] memory_device The OrtMemoryDevice to create the synchronization stream for.
  644. * \param[out] stream The created OrtSyncStreamImpl instance. nullptr if the execution provider is not stream aware.
  645. *
  646. * \snippet{doc} snippets.dox OrtStatus Return Value
  647. *
  648. * \since Version 1.23.
  649. */
  650. ORT_API2_STATUS(CreateSyncStreamForDevice, _In_ OrtEp* this_ptr,
  651. _In_ const OrtMemoryDevice* memory_device,
  652. _Outptr_ OrtSyncStreamImpl** stream);
  653. /** \brief Get a string with details about the EP stack used to produce a compiled model.
  654. *
  655. * This function gets a compatibility information string that contains details about the execution provider
  656. * used to compile a given model. This string can later be used with ValidateCompiledModelCompatibilityInfo
  657. * to determine if a compiled model is compatible with the EP.
  658. *
  659. * The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
  660. *
  661. * \param[in] this_ptr The OrtEp instance.
  662. * \param[in] graph The OrtGraph instance for which to generate compatibility information.
  663. *
  664. * \snippet{doc} snippets.dox OrtStatus Return Value
  665. *
  666. * \since Version 1.23.
  667. */
  668. ORT_API_T(const char*, GetCompiledModelCompatibilityInfo, _In_ OrtEp* this_ptr,
  669. _In_ const OrtGraph* graph);
  670. };
  671. /** \brief The function signature that ORT will call to create OrtEpFactory instances.
  672. *
  673. * This must be available in a function called 'CreateEpFactories' in the execution provider library.
  674. *
  675. * \param[in] registered_name The name the execution library is registered with by RegisterExecutionProviderLibrary
  676. * \param[in] ort_api_base The OrtApiBase instance that is used by the factory to get the OrtApi instance for the
  677. * version of ORT that the library was compiled against.
  678. * \param[in] default_logger The default ORT logger that can be used for logging outside of an inference session.
  679. * \param[in,out] factories The implementation should create and add OrtEpFactory instances to this
  680. * pre-allocated array.
  681. * i.e. usage is `factories[0] = new MyEpFactory();`
  682. * \param[in] max_factories The maximum number of OrtEpFactory instances that can be added to `factories`.
  683. * Current default is to allow 4 factories. This can be increased in the future if needed.
  684. * \param[out] num_factories The number of OrtEpFactory instances created by the factory and added to `factories`.
  685. *
  686. * \snippet{doc} snippets.dox OrtStatus Return Value
  687. *
  688. * \since Version 1.22.
  689. */
  690. typedef OrtStatus* (*CreateEpApiFactoriesFn)(_In_ const char* registered_name, _In_ const OrtApiBase* ort_api_base,
  691. _In_ const OrtLogger* default_logger,
  692. _Inout_ OrtEpFactory** factories, _In_ size_t max_factories,
  693. _Out_ size_t* num_factories);
  694. /** \brief The function signature that ORT will call to release an OrtEpFactory instance.
  695. *
  696. * This must be available in a function called 'ReleaseEpFactory' in the execution provider library.
  697. *
  698. * \param[in] factory The OrtEpFactory instance to release.
  699. *
  700. * \snippet{doc} snippets.dox OrtStatus Return Value
  701. *
  702. * \since Version 1.22.
  703. */
  704. typedef OrtStatus* (*ReleaseEpApiFactoryFn)(_In_ OrtEpFactory* factory);
  705. /**
  706. * \brief The OrtEpFactory provides functions to create and manage execution providers.
  707. * \since Version 1.22.
  708. */
  709. struct OrtEpFactory {
  710. /** \brief The ONNX Runtime version the execution provider was compiled with.
  711. *
  712. * Implementation should set to ORT_API_VERSION.
  713. * ORT will use this to ensure it does not call functions that were not available when the library was compiled.
  714. *
  715. * \since Version 1.22.
  716. */
  717. uint32_t ort_version_supported;
  718. /** \brief Get the name of the execution provider that the factory creates.
  719. *
  720. * The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
  721. *
  722. * \param[in] this_ptr The OrtEpFactory instance.
  723. * \return The name of the execution provider the factory creates.
  724. *
  725. * \since Version 1.22.
  726. */
  727. ORT_API_T(const char*, GetName, const OrtEpFactory* this_ptr);
  728. /** \brief Get the name of vendor who owns the execution provider that the factory creates.
  729. *
  730. * The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
  731. *
  732. * \param[in] this_ptr The OrtEpFactory instance.
  733. * \return vendor The vendor name of the execution provider the factory creates.
  734. *
  735. * \since Version 1.22.
  736. */
  737. ORT_API_T(const char*, GetVendor, const OrtEpFactory* this_ptr); // return EP vendor
  738. /** \brief Get information from the execution provider about OrtHardwareDevice support.
  739. *
  740. * \param[in] this_ptr The OrtEpFactory instance.
  741. * Non-const as the factory is passed through to the CreateEp call via the OrtEpDevice.
  742. * \param[in] devices The OrtHardwareDevice instances that are available.
  743. * \param[in] num_devices The number of OrtHardwareDevice instances.
  744. * \param[out] ep_devices OrtEpDevice instances for each OrtHardwareDevice that the EP can use.
  745. * The implementation should call OrtEpApi::CreateEpDevice to create, and add the OrtEpDevice
  746. * instances to this pre-allocated array. ORT will take ownership of the values returned.
  747. * i.e. usage is `ep_devices[0] = <ptr to OrtEpDevice created with OrtEpApi::CreateEpDevice>;`
  748. * \param[in] max_ep_devices The maximum number of OrtEpDevices that can be added to ep_devices.
  749. * Current default is 8. This can be increased if needed.
  750. * \param[out] num_ep_devices The number of EP devices added to ep_devices.
  751. * \return true if the factory can create an execution provider that uses `device`.
  752. *
  753. * \since Version 1.22.
  754. */
  755. ORT_API2_STATUS(GetSupportedDevices, _In_ OrtEpFactory* this_ptr,
  756. _In_reads_(num_devices) const OrtHardwareDevice* const* devices,
  757. _In_ size_t num_devices,
  758. _Inout_ OrtEpDevice** ep_devices,
  759. _In_ size_t max_ep_devices,
  760. _Out_ size_t* num_ep_devices);
  761. /** \brief Function to create an OrtEp instance for use in a Session.
  762. *
  763. * ORT will call ReleaseEp to release the instance when it is no longer needed.
  764. *
  765. * \param[in] this_ptr The OrtEpFactory instance.
  766. * \param[in] devices The OrtHardwareDevice instances that the execution provider was selected to use.
  767. * May be a subset of the OrtHardwareDevice instances that the execution provider's factory
  768. * set as supported in the call to OrtEpFactory::GetSupportedDevices.
  769. * \param[in] ep_metadata_pairs Execution provider metadata that was provided to OrtEpApi::CreateEpDevice, for each
  770. * device.
  771. * \param[in] num_devices The number of devices the execution provider was selected for.
  772. * \param[in] session_options The OrtSessionOptions instance that contains the configuration options for the
  773. * session. This will include ep_options from GetSupportedDevices as well as any
  774. * user provided overrides.
  775. * Execution provider options will have been added with a prefix of 'ep.[ep name].'.
  776. * The OrtSessionOptions instance will NOT be valid after this call and should not be
  777. * stored for later use.
  778. * \param[in] logger The OrtLogger instance for the session that the execution provider should use for logging.
  779. * \param[out] ep The OrtEp instance created by the factory.
  780. *
  781. * \snippet{doc} snippets.dox OrtStatus Return Value
  782. *
  783. * \since Version 1.22.
  784. */
  785. ORT_API2_STATUS(CreateEp, _In_ OrtEpFactory* this_ptr,
  786. _In_reads_(num_devices) const OrtHardwareDevice* const* devices,
  787. _In_reads_(num_devices) const OrtKeyValuePairs* const* ep_metadata_pairs,
  788. _In_ size_t num_devices,
  789. _In_ const OrtSessionOptions* session_options,
  790. _In_ const OrtLogger* logger, _Outptr_ OrtEp** ep);
  791. /** \brief Release the OrtEp instance.
  792. *
  793. * \param[in] this_ptr The OrtEpFactory instance.
  794. * \param[in] ep The OrtEp instance to release.
  795. *
  796. * \since Version 1.22.
  797. */
  798. ORT_API_T(void, ReleaseEp, OrtEpFactory* this_ptr, struct OrtEp* ep);
  799. /** \brief Get the vendor id who owns the execution provider that the factory creates.
  800. *
  801. * This is typically the PCI vendor ID. See https://pcisig.com/membership/member-companies
  802. *
  803. * \param[in] this_ptr The OrtEpFactory instance.
  804. * \return vendor_id The vendor ID of the execution provider the factory creates.
  805. *
  806. * \since Version 1.23.
  807. */
  808. ORT_API_T(uint32_t, GetVendorId, const OrtEpFactory* this_ptr);
  809. /** \brief Get the version of the execution provider that the factory creates.
  810. *
  811. * The version string should adhere to the Semantic Versioning 2.0 specification
  812. * (https://github.com/semver/semver/blob/v2.0.0/semver.md).
  813. *
  814. * The returned string should be a null-terminated, UTF-8 encoded string. ORT will copy it.
  815. *
  816. * \param[in] this_ptr The OrtEpFactory instance.
  817. * \return The execution provider version string.
  818. *
  819. * \since Version 1.23.
  820. */
  821. ORT_API_T(const char*, GetVersion, _In_ const OrtEpFactory* this_ptr);
  822. /** \brief Validate the compatibility of a compiled model with the execution provider factory for one or more devices.
  823. *
  824. * Given a compatibility info string produced during model compilation, the EP factory should determine whether the
  825. * compiled model is compatible with the EP factory when targeting the provided hardware devices. All devices provided
  826. * must belong to the same execution provider instance that this factory creates.
  827. *
  828. * The EP factory implementation should consider the set of devices (e.g., multi-adapter or multi-GPU scenarios) when
  829. * evaluating compatibility and set `model_compatibility` accordingly.
  830. *
  831. * \param[in] this_ptr The OrtEpFactory instance.
  832. * \param[in] devices Array of OrtHardwareDevice pointers that the EP would run on. All must map to this EP.
  833. * \param[in] num_devices Number of entries in `devices`.
  834. * \param[in] compatibility_info The compatibility information string produced when the model was compiled.
  835. * \param[out] model_compatibility OrtCompiledModelCompatibility value describing the compatibility of the model with the EP.
  836. *
  837. * \snippet{doc} snippets.dox OrtStatus Return Value
  838. *
  839. * \since Version 1.23.
  840. */
  841. ORT_API2_STATUS(ValidateCompiledModelCompatibilityInfo, _In_ OrtEpFactory* this_ptr,
  842. _In_reads_(num_devices) const OrtHardwareDevice* const* devices,
  843. _In_ size_t num_devices,
  844. _In_ const char* compatibility_info,
  845. _Out_ OrtCompiledModelCompatibility* model_compatibility);
  846. /** \brief Create an OrtAllocator that can be shared across sessions for the given OrtMemoryInfo.
  847. *
  848. * The factory that creates the EP is responsible for providing the allocators required by the EP.
  849. * The OrtMemoryInfo instance will match one of the values set in the OrtEpDevice using EpDevice_AddAllocatorInfo.
  850. *
  851. * \param[in] this_ptr The OrtEpFactory instance.
  852. * \param[in] memory_info The OrtMemoryInfo to create the allocator for. May be nullptr.
  853. * \param[in] allocator_options Optional key-value pairs for allocator options, can be nullptr.
  854. * \param[out] allocator The created OrtAllocator instance. Set to nullptr if the default CPU allocator is used.
  855. *
  856. * \snippet{doc} snippets.dox OrtStatus Return Value
  857. *
  858. * \since Version 1.23.
  859. */
  860. ORT_API2_STATUS(CreateAllocator, _In_ OrtEpFactory* this_ptr,
  861. _In_ const OrtMemoryInfo* memory_info,
  862. _In_opt_ const OrtKeyValuePairs* allocator_options,
  863. _Outptr_result_maybenull_ OrtAllocator** allocator);
  864. /** \brief Release an OrtAllocator created by the factory.
  865. *
  866. * \since Version 1.23.
  867. */
  868. ORT_API_T(void, ReleaseAllocator, _In_ OrtEpFactory* this_ptr, _In_ OrtAllocator* allocator);
  869. /** \brief Create an OrtDataTransferImpl instance for the factory.
  870. *
  871. * This is used to create an IDataTransfer implementation that can be used to copy data between devices
  872. * that the execution provider supports.
  873. *
  874. * \param[in] this_ptr The OrtEpFactory instance.
  875. * \param[out] data_transfer The created OrtDataTransferImpl instance. Set to nullptr if not required.
  876. *
  877. * \snippet{doc} snippets.dox OrtStatus Return Value
  878. *
  879. * \since Version 1.23.
  880. */
  881. ORT_API2_STATUS(CreateDataTransfer, _In_ OrtEpFactory* this_ptr,
  882. _Outptr_result_maybenull_ OrtDataTransferImpl** data_transfer);
  883. /** \brief Check if execution providers created by the factory are stream aware.
  884. *
  885. * \param[in] this_ptr The OrtEpFactory instance.
  886. * \return True if the factory creates execution providers that are stream aware and it implements CreateSyncStreamForDevice.
  887. *
  888. * \since Version 1.23.
  889. */
  890. ORT_API_T(bool, IsStreamAware, _In_ const OrtEpFactory* this_ptr);
  891. /** \brief Create a synchronization stream for the given memory device.
  892. *
  893. * This is used to create a synchronization stream for the memory device that can be used for operations outside of
  894. * a session.
  895. *
  896. * \param[in] this_ptr The OrtEpFactory instance.
  897. * \param[in] memory_device The OrtMemoryDevice to create the synchronization stream for.
  898. * \param[in] stream_options Options for stream creation. May be nullptr.
  899. * \param[out] stream The created OrtSyncStreamImpl instance. nullptr if the execution provider is not stream aware.
  900. *
  901. * \snippet{doc} snippets.dox OrtStatus Return Value
  902. *
  903. * \since Version 1.23.
  904. */
  905. ORT_API2_STATUS(CreateSyncStreamForDevice, _In_ OrtEpFactory* this_ptr,
  906. _In_ const OrtMemoryDevice* memory_device,
  907. _In_opt_ const OrtKeyValuePairs* stream_options,
  908. _Outptr_ OrtSyncStreamImpl** stream);
  909. };
  910. #ifdef __cplusplus
  911. }
  912. #endif