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 <sheilk@microsoft.com>
This commit is contained in:
Sheil Kumar 2020-07-25 21:29:46 -07:00 committed by GitHub
parent 1e67fff93c
commit 222fd08f20
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -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)

View file

@ -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 <windows.h>
#endif // USE_DML
namespace winmla = Windows::AI::MachineLearning::Adapter;
#ifdef USE_DML
Microsoft::WRL::ComPtr<IDMLDevice> 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<decltype(&DMLCreateDevice1)>(