@@ -64,6 +64,7 @@ extern "C" {
6464#define _Outptr_result_maybenull_
6565#define _Outptr_result_maybenull_z_
6666#define _In_reads_ (X )
67+ #define _In_reads_opt_
6768#define _Inout_updates_ (X )
6869#define _Out_writes_ (X )
6970#define _Out_writes_opt_ (X )
@@ -322,6 +323,7 @@ ORT_RUNTIME_CLASS(ModelCompilationOptions);
322323ORT_RUNTIME_CLASS (HardwareDevice);
323324ORT_RUNTIME_CLASS (EpDevice);
324325ORT_RUNTIME_CLASS (KeyValuePairs);
326+ ORT_RUNTIME_CLASS (SyncStream); // Opaque class to create an onnxruntime::Stream.
325327
326328#ifdef _MSC_VER
327329typedef _Return_type_success_ (return == 0 ) OrtStatus* OrtStatusPtr;
@@ -426,10 +428,14 @@ typedef enum OrtAllocatorType {
426428 */
427429// Whenever this struct is updated, please also update the MakeKey function in onnxruntime / core / framework / execution_provider.cc
428430typedef enum OrtMemType {
429- OrtMemTypeCPUInput = -2 , // /< Any CPU memory used by non-CPU execution provider
430- OrtMemTypeCPUOutput = -1 , // /< CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED
431- OrtMemTypeCPU = OrtMemTypeCPUOutput, // /< Temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED
432- OrtMemTypeDefault = 0 , // /< The default allocator for execution provider
431+ // / Any CPU memory used by non-CPU execution provider
432+ OrtMemTypeCPUInput = -2 ,
433+ // / CPU accessible memory outputted by non-CPU execution provider, i.e. HOST_ACCESSIBLE
434+ OrtMemTypeCPUOutput = -1 ,
435+ // / CPU accessible memory allocated by non-CPU execution provider, i.e. HOST_ACCESSIBLE
436+ OrtMemTypeCPU = OrtMemTypeCPUOutput,
437+ // / The default allocator for execution provider
438+ OrtMemTypeDefault = 0 ,
433439} OrtMemType;
434440
435441/* * \brief This matches OrtDevice::MemoryType values */
@@ -1743,7 +1749,7 @@ struct OrtApi {
17431749 */
17441750 ORT_API2_STATUS (MemoryInfoGetName, _In_ const OrtMemoryInfo* ptr, _Out_ const char ** out);
17451751
1746- /* * \brief Get the id from ::OrtMemoryInfo
1752+ /* * \brief Get the device id from ::OrtMemoryInfo
17471753 */
17481754 ORT_API2_STATUS (MemoryInfoGetId, _In_ const OrtMemoryInfo* ptr, _Out_ int * out);
17491755
@@ -5384,10 +5390,32 @@ struct OrtApi {
53845390 * \since Version 1.23
53855391 */
53865392 ORT_API2_STATUS (CreateMemoryInfo_V2, _In_ const char * name, _In_ enum OrtMemoryInfoDeviceType device_type,
5387- _In_ uint32_t vendor_id, _In_ int16_t device_id, _In_ enum OrtDeviceMemoryType mem_type,
5393+ _In_ uint32_t vendor_id, _In_ int32_t device_id, _In_ enum OrtDeviceMemoryType mem_type,
53885394 _In_ size_t alignment, enum OrtAllocatorType allocator_type,
53895395 _Outptr_ OrtMemoryInfo** out);
53905396
5397+ /* * \brief Get the device memory type from ::OrtMemoryInfo
5398+ *
5399+ * \param[in] ptr The OrtMemoryInfo instance to query.
5400+ * \param[out] out The device memory type.
5401+ *
5402+ * \snippet{doc} snippets.dox OrtStatus Return Value
5403+ *
5404+ * \since Version 1.23
5405+ */
5406+ ORT_API2_STATUS (MemoryInfoGetDeviceMemType, _In_ const OrtMemoryInfo* ptr, _Out_ OrtDeviceMemoryType* out);
5407+
5408+ /* * \brief Get the vendor id from ::OrtMemoryInfo
5409+ *
5410+ * \param[in] ptr The OrtMemoryInfo instance to query.
5411+ * \param[out] out The vendor id.
5412+ *
5413+ * \snippet{doc} snippets.dox OrtStatus Return Value
5414+ *
5415+ * \since Version 1.23
5416+ */
5417+ ORT_API2_STATUS (MemoryInfoGetVendorId, _In_ const OrtMemoryInfo* ptr, _Out_ uint32_t * out);
5418+
53915419 // / \name OrtValueInfo
53925420 // / @{
53935421
@@ -6068,11 +6096,14 @@ struct OrtApi {
60686096 /* * \brief Get the OrtMemoryInfo for the device.
60696097 *
60706098 * \param[in] ep_device The OrtEpDevice instance to query.
6071- * \return A pointer to the OrtMemoryInfo for the device.
6099+ * \param[in] memory_type The memory type to return.
6100+ * \return A pointer to the OrtMemoryInfo for the device. This may be nullptr if not set.
6101+ * If memory_type is OrtDeviceMemoryType_DEFAULT and nullptr is returned the EP uses CPU memory.
60726102 *
60736103 * \since Version 1.23
60746104 */
6075- ORT_API_T (const OrtMemoryInfo*, EpDevice_MemoryInfo, _In_ const OrtEpDevice* ep_device);
6105+ ORT_API_T (const OrtMemoryInfo*, EpDevice_MemoryInfo, _In_ const OrtEpDevice* ep_device,
6106+ _In_ OrtDeviceMemoryType memory_type);
60766107
60776108 /* * \brief Create/replace a shared allocator for the OrtEpDevice in the OrtEnv.
60786109 *
@@ -6164,6 +6195,141 @@ struct OrtApi {
61646195 * \since Version 1.23.
61656196 */
61666197 ORT_API2_STATUS (GetSessionOptionsConfigEntries, _In_ const OrtSessionOptions* options, _Outptr_ OrtKeyValuePairs** out);
6198+
6199+ /* * \brief Get the OrtMemoryInfo for each input of the session.
6200+ *
6201+ * The memory info can be used to determine where the input tensors are required.
6202+ *
6203+ * The session must be fully initialized before calling this function as the input locations are not known until
6204+ * this has occurred.
6205+ *
6206+ * \param[in] session The OrtSession instance.
6207+ * \param[out] inputs_memory_info Pre-allocated array of size `num_inputs` that will be filled with the
6208+ * OrtMemoryInfo* value for each input.
6209+ * The order is the same as returned by SessionGetInputName.
6210+ * \param[in] num_inputs The number of inputs in the session. Must match SessionGetInputCount.
6211+ *
6212+ * \snippet{doc} snippets.dox OrtStatus Return Value
6213+ *
6214+ * \since Version 1.23
6215+ */
6216+ ORT_API2_STATUS (SessionGetMemoryInfoForInputs, _In_ const OrtSession* session,
6217+ _Out_writes_ (num_inputs) const OrtMemoryInfo** inputs_memory_info,
6218+ _In_ size_t num_inputs);
6219+
6220+ /* * \brief Get the OrtMemoryInfo for each output of the session.
6221+ *
6222+ * The memory info can be used to determine the device the output tensors are produced on.
6223+ * The user can pre-allocate an OrtValue using this information or use IOBinding to keep the data on the device.
6224+ * ORT will copy the output to CPU otherwise.
6225+ *
6226+ * The session must be fully initialized before calling this function as the output locations are not known until
6227+ * this has occurred.
6228+ *
6229+ * \param[in] session The OrtSession instance.
6230+ * \param[out] outputs_memory_info Pre-allocated array of size `num_outputs` that will be filled with
6231+ * OrtMemoryInfo* values for each output.
6232+ * The order is the same as returned by SessionGetOutputName.
6233+ * \param[in] num_outputs The number of outputs in the session. Must match SessionGetOutputCount.
6234+ *
6235+ * \snippet{doc} snippets.dox OrtStatus Return Value
6236+ *
6237+ * \since Version 1.23
6238+ */
6239+ ORT_API2_STATUS (SessionGetMemoryInfoForOutputs, _In_ const OrtSession* session,
6240+ _Out_writes_ (num_outputs) const OrtMemoryInfo** outputs_memory_info,
6241+ _In_ size_t num_outputs);
6242+
6243+ /* * \brief Get the OrtEpDevice (if available) for each input of the session.
6244+ *
6245+ * An OrtEpDevice will be available if auto EP selection is enabled by calling
6246+ * SessionOptionsSetEpSelectionPolicy or SessionOptionsSetEpSelectionPolicyDelegate,
6247+ * or if the OrtEpDevice was manually added to the session using SessionOptionsAppendExecutionProvider_V2.
6248+ *
6249+ * If an OrtEpDevice is not available for the input a nullptr is returned.
6250+ *
6251+ * The returned OrtEpDevice can be used to create an OrtSyncStream via CreateSyncStreamForEpDevice to asynchronously
6252+ * provide input to the inference session Run.
6253+ *
6254+ * The session must be fully initialized before calling this function as the assigned EPs are not known until
6255+ * this has occurred.
6256+ *
6257+ * \param[in] session The OrtSession instance.
6258+ * \param[out] inputs_ep_devices Pre-allocated array of size `num_inputs` that will be filled with
6259+ * OrtEpDevice* values for each input.
6260+ * The order is the same as returned by SessionGetInputName.
6261+ * \param[in] num_inputs The number of inputs in the session. Must match SessionGetInputCount.
6262+ *
6263+ * \snippet{doc} snippets.dox OrtStatus Return Value
6264+ *
6265+ * \since Version 1.23
6266+ */
6267+ ORT_API2_STATUS (SessionGetEpDeviceForInputs, _In_ const OrtSession* session,
6268+ _Out_writes_ (num_inputs) const OrtEpDevice** inputs_ep_devices,
6269+ _In_ size_t num_inputs);
6270+
6271+ /* * \brief Create an OrtSyncStream for the given OrtEpDevice.
6272+ *
6273+ * The OrtSyncStream can be used to enable asynchronous operations.
6274+ * e.g. async usage of CopyTensors to provide input to an OrtSession Run call.
6275+ *
6276+ * An error code of ORT_NOT_IMPLEMENTED will be returned if the EP does not support OrtSyncStream.
6277+ *
6278+ * \param[in] ep_device The OrtEpDevice instance to create the sync stream for.
6279+ * \param[in] stream_options Options for OrtSyncStream creation. May be nullptr.
6280+ * \param[out] stream Output parameter set to the created OrtSyncStream instance.
6281+ *
6282+ * \snippet{doc} snippets.dox OrtStatus Return Value
6283+ *
6284+ * \since Version 1.23
6285+ */
6286+ ORT_API2_STATUS (CreateSyncStreamForEpDevice, _In_ const OrtEpDevice* ep_device,
6287+ _In_opt_ const OrtKeyValuePairs* stream_options,
6288+ _Outptr_ OrtSyncStream** stream);
6289+
6290+ /* * \brief Get the native handle of the sync stream.
6291+ *
6292+ * This returns the native handle for the stream. e.g. cudaStream_t for CUDA streams.
6293+ *
6294+ * \param[in] stream The OrtSyncStream instance to get the handle from.
6295+ *
6296+ * \returns The native handle of the stream.
6297+ *
6298+ * \since Version 1.23
6299+ */
6300+ ORT_API_T (void *, SyncStream_GetHandle, _In_ OrtSyncStream* stream);
6301+
6302+ ORT_CLASS_RELEASE (SyncStream);
6303+
6304+ /* * \brief Copy OrtValue instances containing Tensors between devices.
6305+ *
6306+ * The overall copy must be between a single source device and a single destination device. i.e.
6307+ * - all src_tensors must have matching OrtMemoryInfo,
6308+ * - all dst_tensors must have matching OrtMemoryInfo.
6309+ *
6310+ * OrtValue instances can be created by:
6311+ * - Use GetSharedAllocator to get the shared allocator for the OrtMemoryInfo if you need to allocate memory
6312+ * on the device.
6313+ * - Use CreateTensorAsOrtValue, CreateTensorWithDataAsOrtValue or CreateTensorWithDataAndDeleterAsOrtValue
6314+ * to create an OrtValue containing a tensor depending on whether you have existing data or not, and whether
6315+ * you want ORT to free the existing data once it is done with the OrtValue.
6316+ *
6317+ * \param[in] env The OrtEnv instance to use. The data transfer implementation is provided by an execution provider
6318+ * that is registered in this OrtEnv.
6319+ * \param[in] src_tensors Array of OrtValue instances containing the source tensors to copy.
6320+ * \param[in] dst_tensors Array of OrtValue instances to copy the source tensors to.
6321+ * \param[in] stream Optional OrtSyncStream that can be used to perform the copy asynchronously. May be nullptr.
6322+ * \param[in] num_tensors The number of tensors to copy. The size of `src_tensors` and `dst_tensors` must match.
6323+ *
6324+ * \snippet{doc} snippets.dox OrtStatus Return Value
6325+ *
6326+ * \since Version 1.23
6327+ */
6328+ ORT_API2_STATUS (CopyTensors, _In_ const OrtEnv* env,
6329+ _In_reads_ (num_tensors) const OrtValue* const * src_tensors,
6330+ _In_reads_(num_tensors) OrtValue* const * dst_tensors,
6331+ _In_opt_ OrtSyncStream* stream,
6332+ _In_ size_t num_tensors);
61676333};
61686334
61696335/*
0 commit comments