From 53e7831b5378e52f6a741e92dc733e50b5a3f912 Mon Sep 17 00:00:00 2001 From: Tiago Koji Castro Shibata Date: Tue, 10 Aug 2021 15:19:30 -0700 Subject: [PATCH] Fix Windows Store build (#8481) * Remove APIs unavailable in Store in #8349, #8178, #8065 * Add UWP stubs of C runtime functions * Remove UWP incompatible tests from UWP build * Remove incompatible tests from Store * Use UWP stubs in store only * Skip partition check outside of Windows * Remove unused WRL include * Workaround Windows header not including what it uses * Fix precompiled header name clash * Workaround SDK bugs * DXCore workaround in Win7 * Fix warning * Fix more warnings * Bump WinML to target Windows 8 * Fix more warnings * Remove unnecessary workarounds --- cmake/CMakeLists.txt | 22 +++++------- cmake/onnxruntime_common.cmake | 3 +- cmake/onnxruntime_flatbuffers.cmake | 13 +++++++ cmake/precompiled_header.cmake | 2 +- cmake/uwp_stubs.h | 11 ++++++ cmake/winml.cmake | 25 ++++++++----- cmake/winml_cppwinrt.cmake | 2 +- cmake/winml_unittests.cmake | 2 +- onnxruntime/core/common/cpuid_info.cc | 10 ++++-- onnxruntime/test/platform/threadpool_test.cc | 2 ++ winml/adapter/abi_custom_registry_impl.cpp | 2 +- winml/adapter/winml_adapter_c_api.cpp | 4 +-- winml/adapter/winml_adapter_dml.cpp | 2 +- winml/adapter/winml_adapter_environment.cpp | 4 +-- .../winml_adapter_execution_provider.cpp | 4 +-- winml/adapter/winml_adapter_model.cpp | 2 +- winml/adapter/winml_adapter_session.cpp | 2 +- winml/dll/module.cpp | 8 +++-- .../Api.Experimental/LearningModelBuilder.cpp | 2 +- .../Api.Experimental/LearningModelInputs.cpp | 2 +- .../LearningModelOperator.cpp | 2 +- .../LearningModelOperatorSet.cpp | 2 +- .../Api.Experimental/LearningModelOutputs.cpp | 2 +- .../LearningModelSessionExperimental.cpp | 2 +- ...earningModelSessionOptionsExperimental.cpp | 2 +- .../lib/Api.Image/ConverterResourceStore.cpp | 2 +- winml/lib/Api.Image/D3DDeviceCache.cpp | 2 +- winml/lib/Api.Image/DeviceHelpers.cpp | 2 +- winml/lib/Api.Image/DisjointBufferHelpers.cpp | 2 +- .../lib/Api.Image/ImageConversionHelpers.cpp | 2 +- winml/lib/Api.Image/ImageConverter.cpp | 2 +- winml/lib/Api.Image/NominalRangeConverter.cpp | 2 +- .../Api.Image/TensorToVideoFrameConverter.cpp | 2 +- .../Api.Image/VideoFrameToTensorConverter.cpp | 2 +- winml/lib/Api.Image/inc/DeviceHelpers.h | 6 ++++ .../Api.Ort/OnnxruntimeCpuSessionBuilder.cpp | 2 +- .../OnnxruntimeDescriptorConverter.cpp | 2 +- .../Api.Ort/OnnxruntimeDmlSessionBuilder.cpp | 2 +- winml/lib/Api.Ort/OnnxruntimeEngine.cpp | 2 +- .../lib/Api.Ort/OnnxruntimeEngineBuilder.cpp | 2 +- winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp | 2 +- winml/lib/Api.Ort/OnnxruntimeModel.cpp | 2 +- winml/lib/Api/ImageFeatureDescriptor.cpp | 2 +- winml/lib/Api/ImageFeatureValue.cpp | 2 +- winml/lib/Api/LearningModel.cpp | 36 ++++++++++++------- winml/lib/Api/LearningModelBinding.cpp | 2 +- winml/lib/Api/LearningModelDevice.cpp | 2 +- .../lib/Api/LearningModelEvaluationResult.cpp | 2 +- winml/lib/Api/LearningModelSession.cpp | 2 +- winml/lib/Api/LearningModelSessionOptions.cpp | 2 +- winml/lib/Api/MapFeatureDescriptor.cpp | 2 +- winml/lib/Api/NumericData.cpp | 2 +- winml/lib/Api/SequenceFeatureDescriptor.cpp | 2 +- winml/lib/Api/StringData.cpp | 2 +- winml/lib/Api/TensorFeatureDescriptor.cpp | 2 +- winml/lib/Api/VectorBackedBuffer.cpp | 2 +- winml/lib/Common/CommonDeviceHelpers.cpp | 2 +- winml/lib/Common/inc/CommonDeviceHelpers.h | 6 ++++ winml/lib/Common/inc/StringHelpers.h | 2 ++ winml/lib/Common/inc/common.h | 1 - winml/lib/Telemetry/Telemetry.cpp | 2 +- winml/lib/Telemetry/TelemetryEvent.cpp | 2 +- winml/lib/Telemetry/WinMLTelemetryHelper.cpp | 2 +- winml/test/adapter/AdapterDmlEpTest.cpp | 1 - winml/test/api/APITest.h | 4 +-- winml/test/common/dllload.cpp | 4 +++ 66 files changed, 161 insertions(+), 99 deletions(-) create mode 100644 cmake/uwp_stubs.h diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 6b053a9a69..983fb89488 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -260,12 +260,6 @@ if(NOT WIN32) message(WARNING "Instrument is only supported on Windows now") set(onnxruntime_ENABLE_INSTRUMENT OFF) endif() -else() - if(WINDOWS_STORE) - # cmake/external/protobuf/src/google/protobuf/compiler/subprocess.cc and onnxruntime/core/platform/windows/env.cc call a bunch of Win32 APIs. - # For now, we'll set the API family to desktop globally to expose Win32 symbols in headers; this must be fixed! - add_compile_options("$<$:/FI${CMAKE_CURRENT_SOURCE_DIR}/set_winapi_family_desktop.h>") - endif() endif() if(onnxruntime_USE_OPENMP) @@ -802,7 +796,7 @@ endif() # Adding pytorch CPU info library # TODO do we have to add target_include_directories to each project that uses this? -if(MSVC AND (( CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM.*|arm.*)$" ) OR (CMAKE_GENERATOR_PLATFORM MATCHES "^(ARM.*|arm.*)$" ) )) +if(WINDOWS_STORE OR (MSVC AND (( CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM.*|arm.*)$" ) OR (CMAKE_GENERATOR_PLATFORM MATCHES "^(ARM.*|arm.*)$" ) )) ) # cpuinfo fail to compile with windows arm. else() set(PYTORCH_CPUINFO_DIR external/pytorch_cpuinfo) @@ -1693,8 +1687,8 @@ if (WIN32) if (WINDOWS_STORE) # Setting WINAPI_FAMILY, WINVER and _WIN32_WINNT restrict the APIs exposed in Windows headers to those available # in store or desktop, and that support at least the version of Windows specified - # add_compile_definitions(WINAPI_FAMILY=2) - add_compile_definitions(WINVER=0x0A00 _WIN32_WINNT=0x0A00) # Support Windows 10 + add_compile_definitions(WINAPI_FAMILY=2) # Windows Store app + add_compile_definitions(WINVER=0x0A00 _WIN32_WINNT=0x0A00 NTDDI_VERSION=0x0A000000) # Support Windows 10 or newer # /ZW adds /FUplatform.winmd and /FUwindows.winmd. windows.winmd, in turn, overrides the include path for # the cppwinrt headers, which we set to use the WinML built ones. # Instead, we use /ZW:nostdlib and force include platform.winml only. @@ -1703,10 +1697,12 @@ if (WIN32) link_directories("${msvc_path}/lib/${onnxruntime_target_platform}/store") add_link_options(/APPCONTAINER) else() - add_compile_definitions(WINVER=0x0601) # Support Windows 7 and newer - # add_compile_definitions(WINAPI_FAMILY=3) - # FIXME adding _WIN32_WINNT=0x0601 and WINAPI_FAMILY is desirable. However, it hides some symbols that are used in WRL - # headers and breaks the build of WinML. We should have separate WINVER/_WIN32_WINNT definitions for WinML + add_compile_definitions(WINAPI_FAMILY=100) # Desktop app + if (onnxruntime_USE_WINML) + add_compile_definitions(WINVER=0x0602 _WIN32_WINNT=0x0602 NTDDI_VERSION=0x06020000) # Support Windows 7 and newer + else() + add_compile_definitions(WINVER=0x0601 _WIN32_WINNT=0x0601 NTDDI_VERSION=0x06010000) # Support Windows 7 and newer + endif() endif() endif() diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake index 4688f533f0..0b457bf861 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake @@ -229,7 +229,7 @@ endif() if (ARM64 OR ARM OR X86 OR X64 OR X86_64) - if((ARM64 OR ARM) AND MSVC) + if(WINDOWS_STORE OR ((ARM64 OR ARM) AND MSVC)) # msvc compiler report syntax error with cpuinfo arm source files # and cpuinfo does not have code for getting arm uarch info under windows else() @@ -242,4 +242,3 @@ if (ARM64 OR ARM OR X86 OR X64 OR X86_64) list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo clog) endif() endif() - diff --git a/cmake/onnxruntime_flatbuffers.cmake b/cmake/onnxruntime_flatbuffers.cmake index 49302e92f5..bcb196bcd8 100644 --- a/cmake/onnxruntime_flatbuffers.cmake +++ b/cmake/onnxruntime_flatbuffers.cmake @@ -21,3 +21,16 @@ set_target_properties(onnxruntime_flatbuffers PROPERTIES FOLDER "ONNXRuntime") if (FLATBUFFERS_BUILD_FLATC) add_dependencies(onnxruntime_flatbuffers flatc) endif() + +if (WINDOWS_STORE) + function(target_force_include target scope file) + if (MSVC) + target_compile_options(${target} ${scope} "/FI${file}") + else() + target_compile_options(${target} ${scope} -include "${file}") + endif() + endfunction() + + target_force_include(flatbuffers PRIVATE uwp_stubs.h) + target_force_include(flatc PRIVATE uwp_stubs.h) +endif() diff --git a/cmake/precompiled_header.cmake b/cmake/precompiled_header.cmake index dbdeb2bb50..12b67755fd 100644 --- a/cmake/precompiled_header.cmake +++ b/cmake/precompiled_header.cmake @@ -12,7 +12,7 @@ function(target_precompiled_header target_name header_name) # Generate the source file that builds the precompiled header. The generated file will have # the same base name as the input header name, but has the .cpp extension. - set(pch_source_path ${CMAKE_CURRENT_BINARY_DIR}/${header_base_name}.cpp) + set(pch_source_path ${CMAKE_CURRENT_BINARY_DIR}/${target_name}_${header_base_name}.cpp) set(pch_source_content "// THIS FILE IS GENERATED BY CMAKE\n#include \"${pch_header_path}\"") file(WRITE ${pch_source_path} ${pch_source_content}) set_source_files_properties(${pch_source_path} PROPERTIES COMPILE_FLAGS "/Yc${pch_header_path}") diff --git a/cmake/uwp_stubs.h b/cmake/uwp_stubs.h new file mode 100644 index 0000000000..4495e888b4 --- /dev/null +++ b/cmake/uwp_stubs.h @@ -0,0 +1,11 @@ +#pragma once +// Part of the standard C runtime and the STL are missing when targeting UWP, and some applications that rely on standard, +// cross-platform headers fail to build. +// Here we provide stubs for functions required by some onnxruntime dependencies. +#ifdef __cplusplus +// Extending the std namespace is undefined behavior +// NOLINTNEXTLINE +namespace std { + inline char *getenv(const char*) { return nullptr; } +} +#endif diff --git a/cmake/winml.cmake b/cmake/winml.cmake index b58e8775dd..4efc6fa628 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -175,7 +175,7 @@ target_compile_definitions(winml_lib_telemetry PRIVATE _SCL_SECURE_NO_WARNINGS) target_compile_definitions(winml_lib_telemetry PRIVATE BINARY_NAME=\"${BINARY_NAME}\") # Specify the usage of a precompiled header -target_precompiled_header(winml_lib_telemetry pch.h) +target_precompiled_header(winml_lib_telemetry lib/Telemetry/pch.h) # Includes target_include_directories(winml_lib_telemetry PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers @@ -186,6 +186,7 @@ target_include_directories(winml_lib_telemetry PRIVATE ${CMAKE_SOURCE_DIR}/commo target_include_directories(winml_lib_telemetry PRIVATE ${winml_lib_telemetry_dir}) target_include_directories(winml_lib_telemetry PRIVATE ${winml_lib_common_dir}/inc) target_include_directories(winml_lib_telemetry PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/core/platform/windows) +target_include_directories(winml_lib_telemetry PRIVATE ${REPO_ROOT}/winml) # Properties set_target_properties(winml_lib_telemetry @@ -247,7 +248,7 @@ if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows") endif() # Specify the usage of a precompiled header -target_precompiled_header(winml_lib_ort pch.h) +target_precompiled_header(winml_lib_ort lib/Api.Ort/pch.h) # Includes target_include_directories(winml_lib_ort PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers @@ -323,9 +324,10 @@ target_include_directories(winml_adapter PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INC add_dependencies(winml_adapter ${onnxruntime_EXTERNAL_DEPENDENCIES}) # Specify the usage of a precompiled header -target_precompiled_header(winml_adapter pch.h) +target_precompiled_header(winml_adapter adapter/pch.h) # Includes +target_include_directories(winml_adapter PRIVATE ${REPO_ROOT}/winml) target_include_directories(winml_adapter PRIVATE ${winml_adapter_dir}) target_include_directories(winml_adapter PRIVATE ${winml_lib_common_dir}/inc) @@ -388,7 +390,7 @@ target_compile_definitions(winml_lib_image PRIVATE PLATFORM_WINDOWS) target_compile_definitions(winml_lib_image PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators # Specify the usage of a precompiled header -target_precompiled_header(winml_lib_image pch.h) +target_precompiled_header(winml_lib_image lib/Api.Image/pch.h) # Includes target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers @@ -408,6 +410,7 @@ target_include_directories(winml_lib_image PRIVATE ${ONNXRUNTIME_INCLUDE_DIR}/co target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include) target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) +target_include_directories(winml_lib_image PRIVATE ${REPO_ROOT}/winml) # Properties set_target_properties(winml_lib_image @@ -492,7 +495,7 @@ target_compile_definitions(winml_lib_api PRIVATE PLATFORM_WINDOWS) target_compile_definitions(winml_lib_api PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators # Specify the usage of a precompiled header -target_precompiled_header(winml_lib_api pch.h) +target_precompiled_header(winml_lib_api lib/Api/pch/pch.h) # Includes target_include_directories(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers @@ -524,6 +527,7 @@ target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/Saf target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include) target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) +target_include_directories(winml_lib_api PRIVATE ${REPO_ROOT}/winml) # Properties set_target_properties(winml_lib_api @@ -581,7 +585,7 @@ target_compile_definitions(winml_lib_api_experimental PRIVATE PLATFORM_WINDOWS) target_compile_definitions(winml_lib_api_experimental PRIVATE _SCL_SECURE_NO_WARNINGS) # remove warnings about unchecked iterators # Specify the usage of a precompiled header -target_precompiled_header(winml_lib_api_experimental pch.h) +target_precompiled_header(winml_lib_api_experimental lib/Api.Experimental/pch/pch.h) # Includes target_include_directories(winml_lib_api_experimental PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers @@ -615,6 +619,7 @@ target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include) target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) +target_include_directories(winml_lib_api_experimental PRIVATE ${REPO_ROOT}/winml) # Properties set_target_properties(winml_lib_api_experimental @@ -685,7 +690,8 @@ target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/ target_include_directories(winml_lib_common PRIVATE ${winml_lib_api_dir}) target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) target_include_directories(winml_lib_common PRIVATE ${winml_lib_common_dir}/inc) -target_precompiled_header(winml_lib_common inc/pch.h) +target_include_directories(winml_lib_common PRIVATE ${REPO_ROOT}/winml) +target_precompiled_header(winml_lib_common lib/Common/inc/pch.h) if (onnxruntime_USE_DML) target_add_dml(winml_lib_common) @@ -702,7 +708,7 @@ set_source_files_properties( TRUE) # Add library -onnxruntime_add_shared_library(winml_dll +onnxruntime_add_shared_library(winml_dll ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated/module.g.excl.cpp ${winml_dll_dir}/winml.def ${winml_dll_dir}/winml.rc @@ -733,7 +739,7 @@ if (onnxruntime_WINML_NAMESPACE_OVERRIDE STREQUAL "Windows") endif() # Specify the usage of a precompiled header -target_precompiled_header(winml_dll pch.h) +target_precompiled_header(winml_dll dll/pch.h) # Includes target_include_directories(winml_dll PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers @@ -770,6 +776,7 @@ target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/SafeInt target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/flatbuffers/include) target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/optional-lite/include) target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/cmake/external/mp11/include) +target_include_directories(winml_dll PRIVATE ${REPO_ROOT}/winml) # Properties set_target_properties(winml_dll diff --git a/cmake/winml_cppwinrt.cmake b/cmake/winml_cppwinrt.cmake index e0d2f40ea9..ece5a45861 100644 --- a/cmake/winml_cppwinrt.cmake +++ b/cmake/winml_cppwinrt.cmake @@ -156,7 +156,7 @@ function(target_cppwinrt ${midl_options} ${renamed_idl_fullpath_back_slash} COMMAND - ${cppwinrt_exe} -in ${winmd_filename} -comp ${output_dir_back_slash} -ref ${sdk_metadata_directory} ${add_ref} -out ${generated_dir_back_slash} -verbose + ${cppwinrt_exe} -in ${winmd_filename} -comp ${output_dir_back_slash} -pch dll/pch.h -ref ${sdk_metadata_directory} ${add_ref} -out ${generated_dir_back_slash} -verbose COMMAND # copy the generated component files into a temporary directory where headers exclusions will be applied xcopy ${output_dir_back_slash} ${temp_dir_back_slash}\\ /Y /D diff --git a/cmake/winml_unittests.cmake b/cmake/winml_unittests.cmake index 09c9b9e293..e9ff2e5575 100644 --- a/cmake/winml_unittests.cmake +++ b/cmake/winml_unittests.cmake @@ -191,7 +191,7 @@ set_winml_target_properties(winml_google_test_lib) set_winml_target_properties(winml_test_common) get_winml_test_api_src(${WINML_TEST_SRC_DIR} winml_test_api_src) -if (NOT ${winml_is_inbox}) +if (NOT WINDOWS_STORE AND NOT ${winml_is_inbox}) get_winml_test_api_redist_only_src(${WINML_TEST_SRC_DIR} winml_test_api_redist_only_src) endif() diff --git a/onnxruntime/core/common/cpuid_info.cc b/onnxruntime/core/common/cpuid_info.cc index 29f6360c84..dcc1f7b932 100644 --- a/onnxruntime/core/common/cpuid_info.cc +++ b/onnxruntime/core/common/cpuid_info.cc @@ -22,9 +22,13 @@ #include "core/common/cpuid_info.h" #if defined(CPUIDINFO_ARCH_X86) || defined(CPUIDINFO_ARCH_ARM) - -#if defined(_MSC_VER) && defined(CPUIDINFO_ARCH_ARM) -// pytorch cpu info does not work for Windows ARM +#if _WIN32 +#define NO_WINDOWS_DESKTOP !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +#endif +#if NO_WINDOWS_DESKTOP || (defined(_MSC_VER) && defined(CPUIDINFO_ARCH_ARM)) +// pytorch cpu info does not work for Windows UWP or ARM +// UWP: Some APIs are not available +// ARM: // 1. msvc report syntax error in file src/arm/api.h // 2. features reporting micro-arch in Windows is missing #else diff --git a/onnxruntime/test/platform/threadpool_test.cc b/onnxruntime/test/platform/threadpool_test.cc index efbe04ef53..6ba9493c67 100644 --- a/onnxruntime/test/platform/threadpool_test.cc +++ b/onnxruntime/test/platform/threadpool_test.cc @@ -425,6 +425,7 @@ TEST(ThreadPoolTest, TestStagedMultiLoopSections_4Thread_100Loop) { TestStagedMultiLoopSections("TestStagedMultiLoopSections_4Thread_100Loop", 4, 100); } #ifdef _WIN32 +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #pragma warning(push) #pragma warning(disable : 6387) TEST(ThreadPoolTest, TestStackSize) { @@ -455,5 +456,6 @@ TEST(ThreadPoolTest, TestStackSize) { } #pragma warning(pop) #endif +#endif } // namespace onnxruntime diff --git a/winml/adapter/abi_custom_registry_impl.cpp b/winml/adapter/abi_custom_registry_impl.cpp index 116efcc0a6..3619053440 100644 --- a/winml/adapter/abi_custom_registry_impl.cpp +++ b/winml/adapter/abi_custom_registry_impl.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "adapter/pch.h" #ifdef USE_DML diff --git a/winml/adapter/winml_adapter_c_api.cpp b/winml/adapter/winml_adapter_c_api.cpp index 5e14f47542..8816020bfe 100644 --- a/winml/adapter/winml_adapter_c_api.cpp +++ b/winml/adapter/winml_adapter_c_api.cpp @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "adapter/pch.h" #include "winml_adapter_c_api.h" #include "winml_adapter_apis.h" @@ -105,4 +105,4 @@ const WinmlAdapterApi* ORT_API_CALL OrtGetWinMLAdapter(_In_ const OrtApi* ort_ap } return nullptr; -} \ No newline at end of file +} diff --git a/winml/adapter/winml_adapter_dml.cpp b/winml/adapter/winml_adapter_dml.cpp index deb12a4f3a..baec8f5b30 100644 --- a/winml/adapter/winml_adapter_dml.cpp +++ b/winml/adapter/winml_adapter_dml.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #pragma once -#include "pch.h" +#include "adapter/pch.h" #include "winml_adapter_c_api.h" #include "core/session/ort_apis.h" diff --git a/winml/adapter/winml_adapter_environment.cpp b/winml/adapter/winml_adapter_environment.cpp index c631f45eb5..81789aaaa6 100644 --- a/winml/adapter/winml_adapter_environment.cpp +++ b/winml/adapter/winml_adapter_environment.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #pragma once -#include "pch.h" +#include "adapter/pch.h" #include "winml_adapter_c_api.h" #include "core/session/ort_apis.h" @@ -82,4 +82,4 @@ ORT_API_STATUS_IMPL(winmla::OverrideSchema) { #endif USE_DML. return nullptr; API_IMPL_END -} \ No newline at end of file +} diff --git a/winml/adapter/winml_adapter_execution_provider.cpp b/winml/adapter/winml_adapter_execution_provider.cpp index e9dbcf2a06..0f45772f3c 100644 --- a/winml/adapter/winml_adapter_execution_provider.cpp +++ b/winml/adapter/winml_adapter_execution_provider.cpp @@ -3,7 +3,7 @@ #pragma once -#include "pch.h" +#include "adapter/pch.h" #include "winml_adapter_c_api.h" #include "core/session/ort_apis.h" @@ -88,4 +88,4 @@ ORT_API_STATUS_IMPL(winmla::GetValueMemoryInfo, const OrtValue* value, OrtMemory } return nullptr; API_IMPL_END -} \ No newline at end of file +} diff --git a/winml/adapter/winml_adapter_model.cpp b/winml/adapter/winml_adapter_model.cpp index af77f6f43d..536a4f1ad4 100644 --- a/winml/adapter/winml_adapter_model.cpp +++ b/winml/adapter/winml_adapter_model.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #pragma once -#include "pch.h" +#include "adapter/pch.h" #include "winml_adapter_model.h" diff --git a/winml/adapter/winml_adapter_session.cpp b/winml/adapter/winml_adapter_session.cpp index da6529430a..b24e693e73 100644 --- a/winml/adapter/winml_adapter_session.cpp +++ b/winml/adapter/winml_adapter_session.cpp @@ -2,7 +2,7 @@ // Licensed under the MIT License. #pragma once -#include "pch.h" +#include "adapter/pch.h" #include "winml_adapter_c_api.h" #include "core/session/ort_apis.h" diff --git a/winml/dll/module.cpp b/winml/dll/module.cpp index 43e4969efc..4583a870c0 100644 --- a/winml/dll/module.cpp +++ b/winml/dll/module.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "dll/pch.h" #include #include #include "LearningModelDevice.h" @@ -137,5 +137,9 @@ STDAPI DllGetActivationFactory(HSTRING classId, void** factory) { // LoadLibraryW isn't support on Windows 8.1. This is a workaround so that CppWinRT calls this function for loading libraries void* __stdcall WINRT_IMPL_LoadLibraryW(wchar_t const* name) noexcept { +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) return LoadLibraryExW(name, nullptr, 0); -} \ No newline at end of file +#else + return LoadPackagedLibrary(name, 0); +#endif +} diff --git a/winml/lib/Api.Experimental/LearningModelBuilder.cpp b/winml/lib/Api.Experimental/LearningModelBuilder.cpp index 23a0f0ff19..7296870730 100644 --- a/winml/lib/Api.Experimental/LearningModelBuilder.cpp +++ b/winml/lib/Api.Experimental/LearningModelBuilder.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Experimental/pch/pch.h" #include "LearningModelBuilder.h" #include "LearningModel.h" #include "TensorFeatureDescriptor.h" diff --git a/winml/lib/Api.Experimental/LearningModelInputs.cpp b/winml/lib/Api.Experimental/LearningModelInputs.cpp index e2585edf99..491127ed91 100644 --- a/winml/lib/Api.Experimental/LearningModelInputs.cpp +++ b/winml/lib/Api.Experimental/LearningModelInputs.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Experimental/pch/pch.h" #include "LearningModelInputs.h" #include "LearningModelOperator.h" #include "LearningModelSession.h" diff --git a/winml/lib/Api.Experimental/LearningModelOperator.cpp b/winml/lib/Api.Experimental/LearningModelOperator.cpp index ba35215048..16b96425e9 100644 --- a/winml/lib/Api.Experimental/LearningModelOperator.cpp +++ b/winml/lib/Api.Experimental/LearningModelOperator.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Experimental/pch/pch.h" #include "LearningModelOperator.h" namespace WINML_EXPERIMENTALP { diff --git a/winml/lib/Api.Experimental/LearningModelOperatorSet.cpp b/winml/lib/Api.Experimental/LearningModelOperatorSet.cpp index 15111767f5..d47ae730a0 100644 --- a/winml/lib/Api.Experimental/LearningModelOperatorSet.cpp +++ b/winml/lib/Api.Experimental/LearningModelOperatorSet.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Experimental/pch/pch.h" #include "LearningModelOperatorSet.h" #include "LearningModelOperator.h" diff --git a/winml/lib/Api.Experimental/LearningModelOutputs.cpp b/winml/lib/Api.Experimental/LearningModelOutputs.cpp index 8de00f58d3..01dcfd443e 100644 --- a/winml/lib/Api.Experimental/LearningModelOutputs.cpp +++ b/winml/lib/Api.Experimental/LearningModelOutputs.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Experimental/pch/pch.h" #include "LearningModelOutputs.h" #include "LearningModelBuilder.h" #include "TensorFeatureDescriptor.h" diff --git a/winml/lib/Api.Experimental/LearningModelSessionExperimental.cpp b/winml/lib/Api.Experimental/LearningModelSessionExperimental.cpp index 96e4ad7020..29b017c43e 100644 --- a/winml/lib/Api.Experimental/LearningModelSessionExperimental.cpp +++ b/winml/lib/Api.Experimental/LearningModelSessionExperimental.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Experimental/pch/pch.h" #include "LearningModelSessionOptionsExperimental.h" #include "LearningModelSessionExperimental.h" diff --git a/winml/lib/Api.Experimental/LearningModelSessionOptionsExperimental.cpp b/winml/lib/Api.Experimental/LearningModelSessionOptionsExperimental.cpp index e5e1a9f7d3..ee59e5b7a4 100644 --- a/winml/lib/Api.Experimental/LearningModelSessionOptionsExperimental.cpp +++ b/winml/lib/Api.Experimental/LearningModelSessionOptionsExperimental.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Experimental/pch/pch.h" #include "LearningModelSessionOptionsExperimental.h" #include "winrt/Windows.Foundation.Collections.h" #include "LearningModelSession.h" diff --git a/winml/lib/Api.Image/ConverterResourceStore.cpp b/winml/lib/Api.Image/ConverterResourceStore.cpp index c293974f20..4c3bcad233 100644 --- a/winml/lib/Api.Image/ConverterResourceStore.cpp +++ b/winml/lib/Api.Image/ConverterResourceStore.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Image/pch.h" #include "inc/ConverterResourceStore.h" #include diff --git a/winml/lib/Api.Image/D3DDeviceCache.cpp b/winml/lib/Api.Image/D3DDeviceCache.cpp index fcafbab572..9a5b9c10a2 100644 --- a/winml/lib/Api.Image/D3DDeviceCache.cpp +++ b/winml/lib/Api.Image/D3DDeviceCache.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Image/pch.h" #include "inc/D3DDeviceCache.h" #include #include diff --git a/winml/lib/Api.Image/DeviceHelpers.cpp b/winml/lib/Api.Image/DeviceHelpers.cpp index aee8b38f1b..48a8d9a902 100644 --- a/winml/lib/Api.Image/DeviceHelpers.cpp +++ b/winml/lib/Api.Image/DeviceHelpers.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Image/pch.h" #if USE_DML #include diff --git a/winml/lib/Api.Image/DisjointBufferHelpers.cpp b/winml/lib/Api.Image/DisjointBufferHelpers.cpp index 1a94bd2c16..834a9c39ba 100644 --- a/winml/lib/Api.Image/DisjointBufferHelpers.cpp +++ b/winml/lib/Api.Image/DisjointBufferHelpers.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Image/pch.h" #include "inc/DisjointBufferHelpers.h" namespace _winml { diff --git a/winml/lib/Api.Image/ImageConversionHelpers.cpp b/winml/lib/Api.Image/ImageConversionHelpers.cpp index ce6464522d..a5ebac8579 100644 --- a/winml/lib/Api.Image/ImageConversionHelpers.cpp +++ b/winml/lib/Api.Image/ImageConversionHelpers.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Image/pch.h" #include "inc/ImageConversionHelpers.h" #include diff --git a/winml/lib/Api.Image/ImageConverter.cpp b/winml/lib/Api.Image/ImageConverter.cpp index 8df0249c2b..0ca71c82d8 100644 --- a/winml/lib/Api.Image/ImageConverter.cpp +++ b/winml/lib/Api.Image/ImageConverter.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Image/pch.h" #include "inc/ImageConverter.h" #include "inc/ImageConversionHelpers.h" #include "inc/D3DDeviceCache.h" diff --git a/winml/lib/Api.Image/NominalRangeConverter.cpp b/winml/lib/Api.Image/NominalRangeConverter.cpp index 9df730ef57..63526c3ede 100644 --- a/winml/lib/Api.Image/NominalRangeConverter.cpp +++ b/winml/lib/Api.Image/NominalRangeConverter.cpp @@ -1,4 +1,4 @@ -#include "pch.h" +#include "lib/Api.Image/pch.h" #include "inc/NominalRangeConverter.h" namespace _winml { diff --git a/winml/lib/Api.Image/TensorToVideoFrameConverter.cpp b/winml/lib/Api.Image/TensorToVideoFrameConverter.cpp index caff6c2590..aea1addccc 100644 --- a/winml/lib/Api.Image/TensorToVideoFrameConverter.cpp +++ b/winml/lib/Api.Image/TensorToVideoFrameConverter.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Image/pch.h" #include // winmeta needed for TraceLoggingKeyword #include diff --git a/winml/lib/Api.Image/VideoFrameToTensorConverter.cpp b/winml/lib/Api.Image/VideoFrameToTensorConverter.cpp index 51cba17b4d..c4490db394 100644 --- a/winml/lib/Api.Image/VideoFrameToTensorConverter.cpp +++ b/winml/lib/Api.Image/VideoFrameToTensorConverter.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Image/pch.h" #include // winmeta needed for TraceLoggingKeyword #include diff --git a/winml/lib/Api.Image/inc/DeviceHelpers.h b/winml/lib/Api.Image/inc/DeviceHelpers.h index 9d73ed71ac..ee6b7610de 100644 --- a/winml/lib/Api.Image/inc/DeviceHelpers.h +++ b/winml/lib/Api.Image/inc/DeviceHelpers.h @@ -11,7 +11,13 @@ #define ENABLE_DXCORE 1 #endif #ifdef ENABLE_DXCORE +// dxcore is delay loaded, so there is a runtime check for its existence and it's always okay to reference, +// even in unsupported versions of Windows +#pragma push_macro("_WIN32_WINNT") +#undef _WIN32_WINNT +#define _WIN32_WINNT _WIN32_WINNT_WIN10 #include +#pragma pop_macro("_WIN32_WINNT") #endif namespace _winml { diff --git a/winml/lib/Api.Ort/OnnxruntimeCpuSessionBuilder.cpp b/winml/lib/Api.Ort/OnnxruntimeCpuSessionBuilder.cpp index 687ca2cff9..39b141fdcb 100644 --- a/winml/lib/Api.Ort/OnnxruntimeCpuSessionBuilder.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeCpuSessionBuilder.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Ort/pch.h" #include "OnnxruntimeCpuSessionBuilder.h" #include "OnnxruntimeEngine.h" #include "OnnxruntimeErrors.h" diff --git a/winml/lib/Api.Ort/OnnxruntimeDescriptorConverter.cpp b/winml/lib/Api.Ort/OnnxruntimeDescriptorConverter.cpp index 9e728ee9c6..99bafb836e 100644 --- a/winml/lib/Api.Ort/OnnxruntimeDescriptorConverter.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeDescriptorConverter.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Ort/pch.h" #include diff --git a/winml/lib/Api.Ort/OnnxruntimeDmlSessionBuilder.cpp b/winml/lib/Api.Ort/OnnxruntimeDmlSessionBuilder.cpp index 71c470fd1c..248112468d 100644 --- a/winml/lib/Api.Ort/OnnxruntimeDmlSessionBuilder.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeDmlSessionBuilder.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Ort/pch.h" #ifdef USE_DML diff --git a/winml/lib/Api.Ort/OnnxruntimeEngine.cpp b/winml/lib/Api.Ort/OnnxruntimeEngine.cpp index 665c534348..996a06536b 100644 --- a/winml/lib/Api.Ort/OnnxruntimeEngine.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeEngine.cpp @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Ort/pch.h" #include "OnnxruntimeEngine.h" diff --git a/winml/lib/Api.Ort/OnnxruntimeEngineBuilder.cpp b/winml/lib/Api.Ort/OnnxruntimeEngineBuilder.cpp index e1979c2f48..399e31f85b 100644 --- a/winml/lib/Api.Ort/OnnxruntimeEngineBuilder.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeEngineBuilder.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Ort/pch.h" #include "OnnxruntimeEngine.h" #include "OnnxruntimeEngineBuilder.h" diff --git a/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp b/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp index 55943a16d2..7654bdbbac 100644 --- a/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeEnvironment.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Ort/pch.h" #include "OnnxruntimeEnvironment.h" #include "OnnxruntimeErrors.h" #include "core/platform/windows/TraceLoggingConfig.h" diff --git a/winml/lib/Api.Ort/OnnxruntimeModel.cpp b/winml/lib/Api.Ort/OnnxruntimeModel.cpp index b894b50f47..f5dd943e6a 100644 --- a/winml/lib/Api.Ort/OnnxruntimeModel.cpp +++ b/winml/lib/Api.Ort/OnnxruntimeModel.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api.Ort/pch.h" #include "OnnxruntimeModel.h" #include "core/platform/windows/TraceLoggingConfig.h" #include diff --git a/winml/lib/Api/ImageFeatureDescriptor.cpp b/winml/lib/Api/ImageFeatureDescriptor.cpp index 8dc5a0d669..abf7fded34 100644 --- a/winml/lib/Api/ImageFeatureDescriptor.cpp +++ b/winml/lib/Api/ImageFeatureDescriptor.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "ImageFeatureDescriptor.h" diff --git a/winml/lib/Api/ImageFeatureValue.cpp b/winml/lib/Api/ImageFeatureValue.cpp index 3279f5f87c..2ecfa297f3 100644 --- a/winml/lib/Api/ImageFeatureValue.cpp +++ b/winml/lib/Api/ImageFeatureValue.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "ImageFeatureValue.h" #include "LearningModelBinding.h" #include "LearningModelDevice.h" diff --git a/winml/lib/Api/LearningModel.cpp b/winml/lib/Api/LearningModel.cpp index e16d4f3c02..529754aa1b 100644 --- a/winml/lib/Api/LearningModel.cpp +++ b/winml/lib/Api/LearningModel.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "LearningModel.h" @@ -21,13 +21,23 @@ LearningModel::LearningModel( _winmlt::TelemetryEvent loadModel_event(_winmlt::EventCategory::kModelLoad); WINML_THROW_IF_FAILED(CreateOnnxruntimeEngineFactory(engine_factory_.put())); - auto file_handle = wil::unique_handle(CreateFileW(path.c_str(), - GENERIC_READ, - 0, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_READONLY, - NULL)); + + wil::unique_handle file_handle{ +#if WINVER >= _WIN32_WINNT_WIN8 + CreateFile2(path.c_str(), + GENERIC_READ, + 0, + OPEN_EXISTING, + NULL)}; +#else + CreateFileW(path.c_str(), + GENERIC_READ, + 0, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_READONLY, + NULL)}; +#endif WINML_THROW_HR_IF_TRUE_MSG(__HRESULT_FROM_WIN32(GetLastError()), file_handle.get() == INVALID_HANDLE_VALUE, @@ -53,12 +63,12 @@ LearningModel::LearningModel( WINML_THROW_HR_IF_TRUE_MSG(__HRESULT_FROM_WIN32(GetLastError()), file_mapping == nullptr, "Model load failed!"); - - auto file_size_in_bytes = GetFileSize(file_handle.get(), NULL); - WINML_THROW_IF_FAILED(engine_factory_->CreateModel(buffer, file_size_in_bytes, model_.put())); - + LARGE_INTEGER file_size; + WINML_THROW_HR_IF_FALSE_MSG(__HRESULT_FROM_WIN32(GetLastError()), + GetFileSizeEx(file_handle.get(), &file_size), + "GetFileSizeEx"); + WINML_THROW_IF_FAILED(engine_factory_->CreateModel(buffer, static_cast(file_size.QuadPart), model_.put())); WINML_THROW_HR_IF_TRUE_MSG(E_UNEXPECTED, UnmapViewOfFile(buffer) == 0, "Could not unmap model file."); - WINML_THROW_IF_FAILED(model_->GetModelInfo(model_info_.put())); } WINML_CATCH_ALL diff --git a/winml/lib/Api/LearningModelBinding.cpp b/winml/lib/Api/LearningModelBinding.cpp index 48071b09c7..0c79117a34 100644 --- a/winml/lib/Api/LearningModelBinding.cpp +++ b/winml/lib/Api/LearningModelBinding.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "ConverterResourceStore.h" #include "impl/FeatureCompatibility.h" #include "FeatureValues.h" diff --git a/winml/lib/Api/LearningModelDevice.cpp b/winml/lib/Api/LearningModelDevice.cpp index e23f19a76f..e85fd8cbbe 100644 --- a/winml/lib/Api/LearningModelDevice.cpp +++ b/winml/lib/Api/LearningModelDevice.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "LearningModelDevice.h" #include diff --git a/winml/lib/Api/LearningModelEvaluationResult.cpp b/winml/lib/Api/LearningModelEvaluationResult.cpp index 1df705b332..c4a65af4e1 100644 --- a/winml/lib/Api/LearningModelEvaluationResult.cpp +++ b/winml/lib/Api/LearningModelEvaluationResult.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "LearningModelEvaluationResult.h" namespace WINMLP { diff --git a/winml/lib/Api/LearningModelSession.cpp b/winml/lib/Api/LearningModelSession.cpp index 25efe3e061..2186dd1e75 100644 --- a/winml/lib/Api/LearningModelSession.cpp +++ b/winml/lib/Api/LearningModelSession.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "LearningModelSession.h" diff --git a/winml/lib/Api/LearningModelSessionOptions.cpp b/winml/lib/Api/LearningModelSessionOptions.cpp index cad7465377..4ba2db8790 100644 --- a/winml/lib/Api/LearningModelSessionOptions.cpp +++ b/winml/lib/Api/LearningModelSessionOptions.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "LearningModelSessionOptions.h" namespace WINMLP { diff --git a/winml/lib/Api/MapFeatureDescriptor.cpp b/winml/lib/Api/MapFeatureDescriptor.cpp index 8e04c33ba3..a3334ec056 100644 --- a/winml/lib/Api/MapFeatureDescriptor.cpp +++ b/winml/lib/Api/MapFeatureDescriptor.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "MapFeatureDescriptor.h" diff --git a/winml/lib/Api/NumericData.cpp b/winml/lib/Api/NumericData.cpp index 8c09eebb2e..e426cd0fca 100644 --- a/winml/lib/Api/NumericData.cpp +++ b/winml/lib/Api/NumericData.cpp @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "impl/NumericData.h" #include "VectorBackedBuffer.h" diff --git a/winml/lib/Api/SequenceFeatureDescriptor.cpp b/winml/lib/Api/SequenceFeatureDescriptor.cpp index 8b2050859e..c4a4456e1c 100644 --- a/winml/lib/Api/SequenceFeatureDescriptor.cpp +++ b/winml/lib/Api/SequenceFeatureDescriptor.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "SequenceFeatureDescriptor.h" diff --git a/winml/lib/Api/StringData.cpp b/winml/lib/Api/StringData.cpp index 09bc423fdc..cbca428cb6 100644 --- a/winml/lib/Api/StringData.cpp +++ b/winml/lib/Api/StringData.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "impl/StringData.h" diff --git a/winml/lib/Api/TensorFeatureDescriptor.cpp b/winml/lib/Api/TensorFeatureDescriptor.cpp index dd9a7f6c9a..3dcffa6399 100644 --- a/winml/lib/Api/TensorFeatureDescriptor.cpp +++ b/winml/lib/Api/TensorFeatureDescriptor.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "LearningModel.h" diff --git a/winml/lib/Api/VectorBackedBuffer.cpp b/winml/lib/Api/VectorBackedBuffer.cpp index d12f664956..da2b6a2de4 100644 --- a/winml/lib/Api/VectorBackedBuffer.cpp +++ b/winml/lib/Api/VectorBackedBuffer.cpp @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Api/pch/pch.h" #include "VectorBackedBuffer.h" diff --git a/winml/lib/Common/CommonDeviceHelpers.cpp b/winml/lib/Common/CommonDeviceHelpers.cpp index 8c70f0fb17..c02902e254 100644 --- a/winml/lib/Common/CommonDeviceHelpers.cpp +++ b/winml/lib/Common/CommonDeviceHelpers.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "inc/pch.h" +#include "lib/Common/inc/pch.h" #if USE_DML #include #endif USE_DML diff --git a/winml/lib/Common/inc/CommonDeviceHelpers.h b/winml/lib/Common/inc/CommonDeviceHelpers.h index 0d28f25b6c..eb95eff2e7 100644 --- a/winml/lib/Common/inc/CommonDeviceHelpers.h +++ b/winml/lib/Common/inc/CommonDeviceHelpers.h @@ -13,7 +13,13 @@ #define ENABLE_DXCORE 1 #endif #ifdef ENABLE_DXCORE +// dxcore is delay loaded, so there is a runtime check for its existence and it's okay to reference, +// even in unsupported versions of Windows +#pragma push_macro("_WIN32_WINNT") +#undef _WIN32_WINNT +#define _WIN32_WINNT _WIN32_WINNT_WIN10 #include +#pragma pop_macro("_WIN32_WINNT") #endif // diff --git a/winml/lib/Common/inc/StringHelpers.h b/winml/lib/Common/inc/StringHelpers.h index a321f494b3..067b302a1c 100644 --- a/winml/lib/Common/inc/StringHelpers.h +++ b/winml/lib/Common/inc/StringHelpers.h @@ -3,6 +3,8 @@ #pragma once +#include + // String Helpers namespace _winml::Strings { struct HStringBuilder { diff --git a/winml/lib/Common/inc/common.h b/winml/lib/Common/inc/common.h index bc6df85882..96d3aaf2f6 100644 --- a/winml/lib/Common/inc/common.h +++ b/winml/lib/Common/inc/common.h @@ -27,7 +27,6 @@ // WIL #include #include -#include #include // Windows pollutes with preprocessor that redefine OPTIONAL. diff --git a/winml/lib/Telemetry/Telemetry.cpp b/winml/lib/Telemetry/Telemetry.cpp index baece28ced..26a23c6ec0 100644 --- a/winml/lib/Telemetry/Telemetry.cpp +++ b/winml/lib/Telemetry/Telemetry.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Telemetry/pch.h" WinMLTelemetryHelper telemetry_helper; diff --git a/winml/lib/Telemetry/TelemetryEvent.cpp b/winml/lib/Telemetry/TelemetryEvent.cpp index 027ab4cd7b..64c4c56889 100644 --- a/winml/lib/Telemetry/TelemetryEvent.cpp +++ b/winml/lib/Telemetry/TelemetryEvent.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include "lib/Telemetry/pch.h" #include "inc/TelemetryEvent.h" diff --git a/winml/lib/Telemetry/WinMLTelemetryHelper.cpp b/winml/lib/Telemetry/WinMLTelemetryHelper.cpp index 70c0975aa0..83e8429f35 100644 --- a/winml/lib/Telemetry/WinMLTelemetryHelper.cpp +++ b/winml/lib/Telemetry/WinMLTelemetryHelper.cpp @@ -7,7 +7,7 @@ // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#include "pch.h" +#include "lib/Telemetry/pch.h" WinMLTelemetryHelper::WinMLTelemetryHelper() : provider_(winml_trace_logging_provider) { diff --git a/winml/test/adapter/AdapterDmlEpTest.cpp b/winml/test/adapter/AdapterDmlEpTest.cpp index e849e232ba..ee744616a0 100644 --- a/winml/test/adapter/AdapterDmlEpTest.cpp +++ b/winml/test/adapter/AdapterDmlEpTest.cpp @@ -4,7 +4,6 @@ #include "testPch.h" #include "AdapterDmlEpTest.h" -#include #include "common.h" #include "iengine.h" diff --git a/winml/test/api/APITest.h b/winml/test/api/APITest.h index 0bff68e695..e2f6b959c5 100644 --- a/winml/test/api/APITest.h +++ b/winml/test/api/APITest.h @@ -13,14 +13,14 @@ static void LoadModel(const std::wstring& modelPath, learningModel = winml::LearningModel::LoadFromFilePath(fullPath); }; -static uint64_t GetAdapterIdQuadPart(winml::LearningModelDevice& device) { +static inline uint64_t GetAdapterIdQuadPart(winml::LearningModelDevice& device) { LARGE_INTEGER id; id.LowPart = device.AdapterId().LowPart; id.HighPart = device.AdapterId().HighPart; return id.QuadPart; }; -static _LUID GetAdapterIdAsLUID(winml::LearningModelDevice& device) { +static inline _LUID GetAdapterIdAsLUID(winml::LearningModelDevice& device) { _LUID id; id.LowPart = device.AdapterId().LowPart; id.HighPart = device.AdapterId().HighPart; diff --git a/winml/test/common/dllload.cpp b/winml/test/common/dllload.cpp index 8cf031eedf..3d2f527084 100644 --- a/winml/test/common/dllload.cpp +++ b/winml/test/common/dllload.cpp @@ -37,7 +37,11 @@ HRESULT __stdcall WINRT_RoGetActivationFactory(HSTRING classId_hstring, GUID con if (starts_with(name, winml_dll_prefix)) { const wchar_t* lib_path = winml_dll_path.c_str(); +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) library = LoadLibraryExW(lib_path, nullptr, 0); +#else + library = LoadPackagedLibrary(lib_path, 0); +#endif } else {