From d0e440b9ebea2aeaeeb8ea7d66b07b7563028ba9 Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 14 Jul 2024 01:51:25 +0900 Subject: [PATCH 01/22] build: support vcpkg in cmake-presets --- cmake/CMakeLists.txt | 17 +- cmake/CMakePresets.json | 189 ++++++++++++++++++++ cmake/external/onnxruntime_vcpkg_deps.cmake | 154 ++++++++++++++++ cmake/onnxruntime.cmake | 6 + cmake/onnxruntime_providers_cuda.cmake | 8 +- cmake/onnxruntime_unittests.cmake | 4 + cmake/vcpkg-configuration.json | 25 +++ cmake/vcpkg.json | 77 ++++++++ 8 files changed, 477 insertions(+), 3 deletions(-) create mode 100644 cmake/CMakePresets.json create mode 100644 cmake/external/onnxruntime_vcpkg_deps.cmake create mode 100644 cmake/vcpkg-configuration.json create mode 100644 cmake/vcpkg.json diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index e2fc3da9de35e..e3d2d739e6683 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -38,6 +38,7 @@ include(CheckLanguage) include(CMakeDependentOption) include(FetchContent) include(CheckFunctionExists) +include(GNUInstallDirs) # onnxruntime_providers_* require CMAKE_INSTALL_* variables # TODO: update this once all system adapt c++20 if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") @@ -69,6 +70,7 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_ endif() # Options +option(ONNXRUNTIME_USE_VCPKG "Build with the vcpkg package manager" OFF) option(onnxruntime_RUN_ONNX_TESTS "Enable ONNX Compatibility Testing" OFF) option(onnxruntime_GENERATE_TEST_REPORTS "Enable test report generation" OFF) option(onnxruntime_ENABLE_STATIC_ANALYSIS "Enable static analysis" OFF) @@ -595,7 +597,11 @@ get_filename_component(ORTTRAINING_ROOT "${ORTTRAINING_ROOT}" ABSOLUTE) get_filename_component(REPO_ROOT "${REPO_ROOT}" ABSOLUTE) set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime) -include(external/onnxruntime_external_deps.cmake) +if(ONNXRUNTIME_USE_VCPKG) + include(external/onnxruntime_vcpkg_deps.cmake) +else() + include(external/onnxruntime_external_deps.cmake) +endif() set(ORT_WARNING_FLAGS) if (WIN32) @@ -732,6 +738,15 @@ if (onnxruntime_USE_CUDA) if (onnxruntime_USE_CUDA_NHWC_OPS) add_compile_definitions(ENABLE_CUDA_NHWC_OPS) endif() + # Give more hints for the generator, with FindCUDAToolkit.cmake + find_package(CUDAToolkit REQUIRED) + if(CMAKE_GENERATOR MATCHES "Visual Studio") + set(CMAKE_VS_PLATFORM_TOOLSET_CUDA "${CUDAToolkit_VERSION_MAJOR}.${CUDAToolkit_VERSION_MINOR}") + set(CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR "${CUDAToolkit_TARGET_DIR}/") + endif() + if(NOT DEFINED CMAKE_CUDA_COMPILER) + get_filename_component(CMAKE_CUDA_COMPILER "${CUDAToolkit_NVCC_EXECUTABLE}" ABSOLUTE) + endif() enable_language(CUDA) message( STATUS "CMAKE_CUDA_COMPILER_VERSION: ${CMAKE_CUDA_COMPILER_VERSION}") diff --git a/cmake/CMakePresets.json b/cmake/CMakePresets.json new file mode 100644 index 0000000000000..e3de5765f1305 --- /dev/null +++ b/cmake/CMakePresets.json @@ -0,0 +1,189 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 25, + "patch": 0 + }, + "configurePresets": [ + { + "name": "vcpkg-manifest", + "hidden": true, + "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "environment": { + "VCPKG_FEATURE_FLGAS": "manifests,versions" + } + }, + { + "name": "msvc-static-runtime", + "hidden": true, + "cacheVariables": { + "ONNX_USE_MSVC_STATIC_RUNTIME": true, + "protobuf_MSVC_STATIC_RUNTIME": true, + "gtest_force_shared_crt": false, + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>" + } + }, + { + "name": "unit-test", + "hidden": true, + "cacheVariables": { + "onnxruntime_RUN_ONNX_TESTS": true, + "onnxruntime_BUILD_BENCHMARKS": true, + "onnxruntime_BUILD_UNIT_TESTS": true, + "onnxruntime_GENERATE_TEST_REPORTS": true + } + }, + { + "name": "x64-windows", + "inherits": [ + "msvc-static-runtime", + "unit-test" + ], + "generator": "Visual Studio 17 2022", + "architecture": "x64", + "binaryDir": "${sourceParentDir}/cmake_build/x64-windows", + "installDir": "${sourceParentDir}/cmake_build/out", + "cacheVariables": { + "onnxruntime_USE_XNNPACK": true, + "onnxruntime_USE_DML": true, + "onnxruntime_BUILD_SHARED_LIB": true, + "CMAKE_CONFIGURATION_TYPES": "Debug;Release" + }, + "vendor": { + "microsoft.com/VisualStudioSettings/CMake/1.0": { + "intelliSenseMode": "windows-msvc-x64" + } + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "x64-windows-vcpkg", + "inherits": [ + "unit-test", + "vcpkg-manifest" + ], + "generator": "Visual Studio 17 2022", + "architecture": "x64", + "binaryDir": "${sourceParentDir}/cmake_build/x64-windows", + "installDir": "${sourceParentDir}/cmake_build/out", + "cacheVariables": { + "ONNXRUNTIME_USE_VCPKG": true, + "onnxruntime_USE_XNNPACK": false, + "onnxruntime_USE_DML": false, + "onnxruntime_BUILD_SHARED_LIB": true, + "CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$:Debug>DLL", + "CMAKE_CONFIGURATION_TYPES": "Debug;Release", + "VCPKG_INSTALL_OPTIONS": "--x-feature=tests", + "VCPKG_TARGET_TRIPLET": "x64-windows" + } + }, + { + "name": "x64-osx", + "inherits": [ + "unit-test" + ], + "generator": "Xcode", + "binaryDir": "${sourceParentDir}/cmake_build/x64-osx", + "installDir": "${sourceParentDir}/cmake_build/out", + "cacheVariables": { + "CMAKE_OSX_ARCHITECTURES": "x86_64", + "onnxruntime_BUILD_SHARED_LIB": true, + "onnxruntime_USE_XNNPACK": false, + "onnxruntime_USE_COREML": true, + "onnxruntime_BUILD_OBJC": true, + "onnxruntime_BUILD_APPLE_FRAMEWORK": true, + "CMAKE_CONFIGURATION_TYPES": "Debug;Release" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "x64-osx-vcpkg", + "inherits": [ + "x64-osx", + "vcpkg-manifest" + ], + "cacheVariables": { + "ONNXRUNTIME_USE_VCPKG": true, + "onnxruntime_USE_XNNPACK": false, + "onnxruntime_USE_COREML": false, + "onnxruntime_BUILD_OBJC": false, + "onnxruntime_BUILD_APPLE_FRAMEWORK": false, + "VCPKG_INSTALL_OPTIONS": "--x-feature=tests", + "VCPKG_TARGET_TRIPLET": "x64-osx" + } + } + ], + "buildPresets": [ + { + "name": "x64-windows-debug", + "configurePreset": "x64-windows", + "configuration": "Debug" + }, + { + "name": "x64-windows-vcpkg-debug", + "configurePreset": "x64-windows-vcpkg", + "configuration": "Debug" + }, + { + "name": "x64-osx-debug", + "configurePreset": "x64-osx", + "configuration": "Debug" + }, + { + "name": "x64-osx-vcpkg-debug", + "configurePreset": "x64-osx-vcpkg", + "configuration": "Debug" + } + ], + "testPresets": [ + { + "name": "x64-windows-debug", + "configurePreset": "x64-windows", + "configuration": "Debug", + "output": { + "verbosity": "default", + "outputJUnitFile": "TEST-x64-windows-debug.xml", + "outputLogFile": "TEST-x64-windows-debug.log", + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": false + } + }, + { + "name": "x64-windows-vcpkg-debug", + "inherits": "x64-windows-debug", + "configurePreset": "x64-windows-vcpkg" + }, + { + "name": "x64-osx-debug", + "configurePreset": "x64-osx", + "configuration": "Debug", + "output": { + "verbosity": "default", + "outputJUnitFile": "TEST-x64-osx-debug.xml", + "outputLogFile": "TEST-x64-osx-debug.log", + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": false + } + }, + { + "name": "x64-osx-vcpkg-debug", + "inherits": "x64-osx-debug", + "configurePreset": "x64-osx-vcpkg" + } + ] +} diff --git a/cmake/external/onnxruntime_vcpkg_deps.cmake b/cmake/external/onnxruntime_vcpkg_deps.cmake new file mode 100644 index 0000000000000..f7fcd83825f8c --- /dev/null +++ b/cmake/external/onnxruntime_vcpkg_deps.cmake @@ -0,0 +1,154 @@ +message(STATUS "Using Dependencies from vcpkg...") + +# ABSL should be included before protobuf because protobuf may use absl +find_package(absl CONFIG REQUIRED) +list(APPEND ABSEIL_LIBS + absl::base + absl::city + absl::core_headers + absl::fixed_array + absl::flags + absl::flat_hash_map + absl::flat_hash_set + absl::hash + absl::inlined_vector + absl::low_level_hash + absl::node_hash_map + absl::node_hash_set + absl::optional + absl::raw_hash_set + absl::raw_logging_internal + absl::span + absl::str_format + absl::strings + absl::synchronization + absl::throw_delegate + absl::time +) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${ABSEIL_LIBS}) + +find_package(re2 CONFIG REQUIRED) # re2::re2 +list(APPEND onnxruntime_EXTERNAL_LIBRARIES re2::re2) + +if (onnxruntime_BUILD_UNIT_TESTS) + # gtest and gmock + find_package(GTest CONFIG REQUIRED) # GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main +endif() + +if (onnxruntime_BUILD_BENCHMARKS) + find_package(benchmark CONFIG REQUIRED) # benchmark::benchmark benchmark::benchmark_main +endif() + +# Flatbuffers +find_package(flatbuffers CONFIG REQUIRED) # flatbuffers::flatbuffers +list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES flatbuffers::flatbuffers) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES flatbuffers::flatbuffers) + +find_package(Protobuf CONFIG REQUIRED) # protobuf::libprotobuf protobuf::libprotobuf-lite +if (onnxruntime_USE_FULL_PROTOBUF) + set(PROTOBUF_LIB protobuf::libprotobuf) +else() + set(PROTOBUF_LIB protobuf::libprotobuf-lite) +endif() +list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${PROTOBUF_LIB}) + +if(NOT DEFINED Protobuf_PROTOC_EXECUTABLE) + find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED) +endif() +get_filename_component(ONNX_CUSTOM_PROTOC_EXECUTABLE "${Protobuf_PROTOC_EXECUTABLE}" ABSOLUTE) +include(external/protobuf_function.cmake) + +find_package(date CONFIG REQUIRED) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES date::date) + +# see Hints of FindBoost.cmake +find_path(BOOST_INCLUDEDIR "boost/mp11.hpp" REQUIRED) +find_package(Boost REQUIRED) +add_library(Boost::mp11 ALIAS Boost::headers) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES Boost::mp11) + +find_package(nlohmann_json CONFIG REQUIRED) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES nlohmann_json::nlohmann_json) + +if (onnxruntime_ENABLE_CPUINFO) + find_package(cpuinfo CONFIG REQUIRED) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo) +endif() + +if (NOT WIN32) + find_library(NSYNC_CPP_LIBRARY NAMES nsync_cpp REQUIRED) + add_library(nsync_cpp INTERFACE IMPORTED GLOBAL) + set_target_properties(nsync_cpp PROPERTIES INTERFACE_LINK_LIBRARIES "${NSYNC_CPP_LIBRARY}") + add_library(nsync::nsync_cpp ALIAS nsync_cpp) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync::nsync_cpp) +endif() + +find_package(Microsoft.GSL CONFIG REQUIRED) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES Microsoft.GSL::GSL) +set(GSL_TARGET Microsoft.GSL::GSL) # see onnxruntime_mlas + +# ONNX +find_package(ONNX CONFIG REQUIRED) +if(TARGET ONNX::onnx AND NOT TARGET onnx) + add_library(onnx ALIAS ONNX::onnx) +endif() +if(TARGET ONNX::onnx_proto AND NOT TARGET onnx_proto) + add_library(onnx_proto ALIAS ONNX::onnx_proto) +endif() +list(APPEND onnxruntime_EXTERNAL_LIBRARIES onnx onnx_proto) + +find_package(Eigen3 CONFIG REQUIRED) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES Eigen3::Eigen) +get_property(eigen_INCLUDE_DIRS TARGET Eigen3::Eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + +find_package(wil CONFIG REQUIRED) +list(APPEND onnxruntime_EXTERNAL_LIBRARIES WIL::WIL) + +find_path(SAFEINT_INCLUDE_DIRS "SafeInt.hpp" REQUIRED) +add_library(safeint_interface IMPORTED INTERFACE GLOBAL) +set_target_properties(safeint_interface PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${SAFEINT_INCLUDE_DIRS}" +) + +# XNNPACK EP +if (onnxruntime_USE_XNNPACK) + if (onnxruntime_DISABLE_CONTRIB_OPS) + message(FATAL_ERROR "XNNPACK EP requires the internal NHWC contrib ops to be available " + "but onnxruntime_DISABLE_CONTRIB_OPS is ON") + endif() + find_package(cpuinfo CONFIG REQUIRED) + find_library(PTHREADPOOL_LIBRARY NAMES pthreadpool REQUIRED) + find_library(XNNPACK_LIBRARY NAMES XNNPACK REQUIRED) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo ${PTHREADPOOL_LIBRARY} ${XNNPACK_LIBRARY}) +endif() + +if (onnxruntime_USE_MIMALLOC) + add_compile_definitions(USE_MIMALLOC) + find_package(mimalloc CONFIG REQUIRED) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES mimalloc) +endif() + +if(onnxruntime_ENABLE_ATEN) + message(STATUS "Aten fallback is enabled.") + find_package(dlpack CONFIG REQUIRED) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES dlpack::dlpack) +endif() + +if(onnxruntime_ENABLE_TRAINING OR (onnxruntime_ENABLE_TRAINING_APIS AND onnxruntime_BUILD_UNIT_TESTS)) + find_package(cxxopts CONFIG REQUIRED) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES cxxopts::cxxopts) +endif() + +if (onnxruntime_USE_CUDA) + find_package(CUDAToolkit REQUIRED) + include_directories(${CUDAToolkit_INCLUDE_DIRS}) + list(APPEND onnxruntime_LINK_DIRS ${CUDAToolkit_LIBRARY_DIR}) + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -diag-suppress 2803") + find_package(NvidiaCutlass CONFIG REQUIRED) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES nvidia::cutlass::cutlass) +endif() + +if (onnxruntime_USE_OPENVINO) + find_package(OpenVINO REQUIRED) + # list(APPEND onnxruntime_EXTERNAL_LIBRARIES openvino::runtime) +endif() diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index ec98047750a91..08e8957003aed 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -302,6 +302,9 @@ if(onnxruntime_BUILD_APPLE_FRAMEWORK) # If it's an onnxruntime library, extract .o files from the original cmake build path to a separate directory for # each library to avoid any clashes with filenames (e.g. utils.o) foreach(_LIB ${onnxruntime_INTERNAL_LIBRARIES} ) + if(NOT TARGET ${_LIB}) # if we didn't build from source. it may not a target + continue() + endif() GET_TARGET_PROPERTY(_LIB_TYPE ${_LIB} TYPE) if(_LIB_TYPE STREQUAL "STATIC_LIBRARY") set(CUR_STATIC_LIB_OBJ_DIR ${STATIC_LIB_TEMP_DIR}/$) @@ -332,6 +335,9 @@ if(onnxruntime_BUILD_APPLE_FRAMEWORK) # for external libraries we create a symlink to the .a file foreach(_LIB ${onnxruntime_EXTERNAL_LIBRARIES}) + if(NOT TARGET ${_LIB}) # if we didn't build from source. it may not a target + continue() + endif() GET_TARGET_PROPERTY(_LIB_TYPE ${_LIB} TYPE) if(_LIB_TYPE STREQUAL "STATIC_LIBRARY") add_custom_command(TARGET onnxruntime POST_BUILD diff --git a/cmake/onnxruntime_providers_cuda.cmake b/cmake/onnxruntime_providers_cuda.cmake index 82c31ce6b6b4d..83f483ef10407 100644 --- a/cmake/onnxruntime_providers_cuda.cmake +++ b/cmake/onnxruntime_providers_cuda.cmake @@ -217,8 +217,12 @@ target_link_libraries(${target} PRIVATE CUDA::cuda_driver) endif() - include(cutlass) - target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include) + find_package(NvidiaCutlass REQUIRED) + target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass) + if(MSVC) + # CUTLASS_CONSTEXPR_IF_CXX17 must be constexpr. Correct the __cplusplus value with MSVC + target_compile_options(${target} PRIVATE $<$:-Xcompiler /Zc:__cplusplus>) + endif() target_include_directories(${target} PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES} PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 711a9f77f9094..f04aee31e0889 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -870,6 +870,7 @@ AddTest( DEPENDS ${all_dependencies} TEST_ARGS ${test_all_args} ) +target_include_directories(onnxruntime_test_all PRIVATE ${ONNXRUNTIME_ROOT}/core/flatbuffers/schema) # ort.fbs.h if (MSVC) # The warning means the type of two integral values around a binary operator is narrow than their result. @@ -963,6 +964,9 @@ target_compile_definitions(onnx_test_data_proto PRIVATE "-DONNX_API=") onnxruntime_add_include_to_target(onnx_test_data_proto onnx_proto) target_include_directories(onnx_test_data_proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) set_target_properties(onnx_test_data_proto PROPERTIES FOLDER "ONNXRuntimeTest") +if(NOT DEFINED onnx_SOURCE_DIR) + find_path(onnx_SOURCE_DIR NAMES "onnx/onnx-ml.proto3" "onnx/onnx-ml.proto" REQUIRED) +endif() onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS ${onnx_SOURCE_DIR} TARGET onnx_test_data_proto) # diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json new file mode 100644 index 0000000000000..afc2c77a32584 --- /dev/null +++ b/cmake/vcpkg-configuration.json @@ -0,0 +1,25 @@ +{ + "default-registry": { + "kind": "git", + "repository": "https://github.com/Microsoft/vcpkg", + "baseline": "f7423ee180c4b7f40d43402c2feb3859161ef625" + }, + "registries": [ + { + "repository": "https://github.com/microsoft/vcpkg", + "kind": "git", + "packages": [ + "flatbuffers" + ], + "baseline": "8161f655436492669adc8eb6f269dc41392ffa70" + }, + { + "repository": "https://github.com/luncliff/vcpkg-registry", + "kind": "git", + "packages": [ + "onnx" + ], + "baseline": "d8758aed30032ab7b6988fd42faf0657d49a2880" + } + ] +} diff --git a/cmake/vcpkg.json b/cmake/vcpkg.json new file mode 100644 index 0000000000000..58e2cc9db4572 --- /dev/null +++ b/cmake/vcpkg.json @@ -0,0 +1,77 @@ +{ + "name": "onnxruntime", + "version-date": "2024-07-14", + "description": "ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator", + "homepage": "https://onnxruntime.ai/", + "license": "MIT", + "dependencies": [ + "abseil", + { + "name": "boost-config", + "version>=": "1.82.0" + }, + { + "name": "boost-mp11", + "version>=": "1.82.0" + }, + "cpuinfo", + "cxxopts", + "date", + "dlpack", + "eigen3", + { + "name": "flatbuffers", + "host": true, + "version>=": "23.5.26" + }, + { + "name": "flatbuffers", + "version>=": "23.5.26" + }, + "ms-gsl", + "nlohmann-json", + { + "name": "nsync", + "platform": "!windows" + }, + { + "name": "nsync", + "platform": "!windows", + "version>=": "1.26.0" + }, + { + "name": "onnx", + "version>=": "1.16.0" + }, + "optional-lite", + { + "name": "protobuf", + "version>=": "3.21.12" + }, + { + "name": "protobuf", + "host": true, + "version>=": "3.21.12" + }, + "re2", + "safeint", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + "wil" + ], + "features": { + "tests": { + "description": "Build ONNXRuntime unit tests", + "dependencies": [ + "benchmark", + "gtest" + ] + } + } +} From c41c244b959a81c531b0cc9d1f0a92c94545626f Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 14 Jul 2024 01:52:20 +0900 Subject: [PATCH 02/22] use `std::string` for `abseil::raw_hash_map` `find` --- onnxruntime/core/framework/kernel_type_str_resolver.cc | 4 ---- onnxruntime/core/framework/ort_value_name_idx_map.h | 4 ---- 2 files changed, 8 deletions(-) diff --git a/onnxruntime/core/framework/kernel_type_str_resolver.cc b/onnxruntime/core/framework/kernel_type_str_resolver.cc index d05e02eb3ab32..3142f94f289b3 100644 --- a/onnxruntime/core/framework/kernel_type_str_resolver.cc +++ b/onnxruntime/core/framework/kernel_type_str_resolver.cc @@ -46,12 +46,8 @@ Status KernelTypeStrResolver::ResolveKernelTypeStr(const Node& node, std::string ORT_RETURN_IF(op_it == op_kernel_type_str_map_.end(), "Failed to find op_id: ", op_id); const auto& type_str_map = op_it->second; -#ifdef DISABLE_ABSEIL // TODO(edgchen1) maybe we can use transparent hash/eq to enable lookup with string_view const auto type_str_it = type_str_map.find(std::string(kernel_type_str)); -#else - const auto type_str_it = type_str_map.find(kernel_type_str); -#endif ORT_RETURN_IF(type_str_it == type_str_map.end(), "Failed to find args for kernel type string '", kernel_type_str, diff --git a/onnxruntime/core/framework/ort_value_name_idx_map.h b/onnxruntime/core/framework/ort_value_name_idx_map.h index 1b5f6bcee9bd0..76e7e369514d4 100644 --- a/onnxruntime/core/framework/ort_value_name_idx_map.h +++ b/onnxruntime/core/framework/ort_value_name_idx_map.h @@ -33,11 +33,7 @@ class OrtValueNameIdxMap { common::Status GetIdx(std::string_view name, int& idx) const { idx = -1; -#ifdef DISABLE_ABSEIL auto it = map_.find(std::string(name)); -#else - auto it = map_.find(name); -#endif if (it == map_.end()) { return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Could not find OrtValue with name '", name, "'"); } From 6223414848b2ee7ae194f270f4c4f1b05f98e58e Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 14 Jul 2024 03:11:17 +0900 Subject: [PATCH 03/22] fix case mismatch --- cmake/CMakeLists.txt | 4 ++-- cmake/CMakePresets.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index e3d2d739e6683..b60f4c9b9c663 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -70,7 +70,7 @@ if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_ endif() # Options -option(ONNXRUNTIME_USE_VCPKG "Build with the vcpkg package manager" OFF) +option(onnxruntime_USE_VCPKG "Build with the vcpkg package manager" OFF) option(onnxruntime_RUN_ONNX_TESTS "Enable ONNX Compatibility Testing" OFF) option(onnxruntime_GENERATE_TEST_REPORTS "Enable test report generation" OFF) option(onnxruntime_ENABLE_STATIC_ANALYSIS "Enable static analysis" OFF) @@ -597,7 +597,7 @@ get_filename_component(ORTTRAINING_ROOT "${ORTTRAINING_ROOT}" ABSOLUTE) get_filename_component(REPO_ROOT "${REPO_ROOT}" ABSOLUTE) set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime) -if(ONNXRUNTIME_USE_VCPKG) +if(onnxruntime_USE_VCPKG) include(external/onnxruntime_vcpkg_deps.cmake) else() include(external/onnxruntime_external_deps.cmake) diff --git a/cmake/CMakePresets.json b/cmake/CMakePresets.json index e3de5765f1305..c1e641d759041 100644 --- a/cmake/CMakePresets.json +++ b/cmake/CMakePresets.json @@ -72,7 +72,7 @@ "binaryDir": "${sourceParentDir}/cmake_build/x64-windows", "installDir": "${sourceParentDir}/cmake_build/out", "cacheVariables": { - "ONNXRUNTIME_USE_VCPKG": true, + "onnxruntime_USE_VCPKG": true, "onnxruntime_USE_XNNPACK": false, "onnxruntime_USE_DML": false, "onnxruntime_BUILD_SHARED_LIB": true, @@ -112,7 +112,7 @@ "vcpkg-manifest" ], "cacheVariables": { - "ONNXRUNTIME_USE_VCPKG": true, + "onnxruntime_USE_VCPKG": true, "onnxruntime_USE_XNNPACK": false, "onnxruntime_USE_COREML": false, "onnxruntime_BUILD_OBJC": false, From ff97583dae288d2d47b75836f17a6009085341a8 Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 14 Jul 2024 03:24:09 +0900 Subject: [PATCH 04/22] use later version of vcpkg --- cmake/vcpkg-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json index afc2c77a32584..8869538c0ae8c 100644 --- a/cmake/vcpkg-configuration.json +++ b/cmake/vcpkg-configuration.json @@ -2,7 +2,7 @@ "default-registry": { "kind": "git", "repository": "https://github.com/Microsoft/vcpkg", - "baseline": "f7423ee180c4b7f40d43402c2feb3859161ef625" + "baseline": "1de2026f28ead93ff1773e6e680387643e914ea1" }, "registries": [ { From fabe7d96072c220a429e60d62c310cfa81b6c76a Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 14 Jul 2024 03:24:41 +0900 Subject: [PATCH 05/22] cmake: check option in CUDA provider file --- cmake/onnxruntime_providers_cuda.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmake/onnxruntime_providers_cuda.cmake b/cmake/onnxruntime_providers_cuda.cmake index 83f483ef10407..6e509c7439698 100644 --- a/cmake/onnxruntime_providers_cuda.cmake +++ b/cmake/onnxruntime_providers_cuda.cmake @@ -217,11 +217,16 @@ target_link_libraries(${target} PRIVATE CUDA::cuda_driver) endif() - find_package(NvidiaCutlass REQUIRED) - target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass) - if(MSVC) - # CUTLASS_CONSTEXPR_IF_CXX17 must be constexpr. Correct the __cplusplus value with MSVC - target_compile_options(${target} PRIVATE $<$:-Xcompiler /Zc:__cplusplus>) + if(onnxruntime_USE_VCPKG) + find_package(NvidiaCutlass REQUIRED) + target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass) + if(MSVC) + # CUTLASS_CONSTEXPR_IF_CXX17 must be constexpr. Correct the __cplusplus value with MSVC + target_compile_options(${target} PRIVATE $<$:"-Xcompiler /Zc:__cplusplus">) + endif() + else() + include(cutlass) + target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include) endif() target_include_directories(${target} PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES} From 4b8bc45681fefdc32b99f1570026bf63e90cc90e Mon Sep 17 00:00:00 2001 From: luncliff Date: Sat, 20 Jul 2024 22:34:37 +0900 Subject: [PATCH 06/22] build.py: create --use_vcpkg option and workflow for Windows --- .github/workflows/windows.yml | 22 ++++++++++++++++++++++ tools/ci_build/build.py | 3 +++ 2 files changed, 25 insertions(+) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index b77e48942ec44..32d59e2a8ad45 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -42,3 +42,25 @@ jobs: # The build machine doesn't have a GPU. So the value of CMAKE_CUDA_ARCHITECTURES doesn't matter. - name: Build code run: python tools\ci_build\build.py --windows_sdk_version 10.0.22621.0 --enable_training --build_java --config Debug --build_dir D:\b --skip_submodule_sync --build_csharp --update --build --parallel --cmake_generator "Visual Studio 17 2022" --build_shared_lib --enable_pybind --use_cuda --cuda_home=${{ github.workspace }}\cuda_sdk\v12.2 --enable_cuda_profiling --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=75 + + Windows-Vcpkg: + runs-on: "windows-latest" + steps: + - uses: actions/checkout@v4 + with: + submodules: false + - uses: actions/setup-python@v5 + with: + python-version: '3.11.x' + architecture: 'x64' + + - name: "Run build.py" + run: | + python tools\ci_build\build.py ` + --config Debug --build_dir "${{github.workspace}}/cmake_build" ` + --skip_submodule_sync --skip_tests --compile_no_warning_as_error ` + --cmake_generator "Visual Studio 17 2022" --build_shared_lib ` + --vcpkg ` + --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${{ env.VCPKG_INSTALLATION_ROOT }}\scripts\buildsystems\vcpkg.cmake" ` + --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" + shell: pwsh diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index 75fbf5d0851ae..c43606d5f548c 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -463,6 +463,8 @@ def convert_arg_line_to_args(self, arg_line): action="store_true", help="Disable memory leak checker from Windows build. By default it is enabled in Windows Debug build. This option is Windows only.", ) + # Dependency search with vcpkg + parser.add_argument("--use_vcpkg", action="store_true", help="Use vcpkg to search dependencies. Requires CMAKE_TOOLCHAIN_FILE for vcpkg.cmake") # WebAssembly build parser.add_argument("--build_wasm", action="store_true", help="Build for WebAssembly") @@ -1012,6 +1014,7 @@ def generate_build_tree( # of them to get the best compatibility. "-DPython_EXECUTABLE=" + sys.executable, "-DPYTHON_EXECUTABLE=" + sys.executable, + "-Donnxruntime_USE_VCPKG=" + ("ON" if args.use_vcpkg else "OFF"), "-Donnxruntime_USE_MIMALLOC=" + ("ON" if args.use_mimalloc else "OFF"), "-Donnxruntime_ENABLE_PYTHON=" + ("ON" if args.enable_pybind else "OFF"), "-Donnxruntime_BUILD_CSHARP=" + ("ON" if args.build_csharp else "OFF"), From 36919b0eb7d3baccc00b4a183ebf36e88dc74959 Mon Sep 17 00:00:00 2001 From: luncliff Date: Sat, 20 Jul 2024 23:25:04 +0900 Subject: [PATCH 07/22] gh-actions: jobs for each vcpkg triplet --- .github/workflows/mac.yml | 42 +++++++++++++++++++++++++++++++++++ .github/workflows/windows.yml | 33 +++++++++++++++++++-------- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml index 3d94d30947c76..75a65d022a2fe 100644 --- a/.github/workflows/mac.yml +++ b/.github/workflows/mac.yml @@ -58,6 +58,48 @@ jobs: --use_xnnpack \ --use_binskim_compliant_compile_flags + Vcpkg: + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: ${{ env.python_version }} + - uses: lukka/run-vcpkg@v11 + with: + vcpkgGitCommitId: "1de2026f28ead93ff1773e6e680387643e914ea1" # 2024.07.12 + runVcpkgInstall: false + + - name: "Run build.py(x64-osx)" + run: | + python ./tools/ci_build/build.py \ + --build_dir "build/x64-osx" \ + --skip_submodule_sync \ + --compile_no_warning_as_error \ + --skip_tests \ + --parallel \ + --use_xcode --osx_arch x86_64 \ + --use_vcpkg \ + --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \ + --cmake_extra_defines "VCPKG_TARGET_TRIPLET=x64-osx" \ + --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" + shell: bash + + - name: "Run build.py(arm64-osx)" + run: | + python ./tools/ci_build/build.py \ + --build_dir "build/arm64-osx" \ + --skip_submodule_sync \ + --compile_no_warning_as_error \ + --skip_tests \ + --parallel \ + --use_xcode --osx_arch arm64 \ + --use_vcpkg \ + --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \ + --cmake_extra_defines "VCPKG_TARGET_TRIPLET=arm64-osx" \ + --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" + shell: bash + Objective-C-StaticAnalysis: runs-on: macos-14 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 32d59e2a8ad45..6f5d0fb6e9006 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -43,24 +43,39 @@ jobs: - name: Build code run: python tools\ci_build\build.py --windows_sdk_version 10.0.22621.0 --enable_training --build_java --config Debug --build_dir D:\b --skip_submodule_sync --build_csharp --update --build --parallel --cmake_generator "Visual Studio 17 2022" --build_shared_lib --enable_pybind --use_cuda --cuda_home=${{ github.workspace }}\cuda_sdk\v12.2 --enable_cuda_profiling --cmake_extra_defines CMAKE_CUDA_ARCHITECTURES=75 - Windows-Vcpkg: + Vcpkg: runs-on: "windows-latest" steps: - uses: actions/checkout@v4 - with: - submodules: false - uses: actions/setup-python@v5 with: python-version: '3.11.x' architecture: 'x64' - - name: "Run build.py" + - name: "Run build.py(x64-windows)" + run: | + python tools\ci_build\build.py ` + --build_dir "build/x64-windows" ` + --skip_submodule_sync ` + --compile_no_warning_as_error ` + --skip_tests ` + --parallel ` + --use_vcpkg ` + --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" ` + --cmake_extra_defines "VCPKG_TARGET_TRIPLET=x64-windows" ` + --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" + shell: pwsh + + - name: "Run build.py(arm64-windows)" run: | python tools\ci_build\build.py ` - --config Debug --build_dir "${{github.workspace}}/cmake_build" ` - --skip_submodule_sync --skip_tests --compile_no_warning_as_error ` - --cmake_generator "Visual Studio 17 2022" --build_shared_lib ` - --vcpkg ` - --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${{ env.VCPKG_INSTALLATION_ROOT }}\scripts\buildsystems\vcpkg.cmake" ` + --build_dir "build/arm64-windows" --arm64 ` + --skip_submodule_sync ` + --compile_no_warning_as_error ` + --skip_tests ` + --parallel ` + --use_vcpkg ` + --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" ` + --cmake_extra_defines "VCPKG_TARGET_TRIPLET=arm64-windows" ` --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" shell: pwsh From 310aaa62c2b3eb47cfd08a29a56415400649ef40 Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 21 Jul 2024 21:35:23 +0900 Subject: [PATCH 08/22] vcpkg: update manifest --- cmake/vcpkg.json | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/vcpkg.json b/cmake/vcpkg.json index 58e2cc9db4572..7263496df9251 100644 --- a/cmake/vcpkg.json +++ b/cmake/vcpkg.json @@ -1,6 +1,6 @@ { "name": "onnxruntime", - "version-date": "2024-07-14", + "version-date": "2024-07-21", "description": "ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator", "homepage": "https://onnxruntime.ai/", "license": "MIT", @@ -55,6 +55,7 @@ }, "re2", "safeint", + "utf8-range", { "name": "vcpkg-cmake", "host": true @@ -63,7 +64,11 @@ "name": "vcpkg-cmake-config", "host": true }, - "wil" + "wil", + { + "name": "zlib", + "platform": "windows" + } ], "features": { "tests": { From 6227f5fdc8c1602f5c848378abfec5627d576853 Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 21 Jul 2024 21:39:01 +0900 Subject: [PATCH 09/22] cmake: try merge of onnxruntime_external_*.cmake --- cmake/CMakeLists.txt | 3 +- .../external/onnxruntime_external_deps.cmake | 325 ++++++++++-------- 2 files changed, 181 insertions(+), 147 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index b60f4c9b9c663..9ff8bf06966d4 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -597,9 +597,10 @@ get_filename_component(ORTTRAINING_ROOT "${ORTTRAINING_ROOT}" ABSOLUTE) get_filename_component(REPO_ROOT "${REPO_ROOT}" ABSOLUTE) set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime) -if(onnxruntime_USE_VCPKG) +if(FALSE) # onnxruntime_USE_VCPKG include(external/onnxruntime_vcpkg_deps.cmake) else() + list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) include(external/onnxruntime_external_deps.cmake) endif() diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake index 775576a771529..c1054e0f8fd54 100644 --- a/cmake/external/onnxruntime_external_deps.cmake +++ b/cmake/external/onnxruntime_external_deps.cmake @@ -1,4 +1,4 @@ -message("Loading Dependencies URLs ...") +message(STATUS "Loading Dependencies URLs ...") include(external/helper_functions.cmake) @@ -27,7 +27,9 @@ foreach(ONNXRUNTIME_DEP IN LISTS ONNXRUNTIME_DEPS_LIST) endif() endforeach() -message("Loading Dependencies ...") +message(STATUS "Loading Dependencies ...") +include(FetchContent) + # ABSL should be included before protobuf because protobuf may use absl include(external/abseil-cpp.cmake) @@ -39,6 +41,7 @@ FetchContent_Declare( URL_HASH SHA1=${DEP_SHA1_re2} FIND_PACKAGE_ARGS NAMES re2 ) +onnxruntime_fetchcontent_makeavailable(re2) if (onnxruntime_BUILD_UNIT_TESTS) # WebAssembly threading support in Node.js is still an experimental feature and @@ -65,6 +68,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) URL_HASH SHA1=${DEP_SHA1_googletest} FIND_PACKAGE_ARGS 1.14.0...<2.0.0 NAMES GTest ) + FetchContent_MakeAvailable(googletest) endif() if (onnxruntime_BUILD_BENCHMARKS) @@ -77,50 +81,41 @@ if (onnxruntime_BUILD_BENCHMARKS) google_benchmark URL ${DEP_URL_google_benchmark} URL_HASH SHA1=${DEP_SHA1_google_benchmark} + FIND_PACKAGE_ARGS NAMES benchmark ) + onnxruntime_fetchcontent_makeavailable(google_benchmark) endif() if (NOT WIN32) - FetchContent_Declare( + FetchContent_Declare( google_nsync URL ${DEP_URL_google_nsync} URL_HASH SHA1=${DEP_SHA1_google_nsync} - FIND_PACKAGE_ARGS NAMES nsync - ) -endif() -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) - -FetchContent_Declare( - mimalloc - URL ${DEP_URL_mimalloc} - URL_HASH SHA1=${DEP_SHA1_mimalloc} -) - + FIND_PACKAGE_ARGS NAMES nsync unofficial-nsync + ) + #nsync tests failed on Mac Build + set(NSYNC_ENABLE_TESTS OFF CACHE BOOL "" FORCE) + onnxruntime_fetchcontent_makeavailable(google_nsync) -# Flatbuffers -# We do not need to build flatc for iOS or Android Cross Compile -if (CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten") - set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATC" FORCE) -endif() -set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "FLATBUFFERS_BUILD_TESTS" FORCE) -set(FLATBUFFERS_INSTALL OFF CACHE BOOL "FLATBUFFERS_INSTALL" FORCE) -set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATHASH" FORCE) -set(FLATBUFFERS_BUILD_FLATLIB ON CACHE BOOL "FLATBUFFERS_BUILD_FLATLIB" FORCE) -if(Patch_FOUND) - set(ONNXRUNTIME_FLATBUFFERS_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/flatbuffers/flatbuffers.patch) -else() - set(ONNXRUNTIME_FLATBUFFERS_PATCH_COMMAND "") + if (google_nsync_SOURCE_DIR) + add_library(nsync::nsync_cpp ALIAS nsync_cpp) + target_include_directories(nsync_cpp PUBLIC ${google_nsync_SOURCE_DIR}/public) + endif() + if(TARGET unofficial::nsync::nsync_cpp AND NOT TARGET nsync::nsync_cpp) + message(STATUS "Aliasing unofficial::nsync::nsync_cpp to nsync::nsync_cpp") + add_library(nsync::nsync_cpp ALIAS unofficial::nsync::nsync_cpp) + endif() endif() -#flatbuffers 1.11.0 does not have flatbuffers::IsOutRange, therefore we require 1.12.0+ -FetchContent_Declare( - flatbuffers - URL ${DEP_URL_flatbuffers} - URL_HASH SHA1=${DEP_SHA1_flatbuffers} - PATCH_COMMAND ${ONNXRUNTIME_FLATBUFFERS_PATCH_COMMAND} - FIND_PACKAGE_ARGS 23.5.9 NAMES Flatbuffers -) - +if(onnxruntime_USE_MIMALLOC) + FetchContent_Declare( + mimalloc + URL ${DEP_URL_mimalloc} + URL_HASH SHA1=${DEP_SHA1_mimalloc} + FIND_PACKAGE_ARGS NAMES mimalloc + ) + FetchContent_MakeAvailable(mimalloc) +endif() #Protobuf depends on utf8_range FetchContent_Declare( @@ -133,6 +128,10 @@ FetchContent_Declare( set(utf8_range_ENABLE_TESTS OFF CACHE BOOL "Build test suite" FORCE) set(utf8_range_ENABLE_INSTALL OFF CACHE BOOL "Configure installation" FORCE) +# The next line will generate an error message "fatal: not a git repository", but it is ok. It is from flatbuffers +onnxruntime_fetchcontent_makeavailable(utf8_range) +# protobuf's cmake/utf8_range.cmake has the following line +include_directories(${utf8_range_SOURCE_DIR}) # Download a protoc binary from Internet if needed if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE) @@ -146,12 +145,12 @@ if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE) FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_mac_universal} URL_HASH SHA1=${DEP_SHA1_protoc_mac_universal}) FetchContent_Populate(protoc_binary) if(protoc_binary_SOURCE_DIR) - message("Use prebuilt protoc") + message(STATUS "Use prebuilt protoc") set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc) set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE}) endif() elseif (CMAKE_CROSSCOMPILING) - message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}") + message(STATUS "CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64") FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win64} URL_HASH SHA1=${DEP_SHA1_protoc_win64}) @@ -162,7 +161,7 @@ if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE) endif() if(protoc_binary_SOURCE_DIR) - message("Use prebuilt protoc") + message(STATUS "Use prebuilt protoc") set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc.exe) set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE}) endif() @@ -179,7 +178,7 @@ if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE) endif() if(protoc_binary_SOURCE_DIR) - message("Use prebuilt protoc") + message(STATUS "Use prebuilt protoc") set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc) set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE}) endif() @@ -217,7 +216,7 @@ FetchContent_Declare( URL ${DEP_URL_protobuf} URL_HASH SHA1=${DEP_SHA1_protobuf} PATCH_COMMAND ${ONNXRUNTIME_PROTOBUF_PATCH_COMMAND} - FIND_PACKAGE_ARGS 3.21.12 NAMES Protobuf + FIND_PACKAGE_ARGS NAMES Protobuf protobuf ) set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) @@ -239,6 +238,51 @@ endif() include(protobuf_function) #protobuf end +onnxruntime_fetchcontent_makeavailable(Protobuf) +if(Protobuf_FOUND) + message(STATUS "Protobuf version: ${Protobuf_VERSION}") +else() + # Adjust warning flags + if (TARGET libprotoc) + if (NOT MSVC) + target_compile_options(libprotoc PRIVATE "-w") + endif() + endif() + if (TARGET protoc) + add_executable(protobuf::protoc ALIAS protoc) + if (UNIX AND onnxruntime_ENABLE_LTO) + #https://github.com/protocolbuffers/protobuf/issues/5923 + target_link_options(protoc PRIVATE "-Wl,--no-as-needed") + endif() + if (NOT MSVC) + target_compile_options(protoc PRIVATE "-w") + endif() + get_target_property(PROTOC_OSX_ARCH protoc OSX_ARCHITECTURES) + if (PROTOC_OSX_ARCH) + if (${CMAKE_HOST_SYSTEM_PROCESSOR} IN_LIST PROTOC_OSX_ARCH) + message(STATUS "protoc can run") + else() + list(APPEND PROTOC_OSX_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR}) + set_target_properties(protoc PROPERTIES OSX_ARCHITECTURES "${CMAKE_HOST_SYSTEM_PROCESSOR}") + set_target_properties(libprotoc PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") + set_target_properties(libprotobuf PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") + endif() + endif() + endif() + if (TARGET libprotobuf AND NOT MSVC) + target_compile_options(libprotobuf PRIVATE "-w") + endif() + if (TARGET libprotobuf-lite AND NOT MSVC) + target_compile_options(libprotobuf-lite PRIVATE "-w") + endif() +endif() +if (onnxruntime_USE_FULL_PROTOBUF) + set(PROTOBUF_LIB protobuf::libprotobuf) +else() + set(PROTOBUF_LIB protobuf::libprotobuf-lite) +endif() + +# date set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE) set(USE_SYSTEM_TZ_DB ON CACHE BOOL "" FORCE) @@ -254,7 +298,9 @@ FetchContent_Declare( mp11 URL ${DEP_URL_mp11} URL_HASH SHA1=${DEP_SHA1_mp11} + FIND_PACKAGE_ARGS NAMES boost_mp11 ) +onnxruntime_fetchcontent_makeavailable(mp11) set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_Install OFF CACHE INTERNAL "") @@ -265,6 +311,7 @@ FetchContent_Declare( URL_HASH SHA1=${DEP_SHA1_json} FIND_PACKAGE_ARGS 3.10 NAMES nlohmann_json ) +onnxruntime_fetchcontent_makeavailable(nlohmann_json) #TODO: include clog first if (onnxruntime_ENABLE_CPUINFO) @@ -301,20 +348,6 @@ else() set(CPUINFO_SUPPORTED FALSE) endif() -# xnnpack depends on clog -# Android build should use the system's log library instead of clog -if ((CPUINFO_SUPPORTED OR onnxruntime_USE_XNNPACK) AND NOT ANDROID) - set(CLOG_BUILD_TESTS OFF CACHE BOOL "" FORCE) - FetchContent_Declare( - pytorch_clog - URL ${DEP_URL_pytorch_cpuinfo} - URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo} - SOURCE_SUBDIR deps/clog - ) - set(ONNXRUNTIME_CLOG_PROJ pytorch_clog) - set(ONNXRUNTIME_CLOG_TARGET_NAME clog) -endif() - if (CPUINFO_SUPPORTED) if (CMAKE_SYSTEM_NAME STREQUAL "iOS") set(IOS ON CACHE INTERNAL "") @@ -333,7 +366,7 @@ if (CPUINFO_SUPPORTED) set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE INTERNAL "") set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "") if(onnxruntime_target_platform STREQUAL "ARM64EC") - message("Applying a patch for Windows ARM64EC in cpuinfo") + message(STATUS "Applying a patch for Windows ARM64EC in cpuinfo") FetchContent_Declare( pytorch_cpuinfo URL ${DEP_URL_pytorch_cpuinfo} @@ -350,20 +383,29 @@ if (CPUINFO_SUPPORTED) ) endif() set(ONNXRUNTIME_CPUINFO_PROJ pytorch_cpuinfo) + onnxruntime_fetchcontent_makeavailable(${ONNXRUNTIME_CPUINFO_PROJ}) + if(TARGET cpuinfo::cpuinfo AND NOT TARGET cpuinfo) + message(STATUS "Aliasing cpuinfo::cpuinfo to cpuinfo") + add_library(cpuinfo ALIAS cpuinfo::cpuinfo) + endif() endif() - -if (onnxruntime_BUILD_BENCHMARKS) - onnxruntime_fetchcontent_makeavailable(google_benchmark) -endif() - -if (NOT WIN32) - #nsync tests failed on Mac Build - set(NSYNC_ENABLE_TESTS OFF CACHE BOOL "" FORCE) - onnxruntime_fetchcontent_makeavailable(google_nsync) - if (google_nsync_SOURCE_DIR) - add_library(nsync::nsync_cpp ALIAS nsync_cpp) - target_include_directories(nsync_cpp PUBLIC ${google_nsync_SOURCE_DIR}/public) +# xnnpack depends on clog +# Android build should use the system's log library instead of clog +if ((CPUINFO_SUPPORTED OR onnxruntime_USE_XNNPACK) AND NOT ANDROID) + set(CLOG_BUILD_TESTS OFF CACHE BOOL "" FORCE) + FetchContent_Declare( + pytorch_clog + URL ${DEP_URL_pytorch_cpuinfo} + URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo} + SOURCE_SUBDIR deps/clog + FIND_PACKAGE_ARGS NAMES cpuinfo + ) + set(ONNXRUNTIME_CLOG_PROJ pytorch_clog) + onnxruntime_fetchcontent_makeavailable(${ONNXRUNTIME_CLOG_PROJ}) + set(ONNXRUNTIME_CLOG_TARGET_NAME clog) + if(TARGET cpuinfo::clog) + set(ONNXRUNTIME_CLOG_TARGET_NAME cpuinfo::clog) endif() endif() @@ -383,21 +425,51 @@ else() FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL ) endif() +set(GSL_TARGET "Microsoft.GSL::GSL") +set(GSL_INCLUDE_DIR "$") +onnxruntime_fetchcontent_makeavailable(GSL) + +find_path(safeint_SOURCE_DIR NAMES "SafeInt.hpp") +if(NOT safeint_SOURCE_DIR) + unset(safeint_SOURCE_DIR) + FetchContent_Declare( + safeint + URL ${DEP_URL_safeint} + URL_HASH SHA1=${DEP_SHA1_safeint} + ) + + # use fetch content rather than makeavailable because safeint only includes unconditional test targets + FetchContent_Populate(safeint) +endif() +add_library(safeint_interface INTERFACE) +target_include_directories(safeint_interface INTERFACE ${safeint_SOURCE_DIR}) + + +# Flatbuffers +# We do not need to build flatc for iOS or Android Cross Compile +if (CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + set(FLATBUFFERS_BUILD_FLATC OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATC" FORCE) +endif() +set(FLATBUFFERS_BUILD_TESTS OFF CACHE BOOL "FLATBUFFERS_BUILD_TESTS" FORCE) +set(FLATBUFFERS_INSTALL OFF CACHE BOOL "FLATBUFFERS_INSTALL" FORCE) +set(FLATBUFFERS_BUILD_FLATHASH OFF CACHE BOOL "FLATBUFFERS_BUILD_FLATHASH" FORCE) +set(FLATBUFFERS_BUILD_FLATLIB ON CACHE BOOL "FLATBUFFERS_BUILD_FLATLIB" FORCE) +if(Patch_FOUND) + set(ONNXRUNTIME_FLATBUFFERS_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/flatbuffers/flatbuffers.patch) +else() + set(ONNXRUNTIME_FLATBUFFERS_PATCH_COMMAND "") +endif() +#flatbuffers 1.11.0 does not have flatbuffers::IsOutRange, therefore we require 1.12.0+ FetchContent_Declare( - safeint - URL ${DEP_URL_safeint} - URL_HASH SHA1=${DEP_SHA1_safeint} + flatbuffers + URL ${DEP_URL_flatbuffers} + URL_HASH SHA1=${DEP_SHA1_flatbuffers} + PATCH_COMMAND ${ONNXRUNTIME_FLATBUFFERS_PATCH_COMMAND} + FIND_PACKAGE_ARGS 23.5.9 NAMES Flatbuffers flatbuffers ) -# use fetch content rather than makeavailable because safeint only includes unconditional test targets -FetchContent_Populate(safeint) -# The next line will generate an error message "fatal: not a git repository", but it is ok. It is from flatbuffers -onnxruntime_fetchcontent_makeavailable(utf8_range) -# protobuf's cmake/utf8_range.cmake has the following line -include_directories(${utf8_range_SOURCE_DIR}) - -onnxruntime_fetchcontent_makeavailable(Protobuf nlohmann_json mp11 re2 GSL flatbuffers ${ONNXRUNTIME_CPUINFO_PROJ} ${ONNXRUNTIME_CLOG_PROJ}) +onnxruntime_fetchcontent_makeavailable(flatbuffers) if(NOT flatbuffers_FOUND) if(NOT TARGET flatbuffers::flatbuffers) add_library(flatbuffers::flatbuffers ALIAS flatbuffers) @@ -424,54 +496,6 @@ namespace std { using ::getenv; } endif() endif() -if (onnxruntime_BUILD_UNIT_TESTS) - onnxruntime_fetchcontent_makeavailable(googletest) -endif() - -if(Protobuf_FOUND) - message("Protobuf version: ${Protobuf_VERSION}") -else() - # Adjust warning flags - if (TARGET libprotoc) - if (NOT MSVC) - target_compile_options(libprotoc PRIVATE "-w") - endif() - endif() - if (TARGET protoc) - add_executable(protobuf::protoc ALIAS protoc) - if (UNIX AND onnxruntime_ENABLE_LTO) - #https://github.com/protocolbuffers/protobuf/issues/5923 - target_link_options(protoc PRIVATE "-Wl,--no-as-needed") - endif() - if (NOT MSVC) - target_compile_options(protoc PRIVATE "-w") - endif() - get_target_property(PROTOC_OSX_ARCH protoc OSX_ARCHITECTURES) - if (PROTOC_OSX_ARCH) - if (${CMAKE_HOST_SYSTEM_PROCESSOR} IN_LIST PROTOC_OSX_ARCH) - message("protoc can run") - else() - list(APPEND PROTOC_OSX_ARCH ${CMAKE_HOST_SYSTEM_PROCESSOR}) - set_target_properties(protoc PROPERTIES OSX_ARCHITECTURES "${CMAKE_HOST_SYSTEM_PROCESSOR}") - set_target_properties(libprotoc PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") - set_target_properties(libprotobuf PROPERTIES OSX_ARCHITECTURES "${PROTOC_OSX_ARCH}") - endif() - endif() - endif() - if (TARGET libprotobuf AND NOT MSVC) - target_compile_options(libprotobuf PRIVATE "-w") - endif() - if (TARGET libprotobuf-lite AND NOT MSVC) - target_compile_options(libprotobuf-lite PRIVATE "-w") - endif() -endif() -if (onnxruntime_USE_FULL_PROTOBUF) - set(PROTOBUF_LIB protobuf::libprotobuf) -else() - set(PROTOBUF_LIB protobuf::libprotobuf-lite) -endif() - - # ONNX if (NOT onnxruntime_USE_FULL_PROTOBUF) set(ONNX_USE_LITE_PROTO ON CACHE BOOL "" FORCE) @@ -490,27 +514,32 @@ FetchContent_Declare( URL ${DEP_URL_onnx} URL_HASH SHA1=${DEP_SHA1_onnx} PATCH_COMMAND ${ONNXRUNTIME_ONNX_PATCH_COMMAND} + FIND_PACKAGE_ARGS NAMES ONNX onnx ) - - - - - - -include(eigen) -include(wil) - if (NOT onnxruntime_MINIMAL_BUILD) - onnxruntime_fetchcontent_makeavailable(onnx) + onnxruntime_fetchcontent_makeavailable(onnx) else() include(onnx_minimal) endif() -set(GSL_TARGET "Microsoft.GSL::GSL") -set(GSL_INCLUDE_DIR "$") +if(TARGET ONNX::onnx AND NOT TARGET onnx) + message(STATUS "Aliasing ONNX::onnx to onnx") + add_library(onnx ALIAS ONNX::onnx) +endif() +if(TARGET ONNX::onnx_proto AND NOT TARGET onnx_proto) + message(STATUS "Aliasing ONNX::onnx_proto to onnx_proto") + add_library(onnx_proto ALIAS ONNX::onnx_proto) +endif() -add_library(safeint_interface INTERFACE) -target_include_directories(safeint_interface INTERFACE ${safeint_SOURCE_DIR}) +find_package(Eigen3 CONFIG) +if(NOT Eigen3_FOUND) + include(eigen) +endif() + +find_package(wil CONFIG) +if(NOT wil_FOUND) + include(wil) +endif() # XNNPACK EP if (onnxruntime_USE_XNNPACK) @@ -539,9 +568,11 @@ set(onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK} ${W # The other libs do not have the problem. All the sources are already there. We can compile them in any order. set(onnxruntime_EXTERNAL_DEPENDENCIES onnx_proto flatbuffers::flatbuffers) -target_compile_definitions(onnx PUBLIC $ PRIVATE "__ONNX_DISABLE_STATIC_REGISTRATION") -if (NOT onnxruntime_USE_FULL_PROTOBUF) - target_compile_definitions(onnx PUBLIC "__ONNX_NO_DOC_STRINGS") +if(NOT (onnx_FOUND OR ONNX_FOUND)) # building ONNX from source + target_compile_definitions(onnx PUBLIC $ PRIVATE "__ONNX_DISABLE_STATIC_REGISTRATION") + if (NOT onnxruntime_USE_FULL_PROTOBUF) + target_compile_definitions(onnx PUBLIC "__ONNX_NO_DOC_STRINGS") + endif() endif() if (onnxruntime_RUN_ONNX_TESTS) @@ -550,11 +581,12 @@ endif() if(onnxruntime_ENABLE_ATEN) - message("Aten fallback is enabled.") + message(STATUS "Aten fallback is enabled.") FetchContent_Declare( dlpack URL ${DEP_URL_dlpack} URL_HASH SHA1=${DEP_SHA1_dlpack} + FIND_PACKAGE_ARGS NAMES dlpack ) # We can't use onnxruntime_fetchcontent_makeavailable since some part of the the dlpack code is Linux only. # For example, dlpackcpp.h uses posix_memalign. @@ -568,6 +600,7 @@ if(onnxruntime_ENABLE_TRAINING OR (onnxruntime_ENABLE_TRAINING_APIS AND onnxrunt cxxopts URL ${DEP_URL_cxxopts} URL_HASH SHA1=${DEP_SHA1_cxxopts} + FIND_PACKAGE_ARGS NAMES cxxopts ) set(CXXOPTS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) set(CXXOPTS_BUILD_TESTS OFF CACHE BOOL "" FORCE) @@ -585,7 +618,7 @@ if (onnxruntime_USE_COREML) FetchContent_Populate(coremltools) endif() -message("Finished fetching external dependencies") +message(STATUS "Finished fetching external dependencies") set(onnxruntime_LINK_DIRS ) From 091ea112b0e4d35b9ecc52c1625105c34d505e70 Mon Sep 17 00:00:00 2001 From: luncliff Date: Tue, 23 Jul 2024 22:53:23 +0900 Subject: [PATCH 10/22] python: apply lintrunner suggestions --- tools/ci_build/build.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/ci_build/build.py b/tools/ci_build/build.py index c43606d5f548c..2e71f95fe4cfd 100644 --- a/tools/ci_build/build.py +++ b/tools/ci_build/build.py @@ -464,7 +464,11 @@ def convert_arg_line_to_args(self, arg_line): help="Disable memory leak checker from Windows build. By default it is enabled in Windows Debug build. This option is Windows only.", ) # Dependency search with vcpkg - parser.add_argument("--use_vcpkg", action="store_true", help="Use vcpkg to search dependencies. Requires CMAKE_TOOLCHAIN_FILE for vcpkg.cmake") + parser.add_argument( + "--use_vcpkg", + action="store_true", + help="Use vcpkg to search dependencies. Requires CMAKE_TOOLCHAIN_FILE for vcpkg.cmake", + ) # WebAssembly build parser.add_argument("--build_wasm", action="store_true", help="Build for WebAssembly") From ba5bb5c85163e1ef52fed61087de11f279d60f55 Mon Sep 17 00:00:00 2001 From: luncliff Date: Tue, 23 Jul 2024 21:02:36 +0900 Subject: [PATCH 11/22] ci: update vcpkg-configuration * https://github.com/microsoft/vcpkg/pull/39881 --- cmake/vcpkg-configuration.json | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json index 8869538c0ae8c..36b0d9ae78fac 100644 --- a/cmake/vcpkg-configuration.json +++ b/cmake/vcpkg-configuration.json @@ -2,17 +2,9 @@ "default-registry": { "kind": "git", "repository": "https://github.com/Microsoft/vcpkg", - "baseline": "1de2026f28ead93ff1773e6e680387643e914ea1" + "baseline": "ad40d92ce7161d93986083c55d3200b4661e70ec" }, "registries": [ - { - "repository": "https://github.com/microsoft/vcpkg", - "kind": "git", - "packages": [ - "flatbuffers" - ], - "baseline": "8161f655436492669adc8eb6f269dc41392ffa70" - }, { "repository": "https://github.com/luncliff/vcpkg-registry", "kind": "git", From e37f9d6f7b125e7cac85295d679f4128a64473f2 Mon Sep 17 00:00:00 2001 From: luncliff Date: Tue, 23 Jul 2024 22:25:05 +0900 Subject: [PATCH 12/22] ci: use vcpkg installed flatc, protoc * Detect protoc path for build.py * Run vcpkg for each build.py run Reorganized vcpkg install folder and CMake build directory --- .github/workflows/mac.yml | 54 ++++++++++++++++++++++++++---- .github/workflows/windows.yml | 62 +++++++++++++++++++++++++++++++---- cmake/CMakePresets.json | 1 + 3 files changed, 105 insertions(+), 12 deletions(-) diff --git a/.github/workflows/mac.yml b/.github/workflows/mac.yml index 75a65d022a2fe..6efa8a5592337 100644 --- a/.github/workflows/mac.yml +++ b/.github/workflows/mac.yml @@ -65,38 +65,80 @@ jobs: - uses: actions/setup-python@v5 with: python-version: ${{ env.python_version }} - - uses: lukka/run-vcpkg@v11 + + - name: "Run vcpkg(x64-osx)" + uses: lukka/run-vcpkg@v11 with: + vcpkgDirectory: "${{ runner.temp }}/vcpkg" vcpkgGitCommitId: "1de2026f28ead93ff1773e6e680387643e914ea1" # 2024.07.12 - runVcpkgInstall: false + runVcpkgInstall: true + vcpkgJsonGlob: "cmake/vcpkg.json" + vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json" + env: + VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build" + VCPKG_DEFAULT_TRIPLET: "x64-osx" + # VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching + + - name: "Run compile_schema.py" + run: | + # Runner's host triplet should be x64-osx or arm64-osx + export FLATC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-osx/tools/flatbuffers" + export PATH="$FLATC_DIR:$PATH" + flatc --version + python onnxruntime/core/flatbuffers/schema/compile_schema.py --flatc "$(which flatc)" + + - name: "Detect protoc" + id: protoc-detect + run: | + export PROTOC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-osx/tools/protobuf" + export PATH="$PROTOC_DIR:$PATH" + protoc --version + echo "protoc_path=$(which protoc)" >> "$GITHUB_OUTPUT" - name: "Run build.py(x64-osx)" run: | python ./tools/ci_build/build.py \ --build_dir "build/x64-osx" \ --skip_submodule_sync \ - --compile_no_warning_as_error \ --skip_tests \ + --compile_no_warning_as_error \ --parallel \ - --use_xcode --osx_arch x86_64 \ + --path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" \ + --osx_arch x86_64 \ --use_vcpkg \ --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \ --cmake_extra_defines "VCPKG_TARGET_TRIPLET=x64-osx" \ + --cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" \ --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" shell: bash + - name: "Run vcpkg(arm64-osx)" + uses: lukka/run-vcpkg@v11 + with: + vcpkgDirectory: "${{ runner.temp }}/vcpkg" + vcpkgGitCommitId: "1de2026f28ead93ff1773e6e680387643e914ea1" # 2024.07.12 + runVcpkgInstall: true + vcpkgJsonGlob: "cmake/vcpkg.json" + vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json" + env: + VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build" + VCPKG_DEFAULT_TRIPLET: "arm64-osx" + # VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching + - name: "Run build.py(arm64-osx)" run: | python ./tools/ci_build/build.py \ --build_dir "build/arm64-osx" \ --skip_submodule_sync \ - --compile_no_warning_as_error \ --skip_tests \ + --compile_no_warning_as_error \ --parallel \ - --use_xcode --osx_arch arm64 \ + --path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" \ + --osx_arch arm64 \ --use_vcpkg \ --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \ --cmake_extra_defines "VCPKG_TARGET_TRIPLET=arm64-osx" \ + --cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" \ --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" shell: bash diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6f5d0fb6e9006..d276877b7ad47 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -52,30 +52,80 @@ jobs: python-version: '3.11.x' architecture: 'x64' + - name: "Run vcpkg(x64-windows)" + uses: lukka/run-vcpkg@v11 + with: + vcpkgDirectory: "C:/vcpkg" # use VCPKG_INSTALLATION_ROOT of the image + doNotUpdateVcpkg: true + runVcpkgInstall: true + vcpkgJsonGlob: "cmake/vcpkg.json" + vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json" + env: + VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build" + VCPKG_DEFAULT_TRIPLET: "x64-windows" + # VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching + + - name: "Run compile_schema.py" + run: | + # Runner's host triplet should be x64-windows or arm64-windows + $FLATC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-windows/tools/flatbuffers" + $env:PATH="$FLATC_DIR;$env:PATH" + flatc --version + $FLATC_PATH = Join-Path "$FLATC_DIR" "flatc.exe" + python onnxruntime/core/flatbuffers/schema/compile_schema.py --flatc "$FLATC_PATH" + shell: pwsh + + - name: "Detect protoc" + id: protoc-detect + run: | + $PROTOC_DIR="${{ github.workspace }}/.build/${{ runner.arch }}-windows/tools/protobuf" + $env:PATH="$PROTOC_DIR;$env:PATH" + protoc --version + $PROTOC_PATH = Join-Path "$PROTOC_DIR" "protoc.exe" + "protoc_path=$PROTOC_PATH" >> $env:GITHUB_OUTPUT + shell: pwsh + - name: "Run build.py(x64-windows)" run: | python tools\ci_build\build.py ` - --build_dir "build/x64-windows" ` + --build_dir "cmake_build/x64-windows" ` --skip_submodule_sync ` - --compile_no_warning_as_error ` --skip_tests ` + --compile_no_warning_as_error ` --parallel ` + --path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" ` --use_vcpkg ` - --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" ` + --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" ` --cmake_extra_defines "VCPKG_TARGET_TRIPLET=x64-windows" ` + --cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" ` --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" shell: pwsh + - name: "Run vcpkg(arm64-windows)" + uses: lukka/run-vcpkg@v11 + with: + vcpkgDirectory: "C:/vcpkg" # use VCPKG_INSTALLATION_ROOT of the image + doNotUpdateVcpkg: true + runVcpkgInstall: true + vcpkgJsonGlob: "cmake/vcpkg.json" + vcpkgConfigurationJsonGlob: "cmake/vcpkg-configuration.json" + env: + VCPKG_INSTALLED_DIR: "${{ github.workspace }}/.build" + VCPKG_DEFAULT_TRIPLET: "arm64-windows" + # VCPKG_BINARY_SOURCES: "default" # https://learn.microsoft.com/en-us/vcpkg/reference/binarycaching + - name: "Run build.py(arm64-windows)" run: | python tools\ci_build\build.py ` - --build_dir "build/arm64-windows" --arm64 ` + --build_dir "cmake_build/arm64-windows" --arm64 ` --skip_submodule_sync ` - --compile_no_warning_as_error ` --skip_tests ` + --compile_no_warning_as_error ` --parallel ` + --path_to_protoc_exe "${{ steps.protoc-detect.outputs.protoc_path }}" ` --use_vcpkg ` - --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" ` + --cmake_extra_defines "CMAKE_TOOLCHAIN_FILE:FILEPATH=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" ` --cmake_extra_defines "VCPKG_TARGET_TRIPLET=arm64-windows" ` + --cmake_extra_defines "VCPKG_INSTALLED_DIR:PATH=${{ github.workspace }}/.build" ` --cmake_extra_defines "VCPKG_INSTALL_OPTIONS=--x-feature=tests" shell: pwsh diff --git a/cmake/CMakePresets.json b/cmake/CMakePresets.json index c1e641d759041..b8b728f40dcc3 100644 --- a/cmake/CMakePresets.json +++ b/cmake/CMakePresets.json @@ -11,6 +11,7 @@ "hidden": true, "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", "environment": { + "VCPKG_INSTALLED_DIR": "${sourceParentDir}/.build", "VCPKG_FEATURE_FLGAS": "manifests,versions" } }, From 68920d9d67f553a610a4674c04c2b72ed928cf8e Mon Sep 17 00:00:00 2001 From: luncliff Date: Thu, 25 Jul 2024 02:32:18 +0900 Subject: [PATCH 13/22] cmake: remove unused parts * CUDA build will be tried next time... * Remove onnxruntime_vcpkg_deps.cmake --- cmake/CMakeLists.txt | 8 +- cmake/external/onnxruntime_vcpkg_deps.cmake | 154 -------------------- cmake/onnxruntime_providers_cuda.cmake | 13 +- 3 files changed, 4 insertions(+), 171 deletions(-) delete mode 100644 cmake/external/onnxruntime_vcpkg_deps.cmake diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 9ff8bf06966d4..651806b2b5f08 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -597,12 +597,8 @@ get_filename_component(ORTTRAINING_ROOT "${ORTTRAINING_ROOT}" ABSOLUTE) get_filename_component(REPO_ROOT "${REPO_ROOT}" ABSOLUTE) set(ONNXRUNTIME_INCLUDE_DIR ${REPO_ROOT}/include/onnxruntime) -if(FALSE) # onnxruntime_USE_VCPKG - include(external/onnxruntime_vcpkg_deps.cmake) -else() - list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) - include(external/onnxruntime_external_deps.cmake) -endif() +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) +include(external/onnxruntime_external_deps.cmake) set(ORT_WARNING_FLAGS) if (WIN32) diff --git a/cmake/external/onnxruntime_vcpkg_deps.cmake b/cmake/external/onnxruntime_vcpkg_deps.cmake deleted file mode 100644 index f7fcd83825f8c..0000000000000 --- a/cmake/external/onnxruntime_vcpkg_deps.cmake +++ /dev/null @@ -1,154 +0,0 @@ -message(STATUS "Using Dependencies from vcpkg...") - -# ABSL should be included before protobuf because protobuf may use absl -find_package(absl CONFIG REQUIRED) -list(APPEND ABSEIL_LIBS - absl::base - absl::city - absl::core_headers - absl::fixed_array - absl::flags - absl::flat_hash_map - absl::flat_hash_set - absl::hash - absl::inlined_vector - absl::low_level_hash - absl::node_hash_map - absl::node_hash_set - absl::optional - absl::raw_hash_set - absl::raw_logging_internal - absl::span - absl::str_format - absl::strings - absl::synchronization - absl::throw_delegate - absl::time -) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${ABSEIL_LIBS}) - -find_package(re2 CONFIG REQUIRED) # re2::re2 -list(APPEND onnxruntime_EXTERNAL_LIBRARIES re2::re2) - -if (onnxruntime_BUILD_UNIT_TESTS) - # gtest and gmock - find_package(GTest CONFIG REQUIRED) # GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main -endif() - -if (onnxruntime_BUILD_BENCHMARKS) - find_package(benchmark CONFIG REQUIRED) # benchmark::benchmark benchmark::benchmark_main -endif() - -# Flatbuffers -find_package(flatbuffers CONFIG REQUIRED) # flatbuffers::flatbuffers -list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES flatbuffers::flatbuffers) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES flatbuffers::flatbuffers) - -find_package(Protobuf CONFIG REQUIRED) # protobuf::libprotobuf protobuf::libprotobuf-lite -if (onnxruntime_USE_FULL_PROTOBUF) - set(PROTOBUF_LIB protobuf::libprotobuf) -else() - set(PROTOBUF_LIB protobuf::libprotobuf-lite) -endif() -list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${PROTOBUF_LIB}) - -if(NOT DEFINED Protobuf_PROTOC_EXECUTABLE) - find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED) -endif() -get_filename_component(ONNX_CUSTOM_PROTOC_EXECUTABLE "${Protobuf_PROTOC_EXECUTABLE}" ABSOLUTE) -include(external/protobuf_function.cmake) - -find_package(date CONFIG REQUIRED) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES date::date) - -# see Hints of FindBoost.cmake -find_path(BOOST_INCLUDEDIR "boost/mp11.hpp" REQUIRED) -find_package(Boost REQUIRED) -add_library(Boost::mp11 ALIAS Boost::headers) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES Boost::mp11) - -find_package(nlohmann_json CONFIG REQUIRED) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES nlohmann_json::nlohmann_json) - -if (onnxruntime_ENABLE_CPUINFO) - find_package(cpuinfo CONFIG REQUIRED) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo) -endif() - -if (NOT WIN32) - find_library(NSYNC_CPP_LIBRARY NAMES nsync_cpp REQUIRED) - add_library(nsync_cpp INTERFACE IMPORTED GLOBAL) - set_target_properties(nsync_cpp PROPERTIES INTERFACE_LINK_LIBRARIES "${NSYNC_CPP_LIBRARY}") - add_library(nsync::nsync_cpp ALIAS nsync_cpp) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync::nsync_cpp) -endif() - -find_package(Microsoft.GSL CONFIG REQUIRED) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES Microsoft.GSL::GSL) -set(GSL_TARGET Microsoft.GSL::GSL) # see onnxruntime_mlas - -# ONNX -find_package(ONNX CONFIG REQUIRED) -if(TARGET ONNX::onnx AND NOT TARGET onnx) - add_library(onnx ALIAS ONNX::onnx) -endif() -if(TARGET ONNX::onnx_proto AND NOT TARGET onnx_proto) - add_library(onnx_proto ALIAS ONNX::onnx_proto) -endif() -list(APPEND onnxruntime_EXTERNAL_LIBRARIES onnx onnx_proto) - -find_package(Eigen3 CONFIG REQUIRED) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES Eigen3::Eigen) -get_property(eigen_INCLUDE_DIRS TARGET Eigen3::Eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES) - -find_package(wil CONFIG REQUIRED) -list(APPEND onnxruntime_EXTERNAL_LIBRARIES WIL::WIL) - -find_path(SAFEINT_INCLUDE_DIRS "SafeInt.hpp" REQUIRED) -add_library(safeint_interface IMPORTED INTERFACE GLOBAL) -set_target_properties(safeint_interface PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${SAFEINT_INCLUDE_DIRS}" -) - -# XNNPACK EP -if (onnxruntime_USE_XNNPACK) - if (onnxruntime_DISABLE_CONTRIB_OPS) - message(FATAL_ERROR "XNNPACK EP requires the internal NHWC contrib ops to be available " - "but onnxruntime_DISABLE_CONTRIB_OPS is ON") - endif() - find_package(cpuinfo CONFIG REQUIRED) - find_library(PTHREADPOOL_LIBRARY NAMES pthreadpool REQUIRED) - find_library(XNNPACK_LIBRARY NAMES XNNPACK REQUIRED) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo ${PTHREADPOOL_LIBRARY} ${XNNPACK_LIBRARY}) -endif() - -if (onnxruntime_USE_MIMALLOC) - add_compile_definitions(USE_MIMALLOC) - find_package(mimalloc CONFIG REQUIRED) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES mimalloc) -endif() - -if(onnxruntime_ENABLE_ATEN) - message(STATUS "Aten fallback is enabled.") - find_package(dlpack CONFIG REQUIRED) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES dlpack::dlpack) -endif() - -if(onnxruntime_ENABLE_TRAINING OR (onnxruntime_ENABLE_TRAINING_APIS AND onnxruntime_BUILD_UNIT_TESTS)) - find_package(cxxopts CONFIG REQUIRED) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES cxxopts::cxxopts) -endif() - -if (onnxruntime_USE_CUDA) - find_package(CUDAToolkit REQUIRED) - include_directories(${CUDAToolkit_INCLUDE_DIRS}) - list(APPEND onnxruntime_LINK_DIRS ${CUDAToolkit_LIBRARY_DIR}) - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -diag-suppress 2803") - find_package(NvidiaCutlass CONFIG REQUIRED) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES nvidia::cutlass::cutlass) -endif() - -if (onnxruntime_USE_OPENVINO) - find_package(OpenVINO REQUIRED) - # list(APPEND onnxruntime_EXTERNAL_LIBRARIES openvino::runtime) -endif() diff --git a/cmake/onnxruntime_providers_cuda.cmake b/cmake/onnxruntime_providers_cuda.cmake index 6e509c7439698..82c31ce6b6b4d 100644 --- a/cmake/onnxruntime_providers_cuda.cmake +++ b/cmake/onnxruntime_providers_cuda.cmake @@ -217,17 +217,8 @@ target_link_libraries(${target} PRIVATE CUDA::cuda_driver) endif() - if(onnxruntime_USE_VCPKG) - find_package(NvidiaCutlass REQUIRED) - target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass) - if(MSVC) - # CUTLASS_CONSTEXPR_IF_CXX17 must be constexpr. Correct the __cplusplus value with MSVC - target_compile_options(${target} PRIVATE $<$:"-Xcompiler /Zc:__cplusplus">) - endif() - else() - include(cutlass) - target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include) - endif() + include(cutlass) + target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include) target_include_directories(${target} PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES} PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) From d97ec19a6155b25e5c302cbb912dcb85ee1cd3c2 Mon Sep 17 00:00:00 2001 From: luncliff Date: Thu, 25 Jul 2024 03:01:25 +0900 Subject: [PATCH 14/22] cmake: use vcpkg 2024.07.12 * add dropped changes --- cmake/vcpkg-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json index 36b0d9ae78fac..95fc10210cd98 100644 --- a/cmake/vcpkg-configuration.json +++ b/cmake/vcpkg-configuration.json @@ -2,7 +2,7 @@ "default-registry": { "kind": "git", "repository": "https://github.com/Microsoft/vcpkg", - "baseline": "ad40d92ce7161d93986083c55d3200b4661e70ec" + "baseline": "1de2026f28ead93ff1773e6e680387643e914ea1" }, "registries": [ { From bdee0a9eeca662e8e7d3526a2c385a3143fa31c1 Mon Sep 17 00:00:00 2001 From: luncliff Date: Sat, 27 Jul 2024 09:18:30 +0900 Subject: [PATCH 15/22] vcpkg: use abseil 20240722.rc1 * https://github.com/abseil/abseil-cpp/releases/tag/20240722.rc1 * Remove version value of FetchContent_Declare(abseil_cpp) --- cmake/external/abseil-cpp.cmake | 4 ++-- cmake/vcpkg-configuration.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/external/abseil-cpp.cmake b/cmake/external/abseil-cpp.cmake index 6c5c4b21f5c58..395f2ab43394e 100644 --- a/cmake/external/abseil-cpp.cmake +++ b/cmake/external/abseil-cpp.cmake @@ -27,7 +27,7 @@ FetchContent_Declare( URL ${DEP_URL_abseil_cpp} URL_HASH SHA1=${DEP_SHA1_abseil_cpp} PATCH_COMMAND ${ABSL_PATCH_COMMAND} - FIND_PACKAGE_ARGS 20240116 NAMES absl + FIND_PACKAGE_ARGS NAMES absl ) onnxruntime_fetchcontent_makeavailable(abseil_cpp) @@ -92,4 +92,4 @@ absl::strings_internal absl::symbolize absl::throw_delegate absl::time -absl::time_zone) \ No newline at end of file +absl::time_zone) diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json index 95fc10210cd98..bb8e2638d2725 100644 --- a/cmake/vcpkg-configuration.json +++ b/cmake/vcpkg-configuration.json @@ -9,9 +9,10 @@ "repository": "https://github.com/luncliff/vcpkg-registry", "kind": "git", "packages": [ + "abseil", "onnx" ], - "baseline": "d8758aed30032ab7b6988fd42faf0657d49a2880" + "baseline": "8f14a82699eb749ea5c03b40c644810b703357cd" } ] } From cc3bd14a85c6918ad2eaccfd98a6fecda53c1e22 Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 4 Aug 2024 13:32:43 +0900 Subject: [PATCH 16/22] cmake: correct library search in vcpkg --- .../external/onnxruntime_external_deps.cmake | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake index f1f0676bc2d1b..0857c813d46aa 100644 --- a/cmake/external/onnxruntime_external_deps.cmake +++ b/cmake/external/onnxruntime_external_deps.cmake @@ -407,8 +407,12 @@ if ((CPUINFO_SUPPORTED OR onnxruntime_USE_XNNPACK) AND NOT ANDROID) set(ONNXRUNTIME_CLOG_PROJ pytorch_clog) onnxruntime_fetchcontent_makeavailable(${ONNXRUNTIME_CLOG_PROJ}) set(ONNXRUNTIME_CLOG_TARGET_NAME clog) + # if cpuinfo is from find_package, use it with imported name if(TARGET cpuinfo::clog) set(ONNXRUNTIME_CLOG_TARGET_NAME cpuinfo::clog) + elseif(onnxruntime_USE_VCPKG) + # however, later cpuinfo versions may not contain clog. use cpuinfo + set(ONNXRUNTIME_CLOG_TARGET_NAME cpuinfo::cpuinfo) endif() endif() @@ -534,14 +538,18 @@ if(TARGET ONNX::onnx_proto AND NOT TARGET onnx_proto) add_library(onnx_proto ALIAS ONNX::onnx_proto) endif() -find_package(Eigen3 CONFIG) -if(NOT Eigen3_FOUND) - include(eigen) +if(onnxruntime_USE_VCPKG) + find_package(Eigen3 CONFIG REQUIRED) + get_target_property(eigen_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) +else() + include(eigen) # FetchContent endif() -find_package(wil CONFIG) -if(NOT wil_FOUND) - include(wil) +if(onnxruntime_USE_VCPKG) + find_package(wil CONFIG REQUIRED) + set(WIL_TARGET "WIL::WIL") +else() + include(wil) # FetchContent endif() # XNNPACK EP From 779ff2b28a11432941cf5c1842b169dc9b97556e Mon Sep 17 00:00:00 2001 From: luncliff Date: Sun, 4 Aug 2024 16:44:49 +0900 Subject: [PATCH 17/22] cmake: alias Boost::headers to Boost::mp11 --- cmake/external/onnxruntime_external_deps.cmake | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake index 0857c813d46aa..d6a1f16ee36fb 100644 --- a/cmake/external/onnxruntime_external_deps.cmake +++ b/cmake/external/onnxruntime_external_deps.cmake @@ -301,9 +301,16 @@ FetchContent_Declare( mp11 URL ${DEP_URL_mp11} URL_HASH SHA1=${DEP_SHA1_mp11} - FIND_PACKAGE_ARGS NAMES boost_mp11 + FIND_PACKAGE_ARGS NAMES Boost ) onnxruntime_fetchcontent_makeavailable(mp11) +if(NOT TARGET Boost::mp11) + if(onnxruntime_USE_VCPKG) + find_package(Boost REQUIRED) + endif() + message(STATUS "Aliasing Boost::headers to Boost::mp11") + add_library(Boost::mp11 ALIAS Boost::headers) +endif() set(JSON_BuildTests OFF CACHE INTERNAL "") set(JSON_Install OFF CACHE INTERNAL "") From 2889abfe55edbce2701a8b7330df7eb40628a120 Mon Sep 17 00:00:00 2001 From: luncliff Date: Tue, 6 Aug 2024 01:04:14 +0900 Subject: [PATCH 18/22] vcpkg: use eigen3 from vcpkg-registry --- cmake/vcpkg-configuration.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json index bb8e2638d2725..2f854a7269930 100644 --- a/cmake/vcpkg-configuration.json +++ b/cmake/vcpkg-configuration.json @@ -10,6 +10,7 @@ "kind": "git", "packages": [ "abseil", + "eigen3", "onnx" ], "baseline": "8f14a82699eb749ea5c03b40c644810b703357cd" From 52154c498f376c12aafc08cc390678fa89448f30 Mon Sep 17 00:00:00 2001 From: luncliff Date: Fri, 9 Aug 2024 21:54:35 +0900 Subject: [PATCH 19/22] vcpkg: override eigen3 version --- cmake/vcpkg.json | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmake/vcpkg.json b/cmake/vcpkg.json index 7263496df9251..8ab781bbb5a2e 100644 --- a/cmake/vcpkg.json +++ b/cmake/vcpkg.json @@ -1,4 +1,5 @@ { + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "onnxruntime", "version-date": "2024-07-21", "description": "ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator", @@ -78,5 +79,11 @@ "gtest" ] } - } + }, + "overrides": [ + { + "name": "eigen3", + "version": "2024-01-16" + } + ] } From 4faeeee1706c864ea67cc7b853ce90c4e4c465da Mon Sep 17 00:00:00 2001 From: luncliff Date: Tue, 6 Aug 2024 01:03:54 +0900 Subject: [PATCH 20/22] cmake: fix preset cacheVariables --- cmake/CMakePresets.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmake/CMakePresets.json b/cmake/CMakePresets.json index b8b728f40dcc3..1b7aa11975a3e 100644 --- a/cmake/CMakePresets.json +++ b/cmake/CMakePresets.json @@ -10,8 +10,10 @@ "name": "vcpkg-manifest", "hidden": true, "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake", + "cacheVariables": { + "VCPKG_INSTALLED_DIR": "${sourceParentDir}/.build" + }, "environment": { - "VCPKG_INSTALLED_DIR": "${sourceParentDir}/.build", "VCPKG_FEATURE_FLGAS": "manifests,versions" } }, From dba186270d105eccd58ed901ad372195f97523ae Mon Sep 17 00:00:00 2001 From: luncliff Date: Tue, 10 Sep 2024 21:37:00 +0900 Subject: [PATCH 21/22] vcpkg: use 2024.08.23 * https://github.com/microsoft/vcpkg/releases/tag/2024.08.23 * remove abseil, eigen3 in configuration --- cmake/vcpkg-configuration.json | 4 +--- cmake/vcpkg.json | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json index 2f854a7269930..ad0aa38021194 100644 --- a/cmake/vcpkg-configuration.json +++ b/cmake/vcpkg-configuration.json @@ -2,15 +2,13 @@ "default-registry": { "kind": "git", "repository": "https://github.com/Microsoft/vcpkg", - "baseline": "1de2026f28ead93ff1773e6e680387643e914ea1" + "baseline": "3508985146f1b1d248c67ead13f8f54be5b4f5da" }, "registries": [ { "repository": "https://github.com/luncliff/vcpkg-registry", "kind": "git", "packages": [ - "abseil", - "eigen3", "onnx" ], "baseline": "8f14a82699eb749ea5c03b40c644810b703357cd" diff --git a/cmake/vcpkg.json b/cmake/vcpkg.json index 8ab781bbb5a2e..8c9c3c26a24d8 100644 --- a/cmake/vcpkg.json +++ b/cmake/vcpkg.json @@ -1,7 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "onnxruntime", - "version-date": "2024-07-21", + "version-date": "2024-09-10", "description": "ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator", "homepage": "https://onnxruntime.ai/", "license": "MIT", From a67dd2dcfe3c0393d0be1bae2cb9e1d5d0845232 Mon Sep 17 00:00:00 2001 From: luncliff Date: Tue, 10 Sep 2024 21:41:50 +0900 Subject: [PATCH 22/22] vcpkg: remove eigen3, onnx in manifest * cmake: use eigen from FetchContent * ONNX will be used with FetchContent Current vcpkg upstream doesn't support onnx 1.16.0+. Here, we will mix FetchContent and vcpkg-supported find_package --- cmake/external/onnxruntime_external_deps.cmake | 4 ++-- cmake/vcpkg-configuration.json | 11 +---------- cmake/vcpkg.json | 13 +------------ 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake index 0af107212d602..43f18abbe9522 100644 --- a/cmake/external/onnxruntime_external_deps.cmake +++ b/cmake/external/onnxruntime_external_deps.cmake @@ -542,8 +542,8 @@ if(TARGET ONNX::onnx_proto AND NOT TARGET onnx_proto) add_library(onnx_proto ALIAS ONNX::onnx_proto) endif() -if(onnxruntime_USE_VCPKG) - find_package(Eigen3 CONFIG REQUIRED) +find_package(Eigen3 CONFIG) +if(Eigen3_FOUND) get_target_property(eigen_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) else() include(eigen) # FetchContent diff --git a/cmake/vcpkg-configuration.json b/cmake/vcpkg-configuration.json index ad0aa38021194..f3525977c7bb9 100644 --- a/cmake/vcpkg-configuration.json +++ b/cmake/vcpkg-configuration.json @@ -4,14 +4,5 @@ "repository": "https://github.com/Microsoft/vcpkg", "baseline": "3508985146f1b1d248c67ead13f8f54be5b4f5da" }, - "registries": [ - { - "repository": "https://github.com/luncliff/vcpkg-registry", - "kind": "git", - "packages": [ - "onnx" - ], - "baseline": "8f14a82699eb749ea5c03b40c644810b703357cd" - } - ] + "registries": [] } diff --git a/cmake/vcpkg.json b/cmake/vcpkg.json index 8c9c3c26a24d8..159b8654c1cb1 100644 --- a/cmake/vcpkg.json +++ b/cmake/vcpkg.json @@ -19,7 +19,6 @@ "cxxopts", "date", "dlpack", - "eigen3", { "name": "flatbuffers", "host": true, @@ -40,10 +39,6 @@ "platform": "!windows", "version>=": "1.26.0" }, - { - "name": "onnx", - "version>=": "1.16.0" - }, "optional-lite", { "name": "protobuf", @@ -79,11 +74,5 @@ "gtest" ] } - }, - "overrides": [ - { - "name": "eigen3", - "version": "2024-01-16" - } - ] + } }