From 222fd08f20765103e3bfbaf5de07b7f25373d516 Mon Sep 17 00:00:00 2001 From: Sheil Kumar Date: Sat, 25 Jul 2020 21:29:46 -0700 Subject: [PATCH] DirectML.dll is loaded via LoadLibraryW but should use LoadLibraryExA (#4616) * create dml device via loadlibraryexa * add build_INBOX flag to adapter Co-authored-by: Sheil Kumar --- cmake/winml.cmake | 4 ++++ winml/adapter/winml_adapter_dml.cpp | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 0411ac4aee..26bb827911 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -254,6 +254,10 @@ endif() add_library(winml_adapter ${winml_adapter_files}) +if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows") + target_compile_definitions(winml_adapter PRIVATE "BUILD_INBOX=1") +endif() + # wil requires C++17 set_target_properties(winml_adapter PROPERTIES CXX_STANDARD 17) set_target_properties(winml_adapter PROPERTIES CXX_STANDARD_REQUIRED ON) diff --git a/winml/adapter/winml_adapter_dml.cpp b/winml/adapter/winml_adapter_dml.cpp index 09345b42ef..1c44c96503 100644 --- a/winml/adapter/winml_adapter_dml.cpp +++ b/winml/adapter/winml_adapter_dml.cpp @@ -13,14 +13,20 @@ #include "core/session/abi_session_options_impl.h" #include "core/providers/dml/dml_provider_factory.h" #include "core/providers/dml/DmlExecutionProvider/inc/DmlExecutionProvider.h" +#include #endif // USE_DML namespace winmla = Windows::AI::MachineLearning::Adapter; #ifdef USE_DML Microsoft::WRL::ComPtr CreateDmlDevice(ID3D12Device* d3d12Device) { + DWORD flags = 0; +#ifdef BUILD_INBOX + flags = LOAD_LIBRARY_SEARCH_SYSTEM32; +#endif + // Dynamically load DML to avoid WinML taking a static dependency on DirectML.dll - wil::unique_hmodule dmlDll(LoadLibraryW(L"DirectML.dll")); + wil::unique_hmodule dmlDll(LoadLibraryExA("DirectML.dll", nullptr, flags)); THROW_LAST_ERROR_IF(!dmlDll); auto dmlCreateDevice1Fn = reinterpret_cast(