diff --git a/cmake/winml_unittests.cmake b/cmake/winml_unittests.cmake index 012cb0af07..70198bf119 100644 --- a/cmake/winml_unittests.cmake +++ b/cmake/winml_unittests.cmake @@ -171,6 +171,9 @@ file(GLOB winml_test_common_src CONFIGURE_DEPENDS "${WINML_TEST_SRC_DIR}/common/*.cpp") add_library(winml_test_common STATIC ${winml_test_common_src}) target_compile_options(winml_test_common PRIVATE /wd5205) # workaround cppwinrt SDK bug https://github.com/microsoft/cppwinrt/issues/584 +if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows") + target_compile_definitions(winml_test_common PRIVATE "BUILD_INBOX=1") +endif() add_dependencies(winml_test_common onnx winml_api @@ -192,7 +195,7 @@ add_winml_test( SOURCES ${winml_test_api_src} ${winml_test_api_redist_only_src} LIBS winml_test_common ) -target_delayload(winml_test_api d3d11.dll dxgi.dll d3d12.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll) +target_delayload(winml_test_api dxgi.dll d3d12.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll) if (onnxruntime_USE_DML) target_delayload(winml_test_api directml.dll) endif() @@ -229,9 +232,6 @@ if(onnxruntime_RUN_MODELTEST_IN_DEBUG_MODE) target_compile_definitions(winml_test_image PUBLIC -DRUN_MODELTEST_IN_DEBUG_MODE) endif() target_delayload(winml_test_image d3d12.dll api-ms-win-core-file-l1-2-2.dll api-ms-win-core-synch-l1-2-1.dll) -if (EXISTS ${dxcore_header}) - target_delayload(winml_test_image ext-ms-win-dxcore-l1-*.dll) -endif() get_winml_test_concurrency_src(${WINML_TEST_SRC_DIR} winml_test_concurrency_src) add_winml_test( diff --git a/winml/adapter/winml_adapter_dml.cpp b/winml/adapter/winml_adapter_dml.cpp index 0ca3683236..98e259dced 100644 --- a/winml/adapter/winml_adapter_dml.cpp +++ b/winml/adapter/winml_adapter_dml.cpp @@ -22,36 +22,25 @@ namespace winmla = Windows::AI::MachineLearning::Adapter; EXTERN_C IMAGE_DOS_HEADER __ImageBase; -static std::string System32Path() { - std::string system32_path; - system32_path.reserve(MAX_PATH); - auto size_system32_path = GetSystemDirectoryA(system32_path.data(), MAX_PATH); - FAIL_FAST_IF(size_system32_path == 0); - return system32_path; -} +static std::string CurrentModulePath() { + char path[MAX_PATH]; + FAIL_FAST_IF(0 == GetModuleFileNameA((HINSTANCE)&__ImageBase, path, _countof(path))); -static bool IsCurrentModuleInPath(const std::string& path) { - std::string current_module_path; - current_module_path.reserve(MAX_PATH); - auto size_module_path = GetModuleFileNameA((HINSTANCE)&__ImageBase, current_module_path.data(), MAX_PATH); - FAIL_FAST_IF(size_module_path == 0); - return _strnicmp(path.c_str(), current_module_path.c_str(), path.size()) == 0; + char absolute_path[MAX_PATH]; + char* name; + FAIL_FAST_IF(0 == GetFullPathNameA(path, _countof(path), absolute_path, &name)); + + auto idx = std::distance(absolute_path, name); + auto out_path = std::string(absolute_path); + out_path.resize(idx); + + return out_path; } Microsoft::WRL::ComPtr CreateDmlDevice(ID3D12Device* d3d12Device) { - std::string directml_dll = "directml.dll"; - DWORD flags = 0; -#ifdef BUILD_INBOX - auto system32_path = System32Path(); - if (IsCurrentModuleInPath(system32_path)) - { - flags |= LOAD_LIBRARY_SEARCH_SYSTEM32; - directml_dll = system32_path + "\\" + directml_dll; - } -#endif - // Dynamically load DML to avoid WinML taking a static dependency on DirectML.dll - wil::unique_hmodule dmlDll(LoadLibraryExA(directml_dll.c_str(), nullptr, flags)); + auto directml_dll = CurrentModulePath() + "\\directml.dll"; + wil::unique_hmodule dmlDll(LoadLibraryExA(directml_dll.c_str(), nullptr, 0)); THROW_LAST_ERROR_IF(!dmlDll); auto dmlCreateDevice1Fn = reinterpret_cast( diff --git a/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp b/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp index e3adaaf0fc..b646c2fe6c 100644 --- a/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp @@ -16,39 +16,30 @@ static bool debug_output_ = false; EXTERN_C IMAGE_DOS_HEADER __ImageBase; -static std::string System32Path() { - std::string system32_path; - system32_path.reserve(MAX_PATH); - auto size_system32_path = GetSystemDirectoryA(system32_path.data(), MAX_PATH); - FAIL_FAST_IF(size_system32_path == 0); - return system32_path; -} +static std::string CurrentModulePath() { + char path[MAX_PATH]; + FAIL_FAST_IF(0 == GetModuleFileNameA((HINSTANCE)&__ImageBase, path, _countof(path))); -static bool IsCurrentModuleInPath(const std::string& path) { - std::string current_module_path; - current_module_path.reserve(MAX_PATH); - auto size_module_path = GetModuleFileNameA((HINSTANCE)&__ImageBase, current_module_path.data(), MAX_PATH); - FAIL_FAST_IF(size_module_path == 0); - return _strnicmp(path.c_str(), current_module_path.c_str(), path.size()) == 0; + char absolute_path[MAX_PATH]; + char* name; + FAIL_FAST_IF(0 == GetFullPathNameA(path, _countof(path), absolute_path, &name)); + + auto idx = std::distance(absolute_path, name); + auto out_path = std::string(absolute_path); + out_path.resize(idx); + + return out_path; } static HRESULT GetOnnxruntimeLibrary(HMODULE& module) { #if WINAPI_FAMILY == WINAPI_FAMILY_PC_APP + // Store + Redist (note that this is never built into the inbox dll) auto out_module = LoadPackagedLibrary(L"onnxruntime.dll", 0); #else - std::string onnxruntime_dll = "onnxruntime.dll"; - DWORD flags = 0; -#ifdef BUILD_INBOX - auto system32_path = System32Path(); - if (IsCurrentModuleInPath(system32_path)) - { - flags |= LOAD_LIBRARY_SEARCH_SYSTEM32; - onnxruntime_dll = system32_path + "\\" + onnxruntime_dll; - } + auto onnxruntime_dll = CurrentModulePath() + "\\onnxruntime.dll"; + auto out_module = LoadLibraryExA(onnxruntime_dll.c_str(), nullptr, 0); #endif - auto out_module = LoadLibraryExA(onnxruntime_dll.c_str(), nullptr, flags); -#endif if (out_module == nullptr) { return HRESULT_FROM_WIN32(GetLastError()); } diff --git a/winml/lib/Common/CommonDeviceHelpers.cpp b/winml/lib/Common/CommonDeviceHelpers.cpp index 5dbeef7f5f..8c70f0fb17 100644 --- a/winml/lib/Common/CommonDeviceHelpers.cpp +++ b/winml/lib/Common/CommonDeviceHelpers.cpp @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// #include "dx.h" -// #include #include "inc/pch.h" #if USE_DML #include diff --git a/winml/test/api/LearningModelSessionAPITest.cpp b/winml/test/api/LearningModelSessionAPITest.cpp index 596002d66a..859900d0d2 100644 --- a/winml/test/api/LearningModelSessionAPITest.cpp +++ b/winml/test/api/LearningModelSessionAPITest.cpp @@ -336,12 +336,14 @@ static void NamedDimensionOverride() LearningModelSession session(nullptr); WINML_EXPECT_NO_THROW(session = LearningModelSession(model, device, options)); +#ifndef BUILD_INBOX Experimental::LearningModelSessionExperimental experimental_session(session); Experimental::LearningModelSessionOptionsExperimental experimental_options = experimental_session.Options(); wfc::IMapView internal_overrides = experimental_options.GetNamedDimensionOverrides(); WINML_EXPECT_EQUAL(internal_overrides.Lookup(L"None"), n); WINML_EXPECT_EQUAL(internal_overrides.Lookup(L"DimNameThatDoesntExist"), n); +#endif ILearningModelFeatureDescriptor descriptor = model.InputFeatures().GetAt(0); TensorFeatureDescriptor tensorDescriptor = nullptr; diff --git a/winml/test/common/winrt_headers.h b/winml/test/common/winrt_headers.h index ab8206617b..02fd398c78 100644 --- a/winml/test/common/winrt_headers.h +++ b/winml/test/common/winrt_headers.h @@ -33,16 +33,15 @@ #define CREATE_NATIVE_INTERNAL_HEADER() XSTRINGIFY(NATIVE_INTERNAL_HEADER(WINML_ROOT_NS)) #include CREATE_CPPWINRT_COMPONENT_HEADER() -#include CREATE_CPPWINRT_EXPERIMENTAL_COMPONENT_HEADER() #ifndef BUILD_INBOX +#include CREATE_CPPWINRT_EXPERIMENTAL_COMPONENT_HEADER() +#endif // WinML Native Headers #include CREATE_NATIVE_HEADER() #include CREATE_NATIVE_INTERNAL_HEADER() -#endif - namespace winml = winrt::WINML_ROOT_NS::AI::MachineLearning; namespace wf = winrt::Windows::Foundation; namespace wfc = winrt::Windows::Foundation::Collections;