diff --git a/ports/libtorch/fix-build.patch b/ports/libtorch/fix-build.patch index c29ccb8e9f3994..c68f2feac3c289 100644 --- a/ports/libtorch/fix-build.patch +++ b/ports/libtorch/fix-build.patch @@ -50,13 +50,15 @@ index b46a444..255d7f4 100644 - endif() - set_property(TARGET onnx_proto PROPERTY IMPORTED_LOCATION ${ONNX_PROTO_LIBRARY}) - message("-- Found onnx: ${ONNX_LIBRARY} ${ONNX_PROTO_LIBRARY}") +- list(APPEND Caffe2_DEPENDENCY_LIBS onnx_proto onnx) + find_package(ONNX REQUIRED) -+ set(ONNX_LIBRARY onnx) -+ set(ONNX_PROTO_LIBRARY onnx_proto) ++ set(ONNX_LIBRARY ONNX::onnx) ++ set(ONNX_PROTO_LIBRARY ONNX::onnx_proto) + message("-- Found onnx") - list(APPEND Caffe2_DEPENDENCY_LIBS onnx_proto onnx) ++ list(APPEND Caffe2_DEPENDENCY_LIBS ONNX::onnx_proto ONNX::onnx) endif() include_directories(${FOXI_INCLUDE_DIRS}) + list(APPEND Caffe2_DEPENDENCY_LIBS "${FOXI_LOADER_LIBPATH}") diff --git a/pyproject.toml b/pyproject.toml index eb764cb..c70f317 100644 --- a/pyproject.toml diff --git a/ports/libtorch/vcpkg.json b/ports/libtorch/vcpkg.json index 7f6920cff59eb7..c8c639f2ad4831 100644 --- a/ports/libtorch/vcpkg.json +++ b/ports/libtorch/vcpkg.json @@ -1,7 +1,7 @@ { "name": "libtorch", "version": "2.1.2", - "port-version": 6, + "port-version": 7, "description": "Tensors and Dynamic neural networks in Python with strong GPU acceleration", "homepage": "https://pytorch.org/", "license": null, diff --git a/ports/onnx-optimizer/portfile.cmake b/ports/onnx-optimizer/portfile.cmake index 8f8fc1f8505c98..d9f097fca3f120 100644 --- a/ports/onnx-optimizer/portfile.cmake +++ b/ports/onnx-optimizer/portfile.cmake @@ -30,6 +30,7 @@ vcpkg_cmake_configure( OPTIONS ${FEATURE_OPTIONS} -DONNX_USE_MSVC_STATIC_RUNTIME=${USE_STATIC_RUNTIME} + -DONNX_TARGET_NAME=ONNX::onnx # after 1.16.0 ) if("pybind11" IN_LIST FEATURES) # This target is not in install/export diff --git a/ports/onnx-optimizer/vcpkg.json b/ports/onnx-optimizer/vcpkg.json index 3dfc675137b75e..9d7769ca0bc5b2 100644 --- a/ports/onnx-optimizer/vcpkg.json +++ b/ports/onnx-optimizer/vcpkg.json @@ -1,6 +1,7 @@ { "name": "onnx-optimizer", "version-semver": "0.3.18", + "port-version": 1, "description": "Actively maintained ONNX Optimizer", "homepage": "https://github.com/onnx/optimizer", "license": "Apache-2.0", diff --git a/ports/onnx/fix-cmakelists.patch b/ports/onnx/fix-cmakelists.patch index f8d300103ab205..1927755c6e1668 100644 --- a/ports/onnx/fix-cmakelists.patch +++ b/ports/onnx/fix-cmakelists.patch @@ -1,10 +1,18 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 4dd56b6..2ff3e29 100644 +index 6d7ca84..b72646f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -65,6 +65,27 @@ endif() +@@ -129,6 +129,7 @@ if(ONNX_BUILD_TESTS) + endif() + endif() - include(GNUInstallDirs) ++find_package(protobuf CONFIG REQUIRED) + if((ONNX_USE_LITE_PROTO AND TARGET protobuf::libprotobuf-lite) OR ((NOT ONNX_USE_LITE_PROTO) AND TARGET protobuf::libprotobuf)) + # Sometimes we need to use protoc compiled for host architecture while linking + # libprotobuf against target architecture. See https://github.com/caffe2/caffe +@@ -711,6 +712,27 @@ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/onnx + FILES_MATCHING + PATTERN "*.h") +# install protobuf files +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/onnx/onnx-data.proto @@ -27,41 +35,22 @@ index 4dd56b6..2ff3e29 100644 + ) +endif() + - set(ONNX_ROOT ${PROJECT_SOURCE_DIR}) - - # Read ONNX version -@@ -116,7 +137,8 @@ endif() - # find_package Python has replaced PythonInterp and PythonLibs since cmake 3.12 - # Use the following command in the future; now this is only compatible with the latest pybind11 - # find_package(Python ${PY_VERSION} COMPONENTS Interpreter Development REQUIRED) --find_package(PythonInterp ${PY_VERSION} REQUIRED) -+find_package(Python3 ${PY_VERSION} COMPONENTS Interpreter REQUIRED) -+set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE}) - if(BUILD_ONNX_PYTHON) - find_package(PythonLibs ${PY_VERSION}) - endif() -@@ -434,6 +456,7 @@ target_link_libraries(onnx PUBLIC onnx_proto) - add_onnx_global_defines(onnx) + configure_file( + ${PROJECT_SOURCE_DIR}/cmake/ONNXConfigVersion.cmake.in + ${PROJECT_BINARY_DIR}/ONNXConfigVersion.cmake +diff --git a/cmake/ONNXConfig.cmake.in b/cmake/ONNXConfig.cmake.in +index d588f8a..dbd4398 100644 +--- a/cmake/ONNXConfig.cmake.in ++++ b/cmake/ONNXConfig.cmake.in +@@ -6,9 +6,8 @@ + # library version information + set(ONNX_VERSION "@ONNX_VERSION@") - if(BUILD_ONNX_PYTHON) -+ find_package(Python3 ${PY_VERSION} COMPONENTS Development REQUIRED) - if("${PY_EXT_SUFFIX}" STREQUAL "") - if(MSVC) - set(PY_EXT_SUFFIX ".pyd") -@@ -452,10 +475,14 @@ if(BUILD_ONNX_PYTHON) - target_include_directories(onnx_cpp2py_export PRIVATE - $ - $ -- $) -+ ${Python3_INCLUDE_DIRS}) -+ target_link_directories(onnx_cpp2py_export PRIVATE -+ ${Python3_LIBRARY_DIRS}) -+ target_link_libraries(onnx_cpp2py_export PRIVATE -+ ${Python3_LIBRARIES}) +-list(APPEND CMAKE_PREFIX_PATH "@PROTOBUF_DIR@") +-set(Protobuf_INCLUDE_DIR "@PROTOBUF_INCLUDE_DIR@") +-find_package(Protobuf REQUIRED) ++include(CMakeFindDependencyMacro) ++find_dependency(protobuf CONFIG) - # pybind11 is a header only lib -- find_package(pybind11 2.2 CONFIG) -+ find_package(pybind11 2.2 CONFIG REQUIRED) - if(NOT pybind11_FOUND) - if(EXISTS "${ONNX_ROOT}/third_party/pybind11/include/pybind11/pybind11.h") - add_subdirectory("${ONNX_ROOT}/third_party/pybind11") + # import targets + include ("${CMAKE_CURRENT_LIST_DIR}/ONNXTargets.cmake") diff --git a/ports/onnx/fix-dependency-protobuf.patch b/ports/onnx/fix-dependency-protobuf.patch deleted file mode 100644 index 6ccdac66502656..00000000000000 --- a/ports/onnx/fix-dependency-protobuf.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff --git a/CMakeLists.txt b/CMakeLists.txt -index 1295eab..0fb9f17 100644 ---- a/CMakeLists.txt -+++ b/CMakeLists.txt -@@ -126,6 +126,7 @@ if(ONNX_BUILD_TESTS) - include(googletest) - endif() - -+find_package(protobuf CONFIG REQUIRED) - if((ONNX_USE_LITE_PROTO AND TARGET protobuf::libprotobuf-lite) OR ((NOT ONNX_USE_LITE_PROTO) AND TARGET protobuf::libprotobuf)) - # Sometimes we need to use protoc compiled for host architecture while linking - # libprotobuf against target architecture. See https://github.com/caffe2/caffe diff --git a/ports/onnx/portfile.cmake b/ports/onnx/portfile.cmake index 9d86f8e50793b6..8a9a4a1b727f4e 100644 --- a/ports/onnx/portfile.cmake +++ b/ports/onnx/portfile.cmake @@ -4,10 +4,9 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO onnx/onnx REF "v${VERSION}" - SHA512 b46a4ab70af88053318eba45251c1f71528f15e45a33042877570e8d857febd3ec66e2e811fcda2105a4f17b84c9a1c6a0aaa22756c3287321b3ea29e83127fd + SHA512 ef641447d8d6c4ed9f083793fe14a8568d6aa7b9b7e7b859a4082e9b892acd801230da2027d097ceaa0d68bbd37b2422b89bb7d1d55d5c3b5955c0f9c7c657c5 PATCHES fix-cmakelists.patch - fix-dependency-protobuf.patch ) string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_STATIC_RUNTIME) @@ -64,10 +63,6 @@ vcpkg_cmake_install() vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ONNX) vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") -vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/share/${PORT}/ONNXConfig.cmake" "# import targets" -[[# import targets -include(CMakeFindDependencyMacro) -find_dependency(protobuf CONFIG)]]) file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" diff --git a/ports/onnx/vcpkg.json b/ports/onnx/vcpkg.json index 4bff31b70a4210..c70d2fbb94baac 100644 --- a/ports/onnx/vcpkg.json +++ b/ports/onnx/vcpkg.json @@ -1,7 +1,6 @@ { "name": "onnx", - "version-semver": "1.15.0", - "port-version": 1, + "version-semver": "1.16.0", "description": "Open standard for machine learning interoperability", "homepage": "https://onnx.ai", "license": "Apache-2.0", diff --git a/ports/onnxruntime-gpu/portfile.cmake b/ports/onnxruntime-gpu/portfile.cmake index 666d0f9ca91d9f..ff8a746bb26e52 100644 --- a/ports/onnxruntime-gpu/portfile.cmake +++ b/ports/onnxruntime-gpu/portfile.cmake @@ -1,102 +1,2 @@ -vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY) - -vcpkg_download_distfile(ARCHIVE - URLS "https://github.com/microsoft/onnxruntime/releases/download/v${VERSION}/onnxruntime-win-x64-gpu-${VERSION}.zip" - FILENAME "onnxruntime-win-x64-gpu-${VERSION}.zip" - SHA512 9576eafca59fc7f2af9f62d7ee8aa31208ef965d17f3ad71747d5a9a46cdffd6b3958dc945109d82937555df8bb35319ce92925e66ab707f1ca8e7564ecb3ced -) - -vcpkg_extract_source_archive( - SOURCE_PATH - ARCHIVE "${ARCHIVE}" - NO_REMOVE_ONE_LEVEL -) - -# Download repo for experimental features -vcpkg_from_github( - OUT_SOURCE_PATH REPO_PATH - REPO microsoft/onnxruntime - REF v${VERSION} - SHA512 3bf25e431d175c61953d28b1bf8f6871376684263992451a5b2a66e670768fc66e7027f141c6e3f4d1eddeebeda51f31ea0adf4749e50d99ee89d0a26bec77ce -) - -file(COPY - ${REPO_PATH}/include/onnxruntime/core/session/experimental_onnxruntime_cxx_api.h - ${REPO_PATH}/include/onnxruntime/core/session/experimental_onnxruntime_cxx_inline.h - DESTINATION ${CURRENT_PACKAGES_DIR}/include - ) - -file(MAKE_DIRECTORY - ${CURRENT_PACKAGES_DIR}/include - ${CURRENT_PACKAGES_DIR}/lib - ${CURRENT_PACKAGES_DIR}/bin - ${CURRENT_PACKAGES_DIR}/debug/lib - ${CURRENT_PACKAGES_DIR}/debug/bin - ) - -file(COPY - ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/include - DESTINATION ${CURRENT_PACKAGES_DIR} - ) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/lib) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_cuda.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/lib) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_cuda.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_cuda.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_cuda.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_shared.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_shared.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_tensorrt.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_tensorrt.pdb - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_shared.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/lib) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_shared.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_tensorrt.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/lib) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_tensorrt.lib - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_shared.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_shared.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_tensorrt.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_tensorrt.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) - -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_cuda.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/bin) -file(COPY ${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/lib/onnxruntime_providers_cuda.dll - DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) -# # Handle copyright -vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/onnxruntime-win-x64-gpu-${VERSION}/LICENSE") +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) +message(WARNING "${PORT} is deprecated. Please use port onnxruntime instead.") diff --git a/ports/onnxruntime-gpu/vcpkg.json b/ports/onnxruntime-gpu/vcpkg.json index ac545ae04b7147..5ccbcc71930f2b 100644 --- a/ports/onnxruntime-gpu/vcpkg.json +++ b/ports/onnxruntime-gpu/vcpkg.json @@ -1,8 +1,17 @@ { "name": "onnxruntime-gpu", "version": "1.19.2", + "port-version": 1, "description": "onnxruntime (GPU)", "homepage": "https://github.com/microsoft/onnxruntime", "license": "MIT", - "supports": "windows & !x86 & !uwp & !static & !arm" + "supports": "windows & !x86 & !uwp & !static & !arm", + "dependencies": [ + { + "name": "onnxruntime", + "features": [ + "cuda" + ] + } + ] } diff --git a/ports/onnxruntime/fix-clang-cl-simd-compile.patch b/ports/onnxruntime/fix-clang-cl-simd-compile.patch new file mode 100644 index 00000000000000..2605062f65a295 --- /dev/null +++ b/ports/onnxruntime/fix-clang-cl-simd-compile.patch @@ -0,0 +1,70 @@ +diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake +index 682dcfc..405c65b 100644 +--- a/cmake/onnxruntime_mlas.cmake ++++ b/cmake/onnxruntime_mlas.cmake +@@ -158,15 +158,31 @@ function(setup_mlas_source_for_windows) + ) + set_source_files_properties(${mlas_platform_srcs_avx2} PROPERTIES COMPILE_FLAGS "/arch:AVX2") + ++ file(GLOB_RECURSE mlas_platform_srcs_avx512 CONFIGURE_DEPENDS ++ "${MLAS_SRC_DIR}/intrinsics/avx512/*.cpp" ++ ) ++ set(mlas_platform_srcs_amx "${MLAS_SRC_DIR}/qgemm_kernel_amx.cpp") ++ ++ # clang-cl requires us to enable the platform feature flags explicitly to compile the intrinsics code ++ # unlike MSVC. See: https://github.com/llvm/llvm-project/issues/53520 ++ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") ++ set_source_files_properties(${mlas_platform_srcs_avx512} PROPERTIES COMPILE_FLAGS "/arch:AVX512") ++ set_source_files_properties(${mlas_platform_srcs_amx} PROPERTIES COMPILE_FLAGS "/arch:AVX512 -mamx-tile -mamx-int8") ++ # https://clang.llvm.org/docs/UsersManual.html#cpu-architectures-features-and-limitations ++ set_source_files_properties(${MLAS_SRC_DIR}/qgemm_kernel_sse.cpp PROPERTIES COMPILE_FLAGS "-march=x86-64") ++ set_source_files_properties(${MLAS_SRC_DIR}/qgemm_kernel_sse41.cpp PROPERTIES COMPILE_FLAGS "-march=x86-64-v2") ++ endif() ++ + target_sources(onnxruntime_mlas PRIVATE + ${MLAS_SRC_DIR}/dgemm.cpp + ${mlas_platform_srcs_avx} + ${mlas_platform_srcs_avx2} +- ${MLAS_SRC_DIR}/qgemm_kernel_amx.cpp ++ ${mlas_platform_srcs_avx512} ++ ${mlas_platform_srcs_amx} ++ # ... + ${MLAS_SRC_DIR}/qgemm_kernel_avx2.cpp + ${MLAS_SRC_DIR}/qgemm_kernel_sse.cpp + ${MLAS_SRC_DIR}/qgemm_kernel_sse41.cpp +- ${MLAS_SRC_DIR}/intrinsics/avx512/quantize_avx512f.cpp + ${MLAS_SRC_DIR}/sqnbitgemm_kernel_avx2.cpp + ${MLAS_SRC_DIR}/sqnbitgemm_kernel_avx512.cpp + ${MLAS_SRC_DIR}/sqnbitgemm_kernel_avx512vnni.cpp +@@ -208,9 +224,15 @@ function(setup_mlas_source_for_windows) + ${MLAS_SRC_DIR}/amd64/ErfKernelFma3.asm + ) + if (NOT onnxruntime_ORT_MINIMAL_BUILD) +- target_sources(onnxruntime_mlas PRIVATE ++ set(onnxruntime_mlas_q4gemm_avx512 + ${MLAS_SRC_DIR}/q4gemm_avx512.cpp + ) ++ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") ++ # clang-cl requires us to enable the platform feature flags explicitly to compile the intrinsics code ++ # unlike MSVC. See: https://github.com/llvm/llvm-project/issues/53520 ++ set_source_files_properties(${onnxruntime_mlas_q4gemm_avx512} PROPERTIES COMPILE_FLAGS "/arch:AVX512 -mavx512vnni") ++ endif() ++ target_sources(onnxruntime_mlas PRIVATE ${onnxruntime_mlas_q4gemm_avx512}) + endif() + else() + target_sources(onnxruntime_mlas PRIVATE +diff --git a/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp b/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp +index 68931c5..6c095bd 100644 +--- a/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp ++++ b/onnxruntime/core/mlas/lib/qgemm_kernel_sse41.cpp +@@ -16,6 +16,10 @@ Abstract: + + #include "mlasi.h" + #include "qgemm.h" ++#if defined(__clang__) ++#include ++#include ++#endif + + // N.B. MSVC does not require turning on SSE 4.1 intrinsics and the current use + // for this code is Windows only, so restrict this kernel to that environment. diff --git a/ports/onnxruntime/fix-cmake-cuda.patch b/ports/onnxruntime/fix-cmake-cuda.patch new file mode 100644 index 00000000000000..a66001511c37b6 --- /dev/null +++ b/ports/onnxruntime/fix-cmake-cuda.patch @@ -0,0 +1,40 @@ +diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt +index 02455b2..2223a65 100644 +--- a/cmake/CMakeLists.txt ++++ b/cmake/CMakeLists.txt +@@ -717,6 +717,9 @@ 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) ++ get_filename_component(CMAKE_CUDA_COMPILER "${CUDAToolkit_NVCC_EXECUTABLE}" ABSOLUTE) + enable_language(CUDA) + message( STATUS "CMAKE_CUDA_COMPILER_VERSION: ${CMAKE_CUDA_COMPILER_VERSION}") + +diff --git a/cmake/onnxruntime_providers_cuda.cmake b/cmake/onnxruntime_providers_cuda.cmake +index 1346a9c..9c5b5db 100644 +--- a/cmake/onnxruntime_providers_cuda.cmake ++++ b/cmake/onnxruntime_providers_cuda.cmake +@@ -172,6 +172,10 @@ + # be used due to `&& not_a_const`. This affects too many places for it to be reasonable to disable at a finer + # granularity. + target_compile_options(${target} PRIVATE "$<$:/wd4127>") ++ # CUTLASS_CONSTEXPR_IF_CXX17 must be constexpr. Correct the __cplusplus value with MSVC ++ target_compile_options(${target} PRIVATE "$<$:SHELL:-Xcompiler /Zc:__cplusplus>") ++ # Suppress Microsoft.GSL attribute warnings to simplify build log ++ target_compile_options(${target} PRIVATE "$<$:SHELL:-diag-suppress 2803>") + endif() + endif() + +@@ -211,8 +215,8 @@ + 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) # vcpkg port 'nvidia-cutlass' ++ target_link_libraries(${target} PRIVATE nvidia::cutlass::cutlass) + + target_include_directories(${target} PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} ${eigen_INCLUDE_DIRS} ${TVM_INCLUDES} + PUBLIC ${CUDAToolkit_INCLUDE_DIRS}) diff --git a/ports/onnxruntime/fix-cmake-tensorrt.patch b/ports/onnxruntime/fix-cmake-tensorrt.patch new file mode 100644 index 00000000000000..f6b039a76051f2 --- /dev/null +++ b/ports/onnxruntime/fix-cmake-tensorrt.patch @@ -0,0 +1,31 @@ +diff --git a/cmake/onnxruntime_providers_tensorrt.cmake b/cmake/onnxruntime_providers_tensorrt.cmake +index 1e8f388..bd2e664 100644 +--- a/cmake/onnxruntime_providers_tensorrt.cmake ++++ b/cmake/onnxruntime_providers_tensorrt.cmake +@@ -8,8 +8,13 @@ + set(BUILD_LIBRARY_ONLY 1) + add_definitions("-DONNX_ML=1") + add_definitions("-DONNX_NAMESPACE=onnx") +- set(CUDA_INCLUDE_DIRS ${CUDAToolkit_INCLUDE_DIRS}) +- set(TENSORRT_ROOT ${onnxruntime_TENSORRT_HOME}) ++ if(DEFINED onnxruntime_TENSORRT_HOME) ++ set(TENSORRT_ROOT ${onnxruntime_TENSORRT_HOME}) ++ else() ++ find_package(CUDAToolkit REQUIRED) ++ get_filename_component(TENSORRT_ROOT "${CUDAToolkit_LIBRARY_ROOT}" ABSOLUTE) ++ message(STATUS "Guessing TensorRT with CUDAToolkit_LIBRARY_ROOT: ${TENSORRT_ROOT}") ++ endif() + set(OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) + set(PROTOBUF_LIBRARY ${PROTOBUF_LIB}) + if (WIN32) +@@ -30,8 +35,8 @@ + # There is an issue when running "Debug build" TRT EP with "Release build" TRT builtin parser on Windows. + # We enforce following workaround for now until the real fix. + if (WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug") +- set(onnxruntime_USE_TENSORRT_BUILTIN_PARSER OFF) +- MESSAGE(STATUS "[Note] There is an issue when running \"Debug build\" TRT EP with \"Release build\" TRT built-in parser on Windows. This build will use tensorrt oss parser instead.") ++ # set(onnxruntime_USE_TENSORRT_BUILTIN_PARSER OFF) ++ # MESSAGE(STATUS "[Note] There is an issue when running \"Debug build\" TRT EP with \"Release build\" TRT built-in parser on Windows. This build will use tensorrt oss parser instead.") + endif() + + find_path(TENSORRT_INCLUDE_DIR NvInfer.h diff --git a/ports/onnxruntime/fix-cmake.patch b/ports/onnxruntime/fix-cmake.patch new file mode 100644 index 00000000000000..299eacea4750dc --- /dev/null +++ b/ports/onnxruntime/fix-cmake.patch @@ -0,0 +1,224 @@ +diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt +index ed1c19d..53d1a72 100644 +--- a/cmake/CMakeLists.txt ++++ b/cmake/CMakeLists.txt +@@ -1017,7 +1017,7 @@ function(onnxruntime_set_compile_flags target_name) + endforeach() + endif() + endforeach() +- target_compile_definitions(${target_name} PRIVATE -DPLATFORM_WINDOWS -DNOGDI -DNOMINMAX -D_USE_MATH_DEFINES -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS) ++ target_compile_definitions(${target_name} PRIVATE PLATFORM_WINDOWS NOGDI NOMINMAX _USE_MATH_DEFINES _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS) + if (onnxruntime_ENABLE_MEMLEAK_CHECKER) + target_compile_definitions(${target_name} PRIVATE -DONNXRUNTIME_ENABLE_MEMLEAK_CHECK) + endif() +@@ -1429,13 +1429,13 @@ endif() + set(ORT_BUILD_INFO "ORT Build Info: ") + find_package(Git) + if (Git_FOUND) +- execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%h +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +- OUTPUT_VARIABLE ORT_GIT_COMMIT) ++ # execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%h ++ # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ++ # OUTPUT_VARIABLE ORT_GIT_COMMIT) + string(STRIP "${ORT_GIT_COMMIT}" ORT_GIT_COMMIT) +- execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD +- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +- OUTPUT_VARIABLE ORT_GIT_BRANCH) ++ # execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD ++ # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ++ # OUTPUT_VARIABLE ORT_GIT_BRANCH) + string(STRIP "${ORT_GIT_BRANCH}" ORT_GIT_BRANCH) + string(APPEND ORT_BUILD_INFO "git-branch=${ORT_GIT_BRANCH}, git-commit-id=${ORT_GIT_COMMIT}, ") + endif() +@@ -1835,20 +1835,16 @@ if (onnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS) + ) + endif() + +-if(TARGET onnxruntime) ++if(TRUE) + # Install + include(GNUInstallDirs) + include(CMakePackageConfigHelpers) +- set(PROJECT_CONFIG_CONTENT "@PACKAGE_INIT@\n") +- string(APPEND PROJECT_CONFIG_CONTENT +- "include(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}Targets.cmake\")") +- file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/PROJECT_CONFIG_FILE" ${PROJECT_CONFIG_CONTENT}) + install(EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + # Create config for find_package() + configure_package_config_file( +- "${CMAKE_CURRENT_BINARY_DIR}/PROJECT_CONFIG_FILE" ${PROJECT_NAME}Config.cmake ++ "${PROJECT_SOURCE_DIR}/project-config-template.cmake" ${PROJECT_NAME}Config.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + + write_basic_package_version_file( +diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake +index 896379d..aa9dfcf 100644 +--- a/cmake/onnxruntime_common.cmake ++++ b/cmake/onnxruntime_common.cmake +@@ -135,7 +135,7 @@ target_include_directories(onnxruntime_common + ${OPTIONAL_LITE_INCLUDE_DIR}) + + +-target_link_libraries(onnxruntime_common PUBLIC safeint_interface ${GSL_TARGET} ${ABSEIL_LIBS} date::date) ++target_link_libraries(onnxruntime_common PUBLIC ${GSL_TARGET} ${ABSEIL_LIBS} date::date) + + add_dependencies(onnxruntime_common ${onnxruntime_EXTERNAL_DEPENDENCIES}) + +@@ -218,7 +218,7 @@ endif() + + if (NOT onnxruntime_BUILD_SHARED_LIB) + install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/common DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) +- install(TARGETS onnxruntime_common ++ install(TARGETS onnxruntime_common EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +diff --git a/cmake/onnxruntime_flatbuffers.cmake b/cmake/onnxruntime_flatbuffers.cmake +index 3ab4c19..066fb56 100644 +--- a/cmake/onnxruntime_flatbuffers.cmake ++++ b/cmake/onnxruntime_flatbuffers.cmake +@@ -22,10 +22,9 @@ if (FLATBUFFERS_BUILD_FLATC) + add_dependencies(onnxruntime_flatbuffers flatc) + endif() + if (NOT onnxruntime_BUILD_SHARED_LIB) +- install(TARGETS onnxruntime_flatbuffers ++ install(TARGETS onnxruntime_flatbuffers EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() +- +diff --git a/cmake/onnxruntime_framework.cmake b/cmake/onnxruntime_framework.cmake +index b85edbf..7956519 100644 +--- a/cmake/onnxruntime_framework.cmake ++++ b/cmake/onnxruntime_framework.cmake +@@ -69,9 +69,9 @@ endif() + if(onnxruntime_USE_TENSORRT OR onnxruntime_USE_NCCL) + # TODO: for now, core framework depends on CUDA. It should be moved to TensorRT EP + # TODO: provider_bridge_ort.cc should not include nccl.h +-target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${onnxruntime_CUDNN_HOME}/include PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) ++target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${onnxruntime_CUDNN_HOME}/include ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}) + else() +-target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) ++target_include_directories(onnxruntime_framework PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) + endif() + # Needed for the provider interface, as it includes training headers when training is enabled + if (onnxruntime_ENABLE_TRAINING_OPS) +@@ -127,7 +127,7 @@ if (onnxruntime_BUILD_SHARED_LIB) + install(FILES ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework/provider_options.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/) + else() + install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/framework DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) +- install(TARGETS onnxruntime_framework ++ install(TARGETS onnxruntime_framework EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +diff --git a/cmake/onnxruntime_graph.cmake b/cmake/onnxruntime_graph.cmake +index 4d51325..fba1a68 100644 +--- a/cmake/onnxruntime_graph.cmake ++++ b/cmake/onnxruntime_graph.cmake +@@ -157,7 +157,7 @@ endif() + + if (NOT onnxruntime_BUILD_SHARED_LIB) + install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/graph DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) +- install(TARGETS onnxruntime_graph ++ install(TARGETS onnxruntime_graph EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake +index d888f80..851ff1e 100644 +--- a/cmake/onnxruntime_mlas.cmake ++++ b/cmake/onnxruntime_mlas.cmake +@@ -702,7 +702,7 @@ if (PLATFORM_NAME STREQUAL "macabi") + endif() + + if (NOT onnxruntime_BUILD_SHARED_LIB) +- install(TARGETS onnxruntime_mlas ++ install(TARGETS onnxruntime_mlas EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +diff --git a/cmake/onnxruntime_optimizer.cmake b/cmake/onnxruntime_optimizer.cmake +index 3bae1b8..8764a8a 100644 +--- a/cmake/onnxruntime_optimizer.cmake ++++ b/cmake/onnxruntime_optimizer.cmake +@@ -127,7 +127,7 @@ set_target_properties(onnxruntime_optimizer PROPERTIES FOLDER "ONNXRuntime") + + if (NOT onnxruntime_BUILD_SHARED_LIB) + install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/optimizer DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) +- install(TARGETS onnxruntime_optimizer ++ install(TARGETS onnxruntime_optimizer EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +diff --git a/cmake/onnxruntime_providers_cpu.cmake b/cmake/onnxruntime_providers_cpu.cmake +index bbcc709..81e7a2b 100644 +--- a/cmake/onnxruntime_providers_cpu.cmake ++++ b/cmake/onnxruntime_providers_cpu.cmake +@@ -60,7 +60,7 @@ if(NOT onnxruntime_DISABLE_CONTRIB_OPS) + "${ONNXRUNTIME_ROOT}/contrib_ops/cpu/aten_ops/aten_op_executor.cc" + ) + endif() +- set(onnxruntime_cpu_neural_speed_srcs ++ set(onnxruntime_cpu_neural_speed_srcs + "${ONNXRUNTIME_ROOT}/contrib_ops/cpu/quantization/neural_speed_wrapper.h" + "${ONNXRUNTIME_ROOT}/contrib_ops/cpu/quantization/neural_speed_defs.h" + "${ONNXRUNTIME_ROOT}/contrib_ops/cpu/quantization/neural_speed_gemm.cc" +@@ -258,7 +258,7 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD + message(FATAL_ERROR "onnxruntime_providers_shared unknown platform, need to specify shared library exports for it") + endif() + +- install(TARGETS onnxruntime_providers_shared ++ install(TARGETS onnxruntime_providers_shared EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +@@ -266,7 +266,7 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD + endif() + + if (NOT onnxruntime_BUILD_SHARED_LIB) +- install(TARGETS onnxruntime_providers ++ install(TARGETS onnxruntime_providers EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +diff --git a/cmake/onnxruntime_session.cmake b/cmake/onnxruntime_session.cmake +index 79bee3b..9f5c400 100644 +--- a/cmake/onnxruntime_session.cmake ++++ b/cmake/onnxruntime_session.cmake +@@ -63,7 +63,7 @@ endif() + + if (NOT onnxruntime_BUILD_SHARED_LIB) + install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/session DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime/core) +- install(TARGETS onnxruntime_session ++ install(TARGETS onnxruntime_session EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +diff --git a/cmake/onnxruntime_util.cmake b/cmake/onnxruntime_util.cmake +index ae7e842..7274ea8 100644 +--- a/cmake/onnxruntime_util.cmake ++++ b/cmake/onnxruntime_util.cmake +@@ -9,7 +9,7 @@ file(GLOB_RECURSE onnxruntime_util_srcs CONFIGURE_DEPENDS + source_group(TREE ${ONNXRUNTIME_ROOT}/core FILES ${onnxruntime_util_srcs}) + + onnxruntime_add_static_library(onnxruntime_util ${onnxruntime_util_srcs}) +-target_include_directories(onnxruntime_util PRIVATE ${ONNXRUNTIME_ROOT} PUBLIC ${eigen_INCLUDE_DIRS}) ++target_include_directories(onnxruntime_util PRIVATE ${ONNXRUNTIME_ROOT} ${eigen_INCLUDE_DIRS}) + onnxruntime_add_include_to_target(onnxruntime_util onnxruntime_common onnx onnx_proto ${PROTOBUF_LIB} Boost::mp11) + if(UNIX) + target_compile_options(onnxruntime_util PUBLIC "-Wno-error=comment") +@@ -22,7 +22,7 @@ if (WIN32) + endif() + + if (NOT onnxruntime_BUILD_SHARED_LIB) +- install(TARGETS onnxruntime_util ++ install(TARGETS onnxruntime_util EXPORT ${PROJECT_NAME}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/ports/onnxruntime/fix-llvm-rc-unicode.patch b/ports/onnxruntime/fix-llvm-rc-unicode.patch new file mode 100644 index 00000000000000..6c8db167388b3e --- /dev/null +++ b/ports/onnxruntime/fix-llvm-rc-unicode.patch @@ -0,0 +1,16 @@ +diff --git a/onnxruntime/core/dll/onnxruntime.rc b/onnxruntime/core/dll/onnxruntime.rc +index 4b08dfdb7e..c566a4f713 100644 +--- a/onnxruntime/core/dll/onnxruntime.rc ++++ b/onnxruntime/core/dll/onnxruntime.rc +@@ -32,9 +32,9 @@ BEGIN + VALUE "FileDescription", "ONNX Runtime" + VALUE "FileVersion", VER_STRING + VALUE "InternalName", "ONNX Runtime" +- VALUE "LegalCopyright", "\251 Microsoft Corporation. All rights reserved." ++ VALUE "LegalCopyright", L"\251 Microsoft Corporation. All rights reserved." + VALUE "OriginalFilename", FILE_NAME +- VALUE "ProductName", "Microsoft\256 Windows\256 Operating System" ++ VALUE "ProductName", L"Microsoft\256 Windows\256 Operating System" + VALUE "ProductVersion", VER_STRING + END + END diff --git a/ports/onnxruntime/fix-pr-21348.patch b/ports/onnxruntime/fix-pr-21348.patch new file mode 100644 index 00000000000000..5d9619d012400b --- /dev/null +++ b/ports/onnxruntime/fix-pr-21348.patch @@ -0,0 +1,120 @@ +diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt +index 2e9a50e52217154a9bf27355f211a8db0013befd..e9c7c307eb2aaacb36f7335f55a55cf8287446a0 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,6 +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) + ++list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) + include(external/onnxruntime_external_deps.cmake) + + set(ORT_WARNING_FLAGS) +diff --git a/cmake/external/abseil-cpp.cmake b/cmake/external/abseil-cpp.cmake +index 3223724693a495067d8d8afe761865674b5018d8..dda7c5ff19ba42d1c0249d18bb448482711761bd 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) +diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake +index 927b4ac84b03784149e37e8dff30c4a51ee51160..7e992fb33077c7d8e5224dd40d2d9937867397dc 100644 +--- a/cmake/onnxruntime.cmake ++++ b/cmake/onnxruntime.cmake +@@ -332,6 +332,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}/$) +@@ -362,6 +365,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_unittests.cmake b/cmake/onnxruntime_unittests.cmake +index d5c3af748e528b3340e04e0cf5ce0ade62e0b78b..f0eaaa811741deb9dc5c6d6a21a2fd9148bc3935 100644 +--- a/cmake/onnxruntime_unittests.cmake ++++ b/cmake/onnxruntime_unittests.cmake +@@ -877,6 +877,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. +@@ -970,6 +971,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/onnxruntime/core/framework/kernel_type_str_resolver.cc b/onnxruntime/core/framework/kernel_type_str_resolver.cc +index d05e02eb3ab32d86d79ea733045ec62bcfb8b0c9..3142f94f289b3fb7b8354d037afb1286c8f72802 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 1b5f6bcee9bd0dc582f29ff1c2d94f69ffdef815..76e7e369514d4768e2088aff70054df51fd4e498 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, "'"); + } diff --git a/ports/onnxruntime/onnxruntime_external_deps.cmake b/ports/onnxruntime/onnxruntime_external_deps.cmake new file mode 100644 index 00000000000000..28d0b364d1ba0a --- /dev/null +++ b/ports/onnxruntime/onnxruntime_external_deps.cmake @@ -0,0 +1,655 @@ +message(STATUS "Loading Dependencies URLs ...") + +include(external/helper_functions.cmake) + +file(STRINGS deps.txt ONNXRUNTIME_DEPS_LIST) +foreach(ONNXRUNTIME_DEP IN LISTS ONNXRUNTIME_DEPS_LIST) + # Lines start with "#" are comments + if(NOT ONNXRUNTIME_DEP MATCHES "^#") + # The first column is name + list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_NAME) + # The second column is URL + # The URL below may be a local file path or an HTTPS URL + list(POP_FRONT ONNXRUNTIME_DEP ONNXRUNTIME_DEP_URL) + set(DEP_URL_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP_URL}) + # The third column is SHA1 hash value + set(DEP_SHA1_${ONNXRUNTIME_DEP_NAME} ${ONNXRUNTIME_DEP}) + + if(ONNXRUNTIME_DEP_URL MATCHES "^https://") + # Search a local mirror folder + string(REGEX REPLACE "^https://" "${REPO_ROOT}/mirror/" LOCAL_URL "${ONNXRUNTIME_DEP_URL}") + + if(EXISTS "${LOCAL_URL}") + cmake_path(ABSOLUTE_PATH LOCAL_URL) + set(DEP_URL_${ONNXRUNTIME_DEP_NAME} "${LOCAL_URL}") + endif() + endif() + endif() +endforeach() + +message(STATUS "Loading Dependencies ...") +include(FetchContent) + +# ABSL should be included before protobuf because protobuf may use absl +include(external/abseil-cpp.cmake) + +set(RE2_BUILD_TESTING OFF CACHE BOOL "" FORCE) + +FetchContent_Declare( + re2 + URL ${DEP_URL_re2} + 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 + # not working properly with googletest suite. + if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + set(gtest_disable_pthreads ON) + endif() + set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) + if (IOS OR ANDROID) + # on mobile platforms the absl flags class dumps the flag names (assumably for binary size), which breaks passing + # any args to gtest executables, such as using --gtest_filter to debug a specific test. + # Processing of compile definitions: + # https://github.com/abseil/abseil-cpp/blob/8dc90ff07402cd027daec520bb77f46e51855889/absl/flags/config.h#L21 + # If set, this code throws away the flag and does nothing on registration, which results in no flags being known: + # https://github.com/abseil/abseil-cpp/blob/8dc90ff07402cd027daec520bb77f46e51855889/absl/flags/flag.h#L205-L217 + set(GTEST_HAS_ABSL OFF CACHE BOOL "" FORCE) + else() + set(GTEST_HAS_ABSL ON CACHE BOOL "" FORCE) + endif() + # gtest and gmock + FetchContent_Declare( + googletest + URL ${DEP_URL_googletest} + 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) + # We will not need to test benchmark lib itself. + set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Disable benchmark testing as we don't need it.") + # We will not need to install benchmark since we link it statically. + set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "Disable benchmark install to avoid overwriting vendor install.") + + FetchContent_Declare( + 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( + google_nsync + URL ${DEP_URL_google_nsync} + URL_HASH SHA1=${DEP_SHA1_google_nsync} + 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) + + 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() + +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( + utf8_range + URL ${DEP_URL_utf8_range} + URL_HASH SHA1=${DEP_SHA1_utf8_range} + FIND_PACKAGE_ARGS NAMES utf8_range +) + +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) + # This part of code is only for users' convenience. The code couldn't handle all cases. Users always can manually + # download protoc from Protobuf's Github release page and pass the local path to the ONNX_CUSTOM_PROTOC_EXECUTABLE + # variable. + if (CMAKE_HOST_APPLE) + # Using CMAKE_CROSSCOMPILING is not recommended for Apple target devices. + # https://cmake.org/cmake/help/v3.26/variable/CMAKE_CROSSCOMPILING.html + # To keep it simple, just download and use the universal protoc binary for all Apple host builds. + 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(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(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}) + FetchContent_Populate(protoc_binary) + elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86") + FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_win32} URL_HASH SHA1=${DEP_SHA1_protoc_win32}) + FetchContent_Populate(protoc_binary) + endif() + + if(protoc_binary_SOURCE_DIR) + 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() + elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") + if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "^(x86_64|amd64)$") + FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x64}) + FetchContent_Populate(protoc_binary) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86?)$") + FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_x86} URL_HASH SHA1=${DEP_SHA1_protoc_linux_x86}) + FetchContent_Populate(protoc_binary) + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64.*") + FetchContent_Declare(protoc_binary URL ${DEP_URL_protoc_linux_aarch64} URL_HASH SHA1=${DEP_SHA1_protoc_linux_aarch64}) + FetchContent_Populate(protoc_binary) + endif() + + if(protoc_binary_SOURCE_DIR) + message(STATUS "Use prebuilt protoc") + set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc) + set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE}) + endif() + endif() + + if(NOT ONNX_CUSTOM_PROTOC_EXECUTABLE) + message(FATAL_ERROR "ONNX_CUSTOM_PROTOC_EXECUTABLE must be set to cross-compile.") + endif() + endif() +endif() + +# if ONNX_CUSTOM_PROTOC_EXECUTABLE is set we don't need to build the protoc binary +if (ONNX_CUSTOM_PROTOC_EXECUTABLE) + if (NOT EXISTS "${ONNX_CUSTOM_PROTOC_EXECUTABLE}") + message(FATAL_ERROR "ONNX_CUSTOM_PROTOC_EXECUTABLE is set to '${ONNX_CUSTOM_PROTOC_EXECUTABLE}' " + "but protoc executable was not found there.") + endif() + + set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build protoc" FORCE) +endif() + +#Here we support two build mode: +#1. if ONNX_CUSTOM_PROTOC_EXECUTABLE is set, build Protobuf from source, except protoc.exe. This mode is mainly +# for cross-compiling +#2. if ONNX_CUSTOM_PROTOC_EXECUTABLE is not set, Compile everything(including protoc) from source code. +if(Patch_FOUND) + set(ONNXRUNTIME_PROTOBUF_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/protobuf/protobuf_cmake.patch) +else() + set(ONNXRUNTIME_PROTOBUF_PATCH_COMMAND "") +endif() + +#Protobuf depends on absl and utf8_range +FetchContent_Declare( + Protobuf + URL ${DEP_URL_protobuf} + URL_HASH SHA1=${DEP_SHA1_protobuf} + PATCH_COMMAND ${ONNXRUNTIME_PROTOBUF_PATCH_COMMAND} + FIND_PACKAGE_ARGS NAMES Protobuf protobuf +) + +set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) +#TODO: we'd better to turn the following option off. However, it will cause +# ".\build.bat --config Debug --parallel --skip_submodule_sync --update" fail with an error message: +# install(EXPORT "ONNXTargets" ...) includes target "onnx_proto" which requires target "libprotobuf-lite" that is +# not in any export set. +#set(protobuf_INSTALL OFF CACHE BOOL "Install protobuf binaries and files" FORCE) +set(protobuf_USE_EXTERNAL_GTEST ON CACHE BOOL "" FORCE) + +if (ANDROID) + set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build protobuf with zlib support" FORCE) +endif() + +if (onnxruntime_DISABLE_RTTI) + set(protobuf_DISABLE_RTTI ON CACHE BOOL "Remove runtime type information in the binaries" FORCE) +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) + +FetchContent_Declare( + date + URL ${DEP_URL_date} + URL_HASH SHA1=${DEP_SHA1_date} + FIND_PACKAGE_ARGS 3...<4 NAMES date +) +onnxruntime_fetchcontent_makeavailable(date) + +FetchContent_Declare( + mp11 + URL ${DEP_URL_mp11} + URL_HASH SHA1=${DEP_SHA1_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 "") + +FetchContent_Declare( + nlohmann_json + URL ${DEP_URL_json} + 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) + # Adding pytorch CPU info library + # TODO!! need a better way to find out the supported architectures + list(LENGTH CMAKE_OSX_ARCHITECTURES CMAKE_OSX_ARCHITECTURES_LEN) + if (APPLE) + if (CMAKE_OSX_ARCHITECTURES_LEN LESS_EQUAL 1) + set(CPUINFO_SUPPORTED TRUE) + elseif (onnxruntime_BUILD_APPLE_FRAMEWORK) + # We stitch multiple static libraries together when onnxruntime_BUILD_APPLE_FRAMEWORK is true, + # but that would not work for universal static libraries + message(FATAL_ERROR "universal binary is not supported for apple framework") + endif() + else() + # if xnnpack is enabled in a wasm build it needs clog from cpuinfo, but we won't internally use cpuinfo + # so we don't set CPUINFO_SUPPORTED in the CXX flags below. + if (CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT onnxruntime_USE_XNNPACK) + set(CPUINFO_SUPPORTED FALSE) + else() + set(CPUINFO_SUPPORTED TRUE) + endif() + if (WIN32) + set(CPUINFO_SUPPORTED TRUE) + elseif (NOT ${onnxruntime_target_platform} MATCHES "^(i[3-6]86|AMD64|x86(_64)?|armv[5-8].*|aarch64|arm64)$") + message(WARNING + "Target processor architecture \"${onnxruntime_target_platform}\" is not supported in cpuinfo. " + "cpuinfo not included." + ) + set(CPUINFO_SUPPORTED FALSE) + endif() + endif() +else() + set(CPUINFO_SUPPORTED FALSE) +endif() + +if (CPUINFO_SUPPORTED) + if (CMAKE_SYSTEM_NAME STREQUAL "iOS") + set(IOS ON CACHE INTERNAL "") + set(IOS_ARCH "${CMAKE_OSX_ARCHITECTURES}" CACHE INTERNAL "") + endif() + + # if this is a wasm build with xnnpack (only type of wasm build where cpuinfo is involved) + # we do not use cpuinfo in ORT code, so don't define CPUINFO_SUPPORTED. + if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") + string(APPEND CMAKE_CXX_FLAGS " -DCPUINFO_SUPPORTED") + endif() + + + set(CPUINFO_BUILD_TOOLS OFF CACHE INTERNAL "") + set(CPUINFO_BUILD_UNIT_TESTS OFF CACHE INTERNAL "") + set(CPUINFO_BUILD_MOCK_TESTS OFF CACHE INTERNAL "") + set(CPUINFO_BUILD_BENCHMARKS OFF CACHE INTERNAL "") + if(onnxruntime_target_platform STREQUAL "ARM64EC") + message(STATUS "Applying a patch for Windows ARM64EC in cpuinfo") + FetchContent_Declare( + pytorch_cpuinfo + URL ${DEP_URL_pytorch_cpuinfo} + URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo} + PATCH_COMMAND ${Patch_EXECUTABLE} -p1 < ${PROJECT_SOURCE_DIR}/patches/cpuinfo/9bb12d342fd9479679d505d93a478a6f9cd50a47.patch + FIND_PACKAGE_ARGS NAMES cpuinfo + ) + else() + FetchContent_Declare( + pytorch_cpuinfo + URL ${DEP_URL_pytorch_cpuinfo} + URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo} + FIND_PACKAGE_ARGS NAMES cpuinfo + ) + 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() + +# 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 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() + +if(onnxruntime_USE_CUDA) + FetchContent_Declare( + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} + PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/gsl/1064.patch + FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL + ) +else() + FetchContent_Declare( + GSL + URL ${DEP_URL_microsoft_gsl} + URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} + 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( + 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 +) + +onnxruntime_fetchcontent_makeavailable(flatbuffers) +if(NOT flatbuffers_FOUND) + if(NOT TARGET flatbuffers::flatbuffers) + add_library(flatbuffers::flatbuffers ALIAS flatbuffers) + endif() + if(TARGET flatc AND NOT TARGET flatbuffers::flatc) + add_executable(flatbuffers::flatc ALIAS flatc) + endif() + if (GDK_PLATFORM) + # cstdlib only defines std::getenv when _CRT_USE_WINAPI_FAMILY_DESKTOP_APP is defined, which + # is probably an oversight for GDK/Xbox builds (::getenv exists and works). + file(WRITE ${CMAKE_BINARY_DIR}/gdk_cstdlib_wrapper.h [[ +#pragma once +#ifdef __cplusplus +#include +namespace std { using ::getenv; } +#endif +]]) + if(TARGET flatbuffers) + target_compile_options(flatbuffers PRIVATE /FI${CMAKE_BINARY_DIR}/gdk_cstdlib_wrapper.h) + endif() + if(TARGET flatc) + target_compile_options(flatc PRIVATE /FI${CMAKE_BINARY_DIR}/gdk_cstdlib_wrapper.h) + endif() + endif() +endif() + +# ONNX +if (NOT onnxruntime_USE_FULL_PROTOBUF) + set(ONNX_USE_LITE_PROTO ON CACHE BOOL "" FORCE) +else() + set(ONNX_USE_LITE_PROTO OFF CACHE BOOL "" FORCE) +endif() + +if(Patch_FOUND) + set(ONNXRUNTIME_ONNX_PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/onnx/onnx.patch) +else() + set(ONNXRUNTIME_ONNX_PATCH_COMMAND "") +endif() + +FetchContent_Declare( + onnx + URL ${DEP_URL_onnx} + URL_HASH SHA1=${DEP_SHA1_onnx} + PATCH_COMMAND ${ONNXRUNTIME_ONNX_PATCH_COMMAND} + FIND_PACKAGE_ARGS NAMES ONNX onnx +) +if (NOT onnxruntime_MINIMAL_BUILD) + onnxruntime_fetchcontent_makeavailable(onnx) +else() + include(onnx_minimal) +endif() + +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() + +find_package(Eigen3 CONFIG) +if(Eigen3_FOUND) + get_target_property(eigen_INCLUDE_DIRS Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) +else() + include(eigen) # FetchContent +endif() + +if(onnxruntime_USE_VCPKG) + find_package(wil CONFIG REQUIRED) + set(WIL_TARGET "WIL::WIL") +else() + include(wil) # FetchContent +endif() + +# 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() + include(xnnpack) +endif() + +if (onnxruntime_USE_MIMALLOC) + add_definitions(-DUSE_MIMALLOC) + + set(MI_OVERRIDE OFF CACHE BOOL "" FORCE) + set(MI_BUILD_TESTS OFF CACHE BOOL "" FORCE) + set(MI_DEBUG_FULL OFF CACHE BOOL "" FORCE) + set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE) + onnxruntime_fetchcontent_makeavailable(mimalloc) +endif() + +#onnxruntime_EXTERNAL_LIBRARIES could contain onnx, onnx_proto,libprotobuf, cuda/cudnn, +# dnnl/mklml, onnxruntime_codegen_tvm, tvm and pthread +# pthread is always at the last +set(onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK} ${WIL_TARGET} nlohmann_json::nlohmann_json onnx onnx_proto ${PROTOBUF_LIB} re2::re2 Boost::mp11 safeint_interface flatbuffers::flatbuffers ${GSL_TARGET} ${ABSEIL_LIBS} date::date ${ONNXRUNTIME_CLOG_TARGET_NAME}) +# The source code of onnx_proto is generated, we must build this lib first before starting to compile the other source code that uses ONNX protobuf types. +# 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) + +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) + add_definitions(-DORT_RUN_EXTERNAL_ONNX_TESTS) +endif() + + +if(onnxruntime_ENABLE_ATEN) + 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. + FetchContent_Populate(dlpack) +endif() + +if(onnxruntime_ENABLE_TRAINING OR (onnxruntime_ENABLE_TRAINING_APIS AND onnxruntime_BUILD_UNIT_TESTS)) + # Once code under orttraining/orttraining/models dir is removed "onnxruntime_ENABLE_TRAINING" should be removed from + # this conditional + FetchContent_Declare( + 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) + onnxruntime_fetchcontent_makeavailable(cxxopts) +endif() + +if (onnxruntime_USE_COREML) + FetchContent_Declare( + coremltools + URL ${DEP_URL_coremltools} + URL_HASH SHA1=${DEP_SHA1_coremltools} + PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/coremltools/crossplatformbuild.patch + ) + # we don't build directly so use Populate. selected files are built from onnxruntime_providers_coreml.cmake + FetchContent_Populate(coremltools) +endif() + +message(STATUS "Finished fetching external dependencies") + +set(onnxruntime_LINK_DIRS ) + +if (onnxruntime_USE_CUDA) + find_package(CUDAToolkit REQUIRED) + + if(onnxruntime_CUDNN_HOME) + file(TO_CMAKE_PATH ${onnxruntime_CUDNN_HOME} onnxruntime_CUDNN_HOME) + set(CUDNN_PATH ${onnxruntime_CUDNN_HOME}) + endif() +endif() + +if(onnxruntime_USE_SNPE) + include(external/find_snpe.cmake) + list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SNPE_NN_LIBS}) +endif() + +FILE(TO_NATIVE_PATH ${CMAKE_BINARY_DIR} ORT_BINARY_DIR) +FILE(TO_NATIVE_PATH ${PROJECT_SOURCE_DIR} ORT_SOURCE_DIR) diff --git a/ports/onnxruntime/portfile.cmake b/ports/onnxruntime/portfile.cmake new file mode 100644 index 00000000000000..2461996feda820 --- /dev/null +++ b/ports/onnxruntime/portfile.cmake @@ -0,0 +1,158 @@ +set(ORT_COMMIT "26250ae74d2c9a3c6860625ba4a147ddfb936907") +set(ORT_BRANCH "v${VERSION}") + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO microsoft/onnxruntime + REF ${ORT_BRANCH} + SHA512 3bf25e431d175c61953d28b1bf8f6871376684263992451a5b2a66e670768fc66e7027f141c6e3f4d1eddeebeda51f31ea0adf4749e50d99ee89d0a26bec77ce + PATCHES + revert-pr-21492.patch + fix-pr-21348.patch # cmake, source changes of PR 21348 + fix-cmake.patch + fix-cmake-cuda.patch + fix-cmake-tensorrt.patch # TENSORRT_ROOT is not defined, use CUDAToolkit to search TensorRT + fix-llvm-rc-unicode.patch + fix-clang-cl-simd-compile.patch +) +# copied from PR 21348 to reduce patch size +# caution: https://github.com/microsoft/onnxruntime/blob/45737400a2f3015c11f005ed7603611eaed306a6/cmake/deps.txt#L20-L25 +file(COPY "${CMAKE_CURRENT_LIST_DIR}/onnxruntime_external_deps.cmake" DESTINATION "${SOURCE_PATH}/cmake/external") +file(COPY "${CMAKE_CURRENT_LIST_DIR}/project-config-template.cmake" DESTINATION "${SOURCE_PATH}/cmake") + +find_program(PROTOC NAMES protoc PATHS "${CURRENT_HOST_INSTALLED_DIR}/tools/protobuf" REQUIRED NO_DEFAULT_PATH NO_CMAKE_PATH) +message(STATUS "Using protoc: ${PROTOC}") + +find_program(FLATC NAMES flatc PATHS "${CURRENT_HOST_INSTALLED_DIR}/tools/flatbuffers" REQUIRED NO_DEFAULT_PATH NO_CMAKE_PATH) +message(STATUS "Using flatc: ${FLATC}") + +vcpkg_find_acquire_program(PYTHON3) +get_filename_component(PYTHON_PATH "${PYTHON3}" PATH) +message(STATUS "Using python3: ${PYTHON3}") + +vcpkg_execute_required_process( + COMMAND "${PYTHON3}" onnxruntime/core/flatbuffers/schema/compile_schema.py --flatc "${FLATC}" + LOGNAME compile_schema + WORKING_DIRECTORY "${SOURCE_PATH}" +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + python onnxruntime_ENABLE_PYTHON + training onnxruntime_ENABLE_TRAINING + training onnxruntime_ENABLE_TRAINING_APIS + cuda onnxruntime_USE_CUDA + cuda onnxruntime_USE_CUDA_NHWC_OPS + openvino onnxruntime_USE_OPENVINO + tensorrt onnxruntime_USE_TENSORRT + tensorrt onnxruntime_USE_TENSORRT_BUILTIN_PARSER + directml onnxruntime_USE_DML + directml onnxruntime_USE_CUSTOM_DIRECTML + winml onnxruntime_USE_WINML + coreml onnxruntime_USE_COREML + mimalloc onnxruntime_USE_MIMALLOC + valgrind onnxruntime_USE_VALGRIND + xnnpack onnxruntime_USE_XNNPACK + nnapi onnxruntime_USE_NNAPI_BUILTIN + azure onnxruntime_USE_AZURE + llvm onnxruntime_USE_LLVM + rocm onnxruntime_USE_ROCM + test onnxruntime_BUILD_UNIT_TESTS + test onnxruntime_BUILD_BENCHMARKS + test onnxruntime_RUN_ONNX_TESTS + framework onnxruntime_BUILD_APPLE_FRAMEWORK + framework onnxruntime_BUILD_OBJC + nccl onnxruntime_USE_NCCL + mpi onnxruntime_USE_MPI + INVERTED_FEATURES + cuda onnxruntime_USE_MEMORY_EFFICIENT_ATTENTION +) + +if("tensorrt" IN_LIST FEATURES) + if(DEFINED TENSORRT_ROOT) # if the variable in the triplet, use it + message(STATUS "Using TensorRT: ${TENSORRT_ROOT}") + list(APPEND FEATURE_OPTIONS "-Donnxruntime_TENSORRT_HOME:PATH=${TENSORRT_ROOT}") + endif() +endif() + +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED) + +# see tools/ci_build/build.py +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}/cmake" + OPTIONS + ${FEATURE_OPTIONS} + "-DPython_EXECUTABLE:FILEPATH=${PYTHON3}" + "-DProtobuf_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}" + "-DONNX_CUSTOM_PROTOC_EXECUTABLE:FILEPATH=${PROTOC}" + -DBUILD_PKGCONFIG_FILES=${BUILD_SHARED} + -Donnxruntime_USE_VCPKG=ON + -Donnxruntime_BUILD_SHARED_LIB=${BUILD_SHARED} + -Donnxruntime_BUILD_WEBASSEMBLY=OFF + -Donnxruntime_CROSS_COMPILING=${VCPKG_CROSSCOMPILING} + -Donnxruntime_USE_EXTENSIONS=OFF + -Donnxruntime_USE_NNAPI_BUILTIN=${VCPKG_TARGET_IS_ANDROID} + -Donnxruntime_ENABLE_CPUINFO=ON + -Donnxruntime_ENABLE_MICROSOFT_INTERNAL=OFF + -Donnxruntime_ENABLE_BITCODE=${VCPKG_TARGET_IS_IOS} + -Donnxruntime_ENABLE_PYTHON=OFF + -Donnxruntime_ENABLE_EXTERNAL_CUSTOM_OP_SCHEMAS=OFF + -Donnxruntime_ENABLE_LAZY_TENSOR=OFF + -Donnxruntime_DISABLE_RTTI=OFF + -Donnxruntime_DISABLE_ABSEIL=OFF + -DORT_GIT_COMMIT=${ORT_COMMIT} + -DORT_GIT_BRANCH=${ORT_BRANCH} + --compile-no-warning-as-error + OPTIONS_DEBUG + -Donnxruntime_ENABLE_MEMLEAK_CHECKER=OFF + -Donnxruntime_ENABLE_MEMORY_PROFILE=OFF + -Donnxruntime_DEBUG_NODE_INPUTS_OUTPUTS=1 + MAYBE_UNUSED_VARIABLES + onnxruntime_BUILD_WEBASSEMBLY + onnxruntime_TENSORRT_PLACEHOLDER_BUILDER + onnxruntime_USE_CUSTOM_DIRECTML + Python_EXECUTABLE + ORT_GIT_COMMIT + ORT_GIT_BRANCH +) + +if("cuda" IN_LIST FEATURES) + vcpkg_cmake_build(TARGET onnxruntime_providers_cuda LOGFILE_BASE build-cuda) +endif() +if("tensorrt" IN_LIST FEATURES) + vcpkg_cmake_build(TARGET onnxruntime_providers_tensorrt LOGFILE_BASE build-tensorrt) +endif() +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/onnxruntime) +if(BUILD_SHARED) + vcpkg_fixup_pkgconfig() # pkg_check_modules(libonnxruntime) +endif() + +# cmake function which relocates the onnxruntime_providers_* library before vcpkg_copy_pdbs() +function(relocate_ort_providers PROVIDER_NAME) + if(VCPKG_TARGET_IS_WINDOWS AND (VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")) + # the target is expected to be used without the .lib files + file(RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/${PROVIDER_NAME}.dll" + "${CURRENT_PACKAGES_DIR}/debug/bin/${PROVIDER_NAME}.dll") + file(RENAME "${CURRENT_PACKAGES_DIR}/lib/${PROVIDER_NAME}.dll" + "${CURRENT_PACKAGES_DIR}/bin/${PROVIDER_NAME}.dll") + endif() +endfunction() + +if("cuda" IN_LIST FEATURES) + relocate_ort_providers(onnxruntime_providers_cuda) +endif() +if("tensorrt" IN_LIST FEATURES) + relocate_ort_providers(onnxruntime_providers_tensorrt) +endif() +vcpkg_copy_pdbs() + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/bin" + "${CURRENT_PACKAGES_DIR}/bin" + ) +endif() + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/ports/onnxruntime/project-config-template.cmake b/ports/onnxruntime/project-config-template.cmake new file mode 100644 index 00000000000000..4f8e58415c624c --- /dev/null +++ b/ports/onnxruntime/project-config-template.cmake @@ -0,0 +1,50 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +# sync with portfile.cmake and onnxruntime_vcpkg_deps.cmake ... +find_dependency(absl) +find_dependency(re2) +if("@onnxruntime_BUILD_UNIT_TESTS@") + find_dependency(GTest) +endif() +if("@onnxruntime_BUILD_BENCHMARKS@") + find_dependency(benchmark) +endif() +find_dependency(flatbuffers) +find_dependency(Protobuf) + +find_dependency(date) +find_dependency(Boost) +find_dependency(nlohmann_json) +if("@onnxruntime_ENABLE_CPUINFO@") + find_dependency(cpuinfo) +endif() +if(NOT WIN32) + find_dependency(unofficial-nsync) +endif() +find_dependency(Microsoft.GSL) +find_dependency(ONNX) +find_dependency(Eigen3) +find_dependency(wil) +if("@onnxruntime_USE_XNNPACK@") + find_dependency(cpuinfo) +endif() +if("@onnxruntime_USE_MIMALLOC@") + find_dependency(mimalloc) +endif() +if("@onnxruntime_ENABLE_ATEN@") + find_dependency(dlpack) +endif() +if("@onnxruntime_ENABLE_TRAINING@ OR @onnxruntime_ENABLE_TRAINING_APIS@") + find_dependency(cxxopts) +endif() +if("@onnxruntime_USE_CUDA@") + find_dependency(CUDAToolkit) + find_dependency(NvidiaCutlass) +endif() +if("@onnxruntime_USE_OPENVINO@") + find_dependency(OpenVINO) +endif() + +include("${CMAKE_CURRENT_LIST_DIR}/onnxruntimeTargets.cmake") diff --git a/ports/onnxruntime/revert-pr-21492.patch b/ports/onnxruntime/revert-pr-21492.patch new file mode 100644 index 00000000000000..d5ec5a91ea7a2e --- /dev/null +++ b/ports/onnxruntime/revert-pr-21492.patch @@ -0,0 +1,62 @@ +diff --git a/onnxruntime/core/providers/cpu/math/element_wise_ops.cc b/onnxruntime/core/providers/cpu/math/element_wise_ops.cc +index 5ea6000da1..1d524a9030 100644 +--- a/onnxruntime/core/providers/cpu/math/element_wise_ops.cc ++++ b/onnxruntime/core/providers/cpu/math/element_wise_ops.cc +@@ -705,7 +705,7 @@ Status Min_6::Compute(OpKernelContext* ctx) const { + for (int index = 1; index < inputCount; index++) { + auto& data_n = *ctx->Input(index); + ORT_ENFORCE(data_n.Shape() == shape, "All inputs must have the same shape"); +- min = min.array().template min(EigenMap(data_n).array()); ++ min = min.array().min(EigenMap(data_n).array()); + } + + return Status::OK(); +@@ -721,16 +721,15 @@ struct Min_8::ComputeImpl { + ProcessBroadcastSpanFuncs funcs{ + [](BroadcastHelper& per_iter_bh) { + per_iter_bh.OutputEigen() = +- per_iter_bh.EigenInput1().array().template min(per_iter_bh.ScalarInput0()); ++ per_iter_bh.EigenInput1().array().min(per_iter_bh.ScalarInput0()); + }, + [](BroadcastHelper& per_iter_bh) { + per_iter_bh.OutputEigen() = +- per_iter_bh.EigenInput0().array().template min(per_iter_bh.ScalarInput1()); ++ per_iter_bh.EigenInput0().array().min(per_iter_bh.ScalarInput1()); + }, + [](BroadcastHelper& per_iter_bh) { + per_iter_bh.OutputEigen() = +- per_iter_bh.EigenInput0().array().template min( +- per_iter_bh.EigenInput1().array()); ++ per_iter_bh.EigenInput0().array().min(per_iter_bh.EigenInput1().array()); + }}; + + int input_count = inst.Node().InputArgCount().front(); +@@ -828,7 +827,7 @@ Status Max_6::Compute(OpKernelContext* ctx) const { + for (int index = 1; index < inputCount; index++) { + auto& data_n = *ctx->Input(index); + ORT_ENFORCE(data_n.Shape() == shape, "All inputs must have the same shape"); +- max = max.array().template max(EigenMap(data_n).array()); ++ max = max.array().max(EigenMap(data_n).array()); + } + + return Status::OK(); +@@ -844,16 +843,15 @@ struct Max_8::ComputeImpl { + ProcessBroadcastSpanFuncs funcs{ + [](BroadcastHelper& per_iter_bh) { + per_iter_bh.OutputEigen() = +- per_iter_bh.EigenInput1().array().template max(per_iter_bh.ScalarInput0()); ++ per_iter_bh.EigenInput1().array().max(per_iter_bh.ScalarInput0()); + }, + [](BroadcastHelper& per_iter_bh) { + per_iter_bh.OutputEigen() = +- per_iter_bh.EigenInput0().array().template max(per_iter_bh.ScalarInput1()); ++ per_iter_bh.EigenInput0().array().max(per_iter_bh.ScalarInput1()); + }, + [](BroadcastHelper& per_iter_bh) { + per_iter_bh.OutputEigen() = +- per_iter_bh.EigenInput0().array().template max( +- per_iter_bh.EigenInput1().array()); ++ per_iter_bh.EigenInput0().array().max(per_iter_bh.EigenInput1().array()); + }}; + + int input_count = inst.Node().InputArgCount().front(); diff --git a/ports/onnxruntime/vcpkg.json b/ports/onnxruntime/vcpkg.json new file mode 100644 index 00000000000000..4fb5d43b0a7cf0 --- /dev/null +++ b/ports/onnxruntime/vcpkg.json @@ -0,0 +1,92 @@ +{ + "name": "onnxruntime", + "version-semver": "1.19.2", + "description": "ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator", + "homepage": "https://onnxruntime.ai/", + "license": "MIT", + "supports": "windows | linux | osx", + "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", + "utf8-range", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + "wil" + ], + "features": { + "cuda": { + "description": "Build with CUDA support", + "dependencies": [ + "cuda", + "cudnn", + "nvidia-cutlass" + ] + }, + "tensorrt": { + "description": "Build with TensorRT support", + "dependencies": [ + { + "name": "onnxruntime", + "default-features": false, + "features": [ + "cuda" + ] + } + ] + } + } +} diff --git a/ports/openvino/002-onnx-targets.patch b/ports/openvino/002-onnx-targets.patch new file mode 100644 index 00000000000000..af0c8dc0f6d0da --- /dev/null +++ b/ports/openvino/002-onnx-targets.patch @@ -0,0 +1,17 @@ +diff --git a/thirdparty/dependencies.cmake b/thirdparty/dependencies.cmake +index 075fc664..9d347c57 100644 +--- a/thirdparty/dependencies.cmake ++++ b/thirdparty/dependencies.cmake +@@ -496,6 +496,12 @@ if(ENABLE_OV_ONNX_FRONTEND) + + if(ONNX_FOUND) + # conan and vcpkg create imported targets 'onnx' and 'onnx_proto' ++ if(TARGET ONNX::onnx) ++ add_library(onnx ALIAS ONNX::onnx) ++ endif() ++ if(TARGET ONNX::onnx_proto) ++ add_library(onnx_proto ALIAS ONNX::onnx_proto) ++ endif() + else() + add_subdirectory(thirdparty/onnx) + endif() diff --git a/ports/openvino/portfile.cmake b/ports/openvino/portfile.cmake index db0d3a167c2e9e..945c93914a185e 100644 --- a/ports/openvino/portfile.cmake +++ b/ports/openvino/portfile.cmake @@ -6,6 +6,7 @@ vcpkg_from_github( PATCHES # vcpkg specific patch, because OV creates a file in source tree, which is prohibited 001-disable-tools.patch + 002-onnx-targets.patch HEAD_REF master) vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS diff --git a/ports/openvino/vcpkg.json b/ports/openvino/vcpkg.json index d392279863bf67..f43c76336cff7a 100644 --- a/ports/openvino/vcpkg.json +++ b/ports/openvino/vcpkg.json @@ -2,6 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", "name": "openvino", "version": "2024.4.0", + "port-version": 1, "maintainers": "OpenVINO Developers ", "summary": "This is a port for Open Visual Inference And Optimization toolkit for AI inference", "description": [ diff --git a/scripts/ci.baseline.txt b/scripts/ci.baseline.txt index f5dd1def4f22b4..52946479fb6935 100644 --- a/scripts/ci.baseline.txt +++ b/scripts/ci.baseline.txt @@ -817,6 +817,7 @@ ompl:x64-android=fail omplapp:arm64-osx=skip omplapp:x64-osx=skip omplapp:x64-linux=skip +onnxruntime-gpu:x64-windows=skip # opencc/deps/rapidjson-1.1.0/rapidjson.h: Unknown machine endianess detected # opencc/deps/marisa-0.2.5/lib/marisa/grimoire/io/mapper.cc currently doesn't support UWP. opencc:x64-android=fail diff --git a/versions/baseline.json b/versions/baseline.json index 0b691a5a628f17..f51f936b006871 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -5178,7 +5178,7 @@ }, "libtorch": { "baseline": "2.1.2", - "port-version": 6 + "port-version": 7 }, "libtorrent": { "baseline": "2.0.10", @@ -6533,16 +6533,20 @@ "port-version": 1 }, "onnx": { - "baseline": "1.15.0", - "port-version": 1 + "baseline": "1.16.0", + "port-version": 0 }, "onnx-optimizer": { "baseline": "0.3.18", + "port-version": 1 + }, + "onnxruntime": { + "baseline": "1.19.2", "port-version": 0 }, "onnxruntime-gpu": { "baseline": "1.19.2", - "port-version": 0 + "port-version": 1 }, "oof": { "baseline": "2021-11-23", @@ -6730,7 +6734,7 @@ }, "openvino": { "baseline": "2024.4.0", - "port-version": 0 + "port-version": 1 }, "openvpn3": { "baseline": "3.10", diff --git a/versions/l-/libtorch.json b/versions/l-/libtorch.json index d9d120d0db3d46..aa8977a18ceefa 100644 --- a/versions/l-/libtorch.json +++ b/versions/l-/libtorch.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "63d61f30a809aa1e67d8445bf3bda120193c1741", + "version": "2.1.2", + "port-version": 7 + }, { "git-tree": "12485495c895b105a0b0a35558edce15579a5a98", "version": "2.1.2", diff --git a/versions/o-/onnx-optimizer.json b/versions/o-/onnx-optimizer.json index 8833f7dc14c161..3132e2a394fd5d 100644 --- a/versions/o-/onnx-optimizer.json +++ b/versions/o-/onnx-optimizer.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "d675260496366f3ab94fc2f7b3c18c4da5434278", + "version-semver": "0.3.18", + "port-version": 1 + }, { "git-tree": "e574f424edd5d2fd9ca36c5058f96163d9018725", "version-semver": "0.3.18", diff --git a/versions/o-/onnx.json b/versions/o-/onnx.json index 014174c60c042d..12bd8450e30fb2 100644 --- a/versions/o-/onnx.json +++ b/versions/o-/onnx.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "e1310598f4f00d025fa39c547f32c346a7dcf3ec", + "version-semver": "1.16.0", + "port-version": 0 + }, { "git-tree": "69ad297b15bb801f74d50be6e5d290eab7573be4", "version-semver": "1.15.0", diff --git a/versions/o-/onnxruntime-gpu.json b/versions/o-/onnxruntime-gpu.json index 25ff2e6d6e0543..61183907db045a 100644 --- a/versions/o-/onnxruntime-gpu.json +++ b/versions/o-/onnxruntime-gpu.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "965a6e7162f8f2677f191cbc19b4fa31b066beb7", + "version": "1.19.2", + "port-version": 1 + }, { "git-tree": "e9ce6c51894e80beece7446b501ef2263578ad29", "version": "1.19.2", diff --git a/versions/o-/onnxruntime.json b/versions/o-/onnxruntime.json new file mode 100644 index 00000000000000..217c46f2467335 --- /dev/null +++ b/versions/o-/onnxruntime.json @@ -0,0 +1,9 @@ +{ + "versions": [ + { + "git-tree": "e13ffd9700daacffd52cb8da42c281334b566456", + "version-semver": "1.19.2", + "port-version": 0 + } + ] +} diff --git a/versions/o-/openvino.json b/versions/o-/openvino.json index cce2b4c1a73515..38b1bc9b3a9c08 100644 --- a/versions/o-/openvino.json +++ b/versions/o-/openvino.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "603457e9945b64406f7420644d8862b01d9bd99a", + "version": "2024.4.0", + "port-version": 1 + }, { "git-tree": "e65d1d305cc744e9ff5d96358695cbfe22deb8c3", "version": "2024.4.0",