From 1ae7b4bcbc02edc881ad28685da98e095dfceb17 Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Thu, 16 Jan 2020 14:56:15 -0800 Subject: [PATCH] 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 35c606f641..41de28fdd2 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 52aa2f3989..63a8283429 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 38ec173dfc..e7b4213bc6 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 1b7047318e..9875955e3c 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 258b57224b..7944b60fa4 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 3bebf73418..f41310fac5 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 f9c02ddf0e..71824b3997 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 ea96a1b289..2d53ade270 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 df9db93a6b..03a87653fe 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 57267f146d..83c38baa05 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); }