Skip to content

Commit ad78f56

Browse files
authored
Merge branch 'main' into user/xiha/compat_api
2 parents f8dbd4e + 27e6002 commit ad78f56

25 files changed

+560
-137
lines changed

cmake/onnxruntime_unittests.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,8 +2133,8 @@ if (onnxruntime_BUILD_SHARED_LIB AND
21332133
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/squeeze.cc"
21342134
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/relu.h"
21352135
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/relu.cc"
2136-
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/mul.h"
2137-
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/mul.cc")
2136+
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/binary_op.h"
2137+
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/binary_op.cc")
21382138
onnxruntime_add_shared_library_module(example_plugin_ep_kernel_registry ${onnxruntime_autoep_test_example_plugin_ep_kernel_registry_src})
21392139
target_include_directories(example_plugin_ep_kernel_registry PRIVATE ${REPO_ROOT}/include/onnxruntime/core/session)
21402140
target_link_libraries(example_plugin_ep_kernel_registry PRIVATE onnxruntime ${GSL_TARGET})

include/onnxruntime/core/framework/execution_provider.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,15 @@ class IExecutionProvider {
416416
return InlinedVector<const Node*>();
417417
}
418418

419+
/**
420+
* Returns the underlying OrtEp instance if this IExecutionProvider wraps a plugin EP.
421+
* Otherwise, returns a nullptr (default implementation).
422+
* This is used to retrieve the OrtEp instance from a OrtKernelInfo instance in a plugin EP's kernel implementation.
423+
*/
424+
virtual const OrtEp* GetOrtEp() const {
425+
return nullptr;
426+
}
427+
419428
private:
420429
const std::string type_;
421430

include/onnxruntime/core/session/onnxruntime_c_api.h

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,7 +4215,7 @@ struct OrtApi {
42154215
* If `out` is nullptr, the value of `size` is set to the size of the name
42164216
* string (including null-terminator), and a success status is returned.
42174217
*
4218-
* If the `size` parameter is greater than or equal to the name string's size,
4218+
* If the `size` parameter is greater than or equal to the name string's size and `out` is not nullptr,
42194219
* the value of `size` is set to the true size of the string (including null-terminator),
42204220
* the provided memory is filled with the string's contents, and a success status is returned.
42214221
*
@@ -4231,7 +4231,7 @@ struct OrtApi {
42314231
* \snippet{doc} snippets.dox OrtStatus Return Value
42324232
* \since Version 1.14
42334233
*/
4234-
ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
4234+
ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_opt_ char* out,
42354235
_Inout_ size_t* size);
42364236

42374237
/** \brief Get the name of a ::OrtKernelInfo's output.
@@ -4242,7 +4242,7 @@ struct OrtApi {
42424242
* If `out` is nullptr, the value of `size` is set to the size of the name
42434243
* string (including null-terminator), and a success status is returned.
42444244
*
4245-
* If the `size` parameter is greater than or equal to the name string's size,
4245+
* If the `size` parameter is greater than or equal to the name string's size and `out` is not nullptr,
42464246
* the value of `size` is set to the true size of the string (including null-terminator),
42474247
* the provided memory is filled with the string's contents, and a success status is returned.
42484248
*
@@ -4259,7 +4259,7 @@ struct OrtApi {
42594259
* \snippet{doc} snippets.dox OrtStatus Return Value
42604260
* \since Version 1.14
42614261
*/
4262-
ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
4262+
ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_opt_ char* out,
42634263
_Inout_ size_t* size);
42644264

42654265
/** \brief Get the type information for a ::OrtKernelInfo's input.
@@ -4439,7 +4439,7 @@ struct OrtApi {
44394439
* If `out` is nullptr, the value of `size` is set to the size of the name
44404440
* string (including null-terminator), and a success status is returned.
44414441
*
4442-
* If the `size` parameter is greater than or equal to the name string's size,
4442+
* If the `size` parameter is greater than or equal to the name string's size and `out` is not nullptr,
44434443
* the value of `size` is set to the true size of the string (including null-terminator),
44444444
* the provided memory is filled with the string's contents, and a success status is returned.
44454445
*
@@ -4456,7 +4456,7 @@ struct OrtApi {
44564456
* \snippet{doc} snippets.dox OrtStatus Return Value
44574457
* \since Version 1.15
44584458
*/
4459-
ORT_API2_STATUS(KernelInfo_GetNodeName, _In_ const OrtKernelInfo* info, _Out_ char* out, _Inout_ size_t* size);
4459+
ORT_API2_STATUS(KernelInfo_GetNodeName, _In_ const OrtKernelInfo* info, _Out_opt_ char* out, _Inout_ size_t* size);
44604460

44614461
/** \brief Get the session logger from ::OrtKernelInfo.
44624462
*
@@ -6620,7 +6620,67 @@ struct OrtApi {
66206620
*/
66216621
ORT_API2_STATUS(KernelInfo_GetConfigEntries, _In_ const OrtKernelInfo* info, _Outptr_ OrtKeyValuePairs** out);
66226622

6623-
/** \brief Get the list of available hardware devices.
6623+
/// @}
6624+
/** \brief Get the graph node's operator domain from ::OrtKernelInfo.
6625+
*
6626+
* If `out` is nullptr, the value of `size` is set to the size of the operator domain
6627+
* string (including null-terminator), and a success status is returned.
6628+
*
6629+
* If the `size` parameter is greater than or equal to the string's size and `out` is not nullptr,
6630+
* the value of `size` is set to the true size of the string (including null-terminator),
6631+
* the provided memory is filled with the string's contents, and a success status is returned.
6632+
*
6633+
* If the `size` parameter is less than the actual string's size and `out`
6634+
* is not nullptr, the value of `size` is set to the true size of the string
6635+
* and a failure status with error code ORT_INVALID_ARGUMENT is returned.
6636+
*
6637+
* \param[in] info An instance of ::OrtKernelInfo.
6638+
* \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the
6639+
* operator domain.
6640+
* \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
6641+
*
6642+
* \snippet{doc} snippets.dox OrtStatus Return Value
6643+
* \since Version 1.24
6644+
*/
6645+
ORT_API2_STATUS(KernelInfo_GetOperatorDomain, _In_ const OrtKernelInfo* info, _Out_opt_ char* out,
6646+
_Inout_ size_t* size);
6647+
6648+
/** \brief Get the graph node's operator type from ::OrtKernelInfo.
6649+
*
6650+
* If `out` is nullptr, the value of `size` is set to the size of the operator type
6651+
* string (including null-terminator), and a success status is returned.
6652+
*
6653+
* If the `size` parameter is greater than or equal to the string's size and `out` is not nullptr,
6654+
* the value of `size` is set to the true size of the string (including null-terminator),
6655+
* the provided memory is filled with the string's contents, and a success status is returned.
6656+
*
6657+
* If the `size` parameter is less than the actual string's size and `out`
6658+
* is not nullptr, the value of `size` is set to the true size of the string
6659+
* and a failure status with error code ORT_INVALID_ARGUMENT is returned.
6660+
*
6661+
* \param[in] info An instance of ::OrtKernelInfo.
6662+
* \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the
6663+
* operator type.
6664+
* \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
6665+
*
6666+
* \snippet{doc} snippets.dox OrtStatus Return Value
6667+
* \since Version 1.24
6668+
*/
6669+
ORT_API2_STATUS(KernelInfo_GetOperatorType, _In_ const OrtKernelInfo* info, _Out_opt_ char* out,
6670+
_Inout_ size_t* size);
6671+
6672+
/** \brief Get the opset version in which the given node's operator type was first defined from ::OrtKernelInfo.
6673+
*
6674+
* \param[in] info An instance of ::OrtKernelInfo.
6675+
* \param[out] since_version The opset version in which the node's operator type was first defined.
6676+
*
6677+
* \snippet{doc} snippets.dox OrtStatus Return Value
6678+
* \since Version 1.24
6679+
*/
6680+
ORT_API2_STATUS(KernelInfo_GetOperatorSinceVersion, _In_ const OrtKernelInfo* info,
6681+
_Out_ int* since_version);
6682+
6683+
/** \brief Get the list of available hardware devices.
66246684
*
66256685
* Enumerates hardware devices available on the system. Device discovery results
66266686
* are stored in the ORT environment.

include/onnxruntime/core/session/onnxruntime_cxx_api.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,11 @@ struct KernelInfoImpl : Base<T> {
27822782
Logger GetLogger() const;
27832783

27842784
KeyValuePairs GetConfigEntries() const;
2785+
2786+
std::string GetOperatorDomain() const; ///< Wraps OrtApi::KernelInfo_GetOperatorDomain
2787+
std::string GetOperatorType() const; ///< Wraps OrtApi::KernelInfo_GetOperatorType
2788+
int GetOperatorSinceVersion() const; ///< Wraps OrtApi::KernelInfo_GetOperatorSinceVersion
2789+
const OrtEp* GetEp() const; ///< Wraps OrtEpApi::KernelInfo_GetEp
27852790
};
27862791

27872792
} // namespace detail

include/onnxruntime/core/session/onnxruntime_cxx_inline.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,50 @@ inline KeyValuePairs KernelInfoImpl<T>::GetConfigEntries() const {
28422842
return KeyValuePairs{out};
28432843
}
28442844

2845+
template <typename T>
2846+
inline std::string KernelInfoImpl<T>::GetOperatorDomain() const {
2847+
size_t size = 0;
2848+
2849+
// Feed nullptr for the data buffer to query the true size of the string value
2850+
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorDomain(this->p_, nullptr, &size));
2851+
2852+
std::string out;
2853+
out.resize(size);
2854+
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorDomain(this->p_, &out[0], &size));
2855+
out.resize(size - 1); // remove the terminating character '\0'
2856+
2857+
return out;
2858+
}
2859+
2860+
template <typename T>
2861+
inline std::string KernelInfoImpl<T>::GetOperatorType() const {
2862+
size_t size = 0;
2863+
2864+
// Feed nullptr for the data buffer to query the true size of the string value
2865+
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorType(this->p_, nullptr, &size));
2866+
2867+
std::string out;
2868+
out.resize(size);
2869+
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorType(this->p_, &out[0], &size));
2870+
out.resize(size - 1); // remove the terminating character '\0'
2871+
2872+
return out;
2873+
}
2874+
2875+
template <typename T>
2876+
inline int KernelInfoImpl<T>::GetOperatorSinceVersion() const {
2877+
int out = 0;
2878+
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorSinceVersion(this->p_, &out));
2879+
return out;
2880+
}
2881+
2882+
template <typename T>
2883+
inline const OrtEp* KernelInfoImpl<T>::GetEp() const {
2884+
const OrtEp* ep = nullptr;
2885+
Ort::ThrowOnError(GetEpApi().KernelInfo_GetEp(this->p_, &ep));
2886+
return ep;
2887+
}
2888+
28452889
inline void attr_utils::GetAttr(const OrtKernelInfo* p, const char* name, float& out) {
28462890
Ort::ThrowOnError(GetApi().KernelInfoGetAttribute_float(p, name, &out));
28472891
}

include/onnxruntime/core/session/onnxruntime_ep_c_api.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,18 @@ struct OrtEpApi {
972972
_In_reads_(num_buffers) void** buffer_data_ptrs, _In_reads_(num_buffers) size_t* buffer_data_sizes,
973973
_In_ size_t num_buffers);
974974

975+
/** \brief Get the OrtEp instance to which the node is assigned from the OrtKernelInfo.
976+
*
977+
* \note Used within OrtKernelImpl implementations to obtain a reference to the OrtEp.
978+
*
979+
* \param[in] info The ::OrtKernelInfo instance.
980+
* \param[out] ep Output parameter set to the OrtEp instance associated with the OrtKernelInfo.
981+
*
982+
* \snippet{doc} snippets.dox OrtStatus Return Value
983+
* \since Version 1.24
984+
*/
985+
ORT_API2_STATUS(KernelInfo_GetEp, _In_ const OrtKernelInfo* info, _Outptr_ const OrtEp** ep);
986+
975987
/** \brief Create an OrtDeviceEpIncompatibilityDetails instance.
976988
*
977989
* Used by execution provider factories to create incompatibility details in their

0 commit comments

Comments
 (0)