Skip to content

Commit

Permalink
[VitisAI] Add Version Check. Requsted by Microsoft (microsoft#20347)
Browse files Browse the repository at this point in the history
### Description
<!-- Describe your changes. -->
Add version for onnxruntime_providers_vitisai.dll. So, the
onnxruntime_vitisai_ep.dll can check if the version is compatible.
To make sure the old onnxruntime_vitisai_ep.dll still work, we would
offset the api struct by version field.


### Motivation and Context
<!-- - Why is this change required? What problem does it solve? -->
This is the direct request from Microsoft. The following is the problem
we try to solve:

How would you describe the dependency between (a)
onnxruntime_vitisai_ep.dll and (b) onnxruntime_providers_vitisai.dll?
E.g. for each version of (a) there is a minimum required version of (b),
or for each version of (b) there is minimum required version of (a).

Please note that in practice we won't be able to use the exact version
of ORT/EP that you tested against (because we might need to update ORT
for other reasons), but we might be able to accommodate some version
constraints that you specify. As we approach shipping, we'll lock the
version of ORT/EP to allow for stabilization and more detailed testing
(and work with you if it needs to be updated).
  • Loading branch information
BoarQing authored Apr 19, 2024
1 parent 1256962 commit 9001c69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion onnxruntime/core/providers/vitisai/imp/global_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct OrtVitisAIEpAPI {
const char* json_config);
std::vector<std::unique_ptr<vaip_core::ExecutionProvider>>* (*compile_onnx_model_with_options)(
const std::string& model_path, const onnxruntime::Graph& graph, const onnxruntime::ProviderOptions& options);
uint32_t (*vaip_get_version)();
void Ensure() {
if (handle_)
return;
Expand All @@ -65,6 +66,8 @@ struct OrtVitisAIEpAPI {
::onnxruntime::LogRuntimeError(0, status1, __FILE__, static_cast<const char*>(__FUNCTION__), __LINE__);
ORT_THROW(status1);
}
std::ignore = env.GetSymbolFromLibrary(handle_, "vaip_get_version",
(void**)&vaip_get_version);
}

private:
Expand Down Expand Up @@ -177,8 +180,17 @@ void initialize_vitisai_ep() {
create_kernel_registry(s_domains_vitisaiep);
}

static void set_version_info(vaip_core::OrtApiForVaip& api) {
const char* magic = "VAIP";
std::memcpy(reinterpret_cast<char*>(&api.magic), magic, sizeof(api.magic));
api.major = 1u;
api.minor = 0u;
api.patch = 0u;
}

vaip_core::OrtApiForVaip* create_org_api_hook() {
InitProviderOrtApi();
set_version_info(the_global_api);
the_global_api.host_ = Provider_GetHost();
assert(Ort::Global<void>::api_ != nullptr);
the_global_api.ort_api_ = Ort::Global<void>::api_;
Expand Down Expand Up @@ -359,5 +371,9 @@ vaip_core::OrtApiForVaip* create_org_api_hook() {
the_global_api.get_lib_id = []() -> vaip_core::DllSafe<std::string> {
return vaip_core::DllSafe(std::string(GIT_COMMIT_ID));
};
return &the_global_api;
if (!s_library_vitisaiep.vaip_get_version) {
return reinterpret_cast<vaip_core::OrtApiForVaip*>(&(the_global_api.host_));
} else {
return &the_global_api;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ struct OrtApi;
namespace vaip_core {

struct OrtApiForVaip {
uint32_t magic; // 'VAIP' or something else to make sure the following field
// are not garbage.
uint32_t major; // bump this field changes that are not backward compatible or
// that represent a change in direction for the project
uint32_t minor; // bump this field for adding new features without breaking
// existing behavior
uint32_t patch; // bump this field for fixing some bugs but not introducing
// new functionality
onnxruntime::ProviderHost* host_;
const OrtApi* ort_api_;
// model
Expand Down

0 comments on commit 9001c69

Please sign in to comment.