-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[WIP] Out-Tree EP feature #21450
base: main
Are you sure you want to change the base?
[WIP] Out-Tree EP feature #21450
Changes from 3 commits
0e6a80c
c30a639
7bfe57e
8e7d28d
808bfc3
49e396c
e790105
92f529d
3d83ed1
e29499a
f3678c4
ac5ae0a
0cc78e8
740a687
dad6397
94e9cf7
8698517
3d5d2bf
1f10c28
5e46d0f
85c168d
7bdb36a
7d915b7
4aea94b
865a17f
2811541
c97b19f
36f97b5
2fc7aac
4ad6993
53c736f
5fcb972
c3bb437
d1c657c
3efac97
766fec9
ea2465c
76a9305
330cdb6
6fd50f0
681585f
7db20cb
ff782e0
1d7b2df
a407944
f871b25
e84f00c
5b2de22
b1f8e2a
7acaaab
d150a03
da5b6eb
d280e59
cbe98e7
1529059
fa549f8
a28ad38
aa49805
bc65613
a1a3eea
0fe5f01
6bae1b9
ab75d98
c5510f2
08e3f20
b0b3123
9dbb0b1
5a59803
999e7fd
084f735
2b1cfdf
e337d8f
afe92e1
63f8774
bf359a1
c267ea5
72afdc4
6822206
c8ddc73
e6be85e
ce76175
fefbe27
ce6630c
dc6674b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
Check warning Code scanning / lintrunner CLANGFORMAT/format Warning
See https://clang.llvm.org/docs/ClangFormat.html.
Run lintrunner -a to apply this patch. |
||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include "core/session/onnxruntime_c_api.h" | ||
|
||
namespace onnxruntime { | ||
class ExecutionProviderAdapter : public IExecutionProvider { | ||
public: | ||
Check warning on line 9 in onnxruntime/core/framework/provider_adapter.h GitHub Actions / Lint C++
|
||
ExecutionProviderAdapter(OrtExecutionProvider* ep) : IExecutionProvider(ep->type), ep_impl_(ep) {} | ||
private: | ||
OrtExecutionProvider* ep_impl_; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# usage: | ||
# cd build/ | ||
# cmake -S ../ -B ./ | ||
# cmake --build ./ | ||
cmake_minimum_required(VERSION 3.26) | ||
project(TestOutTreeEp) | ||
add_executable(TestOutTreeEp test.cpp) | ||
|
||
target_include_directories(TestOutTreeEp PUBLIC "../../include/onnxruntime") | ||
target_link_libraries(TestOutTreeEp PUBLIC "/home/leca/code/onnxruntime/build/Linux/Debug/libonnxruntime.so") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "core/session/onnxruntime_c_api.h" | ||
|
||
#include <vector> | ||
|
||
inline void THROW_ON_ERROR(OrtStatus* status) { | ||
if (status != nullptr) abort(); | ||
} | ||
|
||
int main() { | ||
const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION); | ||
OrtEnv* p_env = nullptr; | ||
OrtLoggingLevel log_level = OrtLoggingLevel::ORT_LOGGING_LEVEL_INFO; | ||
THROW_ON_ERROR(g_ort->CreateEnv(log_level, "", &p_env)); | ||
THROW_ON_ERROR(g_ort->RegisterOrtExecutionProviderLibrary("/home/leca/code/onnxruntime/samples/outTreeEp/build/liboutTreeEp.so", p_env, "outTreeEp")); | ||
|
||
OrtSessionOptions* so = nullptr; | ||
THROW_ON_ERROR(g_ort->CreateSessionOptions(&so)); | ||
std::vector<const char*> keys{"int_property", "str_property"}, values{"3", "strvalue"}; | ||
THROW_ON_ERROR(g_ort->SessionOptionsAppendOrtExecutionProvider(so, "outTreeEp", keys.data(), values.data(), keys.size())); | ||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# usage: | ||
# cd build/ | ||
# cmake -S ../ -B ./ | ||
# cmake --build ./ | ||
cmake_minimum_required(VERSION 3.26) | ||
project(outTreeEp VERSION 1.0) | ||
set(CMAKE_CXX_STANDARD 17) | ||
add_library(outTreeEp SHARED out_tree_ep.cc) | ||
target_include_directories(outTreeEp PUBLIC "../../include/onnxruntime") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "out_tree_ep.h" | ||
|
||
#include <memory> | ||
namespace onnxruntime { | ||
|
||
OutTreeEpFactory::OutTreeEpFactory() { | ||
OrtExecutionProviderFactory::CreateExecutionProvider = [](OrtExecutionProviderFactory* this_, const char* const* ep_option_keys, const char* const* ep_option_values, size_t option_size) -> void* { | ||
OutTreeEpInfo info; | ||
for (size_t i = 0; i < option_size; i++) { | ||
if (!strcmp(ep_option_keys[i], "int_property")) info.int_property = std::atoi(ep_option_values[i]); | ||
else if (!strcmp(ep_option_keys[i], "str_property")) info.str_property = ep_option_values[i]; | ||
// TODO(leca): else throw | ||
} | ||
std::unique_ptr<OutTreeEp> ret = std::make_unique<OutTreeEp>("outTreeEp", std::move(info)); | ||
return ret.release(); | ||
}; | ||
} | ||
|
||
} | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
OrtExecutionProviderFactory* RegisterCustomEp() { | ||
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. return Status instead #Resolved 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. Do we have to do this? This function will new a factory object by invoking its constructor which has no return type |
||
std::unique_ptr<onnxruntime::OutTreeEpFactory> ret = std::make_unique<onnxruntime::OutTreeEpFactory>(); | ||
return ret.release(); | ||
} | ||
#ifdef __cplusplus | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
Check warning Code scanning / lintrunner CLANGFORMAT/format Warning
See https://clang.llvm.org/docs/ClangFormat.html.
Run lintrunner -a to apply this patch. |
||
#include "core/session/onnxruntime_c_api.h" | ||
#include <string> | ||
|
||
#ifdef _WIN32 | ||
#define EXPORT_API __declspec(dllexport) | ||
#else | ||
#define EXPORT_API | ||
#endif | ||
|
||
namespace onnxruntime { | ||
|
||
struct OutTreeEpInfo { | ||
int int_property; | ||
std::string str_property; | ||
}; | ||
|
||
struct OutTreeEp : public OrtExecutionProvider { | ||
OutTreeEp(const char* ep_type, const OutTreeEpInfo& ep_info) : info(ep_info) { type = ep_type; } | ||
OutTreeEpInfo info; | ||
}; | ||
|
||
struct OutTreeEpFactory : public OrtExecutionProviderFactory { | ||
OutTreeEpFactory(); | ||
}; | ||
} | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
EXPORT_API OrtExecutionProviderFactory* RegisterCustomEp(); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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.
Given SessionOptionsAppendOrtExecutionProvider allows the user to register the instance of the EP, when do we need this factory? #Resolved
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.
There is another C API RegisterOrtExecutionProviderLibrary which will load the shared library, create plugin EP factory and save it in the Environment.
Please see the implementation of RegisterOrtExecutionProviderLibrary and the usage in test.cpp as examples
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.
Changed to a new Name. Hope it is more clear now.