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
47 changes: 47 additions & 0 deletions onnxruntime/core/providers/vitisai/imp/global_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@
void (*profiler_collect)(
std::vector<EventInfo>& api_events,
std::vector<EventInfo>& kernel_events);
const char* (*get_compiled_model_compatibility_info)(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>* eps,
const void* graph_viewer) = nullptr;
int (*validate_compiled_model_compatibility_info)(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>* eps,
const char* compatibility_info,
const void* const* devices,
size_t num_devices,
int* model_compatibility) = nullptr;
void (*deinitialize_onnxruntime_vitisai_ep)();
void Ensure() {
if (handle_)
Expand Down Expand Up @@ -137,6 +146,8 @@
std::ignore = env.GetSymbolFromLibrary(handle_, "vaip_get_version",
(void**)&vaip_get_version);
std::ignore = env.GetSymbolFromLibrary(handle_, "profiler_collect", (void**)&profiler_collect);
std::ignore = env.GetSymbolFromLibrary(handle_, "get_compiled_model_compatibility_info", (void**)&get_compiled_model_compatibility_info);

Check warning on line 149 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:149: Using C-style cast. Use reinterpret_cast<void**>(...) instead [readability/casting] [4]
std::ignore = env.GetSymbolFromLibrary(handle_, "validate_compiled_model_compatibility_info", (void**)&validate_compiled_model_compatibility_info);

Check warning on line 150 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:150: Using C-style cast. Use reinterpret_cast<void**>(...) instead [readability/casting] [4]
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "create_ep_context_nodes", (void**)&create_ep_context_nodes));
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "vitisai_ep_on_run_start", (void**)&vitisai_ep_on_run_start));
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "vitisai_ep_set_ep_dynamic_options", (void**)&vitisai_ep_set_ep_dynamic_options));
Expand Down Expand Up @@ -179,6 +190,42 @@
}
}

std::string get_compiled_model_compatibility_info(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
const onnxruntime::GraphViewer& graph_viewer) {
std::string result_str;
if (s_library_vitisaiep.get_compiled_model_compatibility_info) {
const char* result = s_library_vitisaiep.get_compiled_model_compatibility_info(&eps, &graph_viewer);
if (result && result[0] != '\0') {
result_str = result;
}
}
return result_str;
}

Status validate_compiled_model_compatibility_info(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
const std::string& compatibility_info,
OrtCompiledModelCompatibility& model_compatibility) {
if (s_library_vitisaiep.validate_compiled_model_compatibility_info) {
// Call with nullptr devices since ORT provider doesn't have device information
int ret_model_compatibility = 0;
int status = s_library_vitisaiep.validate_compiled_model_compatibility_info(
&eps,
compatibility_info.c_str(),
nullptr, // devices - not available
0, // num_devices
&ret_model_compatibility);
if (status == 0) {
model_compatibility = static_cast<OrtCompiledModelCompatibility>(ret_model_compatibility);
return Status::OK();
}
}
// Default to NOT_APPLICABLE
model_compatibility = OrtCompiledModelCompatibility_EP_NOT_APPLICABLE;
return Status::OK();
}

void change_status_with_error(void* status_ptr, int error_code, const char* error_msg) {
auto status = reinterpret_cast<Status*>(status_ptr);
*status = Status(onnxruntime::common::ONNXRUNTIME, error_code, error_msg);
Expand Down
17 changes: 17 additions & 0 deletions onnxruntime/core/providers/vitisai/include/vaip/global_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,20 @@
std::unique_ptr<onnxruntime::IExecutionProvider>
CreateExecutionProviderFromAnotherEp(const std::string& lib, const OrtSessionOptions& session_options,
std::unordered_map<std::string, std::string>& provider_options);

/**
* Get compiled model compatibility information from execution providers.
* Returns a JSON string containing compatibility metadata, or an empty string if unavailable.
*/
std::string get_compiled_model_compatibility_info(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,
const onnxruntime::GraphViewer& graph_viewer);

/**
* Validate compiled model compatibility information against current runtime environment.
* The model_compatibility is output parameter for the compatibility result.
*/
Status validate_compiled_model_compatibility_info(
const std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>& eps,

Check warning on line 62 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 <vector> for vector<> [build/include_what_you_use] [4] Raw Output: onnxruntime/core/providers/vitisai/include/vaip/global_api.h:62: Add #include <vector> for vector<> [build/include_what_you_use] [4]
const std::string& compatibility_info,

Check warning on line 63 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:63: Add #include <string> for string [build/include_what_you_use] [4]
OrtCompiledModelCompatibility& model_compatibility);
18 changes: 18 additions & 0 deletions onnxruntime/core/providers/vitisai/vitisai_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@
return std::make_unique<profiling::VitisaiProfiler>();
}

std::string VitisAIExecutionProvider::GetCompiledModelCompatibilityInfo(
const onnxruntime::GraphViewer& graph_viewer) const {
if (!execution_providers_) {
return {};
}
return get_compiled_model_compatibility_info(**execution_providers_, graph_viewer);
}

common::Status VitisAIExecutionProvider::ValidateCompiledModelCompatibilityInfo(
const std::string& compatibility_info,

Check warning on line 157 in onnxruntime/core/providers/vitisai/vitisai_execution_provider.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/vitisai_execution_provider.cc:157: Add #include <string> for string [build/include_what_you_use] [4]
OrtCompiledModelCompatibility& model_compatibility) const {
if (!execution_providers_) {
model_compatibility = OrtCompiledModelCompatibility_EP_NOT_APPLICABLE;
return Status::OK();
}
return validate_compiled_model_compatibility_info(**execution_providers_, compatibility_info, model_compatibility);
}

std::vector<AllocatorPtr> VitisAIExecutionProvider::CreatePreferredAllocators() {
std::vector<AllocatorPtr> result;
// We do not want arena for 4k alignment, as it would not respect alignment.
Expand Down
14 changes: 14 additions & 0 deletions onnxruntime/core/providers/vitisai/vitisai_execution_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ class VitisAIExecutionProvider : public IExecutionProvider {

std::vector<AllocatorPtr> CreatePreferredAllocators() override;

/**
* Get compiled model compatibility information.
* This method collects compatibility info from all vaip_core execution providers
* and returns it as a JSON string.
*/
std::string GetCompiledModelCompatibilityInfo(const onnxruntime::GraphViewer& graph_viewer) const override;

/**
* Validate compiled model compatibility information.
* This method validates the compatibility info against the current runtime environment.
*/
common::Status ValidateCompiledModelCompatibilityInfo(const std::string& compatibility_info,
OrtCompiledModelCompatibility& model_compatibility) const override;

private:
using my_ep_t = vaip_core::DllSafe<std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>>;
using my_ep_uptr_t = std::shared_ptr<my_ep_t>;
Expand Down
Loading