Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
4f3d004
[EP ABI] Add weight pre-packing support to kernel-based plugin EPs
adrianlizarraga Dec 8, 2025
e954021
Add comment about sharing of prepacked weights (cpu ep only)
adrianlizarraga Dec 8, 2025
fb2998b
Update Mul kernel to pre-pack input b
adrianlizarraga Dec 9, 2025
5e64f79
Apply suggestions from code review
adrianlizarraga Dec 9, 2025
9b1c6a2
Add comments regarding prepack allocator lifetime
adrianlizarraga Dec 9, 2025
c638a1a
Merge branch 'adrianl/plugin-ep-kernel-prepack' of github.com:microso…
adrianlizarraga Dec 9, 2025
717ed4a
Added support for sharing pre-packed weights for cpu-accessible alloc…
adrianlizarraga Dec 11, 2025
bd8f6f0
Define what should happen if OrtKernelImpl::SetSharedPrePackedWeight(…
adrianlizarraga Dec 12, 2025
5c94ec4
Add some missing OrtKernelInfo APIs for plugin EPs
adrianlizarraga Dec 15, 2025
fc1fd16
Merge branch 'main' into adrianl/plugin-ep-kernel-prepack
adrianlizarraga Dec 16, 2025
8b3f56c
Clean up some exception handling
adrianlizarraga Dec 16, 2025
23503a1
Refactor example kernel classes (no inheritance)
adrianlizarraga Dec 17, 2025
7f37ffb
Merge branch 'main' into adrianl/plugin-ep-kernel-prepack
adrianlizarraga Dec 17, 2025
26eca56
Correct use of output param
adrianlizarraga Dec 17, 2025
7af257b
Add more edge-case handling for PrePack() call
adrianlizarraga Dec 17, 2025
515062e
API version checks
adrianlizarraga Dec 17, 2025
347ce4f
Use correct SAL annotation for array parameters
adrianlizarraga Dec 18, 2025
906187d
Clean up some includes
adrianlizarraga Dec 18, 2025
56074f6
Merge branch 'main' into adrianl/KernelPluginEp_KernelInfoApis
adrianlizarraga Dec 18, 2025
1611fc3
Update onnxruntime/core/session/plugin_ep/ep_kernel_registration.cc
adrianlizarraga Dec 19, 2025
cb75d5a
Rename ExecuteIfCustomOpsApiEnabled to ExecuteifKernelApiEnabled
adrianlizarraga Dec 19, 2025
30ca590
Remove OrtAllocator parameter from SharedPrePackedWeightCache_StoreWe…
adrianlizarraga Dec 19, 2025
a5342b9
Clarify what happens when SharedPrePackedWeightCache_StoreWeightData …
adrianlizarraga Dec 20, 2025
c42d7ac
Merge branch 'main' into adrianl/KernelPluginEp_KernelInfoApis
adrianlizarraga Dec 22, 2025
3323330
Move some kernel info apis to OrtApi; Fix unrelated memory leak for K…
adrianlizarraga Dec 22, 2025
51bc731
Merge branch 'main' into adrianl/plugin-ep-kernel-prepack
adrianlizarraga Dec 22, 2025
edf3f2c
Review comments
adrianlizarraga Dec 23, 2025
e94c0aa
C++ API
adrianlizarraga Dec 23, 2025
c8eb3c9
Improve doc for c++ api convenience class
adrianlizarraga Dec 23, 2025
98e3d13
Add buffer_sizes as a parameter to OrtKernelImpl::SetSharedWeightData
adrianlizarraga Dec 24, 2025
c61ae41
Add comment to implementation of OrtKernelImpl::SetSharedPrePackedWeight
adrianlizarraga Dec 24, 2025
02d75d2
Do not prescribe what the kernel impl should return for a situation t…
adrianlizarraga Dec 24, 2025
0a84eda
Update include/onnxruntime/core/session/onnxruntime_ep_c_api.h
adrianlizarraga Dec 24, 2025
5f80f9d
Adjust comments
adrianlizarraga Dec 24, 2025
c60472d
Tweak comment again
adrianlizarraga Dec 24, 2025
12b8394
Merge main and fix conflicts
adrianlizarraga Dec 26, 2025
52453f2
Update example kernel EP to get the OrtEp from OrtKernelInfo and add …
adrianlizarraga Dec 26, 2025
79eadd8
Address copilot review comments
adrianlizarraga Dec 26, 2025
1dc98b2
Address copilot review comment: update error message when APIs for Or…
adrianlizarraga Dec 26, 2025
441c9e2
Add comments to clarify ownership scenarios
adrianlizarraga Dec 27, 2025
5cf9600
Merge branch 'adrianl/plugin-ep-kernel-prepack' into adrianl/KernelPl…
adrianlizarraga Dec 27, 2025
ec0183e
Merge main and fix conflicts
adrianlizarraga Dec 29, 2025
7e89261
Add support for Add kernel to test kernel-based EP. This used as moti…
adrianlizarraga Dec 29, 2025
1ddc9fb
Rename variable from 'mul_kernel' to 'binary_op_kernel'
adrianlizarraga Dec 29, 2025
9e6b06e
Address review comments and fix compiler warnings on Linux
adrianlizarraga Dec 29, 2025
1d496a2
Move KernelContext_GetAllocator memory leak fix to a different PR
adrianlizarraga Dec 30, 2025
6378bf2
Simplify binary op type check
adrianlizarraga Dec 30, 2025
eadc029
Merge branch 'main' into adrianl/KernelPluginEp_KernelInfoApis
adrianlizarraga Jan 5, 2026
cad57e7
Review comments + add new API to get op domain
adrianlizarraga Jan 6, 2026
4fb2be9
Check for NULL size arg in API call. Update comment
adrianlizarraga Jan 6, 2026
ebe58ed
Update SAL annotations for older KernelInfo_* API functions
adrianlizarraga Jan 6, 2026
3968ec3
Update example BinaryOp class to support Sub instead of Add
adrianlizarraga Jan 6, 2026
df45a2f
Update comment for KernelInfo_GetNodeName
adrianlizarraga Jan 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmake/onnxruntime_unittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2133,8 +2133,8 @@ if (onnxruntime_BUILD_SHARED_LIB AND
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/squeeze.cc"
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/relu.h"
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/relu.cc"
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/mul.h"
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/mul.cc")
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/binary_op.h"
"${TEST_SRC_DIR}/autoep/library/example_plugin_ep_kernel_registry/kernels/binary_op.cc")
onnxruntime_add_shared_library_module(example_plugin_ep_kernel_registry ${onnxruntime_autoep_test_example_plugin_ep_kernel_registry_src})
target_include_directories(example_plugin_ep_kernel_registry PRIVATE ${REPO_ROOT}/include/onnxruntime/core/session)
target_link_libraries(example_plugin_ep_kernel_registry PRIVATE onnxruntime ${GSL_TARGET})
Expand Down
9 changes: 9 additions & 0 deletions include/onnxruntime/core/framework/execution_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,15 @@ class IExecutionProvider {
return InlinedVector<const Node*>();
}

/**
* Returns the underlying OrtEp instance if this IExecutionProvider wraps a plugin EP.
* Otherwise, returns a nullptr (default implementation).
* This is used to retrieve the OrtEp instance from a OrtKernelInfo instance in a plugin EP's kernel implementation.
*/
virtual const OrtEp* GetOrtEp() const {
return nullptr;
}

private:
const std::string type_;

Expand Down
71 changes: 65 additions & 6 deletions include/onnxruntime/core/session/onnxruntime_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -4204,7 +4204,7 @@ struct OrtApi {
* If `out` is nullptr, the value of `size` is set to the size of the name
* string (including null-terminator), and a success status is returned.
*
* If the `size` parameter is greater than or equal to the name string's size,
* If the `size` parameter is greater than or equal to the name string's size and `out` is not nullptr,
* the value of `size` is set to the true size of the string (including null-terminator),
* the provided memory is filled with the string's contents, and a success status is returned.
*
Expand All @@ -4220,7 +4220,7 @@ struct OrtApi {
* \snippet{doc} snippets.dox OrtStatus Return Value
* \since Version 1.14
*/
ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
ORT_API2_STATUS(KernelInfo_GetInputName, _In_ const OrtKernelInfo* info, size_t index, _Out_opt_ char* out,
_Inout_ size_t* size);

/** \brief Get the name of a ::OrtKernelInfo's output.
Expand All @@ -4231,7 +4231,7 @@ struct OrtApi {
* If `out` is nullptr, the value of `size` is set to the size of the name
* string (including null-terminator), and a success status is returned.
*
* If the `size` parameter is greater than or equal to the name string's size,
* If the `size` parameter is greater than or equal to the name string's size and `out` is not nullptr,
* the value of `size` is set to the true size of the string (including null-terminator),
* the provided memory is filled with the string's contents, and a success status is returned.
*
Expand All @@ -4248,7 +4248,7 @@ struct OrtApi {
* \snippet{doc} snippets.dox OrtStatus Return Value
* \since Version 1.14
*/
ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_ char* out,
ORT_API2_STATUS(KernelInfo_GetOutputName, _In_ const OrtKernelInfo* info, size_t index, _Out_opt_ char* out,
_Inout_ size_t* size);

/** \brief Get the type information for a ::OrtKernelInfo's input.
Expand Down Expand Up @@ -4428,7 +4428,7 @@ struct OrtApi {
* If `out` is nullptr, the value of `size` is set to the size of the name
* string (including null-terminator), and a success status is returned.
*
* If the `size` parameter is greater than or equal to the name string's size,
* If the `size` parameter is greater than or equal to the name string's size and `out` is not nullptr,
* the value of `size` is set to the true size of the string (including null-terminator),
* the provided memory is filled with the string's contents, and a success status is returned.
*
Expand All @@ -4445,7 +4445,7 @@ struct OrtApi {
* \snippet{doc} snippets.dox OrtStatus Return Value
* \since Version 1.15
*/
ORT_API2_STATUS(KernelInfo_GetNodeName, _In_ const OrtKernelInfo* info, _Out_ char* out, _Inout_ size_t* size);
ORT_API2_STATUS(KernelInfo_GetNodeName, _In_ const OrtKernelInfo* info, _Out_opt_ char* out, _Inout_ size_t* size);

/** \brief Get the session logger from ::OrtKernelInfo.
*
Expand Down Expand Up @@ -6608,6 +6608,65 @@ struct OrtApi {
* \since Version 1.24
*/
ORT_API2_STATUS(KernelInfo_GetConfigEntries, _In_ const OrtKernelInfo* info, _Outptr_ OrtKeyValuePairs** out);

/** \brief Get the graph node's operator domain from ::OrtKernelInfo.
*
* If `out` is nullptr, the value of `size` is set to the size of the operator domain
* string (including null-terminator), and a success status is returned.
*
* If the `size` parameter is greater than or equal to the string's size and `out` is not nullptr,
* the value of `size` is set to the true size of the string (including null-terminator),
* the provided memory is filled with the string's contents, and a success status is returned.
*
* If the `size` parameter is less than the actual string's size and `out`
* is not nullptr, the value of `size` is set to the true size of the string
* and a failure status with error code ORT_INVALID_ARGUMENT is returned.
*
* \param[in] info An instance of ::OrtKernelInfo.
* \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the
* operator domain.
* \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
*
* \snippet{doc} snippets.dox OrtStatus Return Value
* \since Version 1.24
*/
ORT_API2_STATUS(KernelInfo_GetOperatorDomain, _In_ const OrtKernelInfo* info, _Out_opt_ char* out,
_Inout_ size_t* size);

/** \brief Get the graph node's operator type from ::OrtKernelInfo.
*
* If `out` is nullptr, the value of `size` is set to the size of the operator type
* string (including null-terminator), and a success status is returned.
*
* If the `size` parameter is greater than or equal to the string's size and `out` is not nullptr,
* the value of `size` is set to the true size of the string (including null-terminator),
* the provided memory is filled with the string's contents, and a success status is returned.
*
* If the `size` parameter is less than the actual string's size and `out`
* is not nullptr, the value of `size` is set to the true size of the string
* and a failure status with error code ORT_INVALID_ARGUMENT is returned.
*
* \param[in] info An instance of ::OrtKernelInfo.
* \param[out] out Memory location into which to write the UTF-8 null-terminated string representing the
* operator type.
* \param[in,out] size Pointer to the size of the `out` buffer. See above comments for details.
*
* \snippet{doc} snippets.dox OrtStatus Return Value
* \since Version 1.24
*/
ORT_API2_STATUS(KernelInfo_GetOperatorType, _In_ const OrtKernelInfo* info, _Out_opt_ char* out,
_Inout_ size_t* size);

/** \brief Get the opset version in which the given node's operator type was first defined from ::OrtKernelInfo.
*
* \param[in] info An instance of ::OrtKernelInfo.
* \param[out] since_version The opset version in which the node's operator type was first defined.
*
* \snippet{doc} snippets.dox OrtStatus Return Value
* \since Version 1.24
*/
ORT_API2_STATUS(KernelInfo_GetOperatorSinceVersion, _In_ const OrtKernelInfo* info,
_Out_ int* since_version);
};

/*
Expand Down
5 changes: 5 additions & 0 deletions include/onnxruntime/core/session/onnxruntime_cxx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,11 @@ struct KernelInfoImpl : Base<T> {
Logger GetLogger() const;

KeyValuePairs GetConfigEntries() const;

std::string GetOperatorDomain() const; ///< Wraps OrtApi::KernelInfo_GetOperatorDomain
std::string GetOperatorType() const; ///< Wraps OrtApi::KernelInfo_GetOperatorType
int GetOperatorSinceVersion() const; ///< Wraps OrtApi::KernelInfo_GetOperatorSinceVersion
const OrtEp* GetEp() const; ///< Wraps OrtEpApi::KernelInfo_GetEp
};

} // namespace detail
Expand Down
44 changes: 44 additions & 0 deletions include/onnxruntime/core/session/onnxruntime_cxx_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -2842,6 +2842,50 @@ inline KeyValuePairs KernelInfoImpl<T>::GetConfigEntries() const {
return KeyValuePairs{out};
}

template <typename T>
inline std::string KernelInfoImpl<T>::GetOperatorDomain() const {
size_t size = 0;

// Feed nullptr for the data buffer to query the true size of the string value
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorDomain(this->p_, nullptr, &size));

std::string out;
out.resize(size);
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorDomain(this->p_, &out[0], &size));
out.resize(size - 1); // remove the terminating character '\0'

return out;
}

template <typename T>
inline std::string KernelInfoImpl<T>::GetOperatorType() const {
size_t size = 0;

// Feed nullptr for the data buffer to query the true size of the string value
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorType(this->p_, nullptr, &size));

std::string out;
out.resize(size);
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorType(this->p_, &out[0], &size));
out.resize(size - 1); // remove the terminating character '\0'

return out;
}

template <typename T>
inline int KernelInfoImpl<T>::GetOperatorSinceVersion() const {
int out = 0;
Ort::ThrowOnError(GetApi().KernelInfo_GetOperatorSinceVersion(this->p_, &out));
return out;
}

template <typename T>
inline const OrtEp* KernelInfoImpl<T>::GetEp() const {
const OrtEp* ep = nullptr;
Ort::ThrowOnError(GetEpApi().KernelInfo_GetEp(this->p_, &ep));
return ep;
}

inline void attr_utils::GetAttr(const OrtKernelInfo* p, const char* name, float& out) {
Ort::ThrowOnError(GetApi().KernelInfoGetAttribute_float(p, name, &out));
}
Expand Down
12 changes: 12 additions & 0 deletions include/onnxruntime/core/session/onnxruntime_ep_c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,18 @@ struct OrtEpApi {
_In_ OrtSharedPrePackedWeightCache* prepacked_weight_cache,
_In_reads_(num_buffers) void** buffer_data_ptrs, _In_reads_(num_buffers) size_t* buffer_data_sizes,
_In_ size_t num_buffers);

/** \brief Get the OrtEp instance to which the node is assigned from the OrtKernelInfo.
*
* \note Used within OrtKernelImpl implementations to obtain a reference to the OrtEp.
*
* \param[in] info The ::OrtKernelInfo instance.
* \param[out] ep Output parameter set to the OrtEp instance associated with the OrtKernelInfo.
*
* \snippet{doc} snippets.dox OrtStatus Return Value
* \since Version 1.24
*/
ORT_API2_STATUS(KernelInfo_GetEp, _In_ const OrtKernelInfo* info, _Outptr_ const OrtEp** ep);
};

/**
Expand Down
Loading
Loading