Skip to content
Open
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
35 changes: 15 additions & 20 deletions onnxruntime/core/providers/vitisai/imp/global_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -593,25 +593,17 @@
ExternalEpLibaray(const std::string& libray_name) : libray_name_{libray_name} {
Ensure();
}
onnxruntime::Provider* (*GetProvider)();
onnxruntime::Provider* (*get_provider_api)();

void Ensure() {
if (handle_)
return;
auto& env = Provider_GetHost()->Env__Default();
#ifdef _WIN32
// this dll is already linked to the executable, normally a test program
if (!handle_) {
// First try loading with full path
auto library_filename = PathString(libray_name_.c_str());
auto module_relative_full_path = env.GeRuntimePath() + PathString(LIBRARY_PREFIX ORT_TSTR("onnxruntime_vitisai_ep") LIBRARY_EXTENSION);
ORT_THROW_IF_ERROR(env.LoadDynamicLibrary(module_relative_full_path, true, &handle_));
}
#else
auto full_path = env.GetRuntimePath() + PathString(LIBRARY_PREFIX ORT_TSTR("onnxruntime_vitisai_ep") LIBRARY_EXTENSION);
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_));
#endif
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "GetProvider", (void**)&GetProvider));
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "GetProvider", (void**)&get_provider_api));

Check warning on line 605 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:605: Using C-style cast. Use reinterpret_cast<void**>(...) instead [readability/casting] [4]
get_provider_api()->Initialize();
}
void Clear() {
if (handle_) {
Expand All @@ -626,16 +618,19 @@
std::string libray_name_;
void* handle_{};
};
static std::unordered_map<std::string, ExternalEpLibaray> g_external_ep_libaries;
static std::unordered_map<std::string, std::unique_ptr<ExternalEpLibaray>> g_external_ep_libaries;

std::unique_ptr<IExecutionProvider>
CreateExecutionProviderFromAnotherEp(const std::string& lib,
std::unique_ptr<onnxruntime::IExecutionProvider>
CreateExecutionProviderFromAnotherEp(const std::string& lib, const OrtSessionOptions& session_options,
std::unordered_map<std::string, std::string>& provider_options) {
auto it = g_external_ep_libaries.find(lib);
if (it == g_external_ep_libaries.end()) {
it = g_external_ep_libaries.emplace(lib).first;
it = g_external_ep_libaries.emplace(lib, std::make_unique<ExternalEpLibaray>(lib)).first;
}
auto ep_factory= it->second->GetProvider()->CreateExecutionProviderFactory(static_cast<void*>(&provider_options));
auto ep = ep_factory->CreateProvider();
return ep;
auto get_provider_func = it->second->get_provider_api;
auto provider = get_provider_func();
std::unique_ptr<onnxruntime::IExecutionProvider> ret;

Check warning on line 632 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:632: Add #include <memory> for unique_ptr<> [build/include_what_you_use] [4]
std::ignore = provider->CreateIExecutionProvider(nullptr, nullptr, 0, const_cast<onnxruntime::ProviderOptions&>(provider_options), session_options, *((OrtLogger*)nullptr), ret);

Check warning on line 633 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:633: Using C-style cast. Use reinterpret_cast<OrtLogger*>(...) instead [readability/casting] [4]

return ret;
}
6 changes: 4 additions & 2 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,6 +42,6 @@
void profiler_collect(
std::vector<EventInfo>& api_events,
std::vector<EventInfo>& kernel_events);
std::unique_ptr<IExecutionProvider>
CreateExecutionProviderFromAnotherEp(const std::string& lib,
std::unique_ptr<onnxruntime::IExecutionProvider>
CreateExecutionProviderFromAnotherEp(const std::string& lib, const OrtSessionOptions& session_options,
std::unordered_map<std::string, std::string>& provider_options);
17 changes: 9 additions & 8 deletions onnxruntime/core/providers/vitisai/vitisai_provider_factory.cc
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 All @@ -28,10 +27,7 @@
};

std::unique_ptr<IExecutionProvider> VitisAIProviderFactory::CreateProvider() {
auto it = info_.find("external_ep_libray");
if (it != info_.end()) {
return CreateExecutionProviderFromAnotherEp(*it, info_);
}
// can not get session options, so this api can't create anotherep
return std::make_unique<VitisAIExecutionProvider>(info_);
}

Expand Down Expand Up @@ -60,9 +56,14 @@
provider_options["ort_session_config." + key] = value;
}
}
auto it = provider_options.find("external_ep_libray");

auto it = provider_options.find("llm"); // to be finalized
if (it != provider_options.end() && info_.find("external_ep_library") == info_.end()) {
provider_options["external_ep_libray"] = "onnxruntime_providers_ryzenai";
}
it = provider_options.find("external_ep_libray");
if (it != provider_options.end()) {
return CreateExecutionProviderFromAnotherEp(*it, provider_options);
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));
Expand All @@ -88,7 +89,7 @@
}
};
// Get provider specific custom op domain list. Provider has the resposibility to release OrtCustomOpDomain instances it creates.
void GetCustomOpDomainList(IExecutionProviderFactory*, std::vector<OrtCustomOpDomain*>&) override {};
void GetCustomOpDomainList(IExecutionProviderFactory*, std::vector<OrtCustomOpDomain*>&) override{};

Check warning on line 92 in onnxruntime/core/providers/vitisai/vitisai_provider_factory.cc

View workflow job for this annotation

GitHub Actions / Optional Lint C++

[cpplint] reported by reviewdog 🐶 Add #include <vector> for vector<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/vitisai_provider_factory.cc:92: Add #include <vector> for vector<> [build/include_what_you_use] [4]
// Called right after loading the shared library, if this throws any errors Shutdown() will be called and the library unloaded
void Initialize() override { initialize_vitisai_ep(); }
// Called right before unloading the shared library
Expand Down
Loading