Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 50 additions & 0 deletions onnxruntime/core/providers/vitisai/imp/global_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,53 @@
return &the_global_api;
}
}

struct ExternalEpLibaray {
ExternalEpLibaray(const std::string& libray_name) : libray_name_{libray_name} {

Check warning on line 616 in onnxruntime/core/providers/vitisai/imp/global_api.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Single-parameter constructors should be marked explicit. [runtime/explicit] [4] Raw Output: onnxruntime/core/providers/vitisai/imp/global_api.cc:616: Single-parameter constructors should be marked explicit. [runtime/explicit] [4]
Ensure();
}
onnxruntime::Provider* (*get_provider_api)();
void (*create_ep_factories)(void*, const OrtApiBase*, void*, OrtEpFactory**, size_t, size_t*);
void (*set_session_option)(OrtSessionOptions*);

void Ensure() {
if (handle_)
return;
auto& env = Provider_GetHost()->Env__Default();
auto library_filename = PathString(LIBRARY_PREFIX) + PathString(libray_name_.begin(), libray_name_.end()) + LIBRARY_EXTENSION;
auto full_path = env.GetRuntimePath() + library_filename;
ORT_THROW_IF_ERROR(env.LoadDynamicLibrary(full_path, true, &handle_));
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "GetProvider", (void**)&get_provider_api));

Check warning on line 630 in onnxruntime/core/providers/vitisai/imp/global_api.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Using C-style cast. Use reinterpret_cast<void**>(...) instead [readability/casting] [4] Raw Output: onnxruntime/core/providers/vitisai/imp/global_api.cc:630: Using C-style cast. Use reinterpret_cast<void**>(...) instead [readability/casting] [4]
}

void Clear() {
if (handle_) {
auto& env = Provider_GetHost()->Env__Default();
auto status = env.UnloadDynamicLibrary(handle_);
vai_assert(status.IsOK(), status.ErrorMessage());
handle_ = nullptr;
}
}

private:
std::string libray_name_;
void* handle_{};
};
static std::unordered_map<std::string, std::unique_ptr<ExternalEpLibaray>> g_external_ep_libaries;

std::unique_ptr<onnxruntime::IExecutionProvider>
CreateExecutionProviderFromAnotherEp(const std::string& lib, const OrtSessionOptions& session_options,
std::unordered_map<std::string, std::string>& provider_options) {

Check warning on line 650 in onnxruntime/core/providers/vitisai/imp/global_api.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <unordered_map> for unordered_map<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/imp/global_api.cc:650: Add #include <unordered_map> for unordered_map<> [build/include_what_you_use] [4]

Check warning on line 650 in onnxruntime/core/providers/vitisai/imp/global_api.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/imp/global_api.cc:650: Add #include <string> for string [build/include_what_you_use] [4]
auto it = g_external_ep_libaries.find(lib);
if (it == g_external_ep_libaries.end()) {
it = g_external_ep_libaries.emplace(lib, std::make_unique<ExternalEpLibaray>(lib)).first;
}
auto ep_lib = it->second.get();
auto get_provider_func = ep_lib->get_provider_api;
auto provider = get_provider_func();
std::unique_ptr<onnxruntime::IExecutionProvider> ret;

Check warning on line 658 in onnxruntime/core/providers/vitisai/imp/global_api.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <memory> for unique_ptr<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/imp/global_api.cc:658: Add #include <memory> for unique_ptr<> [build/include_what_you_use] [4]
provider->Initialize();
std::ignore = provider->CreateIExecutionProvider(nullptr, nullptr, 0, const_cast<onnxruntime::ProviderOptions&>(provider_options), session_options, *((OrtLogger*)nullptr), ret);

Check warning on line 660 in onnxruntime/core/providers/vitisai/imp/global_api.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Using C-style cast. Use reinterpret_cast<OrtLogger*>(...) instead [readability/casting] [4] Raw Output: onnxruntime/core/providers/vitisai/imp/global_api.cc:660: Using C-style cast. Use reinterpret_cast<OrtLogger*>(...) instead [readability/casting] [4]

return ret;
}
5 changes: 5 additions & 0 deletions onnxruntime/core/providers/vitisai/include/vaip/global_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#define ORT_API_MANUAL_INIT
#include "core/session/onnxruntime_cxx_api.h"
#include "core/framework/provider_options.h"
#include "core/framework/execution_provider.h"
#include "vaip/my_ort.h"
#include "vaip/dll_safe.h"
#include "vaip/custom_op.h"
#include <optional>
#include <memory>

Check warning on line 14 in onnxruntime/core/providers/vitisai/include/vaip/global_api.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Found C++ system header after other header. Should be: global_api.h, c system, c++ system, other. [build/include_order] [4] Raw Output: onnxruntime/core/providers/vitisai/include/vaip/global_api.h:14: Found C++ system header after other header. Should be: global_api.h, c system, c++ system, other. [build/include_order] [4]
void initialize_vitisai_ep();
void deinitialize_vitisai_ep();
vaip_core::DllSafe<std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>> compile_onnx_model(const onnxruntime::GraphViewer& graph_viewer, const onnxruntime::logging::Logger& logger, const onnxruntime::ProviderOptions& options);
Expand Down Expand Up @@ -40,3 +42,6 @@
void profiler_collect(
std::vector<EventInfo>& api_events,
std::vector<EventInfo>& kernel_events);
std::unique_ptr<onnxruntime::IExecutionProvider>
CreateExecutionProviderFromAnotherEp(const std::string& lib, const OrtSessionOptions& session_options,
std::unordered_map<std::string, std::string>& provider_options);

Check warning on line 47 in onnxruntime/core/providers/vitisai/include/vaip/global_api.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <unordered_map> for unordered_map<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/include/vaip/global_api.h:47: Add #include <unordered_map> for unordered_map<> [build/include_what_you_use] [4]

Check warning on line 47 in onnxruntime/core/providers/vitisai/include/vaip/global_api.h

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <string> for string [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/include/vaip/global_api.h:47: Add #include <string> for string [build/include_what_you_use] [4]
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <cctype>
#include <unordered_map>
#include <string>

#include "vaip/global_api.h"
#include "./vitisai_execution_provider.h"
#include "core/framework/execution_provider.h"
Expand Down Expand Up @@ -57,6 +56,10 @@ std::unique_ptr<IExecutionProvider> VitisAIProviderFactory::CreateProvider(const
}
}

auto it = provider_options.find("external_ep_libray");
if (it != provider_options.end()) {
return CreateExecutionProviderFromAnotherEp(it->second, session_options, provider_options);
}
auto ep_instance = std::make_unique<VitisAIExecutionProvider>(provider_options);
ep_instance->SetLogger(reinterpret_cast<const logging::Logger*>(&session_logger));
return ep_instance;
Expand Down
Loading