[VitisAI] Fix duplicate onnxruntime_vitisai_ep.dll loaded (#20968)

### Description
<!-- Describe your changes. -->
Check if the onnxruntime_vitisai_ep.dll already linked. If yes, don't
use dlopen.

### Motivation and Context
<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
If a executable is linked directly with onnxruntime_vitisai_ep.dll.
dlopen would cause two DLL with same content loaded. So we have to check
that case.
Linux can detect such situation automatically.
This commit is contained in:
Yueqing Zhang 2024-06-14 06:17:07 +08:00 committed by GitHub
parent 8edec47c6c
commit f5b6f6dc26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -57,8 +57,17 @@ struct OrtVitisAIEpAPI {
if (handle_)
return;
auto& env = Provider_GetHost()->Env__Default();
#ifdef _WIN32
// this dll is already linked to the executable, normally a test program
handle_ = reinterpret_cast<void*>(GetModuleHandle(TEXT("onnxruntime_vitisai_ep.dll")));
if (!handle_) {
auto full_path = env.GetRuntimePath() + PathString(LIBRARY_PREFIX ORT_TSTR("onnxruntime_vitisai_ep") LIBRARY_EXTENSION);
ORT_THROW_IF_ERROR(env.LoadDynamicLibrary(full_path, true, &handle_));
}
#else
auto full_path = env.GetRuntimePath() + PathString(LIBRARY_PREFIX ORT_TSTR("onnxruntime_vitisai_ep") LIBRARY_EXTENSION);
ORT_THROW_IF_ERROR(env.LoadDynamicLibrary(full_path, true, &handle_));
#endif
ORT_THROW_IF_ERROR(env.GetSymbolFromLibrary(handle_, "initialize_onnxruntime_vitisai_ep", (void**)&initialize_onnxruntime_vitisai_ep));
auto status1 = env.GetSymbolFromLibrary(handle_, "compile_onnx_model_vitisai_ep_with_options", (void**)&compile_onnx_model_with_options);
auto status2 = env.GetSymbolFromLibrary(handle_, "compile_onnx_model_vitisai_ep", (void**)&compile_onnx_model_3);