From 1ae7b4bcbc02edc881ad28685da98e095dfceb17 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Thu, 16 Jan 2020 14:56:15 -0800 Subject: [PATCH 1/8] Revert "CMake cross-generator fixes (#2790)" This reverts commit dbe7d97fa1ab155f1309bced87199527e8f35bd2. --- cmake/external/dml.cmake | 8 +- cmake/onnxruntime_common.cmake | 16 ---- cmake/onnxruntime_mlas.cmake | 6 +- cmake/onnxruntime_providers.cmake | 35 +++----- cmake/onnxruntime_unittests.cmake | 87 ++++++++++++++++++- cmake/precompiled_header.cmake | 15 ++-- cmake/winml.cmake | 23 ++--- cmake/winml_cppwinrt.cmake | 69 +++++++-------- cmake/winml_sdk_helpers.cmake | 24 +---- .../core/platform/windows/debug_alloc.cc | 8 +- 10 files changed, 160 insertions(+), 131 deletions(-) diff --git a/cmake/external/dml.cmake b/cmake/external/dml.cmake index 35c606f6412e8..41de28fdd2e0a 100644 --- a/cmake/external/dml.cmake +++ b/cmake/external/dml.cmake @@ -20,17 +20,19 @@ if (NOT onnxruntime_USE_CUSTOM_DIRECTML) set(NUGET_CONFIG ${PROJECT_SOURCE_DIR}/../NuGet.config) set(PACKAGES_CONFIG ${PROJECT_SOURCE_DIR}/../packages.config) set(PACKAGES_DIR ${CMAKE_CURRENT_BINARY_DIR}/packages) - set(DML_PACKAGE_DIR ${PACKAGES_DIR}/DirectML.0.0.1) # Restore nuget packages, which will pull down the DirectML redist package add_custom_command( - OUTPUT ${DML_PACKAGE_DIR}/bin/x64/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86/DirectML.lib + OUTPUT restore_packages.stamp DEPENDS ${PACKAGES_CONFIG} ${NUGET_CONFIG} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/nuget/src/nuget restore ${PACKAGES_CONFIG} -PackagesDirectory ${PACKAGES_DIR} -ConfigFile ${NUGET_CONFIG} + COMMAND ${CMAKE_COMMAND} -E touch restore_packages.stamp VERBATIM) - add_custom_target(RESTORE_PACKAGES ALL DEPENDS ${DML_PACKAGE_DIR}/bin/x64/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86/DirectML.lib) + add_custom_target(RESTORE_PACKAGES ALL DEPENDS restore_packages.stamp) add_dependencies(RESTORE_PACKAGES nuget) + + list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES RESTORE_PACKAGES) else() include_directories(${dml_INCLUDE_DIR}) endif() diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake index 52aa2f3989d9d..63a8283429dce 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake @@ -44,22 +44,6 @@ else() endif() endif() -if(CMAKE_GENERATOR_PLATFORM) - # Multi-platform generator - set(onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM}) -else() - set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) -endif() -if(onnxruntime_target_platform STREQUAL "ARM64") - set(onnxruntime_target_platform "ARM64") -elseif(onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") - set(onnxruntime_target_platform "ARM") -elseif(onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64") - set(onnxruntime_target_platform "x64") -elseif(onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686") - set(onnxruntime_target_platform "x86") -endif() - file(GLOB onnxruntime_common_src CONFIGURE_DEPENDS ${onnxruntime_common_src_patterns} ) diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake index 38ec173dfc0b1..e7b4213bc6cbb 100644 --- a/cmake/onnxruntime_mlas.cmake +++ b/cmake/onnxruntime_mlas.cmake @@ -19,7 +19,7 @@ set(mlas_common_srcs ) if(MSVC) - if(onnxruntime_target_platform STREQUAL "ARM64") + if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") set(asm_filename ${ONNXRUNTIME_ROOT}/core/mlas/lib/arm64/SgemmKernelNeon.asm) set(pre_filename ${CMAKE_CURRENT_BINARY_DIR}/SgemmKernelNeon.i) set(obj_filename ${CMAKE_CURRENT_BINARY_DIR}/SgemmKernelNeon.obj) @@ -38,11 +38,11 @@ if(MSVC) armasm64.exe ${ARMASM_FLAGS} ${pre_filename} ${obj_filename} ) set(mlas_platform_srcs ${obj_filename}) - elseif(onnxruntime_target_platform STREQUAL "ARM") + elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") set(mlas_platform_srcs ${ONNXRUNTIME_ROOT}/core/mlas/lib/arm/sgemmc.cpp ) - elseif(onnxruntime_target_platform STREQUAL "x64") + elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x64" OR CMAKE_GENERATOR MATCHES "Win64") enable_language(ASM_MASM) set(mlas_platform_srcs diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake index 1b7047318ee85..9875955e3cd89 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake @@ -217,7 +217,7 @@ if (onnxruntime_USE_TENSORRT) if ( CMAKE_COMPILER_IS_GNUCC ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-missing-field-initializers") endif() - set(CXX_VERSION_DEFINED TRUE) + set(CXX_VERSION_DEFINED TRUE) add_subdirectory(${ONNXRUNTIME_ROOT}/../cmake/external/onnx-tensorrt) set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) if (WIN32) @@ -303,7 +303,7 @@ if (onnxruntime_USE_OPENVINO) if(WIN32) set(OPENVINO_LIB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/lib/intel64/Release) set(OPENVINO_TBB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/lib/intel64/Release) - set(OPENVINO_MKL_TINY_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/bin/intel64/Release) + set(OPENVINO_MKL_TINY_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/bin/intel64/Release) else() set(OPENVINO_LIB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/lib/intel64/) set(OPENVINO_TBB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/external/tbb/lib) @@ -327,9 +327,9 @@ if (onnxruntime_USE_OPENVINO) else() target_include_directories(onnxruntime_providers_openvino SYSTEM PUBLIC ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${OPENVINO_INCLUDE_DIR} ${OPENVINO_EXTENSIONS_DIR} ${OPENVINO_LIB_DIR} ${OPENVINO_TBB_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS}) endif() - - if (WIN32) - string(REPLACE "include" "libs" PYTHON_LIB ${PYTHON_INCLUDE_DIRS}) + + if (WIN32) + string(REPLACE "include" "libs" PYTHON_LIB ${PYTHON_INCLUDE_DIRS}) find_package(InferenceEngine 2.1 REQUIRED) set(PYTHON_LIBRARIES ${PYTHON_LIB}) set(OPENVINO_CPU_EXTENSION_DIR ${onnxruntime_BINARY_DIR}/ie_cpu_extension/${CMAKE_BUILD_TYPE}) @@ -430,37 +430,22 @@ if (onnxruntime_USE_DML) onnxruntime_add_include_to_target(onnxruntime_providers_dml onnxruntime_common onnxruntime_framework onnx onnx_proto protobuf::libprotobuf) add_dependencies(onnxruntime_providers_dml ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_providers_dml PRIVATE ${ONNXRUNTIME_ROOT} ${ONNXRUNTIME_ROOT}/../cmake/external/wil/include) - - if(NOT onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_target_platform STREQUAL "x64") - message(FATAL_ERROR "Target platform ${onnxruntime_target_platform} is not supported by DML") - endif() - foreach(file "DirectML.dll" "DirectML.pdb" "DirectML.Debug.dll" "DirectML.Debug.pdb") - add_custom_command(TARGET onnxruntime_providers_dml - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - "${DML_PACKAGE_DIR}/bin/${onnxruntime_target_platform}/${file}" $) - endforeach() - - function(target_add_dml target) - target_link_libraries(${target} PRIVATE "${DML_PACKAGE_DIR}/bin/${onnxruntime_target_platform}/DirectML.lib") - target_include_directories(${target} PRIVATE "${DML_PACKAGE_DIR}/include") - endfunction() - - target_add_dml(onnxruntime_providers_dml) - target_link_libraries(onnxruntime_providers_dml PRIVATE d3d12.lib dxgi.lib delayimp.lib) + + target_link_libraries(onnxruntime_providers_dml ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) + target_link_libraries(onnxruntime_providers_dml d3d12.lib dxgi.lib) list(APPEND ONNXRUNTIME_LINKER_FLAGS "/DELAYLOAD:DirectML.dll /DELAYLOAD:d3d12.dll /DELAYLOAD:dxgi.dll") # The DML EP requires C++17 set_target_properties(onnxruntime_providers_dml PROPERTIES CXX_STANDARD 17) set_target_properties(onnxruntime_providers_dml PROPERTIES CXX_STANDARD_REQUIRED ON) - + target_compile_definitions(onnxruntime_providers_dml PRIVATE ONNX_NAMESPACE=onnx ONNX_ML LOTUS_LOG_THRESHOLD=2 LOTUS_ENABLE_STDERR_LOGGING PLATFORM_WINDOWS) target_compile_definitions(onnxruntime_providers_dml PRIVATE UNICODE _UNICODE NOMINMAX) if (MSVC) target_compile_definitions(onnxruntime_providers_dml PRIVATE _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) target_compile_options(onnxruntime_providers_dml PRIVATE "/W3") endif() - + install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/dml DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers) set_target_properties(onnxruntime_providers_dml PROPERTIES LINKER_LANGUAGE CXX) diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 258b57224b02b..7944b60fa4c13 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -44,7 +44,7 @@ function(AddTest) endif() if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS AND onnxruntime_ENABLE_PYTHON) target_compile_definitions(${_UT_TARGET} PRIVATE ENABLE_LANGUAGE_INTEROP_OPS) - endif() + endif() if (WIN32) if (onnxruntime_USE_CUDA) # disable a warning from the CUDA headers about unreferenced local functions @@ -318,7 +318,7 @@ if (onnxruntime_USE_DNNL) target_compile_definitions(onnxruntime_test_utils_for_framework PUBLIC USE_DNNL=1) endif() if (onnxruntime_USE_DML) - target_add_dml(onnxruntime_test_utils_for_framework) + target_link_libraries(onnxruntime_test_utils_for_framework PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) endif() add_dependencies(onnxruntime_test_utils_for_framework ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_test_utils_for_framework PUBLIC "${TEST_SRC_DIR}/util/include" PRIVATE ${eigen_INCLUDE_DIRS} ${ONNXRUNTIME_ROOT}) @@ -336,7 +336,7 @@ if (onnxruntime_USE_DNNL) target_compile_definitions(onnxruntime_test_utils PUBLIC USE_DNNL=1) endif() if (onnxruntime_USE_DML) - target_add_dml(onnxruntime_test_utils) + target_link_libraries(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) endif() add_dependencies(onnxruntime_test_utils ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_test_utils PUBLIC "${TEST_SRC_DIR}/util/include" PRIVATE ${eigen_INCLUDE_DIRS} ${ONNXRUNTIME_ROOT}) @@ -711,6 +711,87 @@ if (onnxruntime_BUILD_SHARED_LIB) ) endif() +if (onnxruntime_BUILD_SERVER) + file(GLOB onnxruntime_test_server_src + "${TEST_SRC_DIR}/server/unit_tests/*.cc" + "${TEST_SRC_DIR}/server/unit_tests/*.h" + ) + + file(GLOB onnxruntime_integration_test_server_src + "${TEST_SRC_DIR}/server/integration_tests/*.py" + ) + if(NOT WIN32) + if(HAS_UNUSED_PARAMETER) + set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/json_handling_tests.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) + set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/converter_tests.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) + set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/util_tests.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) + set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/prediction_service_impl_test.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) + set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/executor_test.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) + endif() + endif() + + add_library(onnxruntime_test_utils_for_server ${onnxruntime_test_server_src}) + onnxruntime_add_include_to_target(onnxruntime_test_utils_for_server onnxruntime_test_utils_for_framework gtest gmock onnx onnx_proto server_proto server_grpc_proto) + add_dependencies(onnxruntime_test_utils_for_server onnxruntime_server_lib onnxruntime_server_http_core_lib Boost ${onnxruntime_EXTERNAL_DEPENDENCIES}) + target_include_directories(onnxruntime_test_utils_for_server PUBLIC ${Boost_INCLUDE_DIR} ${REPO_ROOT}/cmake/external/re2 ${CMAKE_CURRENT_BINARY_DIR}/onnx ${ONNXRUNTIME_ROOT}/server ${ONNXRUNTIME_ROOT}/server/http ${ONNXRUNTIME_ROOT}/server/http/core ${ONNXRUNTIME_ROOT}/server/grpc ${ONNXRUNTIME_ROOT}/server ${ONNXRUNTIME_ROOT}/server/core PRIVATE ${ONNXRUNTIME_ROOT}) + if (onnxruntime_USE_OPENVINO) + message(${OPENVINO_INCLUDE_DIR}) + target_include_directories(onnxruntime_test_utils_for_server PUBLIC ${OPENVINO_INCLUDE_DIR} ${OPENVINO_TBB_INCLUDE_DIR}) + endif() + if(UNIX) + target_compile_options(onnxruntime_test_utils_for_server PRIVATE "$<$:SHELL:-Xcompiler -Wno-error=sign-compare>" + "$<$>:-Wno-error=sign-compare>") + endif() + target_link_libraries(onnxruntime_test_utils_for_server ${Boost_LIBRARIES} spdlog::spdlog server_grpc_proto) + + + AddTest( + TARGET onnxruntime_server_tests + SOURCES ${onnxruntime_test_server_src} + LIBS ${onnxruntime_test_server_libs} server_proto server_grpc_proto onnxruntime_server_lib ${onnxruntime_test_providers_libs} + DEPENDS ${onnxruntime_EXTERNAL_DEPENDENCIES} + ) + + onnxruntime_protobuf_generate( + APPEND_PATH IMPORT_DIRS ${REPO_ROOT}/cmake/external/protobuf/src ${ONNXRUNTIME_ROOT}/server/protobuf ${ONNXRUNTIME_ROOT}/core/protobuf + PROTOS ${ONNXRUNTIME_ROOT}/server/protobuf/predict.proto ${ONNXRUNTIME_ROOT}/server/protobuf/onnx-ml.proto + LANGUAGE python + TARGET onnxruntime_server_tests + OUT_VAR server_test_py) + + set(grpc_py "${CMAKE_CURRENT_BINARY_DIR}/prediction_service_pb2_grpc.py") + + add_custom_command( + TARGET onnxruntime_server_tests + COMMAND $ + ARGS + --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" + --plugin=protoc-gen-grpc="${_GRPC_PY_PLUGIN_EXECUTABLE}" + -I ${grpc_proto_path} + "${grpc_proto}" + DEPENDS "${grpc_proto}" + COMMENT "Running ${_GRPC_PY_PLUGIN_EXECUTABLE} on ${grpc_proto}" + ) + + add_custom_command( + TARGET onnxruntime_server_tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/server_test + COMMAND ${CMAKE_COMMAND} -E copy + ${onnxruntime_integration_test_server_src} + ${CMAKE_CURRENT_BINARY_DIR}/server_test/ + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/onnx_ml_pb2.py + ${CMAKE_CURRENT_BINARY_DIR}/server_test/ + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_CURRENT_BINARY_DIR}/predict_pb2.py + ${CMAKE_CURRENT_BINARY_DIR}/server_test/ + COMMAND ${CMAKE_COMMAND} -E copy + ${grpc_py} + ${CMAKE_CURRENT_BINARY_DIR}/server_test/ + ) + +endif() + #some ETW tools if(WIN32 AND onnxruntime_ENABLE_INSTRUMENT) add_executable(generate_perf_report_from_etl ${ONNXRUNTIME_ROOT}/tool/etw/main.cc ${ONNXRUNTIME_ROOT}/tool/etw/eparser.h ${ONNXRUNTIME_ROOT}/tool/etw/eparser.cc ${ONNXRUNTIME_ROOT}/tool/etw/TraceSession.h ${ONNXRUNTIME_ROOT}/tool/etw/TraceSession.cc) diff --git a/cmake/precompiled_header.cmake b/cmake/precompiled_header.cmake index 3bebf7341809b..f41310fac524c 100644 --- a/cmake/precompiled_header.cmake +++ b/cmake/precompiled_header.cmake @@ -2,7 +2,8 @@ # header name as input. The function will generate a .cpp file that includes the header and is used # to generate the precompiled header; this source file is added to the target's sources. function(target_precompiled_header target_name header_name) - if (MSVC AND CMAKE_VS_PLATFORM_TOOLSET) + if (MSVC) + # The input precompiled header source (i.e. the '.h' file used for the precompiled header). set(pch_header_path ${header_name}) get_filename_component(header_base_name ${header_name} NAME_WE) @@ -13,14 +14,14 @@ function(target_precompiled_header target_name header_name) 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}") - + # The target's C++ sources use the precompiled header (/Yu). Source-level properties will - # take precedence over target-level properties, so this will not change the generated source + # take precedence over target-level properties, so this will not change the generated source # file's property to create the precompiled header (/Yc). target_compile_options(${target_name} PRIVATE $<$:/Yu${header_name}>) - + # Append generated precompiled source to target's sources. target_sources(${target_name} PRIVATE ${pch_source_path}) - - endif() -endfunction() + + endif(MSVC) +endfunction() \ No newline at end of file diff --git a/cmake/winml.cmake b/cmake/winml.cmake index f9c02ddf0e9e5..71824b3997fcf 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -132,7 +132,7 @@ list(APPEND winml_adapter_files ${winml_adapter_dir}/WinMLAdapter.cpp ${winml_adapter_dir}/WinMLAdapter.h ${winml_adapter_dir}/ZeroCopyInputStreamWrapper.cpp - ${winml_adapter_dir}/ZeroCopyInputStreamWrapper.h + ${winml_adapter_dir}/ZeroCopyInputStreamWrapper.h ) if (onnxruntime_USE_DML) @@ -159,7 +159,6 @@ add_dependencies(winml_adapter ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_precompiled_header(winml_adapter pch.h) # Includes -target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers @@ -182,11 +181,11 @@ add_dependencies(winml_adapter winml_api_native_internal) # Link libraries target_link_libraries(winml_adapter PRIVATE wil) if (onnxruntime_USE_DML) - target_add_dml(winml_adapter) + target_link_libraries(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) endif(onnxruntime_USE_DML) # add it to the onnxruntime shared library -set(onnxruntime_winml winml_adapter) +set(onnxruntime_winml windowsapp.lib winml_adapter) list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES winml_adapter) ########################### @@ -231,7 +230,6 @@ target_compile_definitions(winml_lib_image PRIVATE _SCL_SECURE_NO_WARNINGS) target_precompiled_header(winml_lib_image pch.h) # Includes -target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers @@ -260,7 +258,7 @@ add_dependencies(winml_lib_image winml_api_native_internal) # Link libraries target_link_libraries(winml_lib_image PRIVATE wil) if (onnxruntime_USE_DML) - target_add_dml(winml_lib_image) + target_link_libraries(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) endif(onnxruntime_USE_DML) @@ -362,7 +360,7 @@ add_dependencies(winml_lib_api winml_api_native_internal) # Link libraries target_link_libraries(winml_lib_api PRIVATE wil) if (onnxruntime_USE_DML) - target_add_dml(winml_lib_api) + target_link_libraries(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) endif(onnxruntime_USE_DML) @@ -440,13 +438,6 @@ if (onnxruntime_USE_DML) set(delayload_dml "/DELAYLOAD:directml.dll") endif(onnxruntime_USE_DML) -# The default libraries to link with in Windows are kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib -# Remove them and use the onecore umbrella library instead -foreach(default_lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdgl32.lib advapi32.lib) - set(removed_libs "${removed_libs} /NODEFAULTLIB:${default_lib}") -endforeach() -set(CMAKE_C_STANDARD_LIBRARIES "${removed_libs} onecoreuap.lib") -set(CMAKE_CXX_STANDARD_LIBRARIES "${removed_libs} onecoreuap.lib") set_target_properties(winml_dll PROPERTIES LINK_FLAGS @@ -476,10 +467,11 @@ endif("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") target_link_libraries(winml_dll PRIVATE onnxruntime) target_link_libraries(winml_dll PRIVATE re2) target_link_libraries(winml_dll PRIVATE wil) +#target_link_libraries(winml_dll PRIVATE windowsapp.lib) target_link_libraries(winml_dll PRIVATE winml_lib_api) target_link_libraries(winml_dll PRIVATE winml_lib_image) target_link_libraries(winml_dll PRIVATE winml_lib_telemetry) -target_link_libraries(winml_dll PRIVATE delayimp.lib) +target_link_libraries(winml_dll PRIVATE onecoreuap_apiset.lib) target_link_libraries(winml_dll PRIVATE ${DBGHELP}) # 1 of 3 projects that fail in link with 'failed to do memory mapped file I/O' (Only release) @@ -491,7 +483,6 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") set_target_properties(winml_dll PROPERTIES VS_GLOBAL_PreferredToolArchitecture "x64") endif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") -option(onnxruntime_BUILD_WINML_TESTS "Build WinML tests" ON) if (onnxruntime_BUILD_WINML_TESTS) include(winml_unittests.cmake) endif() diff --git a/cmake/winml_cppwinrt.cmake b/cmake/winml_cppwinrt.cmake index ea96a1b289764..2d53ade270b2b 100644 --- a/cmake/winml_cppwinrt.cmake +++ b/cmake/winml_cppwinrt.cmake @@ -102,7 +102,7 @@ function(target_cppwinrt # Get directory get_filename_component(idl_source_directory ${file} DIRECTORY) - set(target_outputs ${CMAKE_CURRENT_BINARY_DIR}/${target_name}) + set(target_outputs ${CMAKE_CURRENT_BINARY_DIR}/${target_name}) convert_forward_slashes_to_back(${target_outputs}/comp output_dir_back_slash) convert_forward_slashes_to_back(${target_outputs}/temp temp_dir_back_slash) convert_forward_slashes_to_back(${target_outputs}/comp_generated generated_dir_back_slash) @@ -126,53 +126,50 @@ function(target_cppwinrt /tlb ${tlb_filename} ${idl_file_forward_slash} COMMAND - ${cppwinrt_exe} -in ${winmd_filename} -comp ${output_dir_back_slash} -ref ${sdk_metadata_directory} -out ${generated_dir_back_slash} -verbose + ${cppwinrt_exe} -in \"${winmd_filename}\" -comp \"${output_dir_back_slash}\" -ref \"${sdk_metadata_directory}\" -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 + xcopy \"${output_dir_back_slash}\" \"${temp_dir_back_slash}\\\" /Y /D COMMAND # for each file in the temp directory, ensure it is not in the exclusions list. # if it is, then we need to delete it. - cmd /C "@echo off \ - for /f %I in ('dir /b ${temp_dir_back_slash}') \ - do \ - ( \ - for /f %E in (${CPPWINRT_COMPONENT_EXCLUSION_LIST}) \ - do \ - ( \ - if %E == %I \ - ( \ - del ${temp_dir_back_slash}\\%I \ - ) \ - ) \ - )" + for /f %%I in ('dir /b \"${temp_dir_back_slash}\"') + do + ( + for /f %%E in (${CPPWINRT_COMPONENT_EXCLUSION_LIST}) + do + ( + if %%E == %%I + ( + del \"${temp_dir_back_slash}\\%%I\" + ) + ) + ) COMMAND # for each file in the temp directory, copy the file back into the source tree # unless the file already exists - cmd /C "@echo off \ - for /f %I in ('dir /b ${temp_dir_back_slash}') \ - do \ - ( \ - if not exist ${out_sources_folder}\\%I \ - ( \ - copy ${temp_dir_back_slash}\\%I ${out_sources_folder}\\%I \ - ) \ - )" + for /f %%I in ('dir /b \"${temp_dir_back_slash}\"') + do + ( + if not exist \"${out_sources_folder}\\%%I\" + ( + xcopy \"${temp_dir_back_slash}\\%%I\" \"${out_sources_folder}\\%%I\" + ) + ) COMMAND # open the generated module.g.cpp and strip all the includes (lines) containing excluded headers # write the new file out to module.g.excl.cpp. - powershell -Command "& { \ - $exclusions = get-content '${CPPWINRT_COMPONENT_EXCLUSION_LIST}'; \ - (get-content '${module_g_cpp_back_slash}') \ - | where { \ - $str = $_; \ - $matches = ($exclusions | where { $str -match $_ }); \ - $matches.Length -eq 0 } \ - | Out-File '${module_g_ecxl_cpp_back_slash}' \ - }" + powershell -Command \"& { + $exclusions = get-content '${CPPWINRT_COMPONENT_EXCLUSION_LIST}'\; + (get-content '${module_g_cpp_back_slash}') + | where { + $str = $_\; + $matches = ($exclusions | where { $str -match $_ }) \; + $matches.Length -eq 0 } + | Out-File '${module_g_ecxl_cpp_back_slash}' + }\" BYPRODUCTS ${generated_dir_back_slash}/module.g.excl.cpp - VERBATIM ) add_custom_target( @@ -217,4 +214,4 @@ function(add_generate_cppwinrt_sdk_headers_target set_target_properties(${target_name} PROPERTIES FOLDER ${folder_name}) endif() -endfunction() +endfunction() \ No newline at end of file diff --git a/cmake/winml_sdk_helpers.cmake b/cmake/winml_sdk_helpers.cmake index df9db93a6b467..03a87653fe986 100644 --- a/cmake/winml_sdk_helpers.cmake +++ b/cmake/winml_sdk_helpers.cmake @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -# utility +# utility function(convert_forward_slashes_to_back input output) string(REGEX REPLACE "/" "\\\\" backwards ${input}) set(${output} ${backwards} PARENT_SCOPE) @@ -16,23 +16,7 @@ function(get_installed_sdk set(${sdk_folder} ${win10_sdk_root} PARENT_SCOPE) # return the sdk version - if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) - set(${output_sdk_version} ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} PARENT_SCOPE) - else() - # choose the SDK matching the system version, or fallback to the latest - file(GLOB win10_sdks RELATIVE "${win10_sdk_root}/UnionMetadata" "${win10_sdk_root}/UnionMetadata/*.*.*.*") - list(GET win10_sdks 0 latest_sdk) - foreach(sdk IN LISTS win10_sdks) - string(FIND ${sdk} ${CMAKE_SYSTEM_VERSION} is_system_version) - if(NOT ${is_system_version} EQUAL -1) - set(${output_sdk_version} ${sdk} PARENT_SCOPE) - return() - elseif(sdk VERSION_GREATER latest_sdk) - set(latest_sdk ${sdk}) - endif() - endforeach() - set(${output_sdk_version} ${latest_sdk} PARENT_SCOPE) - endif() + set(${output_sdk_version} ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} PARENT_SCOPE) endfunction() # current sdk binary directory @@ -111,7 +95,7 @@ function(get_sdk set(${output_sdk_version} ${winml_WINDOWS_SDK_VERSION_OVERRIDE} PARENT_SCOPE) else() message( - FATAL_ERROR + FATAL_ERROR "Options winml_WINDOWS_SDK_DIR_OVERRIDE and winml_WINDOWS_SDK_VERSION_OVERRIDE must be defined together, or not at all.") endif() -endfunction() +endfunction() \ No newline at end of file diff --git a/onnxruntime/core/platform/windows/debug_alloc.cc b/onnxruntime/core/platform/windows/debug_alloc.cc index 57267f146d884..83c38baa05248 100644 --- a/onnxruntime/core/platform/windows/debug_alloc.cc +++ b/onnxruntime/core/platform/windows/debug_alloc.cc @@ -232,8 +232,12 @@ Memory_LeakCheck::~Memory_LeakCheck() { _snprintf_s(buffer, _TRUNCATE, "%d bytes of memory leaked in %d allocations", leaked_bytes, leak_count); string.append(buffer); - std::cout << "\n----- MEMORY LEAKS: " << string.c_str() << "\n"; - if (!IsDebuggerPresent()) { + // If we're being actively debugged, show a message box to get the dev's attention + if (IsDebuggerPresent()) + MessageBoxA(nullptr, string.c_str(), "Warning", MB_OK | MB_ICONWARNING); + else { + // If we're on the command line (like on a build machine), output to the console and exit(-1) + std::cout << "\n----- MEMORY LEAKS: " << string.c_str() << "\n"; exit(-1); } From 5786fb8bf03c658c402fdd41c3cd6df761fe2a2f Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Thu, 16 Jan 2020 16:31:33 -0800 Subject: [PATCH 2/8] add additional suppress warning in onnx_proto --- cmake/onnx/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/onnx/CMakeLists.txt b/cmake/onnx/CMakeLists.txt index 1048c90bd2c5c..0e2a09384f85a 100644 --- a/cmake/onnx/CMakeLists.txt +++ b/cmake/onnx/CMakeLists.txt @@ -6,7 +6,7 @@ target_include_directories(onnx_proto PUBLIC $) onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS ${ONNXRUNTIME_ROOT}/core/protobuf TARGET onnx_proto) if (WIN32) - target_compile_options(onnx_proto PRIVATE "/wd4146" "/wd4125" "/wd4456" "/wd4267") + target_compile_options(onnx_proto PRIVATE "/wd4146" "/wd4125" "/wd4456" "/wd4267" "/wd4309") else() if(HAS_UNUSED_VARIABLE) target_compile_options(onnx_proto PRIVATE "-Wno-unused-variable") From fdc78c2496240127a816869a0a900c27b5d66942 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Thu, 16 Jan 2020 17:32:44 -0800 Subject: [PATCH 3/8] ignore /wd4996 warning --- cmake/onnx/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/onnx/CMakeLists.txt b/cmake/onnx/CMakeLists.txt index 0e2a09384f85a..d14f51e455b41 100644 --- a/cmake/onnx/CMakeLists.txt +++ b/cmake/onnx/CMakeLists.txt @@ -51,6 +51,7 @@ if (WIN32) /wd4100 # 'param' : unreferenced formal parameter /wd4244 # 'argument' conversion from 'google::protobuf::int64' to 'int', possible loss of data /EHsc # exception handling - C++ may throw, extern "C" will not + /wd4996 # 'argument' Using double parameter version instead of single parameter version of SetTotalBytesLimit(). The second parameter is ignored. ) set(onnx_static_library_flags -IGNORE:4221 # LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library From 7379329976bac53243600c59dbee9f6c47218811 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Fri, 17 Jan 2020 15:15:32 -0800 Subject: [PATCH 4/8] DML execution provider fixes --- .../src/Operators/DmlOperatorPooling.cpp | 2 +- .../DmlExecutionProvider/src/Operators/DmlOperatorSlice.cpp | 2 +- .../src/Operators/OperatorRegistration.h | 6 +++--- .../dml/OperatorAuthorHelper/MLOperatorAuthorHelper.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorPooling.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorPooling.cpp index 7f27291ede562..b64ae7dc751ae 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorPooling.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorPooling.cpp @@ -134,7 +134,7 @@ class DmlOperatorPoolingTemplate : public DmlOperatorPooling } }; -void QueryMaxPool(IMLOperatorSupportQueryContextPrivate* context, bool *isSupported) +void CALLBACK QueryMaxPool(IMLOperatorSupportQueryContextPrivate* context, bool *isSupported) { *isSupported = false; diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorSlice.cpp b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorSlice.cpp index e167a89f0606e..0e9d0feb5a815 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorSlice.cpp +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/DmlOperatorSlice.cpp @@ -71,7 +71,7 @@ class DmlOperatorSliceTemplate : public DmlOperatorSlice } }; -void QuerySlice(IMLOperatorSupportQueryContextPrivate* context, bool *isSupported) +void CALLBACK QuerySlice(IMLOperatorSupportQueryContextPrivate* context, bool *isSupported) { *isSupported = (context->GetInputCount() <= 4); } diff --git a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.h b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.h index 186608d78b586..45923d528dc05 100644 --- a/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.h +++ b/onnxruntime/core/providers/dml/DmlExecutionProvider/src/Operators/OperatorRegistration.h @@ -8,8 +8,8 @@ interface IMLOperatorKernel; class MLOperatorKernelCreationContext; // Forward declares an external creation function. -#define DML_OP_EXTERN_CREATION_FUNCTION(operatorName) extern void Create##operatorName(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel) -#define DML_OP_EXTERN_QUERY_FUNCTION(operatorName) extern void Query##operatorName(IMLOperatorSupportQueryContextPrivate* context, bool *isSupported); +#define DML_OP_EXTERN_CREATION_FUNCTION(operatorName) extern void CALLBACK Create##operatorName(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel) +#define DML_OP_EXTERN_QUERY_FUNCTION(operatorName) extern void CALLBACK Query##operatorName(IMLOperatorSupportQueryContextPrivate* context, bool* isSupported); // Declares a callback creation function of the given operator class. // This does not register it, just declares it for usage by registration later. @@ -20,7 +20,7 @@ class MLOperatorKernelCreationContext; // commas in them break the macro, and so they are stuffed into the VA_ARGS. // #define DML_OP_DEFINE_CREATION_FUNCTION(operatorName, ...)\ -extern void Create##operatorName(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel)\ +extern void CALLBACK Create##operatorName(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel)\ {\ using T = __VA_ARGS__; \ THROW_IF_FAILED(MLOperatorKernel::CreateInstance(*kernelInfo, /*out*/ opKernel));\ diff --git a/onnxruntime/core/providers/dml/OperatorAuthorHelper/MLOperatorAuthorHelper.h b/onnxruntime/core/providers/dml/OperatorAuthorHelper/MLOperatorAuthorHelper.h index b15955e0e533d..7fee23b8d0004 100644 --- a/onnxruntime/core/providers/dml/OperatorAuthorHelper/MLOperatorAuthorHelper.h +++ b/onnxruntime/core/providers/dml/OperatorAuthorHelper/MLOperatorAuthorHelper.h @@ -734,7 +734,7 @@ class MLOperatorKernel : public Microsoft::WRL::RuntimeClass< using MLOperatorTypeInferenceFunction = void (CALLBACK*)(IMLOperatorTypeInferenceContext*); using MLOperatorShapeInferenceFunction = void (CALLBACK*)(IMLOperatorShapeInferenceContext*); -using MLOperatorKernelCreateFn = void(*)(IMLOperatorKernelCreationContext*, IMLOperatorKernel**); +using MLOperatorKernelCreateFn = void(CALLBACK*)(IMLOperatorKernelCreationContext*, IMLOperatorKernel**); using MLOperatorSupportQueryFunction = void (CALLBACK*)(IMLOperatorSupportQueryContextPrivate*, bool*); class MLOperatorShapeInferrer : public Microsoft::WRL::RuntimeClass< From 3e3a6c03151ce56ad60682903f4d4e5939a6ead3 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Fri, 17 Jan 2020 16:21:30 -0800 Subject: [PATCH 5/8] Revert "Revert "CMake cross-generator fixes (#2790)"" This reverts commit 1ae7b4bcbc02edc881ad28685da98e095dfceb17. --- cmake/external/dml.cmake | 8 +- cmake/onnxruntime_common.cmake | 16 ++++ cmake/onnxruntime_mlas.cmake | 6 +- cmake/onnxruntime_providers.cmake | 35 +++++--- cmake/onnxruntime_unittests.cmake | 87 +------------------ cmake/precompiled_header.cmake | 15 ++-- cmake/winml.cmake | 23 +++-- cmake/winml_cppwinrt.cmake | 69 ++++++++------- cmake/winml_sdk_helpers.cmake | 24 ++++- .../core/platform/windows/debug_alloc.cc | 8 +- 10 files changed, 131 insertions(+), 160 deletions(-) diff --git a/cmake/external/dml.cmake b/cmake/external/dml.cmake index 41de28fdd2e0a..35c606f6412e8 100644 --- a/cmake/external/dml.cmake +++ b/cmake/external/dml.cmake @@ -20,19 +20,17 @@ if (NOT onnxruntime_USE_CUSTOM_DIRECTML) set(NUGET_CONFIG ${PROJECT_SOURCE_DIR}/../NuGet.config) set(PACKAGES_CONFIG ${PROJECT_SOURCE_DIR}/../packages.config) set(PACKAGES_DIR ${CMAKE_CURRENT_BINARY_DIR}/packages) + set(DML_PACKAGE_DIR ${PACKAGES_DIR}/DirectML.0.0.1) # Restore nuget packages, which will pull down the DirectML redist package add_custom_command( - OUTPUT restore_packages.stamp + OUTPUT ${DML_PACKAGE_DIR}/bin/x64/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86/DirectML.lib DEPENDS ${PACKAGES_CONFIG} ${NUGET_CONFIG} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/nuget/src/nuget restore ${PACKAGES_CONFIG} -PackagesDirectory ${PACKAGES_DIR} -ConfigFile ${NUGET_CONFIG} - COMMAND ${CMAKE_COMMAND} -E touch restore_packages.stamp VERBATIM) - add_custom_target(RESTORE_PACKAGES ALL DEPENDS restore_packages.stamp) + add_custom_target(RESTORE_PACKAGES ALL DEPENDS ${DML_PACKAGE_DIR}/bin/x64/DirectML.lib ${DML_PACKAGE_DIR}/bin/x86/DirectML.lib) add_dependencies(RESTORE_PACKAGES nuget) - - list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES RESTORE_PACKAGES) else() include_directories(${dml_INCLUDE_DIR}) endif() diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake index 63a8283429dce..52aa2f3989d9d 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake @@ -44,6 +44,22 @@ else() endif() endif() +if(CMAKE_GENERATOR_PLATFORM) + # Multi-platform generator + set(onnxruntime_target_platform ${CMAKE_GENERATOR_PLATFORM}) +else() + set(onnxruntime_target_platform ${CMAKE_SYSTEM_PROCESSOR}) +endif() +if(onnxruntime_target_platform STREQUAL "ARM64") + set(onnxruntime_target_platform "ARM64") +elseif(onnxruntime_target_platform STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") + set(onnxruntime_target_platform "ARM") +elseif(onnxruntime_target_platform STREQUAL "x64" OR onnxruntime_target_platform STREQUAL "x86_64" OR onnxruntime_target_platform STREQUAL "AMD64" OR CMAKE_GENERATOR MATCHES "Win64") + set(onnxruntime_target_platform "x64") +elseif(onnxruntime_target_platform STREQUAL "x86" OR onnxruntime_target_platform STREQUAL "i386" OR onnxruntime_target_platform STREQUAL "i686") + set(onnxruntime_target_platform "x86") +endif() + file(GLOB onnxruntime_common_src CONFIGURE_DEPENDS ${onnxruntime_common_src_patterns} ) diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake index e7b4213bc6cbb..38ec173dfc0b1 100644 --- a/cmake/onnxruntime_mlas.cmake +++ b/cmake/onnxruntime_mlas.cmake @@ -19,7 +19,7 @@ set(mlas_common_srcs ) if(MSVC) - if(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64") + if(onnxruntime_target_platform STREQUAL "ARM64") set(asm_filename ${ONNXRUNTIME_ROOT}/core/mlas/lib/arm64/SgemmKernelNeon.asm) set(pre_filename ${CMAKE_CURRENT_BINARY_DIR}/SgemmKernelNeon.i) set(obj_filename ${CMAKE_CURRENT_BINARY_DIR}/SgemmKernelNeon.obj) @@ -38,11 +38,11 @@ if(MSVC) armasm64.exe ${ARMASM_FLAGS} ${pre_filename} ${obj_filename} ) set(mlas_platform_srcs ${obj_filename}) - elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "ARM" OR CMAKE_GENERATOR MATCHES "ARM") + elseif(onnxruntime_target_platform STREQUAL "ARM") set(mlas_platform_srcs ${ONNXRUNTIME_ROOT}/core/mlas/lib/arm/sgemmc.cpp ) - elseif(CMAKE_GENERATOR_PLATFORM STREQUAL "x64" OR CMAKE_GENERATOR MATCHES "Win64") + elseif(onnxruntime_target_platform STREQUAL "x64") enable_language(ASM_MASM) set(mlas_platform_srcs diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake index 9875955e3cd89..1b7047318ee85 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake @@ -217,7 +217,7 @@ if (onnxruntime_USE_TENSORRT) if ( CMAKE_COMPILER_IS_GNUCC ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-missing-field-initializers") endif() - set(CXX_VERSION_DEFINED TRUE) + set(CXX_VERSION_DEFINED TRUE) add_subdirectory(${ONNXRUNTIME_ROOT}/../cmake/external/onnx-tensorrt) set(CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS}) if (WIN32) @@ -303,7 +303,7 @@ if (onnxruntime_USE_OPENVINO) if(WIN32) set(OPENVINO_LIB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/lib/intel64/Release) set(OPENVINO_TBB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/lib/intel64/Release) - set(OPENVINO_MKL_TINY_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/bin/intel64/Release) + set(OPENVINO_MKL_TINY_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/bin/intel64/Release) else() set(OPENVINO_LIB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/lib/intel64/) set(OPENVINO_TBB_DIR $ENV{INTEL_OPENVINO_DIR}/deployment_tools/inference_engine/external/tbb/lib) @@ -327,9 +327,9 @@ if (onnxruntime_USE_OPENVINO) else() target_include_directories(onnxruntime_providers_openvino SYSTEM PUBLIC ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${OPENVINO_INCLUDE_DIR} ${OPENVINO_EXTENSIONS_DIR} ${OPENVINO_LIB_DIR} ${OPENVINO_TBB_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS}) endif() - - if (WIN32) - string(REPLACE "include" "libs" PYTHON_LIB ${PYTHON_INCLUDE_DIRS}) + + if (WIN32) + string(REPLACE "include" "libs" PYTHON_LIB ${PYTHON_INCLUDE_DIRS}) find_package(InferenceEngine 2.1 REQUIRED) set(PYTHON_LIBRARIES ${PYTHON_LIB}) set(OPENVINO_CPU_EXTENSION_DIR ${onnxruntime_BINARY_DIR}/ie_cpu_extension/${CMAKE_BUILD_TYPE}) @@ -430,22 +430,37 @@ if (onnxruntime_USE_DML) onnxruntime_add_include_to_target(onnxruntime_providers_dml onnxruntime_common onnxruntime_framework onnx onnx_proto protobuf::libprotobuf) add_dependencies(onnxruntime_providers_dml ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_providers_dml PRIVATE ${ONNXRUNTIME_ROOT} ${ONNXRUNTIME_ROOT}/../cmake/external/wil/include) - - target_link_libraries(onnxruntime_providers_dml ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) - target_link_libraries(onnxruntime_providers_dml d3d12.lib dxgi.lib) + + if(NOT onnxruntime_target_platform STREQUAL "x86" AND NOT onnxruntime_target_platform STREQUAL "x64") + message(FATAL_ERROR "Target platform ${onnxruntime_target_platform} is not supported by DML") + endif() + foreach(file "DirectML.dll" "DirectML.pdb" "DirectML.Debug.dll" "DirectML.Debug.pdb") + add_custom_command(TARGET onnxruntime_providers_dml + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${DML_PACKAGE_DIR}/bin/${onnxruntime_target_platform}/${file}" $) + endforeach() + + function(target_add_dml target) + target_link_libraries(${target} PRIVATE "${DML_PACKAGE_DIR}/bin/${onnxruntime_target_platform}/DirectML.lib") + target_include_directories(${target} PRIVATE "${DML_PACKAGE_DIR}/include") + endfunction() + + target_add_dml(onnxruntime_providers_dml) + target_link_libraries(onnxruntime_providers_dml PRIVATE d3d12.lib dxgi.lib delayimp.lib) list(APPEND ONNXRUNTIME_LINKER_FLAGS "/DELAYLOAD:DirectML.dll /DELAYLOAD:d3d12.dll /DELAYLOAD:dxgi.dll") # The DML EP requires C++17 set_target_properties(onnxruntime_providers_dml PROPERTIES CXX_STANDARD 17) set_target_properties(onnxruntime_providers_dml PROPERTIES CXX_STANDARD_REQUIRED ON) - + target_compile_definitions(onnxruntime_providers_dml PRIVATE ONNX_NAMESPACE=onnx ONNX_ML LOTUS_LOG_THRESHOLD=2 LOTUS_ENABLE_STDERR_LOGGING PLATFORM_WINDOWS) target_compile_definitions(onnxruntime_providers_dml PRIVATE UNICODE _UNICODE NOMINMAX) if (MSVC) target_compile_definitions(onnxruntime_providers_dml PRIVATE _SILENCE_CXX17_ITERATOR_BASE_CLASS_DEPRECATION_WARNING) target_compile_options(onnxruntime_providers_dml PRIVATE "/W3") endif() - + install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/providers/dml DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core/providers) set_target_properties(onnxruntime_providers_dml PROPERTIES LINKER_LANGUAGE CXX) diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 7944b60fa4c13..258b57224b02b 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -44,7 +44,7 @@ function(AddTest) endif() if (onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS AND onnxruntime_ENABLE_PYTHON) target_compile_definitions(${_UT_TARGET} PRIVATE ENABLE_LANGUAGE_INTEROP_OPS) - endif() + endif() if (WIN32) if (onnxruntime_USE_CUDA) # disable a warning from the CUDA headers about unreferenced local functions @@ -318,7 +318,7 @@ if (onnxruntime_USE_DNNL) target_compile_definitions(onnxruntime_test_utils_for_framework PUBLIC USE_DNNL=1) endif() if (onnxruntime_USE_DML) - target_link_libraries(onnxruntime_test_utils_for_framework PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) + target_add_dml(onnxruntime_test_utils_for_framework) endif() add_dependencies(onnxruntime_test_utils_for_framework ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_test_utils_for_framework PUBLIC "${TEST_SRC_DIR}/util/include" PRIVATE ${eigen_INCLUDE_DIRS} ${ONNXRUNTIME_ROOT}) @@ -336,7 +336,7 @@ if (onnxruntime_USE_DNNL) target_compile_definitions(onnxruntime_test_utils PUBLIC USE_DNNL=1) endif() if (onnxruntime_USE_DML) - target_link_libraries(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) + target_add_dml(onnxruntime_test_utils) endif() add_dependencies(onnxruntime_test_utils ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_include_directories(onnxruntime_test_utils PUBLIC "${TEST_SRC_DIR}/util/include" PRIVATE ${eigen_INCLUDE_DIRS} ${ONNXRUNTIME_ROOT}) @@ -711,87 +711,6 @@ if (onnxruntime_BUILD_SHARED_LIB) ) endif() -if (onnxruntime_BUILD_SERVER) - file(GLOB onnxruntime_test_server_src - "${TEST_SRC_DIR}/server/unit_tests/*.cc" - "${TEST_SRC_DIR}/server/unit_tests/*.h" - ) - - file(GLOB onnxruntime_integration_test_server_src - "${TEST_SRC_DIR}/server/integration_tests/*.py" - ) - if(NOT WIN32) - if(HAS_UNUSED_PARAMETER) - set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/json_handling_tests.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) - set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/converter_tests.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) - set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/util_tests.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) - set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/prediction_service_impl_test.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) - set_source_files_properties("${TEST_SRC_DIR}/server/unit_tests/executor_test.cc" PROPERTIES COMPILE_FLAGS -Wno-unused-parameter) - endif() - endif() - - add_library(onnxruntime_test_utils_for_server ${onnxruntime_test_server_src}) - onnxruntime_add_include_to_target(onnxruntime_test_utils_for_server onnxruntime_test_utils_for_framework gtest gmock onnx onnx_proto server_proto server_grpc_proto) - add_dependencies(onnxruntime_test_utils_for_server onnxruntime_server_lib onnxruntime_server_http_core_lib Boost ${onnxruntime_EXTERNAL_DEPENDENCIES}) - target_include_directories(onnxruntime_test_utils_for_server PUBLIC ${Boost_INCLUDE_DIR} ${REPO_ROOT}/cmake/external/re2 ${CMAKE_CURRENT_BINARY_DIR}/onnx ${ONNXRUNTIME_ROOT}/server ${ONNXRUNTIME_ROOT}/server/http ${ONNXRUNTIME_ROOT}/server/http/core ${ONNXRUNTIME_ROOT}/server/grpc ${ONNXRUNTIME_ROOT}/server ${ONNXRUNTIME_ROOT}/server/core PRIVATE ${ONNXRUNTIME_ROOT}) - if (onnxruntime_USE_OPENVINO) - message(${OPENVINO_INCLUDE_DIR}) - target_include_directories(onnxruntime_test_utils_for_server PUBLIC ${OPENVINO_INCLUDE_DIR} ${OPENVINO_TBB_INCLUDE_DIR}) - endif() - if(UNIX) - target_compile_options(onnxruntime_test_utils_for_server PRIVATE "$<$:SHELL:-Xcompiler -Wno-error=sign-compare>" - "$<$>:-Wno-error=sign-compare>") - endif() - target_link_libraries(onnxruntime_test_utils_for_server ${Boost_LIBRARIES} spdlog::spdlog server_grpc_proto) - - - AddTest( - TARGET onnxruntime_server_tests - SOURCES ${onnxruntime_test_server_src} - LIBS ${onnxruntime_test_server_libs} server_proto server_grpc_proto onnxruntime_server_lib ${onnxruntime_test_providers_libs} - DEPENDS ${onnxruntime_EXTERNAL_DEPENDENCIES} - ) - - onnxruntime_protobuf_generate( - APPEND_PATH IMPORT_DIRS ${REPO_ROOT}/cmake/external/protobuf/src ${ONNXRUNTIME_ROOT}/server/protobuf ${ONNXRUNTIME_ROOT}/core/protobuf - PROTOS ${ONNXRUNTIME_ROOT}/server/protobuf/predict.proto ${ONNXRUNTIME_ROOT}/server/protobuf/onnx-ml.proto - LANGUAGE python - TARGET onnxruntime_server_tests - OUT_VAR server_test_py) - - set(grpc_py "${CMAKE_CURRENT_BINARY_DIR}/prediction_service_pb2_grpc.py") - - add_custom_command( - TARGET onnxruntime_server_tests - COMMAND $ - ARGS - --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" - --plugin=protoc-gen-grpc="${_GRPC_PY_PLUGIN_EXECUTABLE}" - -I ${grpc_proto_path} - "${grpc_proto}" - DEPENDS "${grpc_proto}" - COMMENT "Running ${_GRPC_PY_PLUGIN_EXECUTABLE} on ${grpc_proto}" - ) - - add_custom_command( - TARGET onnxruntime_server_tests POST_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/server_test - COMMAND ${CMAKE_COMMAND} -E copy - ${onnxruntime_integration_test_server_src} - ${CMAKE_CURRENT_BINARY_DIR}/server_test/ - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/onnx_ml_pb2.py - ${CMAKE_CURRENT_BINARY_DIR}/server_test/ - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/predict_pb2.py - ${CMAKE_CURRENT_BINARY_DIR}/server_test/ - COMMAND ${CMAKE_COMMAND} -E copy - ${grpc_py} - ${CMAKE_CURRENT_BINARY_DIR}/server_test/ - ) - -endif() - #some ETW tools if(WIN32 AND onnxruntime_ENABLE_INSTRUMENT) add_executable(generate_perf_report_from_etl ${ONNXRUNTIME_ROOT}/tool/etw/main.cc ${ONNXRUNTIME_ROOT}/tool/etw/eparser.h ${ONNXRUNTIME_ROOT}/tool/etw/eparser.cc ${ONNXRUNTIME_ROOT}/tool/etw/TraceSession.h ${ONNXRUNTIME_ROOT}/tool/etw/TraceSession.cc) diff --git a/cmake/precompiled_header.cmake b/cmake/precompiled_header.cmake index f41310fac524c..3bebf7341809b 100644 --- a/cmake/precompiled_header.cmake +++ b/cmake/precompiled_header.cmake @@ -2,8 +2,7 @@ # header name as input. The function will generate a .cpp file that includes the header and is used # to generate the precompiled header; this source file is added to the target's sources. function(target_precompiled_header target_name header_name) - if (MSVC) - + if (MSVC AND CMAKE_VS_PLATFORM_TOOLSET) # The input precompiled header source (i.e. the '.h' file used for the precompiled header). set(pch_header_path ${header_name}) get_filename_component(header_base_name ${header_name} NAME_WE) @@ -14,14 +13,14 @@ function(target_precompiled_header target_name header_name) 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}") - + # The target's C++ sources use the precompiled header (/Yu). Source-level properties will - # take precedence over target-level properties, so this will not change the generated source + # take precedence over target-level properties, so this will not change the generated source # file's property to create the precompiled header (/Yc). target_compile_options(${target_name} PRIVATE $<$:/Yu${header_name}>) - + # Append generated precompiled source to target's sources. target_sources(${target_name} PRIVATE ${pch_source_path}) - - endif(MSVC) -endfunction() \ No newline at end of file + + endif() +endfunction() diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 71824b3997fcf..f9c02ddf0e9e5 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -132,7 +132,7 @@ list(APPEND winml_adapter_files ${winml_adapter_dir}/WinMLAdapter.cpp ${winml_adapter_dir}/WinMLAdapter.h ${winml_adapter_dir}/ZeroCopyInputStreamWrapper.cpp - ${winml_adapter_dir}/ZeroCopyInputStreamWrapper.h + ${winml_adapter_dir}/ZeroCopyInputStreamWrapper.h ) if (onnxruntime_USE_DML) @@ -159,6 +159,7 @@ add_dependencies(winml_adapter ${onnxruntime_EXTERNAL_DEPENDENCIES}) target_precompiled_header(winml_adapter pch.h) # Includes +target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers @@ -181,11 +182,11 @@ add_dependencies(winml_adapter winml_api_native_internal) # Link libraries target_link_libraries(winml_adapter PRIVATE wil) if (onnxruntime_USE_DML) - target_link_libraries(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) + target_add_dml(winml_adapter) endif(onnxruntime_USE_DML) # add it to the onnxruntime shared library -set(onnxruntime_winml windowsapp.lib winml_adapter) +set(onnxruntime_winml winml_adapter) list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES winml_adapter) ########################### @@ -230,6 +231,7 @@ target_compile_definitions(winml_lib_image PRIVATE _SCL_SECURE_NO_WARNINGS) target_precompiled_header(winml_lib_image pch.h) # Includes +target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # windows machine learning generated component headers target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers target_include_directories(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers @@ -258,7 +260,7 @@ add_dependencies(winml_lib_image winml_api_native_internal) # Link libraries target_link_libraries(winml_lib_image PRIVATE wil) if (onnxruntime_USE_DML) - target_link_libraries(winml_lib_image PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) + target_add_dml(winml_lib_image) endif(onnxruntime_USE_DML) @@ -360,7 +362,7 @@ add_dependencies(winml_lib_api winml_api_native_internal) # Link libraries target_link_libraries(winml_lib_api PRIVATE wil) if (onnxruntime_USE_DML) - target_link_libraries(winml_lib_api PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/packages/DirectML.0.0.1/build/DirectML.targets) + target_add_dml(winml_lib_api) endif(onnxruntime_USE_DML) @@ -438,6 +440,13 @@ if (onnxruntime_USE_DML) set(delayload_dml "/DELAYLOAD:directml.dll") endif(onnxruntime_USE_DML) +# The default libraries to link with in Windows are kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib +# Remove them and use the onecore umbrella library instead +foreach(default_lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdgl32.lib advapi32.lib) + set(removed_libs "${removed_libs} /NODEFAULTLIB:${default_lib}") +endforeach() +set(CMAKE_C_STANDARD_LIBRARIES "${removed_libs} onecoreuap.lib") +set(CMAKE_CXX_STANDARD_LIBRARIES "${removed_libs} onecoreuap.lib") set_target_properties(winml_dll PROPERTIES LINK_FLAGS @@ -467,11 +476,10 @@ endif("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") target_link_libraries(winml_dll PRIVATE onnxruntime) target_link_libraries(winml_dll PRIVATE re2) target_link_libraries(winml_dll PRIVATE wil) -#target_link_libraries(winml_dll PRIVATE windowsapp.lib) target_link_libraries(winml_dll PRIVATE winml_lib_api) target_link_libraries(winml_dll PRIVATE winml_lib_image) target_link_libraries(winml_dll PRIVATE winml_lib_telemetry) -target_link_libraries(winml_dll PRIVATE onecoreuap_apiset.lib) +target_link_libraries(winml_dll PRIVATE delayimp.lib) target_link_libraries(winml_dll PRIVATE ${DBGHELP}) # 1 of 3 projects that fail in link with 'failed to do memory mapped file I/O' (Only release) @@ -483,6 +491,7 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Release") set_target_properties(winml_dll PROPERTIES VS_GLOBAL_PreferredToolArchitecture "x64") endif("${CMAKE_BUILD_TYPE}" STREQUAL "Release") +option(onnxruntime_BUILD_WINML_TESTS "Build WinML tests" ON) if (onnxruntime_BUILD_WINML_TESTS) include(winml_unittests.cmake) endif() diff --git a/cmake/winml_cppwinrt.cmake b/cmake/winml_cppwinrt.cmake index 2d53ade270b2b..ea96a1b289764 100644 --- a/cmake/winml_cppwinrt.cmake +++ b/cmake/winml_cppwinrt.cmake @@ -102,7 +102,7 @@ function(target_cppwinrt # Get directory get_filename_component(idl_source_directory ${file} DIRECTORY) - set(target_outputs ${CMAKE_CURRENT_BINARY_DIR}/${target_name}) + set(target_outputs ${CMAKE_CURRENT_BINARY_DIR}/${target_name}) convert_forward_slashes_to_back(${target_outputs}/comp output_dir_back_slash) convert_forward_slashes_to_back(${target_outputs}/temp temp_dir_back_slash) convert_forward_slashes_to_back(${target_outputs}/comp_generated generated_dir_back_slash) @@ -126,50 +126,53 @@ function(target_cppwinrt /tlb ${tlb_filename} ${idl_file_forward_slash} COMMAND - ${cppwinrt_exe} -in \"${winmd_filename}\" -comp \"${output_dir_back_slash}\" -ref \"${sdk_metadata_directory}\" -out \"${generated_dir_back_slash}\" -verbose + ${cppwinrt_exe} -in ${winmd_filename} -comp ${output_dir_back_slash} -ref ${sdk_metadata_directory} -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 + xcopy ${output_dir_back_slash} ${temp_dir_back_slash}\\ /Y /D COMMAND # for each file in the temp directory, ensure it is not in the exclusions list. # if it is, then we need to delete it. - for /f %%I in ('dir /b \"${temp_dir_back_slash}\"') - do - ( - for /f %%E in (${CPPWINRT_COMPONENT_EXCLUSION_LIST}) - do - ( - if %%E == %%I - ( - del \"${temp_dir_back_slash}\\%%I\" - ) - ) - ) + cmd /C "@echo off \ + for /f %I in ('dir /b ${temp_dir_back_slash}') \ + do \ + ( \ + for /f %E in (${CPPWINRT_COMPONENT_EXCLUSION_LIST}) \ + do \ + ( \ + if %E == %I \ + ( \ + del ${temp_dir_back_slash}\\%I \ + ) \ + ) \ + )" COMMAND # for each file in the temp directory, copy the file back into the source tree # unless the file already exists - for /f %%I in ('dir /b \"${temp_dir_back_slash}\"') - do - ( - if not exist \"${out_sources_folder}\\%%I\" - ( - xcopy \"${temp_dir_back_slash}\\%%I\" \"${out_sources_folder}\\%%I\" - ) - ) + cmd /C "@echo off \ + for /f %I in ('dir /b ${temp_dir_back_slash}') \ + do \ + ( \ + if not exist ${out_sources_folder}\\%I \ + ( \ + copy ${temp_dir_back_slash}\\%I ${out_sources_folder}\\%I \ + ) \ + )" COMMAND # open the generated module.g.cpp and strip all the includes (lines) containing excluded headers # write the new file out to module.g.excl.cpp. - powershell -Command \"& { - $exclusions = get-content '${CPPWINRT_COMPONENT_EXCLUSION_LIST}'\; - (get-content '${module_g_cpp_back_slash}') - | where { - $str = $_\; - $matches = ($exclusions | where { $str -match $_ }) \; - $matches.Length -eq 0 } - | Out-File '${module_g_ecxl_cpp_back_slash}' - }\" + powershell -Command "& { \ + $exclusions = get-content '${CPPWINRT_COMPONENT_EXCLUSION_LIST}'; \ + (get-content '${module_g_cpp_back_slash}') \ + | where { \ + $str = $_; \ + $matches = ($exclusions | where { $str -match $_ }); \ + $matches.Length -eq 0 } \ + | Out-File '${module_g_ecxl_cpp_back_slash}' \ + }" BYPRODUCTS ${generated_dir_back_slash}/module.g.excl.cpp + VERBATIM ) add_custom_target( @@ -214,4 +217,4 @@ function(add_generate_cppwinrt_sdk_headers_target set_target_properties(${target_name} PROPERTIES FOLDER ${folder_name}) endif() -endfunction() \ No newline at end of file +endfunction() diff --git a/cmake/winml_sdk_helpers.cmake b/cmake/winml_sdk_helpers.cmake index 03a87653fe986..df9db93a6b467 100644 --- a/cmake/winml_sdk_helpers.cmake +++ b/cmake/winml_sdk_helpers.cmake @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) -# utility +# utility function(convert_forward_slashes_to_back input output) string(REGEX REPLACE "/" "\\\\" backwards ${input}) set(${output} ${backwards} PARENT_SCOPE) @@ -16,7 +16,23 @@ function(get_installed_sdk set(${sdk_folder} ${win10_sdk_root} PARENT_SCOPE) # return the sdk version - set(${output_sdk_version} ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} PARENT_SCOPE) + if(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION) + set(${output_sdk_version} ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} PARENT_SCOPE) + else() + # choose the SDK matching the system version, or fallback to the latest + file(GLOB win10_sdks RELATIVE "${win10_sdk_root}/UnionMetadata" "${win10_sdk_root}/UnionMetadata/*.*.*.*") + list(GET win10_sdks 0 latest_sdk) + foreach(sdk IN LISTS win10_sdks) + string(FIND ${sdk} ${CMAKE_SYSTEM_VERSION} is_system_version) + if(NOT ${is_system_version} EQUAL -1) + set(${output_sdk_version} ${sdk} PARENT_SCOPE) + return() + elseif(sdk VERSION_GREATER latest_sdk) + set(latest_sdk ${sdk}) + endif() + endforeach() + set(${output_sdk_version} ${latest_sdk} PARENT_SCOPE) + endif() endfunction() # current sdk binary directory @@ -95,7 +111,7 @@ function(get_sdk set(${output_sdk_version} ${winml_WINDOWS_SDK_VERSION_OVERRIDE} PARENT_SCOPE) else() message( - FATAL_ERROR + FATAL_ERROR "Options winml_WINDOWS_SDK_DIR_OVERRIDE and winml_WINDOWS_SDK_VERSION_OVERRIDE must be defined together, or not at all.") endif() -endfunction() \ No newline at end of file +endfunction() diff --git a/onnxruntime/core/platform/windows/debug_alloc.cc b/onnxruntime/core/platform/windows/debug_alloc.cc index 83c38baa05248..57267f146d884 100644 --- a/onnxruntime/core/platform/windows/debug_alloc.cc +++ b/onnxruntime/core/platform/windows/debug_alloc.cc @@ -232,12 +232,8 @@ Memory_LeakCheck::~Memory_LeakCheck() { _snprintf_s(buffer, _TRUNCATE, "%d bytes of memory leaked in %d allocations", leaked_bytes, leak_count); string.append(buffer); - // If we're being actively debugged, show a message box to get the dev's attention - if (IsDebuggerPresent()) - MessageBoxA(nullptr, string.c_str(), "Warning", MB_OK | MB_ICONWARNING); - else { - // If we're on the command line (like on a build machine), output to the console and exit(-1) - std::cout << "\n----- MEMORY LEAKS: " << string.c_str() << "\n"; + std::cout << "\n----- MEMORY LEAKS: " << string.c_str() << "\n"; + if (!IsDebuggerPresent()) { exit(-1); } From 95b67458d009d3b8668d898dcc427607a605f745 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Fri, 17 Jan 2020 17:34:01 -0800 Subject: [PATCH 6/8] Update func signature of custom op function overloads --- winml/test/scenario/cppwinrt/CustomOps.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winml/test/scenario/cppwinrt/CustomOps.cpp b/winml/test/scenario/cppwinrt/CustomOps.cpp index eb47843b95de6..f1071d52ccb8b 100644 --- a/winml/test/scenario/cppwinrt/CustomOps.cpp +++ b/winml/test/scenario/cppwinrt/CustomOps.cpp @@ -288,13 +288,13 @@ class FooKernel }; template -void CreateABIFooKernel(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel) +void CALLBACK CreateABIFooKernel(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel) { HRESULT hr = MLOperatorKernel>::CreateInstance(*kernelInfo, opKernel); THROW_IF_FAILED(hr); } -void CreateTruncatedABIFooKernel(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel) +void CALLBACK CreateTruncatedABIFooKernel(IMLOperatorKernelCreationContext* kernelInfo, IMLOperatorKernel** opKernel) { HRESULT hr = MLOperatorKernel>::CreateInstance(*kernelInfo, opKernel); THROW_IF_FAILED(hr); From 451c193eb06960176d6c84475e90ba9ec000790f Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Tue, 21 Jan 2020 15:19:02 -0800 Subject: [PATCH 7/8] common devicehelpers fixes --- cmake/winml.cmake | 6 +++++- winml/lib/Common/CommonDeviceHelpers.cpp | 1 + winml/lib/Common/inc/CommonDeviceHelpers.h | 1 - 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 2958a16681793..476654a826201 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -386,12 +386,16 @@ target_compile_definitions(winml_lib_common PRIVATE PLATFORM_WINDOWS _SCL_SECURE_NO_WARNINGS) add_dependencies(winml_lib_common winml_sdk_cppwinrt) +add_dependencies(winml_lib_common winml_api) +add_dependencies(winml_lib_common winml_api_native) +add_dependencies(winml_lib_common winml_api_native_internal) target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api) # windows machine learning generated component headers target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml_api/comp_generated) # windows machine learning generated component headers +target_include_directories(winml_lib_common PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/winml/sdk/cppwinrt/include) # sdk cppwinrt headers 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) ########################### # Add winml_dll ########################### diff --git a/winml/lib/Common/CommonDeviceHelpers.cpp b/winml/lib/Common/CommonDeviceHelpers.cpp index 292d665ffdf1b..74baa9c8daf90 100644 --- a/winml/lib/Common/CommonDeviceHelpers.cpp +++ b/winml/lib/Common/CommonDeviceHelpers.cpp @@ -7,6 +7,7 @@ #if USE_DML #include #endif USE_DML +#include "winrt_headers.h" #include "inc/CommonDeviceHelpers.h" #include #include diff --git a/winml/lib/Common/inc/CommonDeviceHelpers.h b/winml/lib/Common/inc/CommonDeviceHelpers.h index 38f1aa1e8a13c..14ffe2aeaa035 100644 --- a/winml/lib/Common/inc/CommonDeviceHelpers.h +++ b/winml/lib/Common/inc/CommonDeviceHelpers.h @@ -3,7 +3,6 @@ #pragma once -#include "winrt_headers.h" #include #include #include From b39eb6d89b6a08d1acdf304bec0a9f27ad01bf72 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Wed, 22 Jan 2020 14:02:09 -0800 Subject: [PATCH 8/8] Add pch.h for winml_lib_common --- cmake/winml.cmake | 3 ++- winml/lib/Common/CommonDeviceHelpers.cpp | 3 +-- winml/lib/Common/inc/pch.h | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 winml/lib/Common/inc/pch.h diff --git a/cmake/winml.cmake b/cmake/winml.cmake index 476654a826201..088ef107a8830 100644 --- a/cmake/winml.cmake +++ b/cmake/winml.cmake @@ -166,7 +166,6 @@ target_include_directories(winml_adapter PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/win target_include_directories(winml_adapter PRIVATE ${winml_lib_api_dir}) # needed for generated headers target_include_directories(winml_adapter PRIVATE ${winml_lib_dir}) target_include_directories(winml_adapter PRIVATE ${winml_adapter_dir}) -target_include_directories(winml_adapter PRIVATE ${winml_lib_common_dir}/inc) set_target_properties(winml_adapter PROPERTIES @@ -396,6 +395,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) + ########################### # Add winml_dll ########################### diff --git a/winml/lib/Common/CommonDeviceHelpers.cpp b/winml/lib/Common/CommonDeviceHelpers.cpp index 74baa9c8daf90..e4e0fd63eb7f3 100644 --- a/winml/lib/Common/CommonDeviceHelpers.cpp +++ b/winml/lib/Common/CommonDeviceHelpers.cpp @@ -3,11 +3,10 @@ // #include "dx.h" // #include - +#include "inc/pch.h" #if USE_DML #include #endif USE_DML -#include "winrt_headers.h" #include "inc/CommonDeviceHelpers.h" #include #include diff --git a/winml/lib/Common/inc/pch.h b/winml/lib/Common/inc/pch.h new file mode 100644 index 0000000000000..5d070d0c86c3f --- /dev/null +++ b/winml/lib/Common/inc/pch.h @@ -0,0 +1 @@ +#include "winrt_headers.h" \ No newline at end of file