mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-05-23 22:13:38 +00:00
DirectML.dll load fails when executable path contains Non-English characters (#9229)
* enable unicode dml * add wide string L prefix * Add Fail Fast back Co-authored-by: Sheil Kumar <sheilk@microsoft.com>
This commit is contained in:
parent
634bb5ede0
commit
c6cb49c5a1
1 changed files with 12 additions and 17 deletions
|
|
@ -22,30 +22,25 @@ namespace winmla = Windows::AI::MachineLearning::Adapter;
|
|||
|
||||
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
static std::string CurrentModulePath() {
|
||||
char path[MAX_PATH];
|
||||
FAIL_FAST_IF(0 == GetModuleFileNameA((HINSTANCE)&__ImageBase, path, _countof(path)));
|
||||
static std::wstring CurrentModulePath() {
|
||||
WCHAR path[MAX_PATH];
|
||||
FAIL_FAST_IF(0 == GetModuleFileNameW((HINSTANCE)&__ImageBase, path, _countof(path)));
|
||||
|
||||
char absolute_path[MAX_PATH];
|
||||
char* name;
|
||||
FAIL_FAST_IF(0 == GetFullPathNameA(path, _countof(path), absolute_path, &name));
|
||||
WCHAR absolute_path[MAX_PATH];
|
||||
WCHAR* name;
|
||||
FAIL_FAST_IF(0 == GetFullPathNameW(path, _countof(path), absolute_path, &name));
|
||||
|
||||
auto idx = std::distance(absolute_path, name);
|
||||
auto out_path = std::string(absolute_path);
|
||||
out_path.resize(idx);
|
||||
auto idx = std::distance(absolute_path, name);
|
||||
auto out_path = std::wstring(absolute_path);
|
||||
out_path.resize(idx);
|
||||
|
||||
return out_path;
|
||||
return out_path;
|
||||
}
|
||||
|
||||
Microsoft::WRL::ComPtr<IDMLDevice> CreateDmlDevice(ID3D12Device* d3d12Device) {
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
|
||||
// Dynamically load DML to avoid WinML taking a static dependency on DirectML.dll
|
||||
auto directml_dll = CurrentModulePath() + "\\DirectML.dll";
|
||||
wil::unique_hmodule dmlDll(LoadLibraryExA(directml_dll.c_str(), nullptr, 0));
|
||||
#elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PC_APP)
|
||||
wil::unique_hmodule dmlDll(LoadPackagedLibrary(L"DirectML.dll", 0));
|
||||
#endif
|
||||
|
||||
auto directml_dll = CurrentModulePath() + L"DirectML.dll";
|
||||
wil::unique_hmodule dmlDll(LoadLibraryExW(directml_dll.c_str(), nullptr, 0));
|
||||
THROW_LAST_ERROR_IF(!dmlDll);
|
||||
|
||||
auto dmlCreateDevice1Fn = reinterpret_cast<decltype(&DMLCreateDevice1)>(
|
||||
|
|
|
|||
Loading…
Reference in a new issue