-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[EP ABI] Initial support for kernel-based EPs #26206
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
Open
adrianlizarraga
wants to merge
34
commits into
main
Choose a base branch
from
adrianl/ep-abi-kernel-based-eps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
8c03c61
Sketch API funcs
adrianlizarraga 40d7866
Merge branch 'main' into adrianl/ep-abi-kernel-based-eps
adrianlizarraga ec46ea5
Implement more c apis
adrianlizarraga e8532a9
OpKernel class for plugin EPs
adrianlizarraga 246681c
Initialize PluginExecutionProvider's kernel registry
adrianlizarraga 6b61b91
Move files to session
adrianlizarraga 4a112fc
Add API to set kernel def I/O memory types
adrianlizarraga 0f870d0
Add C API to add type constraints to a kernel definition
adrianlizarraga 9be6923
Start implementing MemcpyFromHost kernel in example EP
adrianlizarraga 5df3fb5
Get kernel for MemcpyFromHost working for example plugin EP!
adrianlizarraga 5aade60
Moved example plugin EP's kernel stuff to different file
adrianlizarraga d159b38
Add separate utility to load OrtMLDataTypes
adrianlizarraga 8187233
Add MLDataTypes::GetTensorType()
adrianlizarraga bf92f04
Add C++ Ort::KernelDefBuilder to allow creation of macro
adrianlizarraga da14d65
Create macro for defining BuildKernelCreateInfo functions for each op
adrianlizarraga 73ae307
Move kernels to separate directory/files
adrianlizarraga fb4a6a6
Use data transfer in MemcpyFromHost and MemcpyToHost
adrianlizarraga b8867d6
Release OrtKernelCreateInfo instances if an error occurs
adrianlizarraga de8be32
Move typedef and add forward-declaration of OrtKernelImpl for gcc
adrianlizarraga dc78ec3
Merge branch 'main' into adrianl/ep-abi-kernel-based-eps
adrianlizarraga 8babb63
Apply suggestions from code review
adrianlizarraga 90bf598
Simplify with OrtKernelRegistry
adrianlizarraga 9f95589
Pass custom state to kernel creation in plugin EP
adrianlizarraga 90e4fc1
Clean up
adrianlizarraga 5f52cdc
ExampleEp: cache kernel registry in factory so it can be reused by al…
adrianlizarraga 9bfc281
Add C API to lookup a kernel from within OrtEp::GetCapability
adrianlizarraga 60ea06c
Disambiguate a compiled subgraph (of one node) from a registered kern…
adrianlizarraga 33ffd8d
Add unit test for EpGraphSupportInfo_LookUpKernel()
adrianlizarraga 31cdc82
Add missing include needed for linux ci
adrianlizarraga 93b99e6
Add KernelDef to C++ api and add basic getters
adrianlizarraga 995e25b
Add documentation comments
adrianlizarraga 0f7145f
Remove incorrect comment
adrianlizarraga f528f6f
Add missing API_IMPL_BEGIN/END macro calls
adrianlizarraga 9fbf230
Merge branch 'main' into adrianl/ep-abi-kernel-based-eps
adrianlizarraga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -644,6 +644,8 @@ ORT_DEFINE_RELEASE(ValueInfo); | |||||
|
||||||
ORT_DEFINE_RELEASE_FROM_API_STRUCT(ModelCompilationOptions, GetCompileApi); | ||||||
ORT_DEFINE_RELEASE_FROM_API_STRUCT(EpDevice, GetEpApi); | ||||||
ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDef, GetEpApi); | ||||||
ORT_DEFINE_RELEASE_FROM_API_STRUCT(KernelDefBuilder, GetEpApi); | ||||||
|
||||||
// This is defined explicitly since OrtTensorRTProviderOptionsV2 is not a C API type, | ||||||
// but the struct has V2 in its name to indicate that it is the second version of the options. | ||||||
|
@@ -3284,5 +3286,64 @@ struct Model : detail::ModelImpl<OrtModel> { | |||||
explicit Model(const std::vector<DomainOpsetPair>& opsets); | ||||||
#endif | ||||||
}; | ||||||
|
||||||
namespace detail { | ||||||
template <typename T> | ||||||
struct ConstKernelDefImpl : Base<T> { | ||||||
using B = Base<T>; | ||||||
using B::B; | ||||||
|
||||||
///< Wraps OrtEpApi::KernelDef_GetOperatorType | ||||||
const char* GetOperatorType() const; | ||||||
|
||||||
///< Wraps OrtEpApi::KernelDef_GetDomain | ||||||
const char* GetDomain() const; | ||||||
|
||||||
///< Wraps OrtEpApi::KernelDef_GetSinceVersion | ||||||
std::pair<int, int> GetSinceVersion() const; | ||||||
|
||||||
///< Wraps OrtEpApi::KernelDef_GetExecutionProvider | ||||||
const char* GetExecutionProvider() const; | ||||||
|
||||||
///< Wraps OrtEpApi::KernelDef_GetInputMemType | ||||||
OrtMemType GetInputMemType(size_t input_index) const; | ||||||
|
||||||
///< Wraps OrtEpApi::KernelDef_GetOutputMemType | ||||||
OrtMemType GetOutputMemType(size_t output_index) const; | ||||||
}; | ||||||
} // namespace detail | ||||||
|
||||||
using ConstKernelDef = detail::ConstKernelDefImpl<detail::Unowned<const OrtKernelDef>>; | ||||||
|
||||||
struct KernelDef : detail::ConstKernelDefImpl<OrtKernelDef> { | ||||||
using Base = detail::ConstKernelDefImpl<OrtKernelDef>; | ||||||
using Base::Base; | ||||||
|
||||||
explicit KernelDef(std::nullptr_t) {} | ||||||
explicit KernelDef(OrtKernelDef* p) : detail::ConstKernelDefImpl<OrtKernelDef>{p} {} | ||||||
|
||||||
ConstKernelDef GetConst() const { return ConstKernelDef{this->p_}; } | ||||||
}; | ||||||
|
||||||
/** \brief Builder for OrtKernelDef. | ||||||
* | ||||||
* Used by plugin EPs to build a kernel definition. | ||||||
*/ | ||||||
struct KernelDefBuilder : detail::Base<OrtKernelDefBuilder> { | ||||||
KernelDefBuilder(); ///< Wraps OrtEpApi::CreateKernelDefBuilder | ||||||
explicit KernelDefBuilder(std::nullptr_t) {} ///< Create an empty object, must be assigned a valid one to be used | ||||||
explicit KernelDefBuilder(OrtKernelDefBuilder* ort_kernel_def_builder); | ||||||
|
||||||
KernelDefBuilder& SetOperatorType(const char* op_type); | ||||||
KernelDefBuilder& SetDomain(const char* domain); | ||||||
KernelDefBuilder& SetSinceVersion(int since_version_start, int since_version_end = -1); | ||||||
KernelDefBuilder& SetExecutionProvider(const char* ep_name); | ||||||
KernelDefBuilder& SetInputMemType(size_t input_index, OrtMemType mem_type); | ||||||
KernelDefBuilder& SetOutputMemType(size_t output_index, OrtMemType mem_type); | ||||||
KernelDefBuilder& AddTypeConstraint(const char* arg_name, const OrtMLDataType* data_types); | ||||||
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. nit: it is one data type with this overload, right?
Suggested change
|
||||||
KernelDefBuilder& AddTypeConstraint(const char* arg_name, const std::vector<const OrtMLDataType*>& data_types); | ||||||
|
||||||
KernelDef Build(); | ||||||
}; | ||||||
} // namespace Ort | ||||||
#include "onnxruntime_cxx_inline.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If any of the information for any getters is optional, suggest returning a status
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.
The underlying C API function
OrtEpApi::KernelDef_GetExecutionProvider
returns theconst char*
directly (doesn't return a status).Sorry, I don't fully understand the comment. Is the request to make this return a status instead? What is meant by "information for any getters is optional"?
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.
This was a general comment not to be bound to throwing exceptions by default. In this case, the data is returned without error reporting.