From 5aeda90a2368c3dfc2982d8ce1f817ad9fcb9a5e Mon Sep 17 00:00:00 2001 From: Park DongHa Date: Thu, 28 Sep 2023 10:23:43 +0900 Subject: [PATCH] [onnxruntime] Update to 1.16.0 (#118) * [onnxruntime] rewriting fix-cmake.patch * [onnxruntime] fix flatbuffers related error * [onnxruntime] add missing dependencies * [onnxruntime] fixing 'training' feature build * requires https://github.com/dmlc/dlpack * [onnxruntime] rewriting patch files * [onnxruntime] fixing xnnpack update * [onnxruntime] rewriting patch files * [onnxruntime] fix wil, nsync import * [onnxruntime] disable COMPILE_WARNING_AS_ERROR * [onnxruntime] update to 1.16.0 * circleci: use branch cache * [onnx] workaround pip3 failure * [onnxruntime] fix osx build errors * circleci: change port list * format the ports * update baseline --- .circleci/config.yml | 10 +- .circleci/port-setup.txt | 3 +- .circleci/port-windows.txt | 3 +- ports/onnx/portfile.cmake | 24 +- ports/onnx/vcpkg.json | 13 +- ports/onnxruntime/fix-cmake.patch | 764 +++++++++++++----- .../onnxruntime/fix-source-flatbuffers.patch | 162 ++++ ports/onnxruntime/fix-sources.patch | 187 ----- ports/onnxruntime/portfile.cmake | 111 ++- ports/onnxruntime/support-windows10.patch | 16 - ports/onnxruntime/vcpkg.json | 47 +- versions/baseline.json | 6 +- versions/o-/onnx.json | 5 + versions/o-/onnxruntime.json | 5 + 14 files changed, 887 insertions(+), 469 deletions(-) create mode 100644 ports/onnxruntime/fix-source-flatbuffers.patch delete mode 100644 ports/onnxruntime/fix-sources.patch delete mode 100644 ports/onnxruntime/support-windows10.patch diff --git a/.circleci/config.yml b/.circleci/config.yml index ac89aab7..2cf3366a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -91,9 +91,11 @@ jobs: Pop-Location - restore_cache: keys: + - v2338-downs-{{ .Branch }} - v2338-downs-{{ checksum ".circleci/config.yml" }} - restore_cache: keys: + - v2338-bins-{{ .Branch }} - v2338-bins-{{ checksum ".circleci/config.yml" }} - run: name: "Install: port-windows.txt" @@ -114,15 +116,13 @@ jobs: paths: - C:/vcpkg-bins - save_cache: - key: v2338-downs-{{ checksum ".circleci/config.yml" }} + key: v2338-downs-{{ .Branch }} paths: - - C:/vcpkg-downs - when: always + - C:/vcpkg-bins - save_cache: - key: v2338-bins-{{ checksum ".circleci/config.yml" }} + key: v2338-bins-{{ .Branch }} paths: - C:/vcpkg-bins - when: always - store_artifacts: name: "Upload buildtrees log" path: vcpkg/buildtrees/ # buildtrees-log diff --git a/.circleci/port-setup.txt b/.circleci/port-setup.txt index d0194a9e..1fa8ea1d 100644 --- a/.circleci/port-setup.txt +++ b/.circleci/port-setup.txt @@ -11,10 +11,11 @@ zstd:x64-windows draco:x64-windows civetweb:x64-windows cgltf:x64-windows -protobuf[zlib]:x64-windows +protobuf:x64-windows grpc[codegen]:x64-windows flatbuffers:x64-windows opencl:x64-windows egl-registry:x64-windows opengl-registry:x64-windows vulkan-headers:x64-windows +nlohmann-json:x64-windows \ No newline at end of file diff --git a/.circleci/port-windows.txt b/.circleci/port-windows.txt index 7ea3e384..69c28500 100644 --- a/.circleci/port-windows.txt +++ b/.circleci/port-windows.txt @@ -1 +1,2 @@ -google-filament[gles3,test]:x64-windows +grpc[codegen]:x64-windows +onnxruntime[directml,xnnpack,test]:x64-windows \ No newline at end of file diff --git a/ports/onnx/portfile.cmake b/ports/onnx/portfile.cmake index b261b19e..cc3b4d67 100644 --- a/ports/onnx/portfile.cmake +++ b/ports/onnx/portfile.cmake @@ -31,19 +31,22 @@ vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS protobuf-lite ONNX_USE_LITE_PROTO ) -# Like protoc, python is required for codegen. -x_vcpkg_get_python_packages( - PYTHON_VERSION 3 - PACKAGES numpy pybind11 - OUT_PYTHON_VAR PYTHON3 -) +if("python" IN_LIST FEATURES) + x_vcpkg_get_python_packages( + PYTHON_VERSION 3 + PACKAGES numpy pybind11 + OUT_PYTHON_VAR PYTHON3 + ) + get_filename_component(PYTHON_PATH "${PYTHON3}" PATH) +else() + vcpkg_find_acquire_program(PYTHON3) + get_filename_component(PYTHON_PATH "${PYTHON3}" PATH) +endif() message(STATUS "Using python3: ${PYTHON3}") -get_filename_component(PYTHON_PATH "${PYTHON3}" PATH) -get_filename_component(PYTHON_ROOT "${PYTHON_PATH}" PATH) -# PATH for .bat scripts so it can find 'python' vcpkg_add_to_path(PREPEND "${PYTHON_PATH}") if("python" IN_LIST FEATURES) + get_filename_component(PYTHON_ROOT "${PYTHON_PATH}" PATH) find_path(pybind11_DIR NAMES pybind11Targets.cmake PATHS "${PYTHON_ROOT}/Lib/site-packages/pybind11/share/cmake/pybind11" REQUIRED) message(STATUS "Using pybind11: ${pybind11_DIR}") list(APPEND FEATURE_OPTIONS @@ -74,8 +77,6 @@ vcpkg_cmake_configure( vcpkg_cmake_install() vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ONNX) -file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright) - file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" "${CURRENT_PACKAGES_DIR}/debug/share" @@ -105,3 +106,4 @@ file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/include/onnx/onnx_data" "${CURRENT_PACKAGES_DIR}/include/onnx/onnx_operators_ml" ) +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") \ No newline at end of file diff --git a/ports/onnx/vcpkg.json b/ports/onnx/vcpkg.json index 1c694171..0bc0d662 100644 --- a/ports/onnx/vcpkg.json +++ b/ports/onnx/vcpkg.json @@ -1,6 +1,7 @@ { "name": "onnx", "version-semver": "1.14.1", + "port-version": 1, "description": "Open standard for machine learning interoperability", "homepage": "https://onnx.ai", "license": "Apache-2.0", @@ -17,16 +18,18 @@ { "name": "vcpkg-cmake-config", "host": true - }, - { - "name": "vcpkg-get-python-packages", - "host": true } ], "features": { "python": { "description": "Build Python binaries", - "supports": "x64" + "supports": "x64", + "dependencies": [ + { + "name": "vcpkg-get-python-packages", + "host": true + } + ] } } } diff --git a/ports/onnxruntime/fix-cmake.patch b/ports/onnxruntime/fix-cmake.patch index f7a10468..bd141a5b 100644 --- a/ports/onnxruntime/fix-cmake.patch +++ b/ports/onnxruntime/fix-cmake.patch @@ -1,235 +1,615 @@ diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt -index fb4899d..4b86657 100644 +index 82a4547..ab5ed03 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt -@@ -20,6 +20,7 @@ project(onnxruntime C CXX ASM) - # Needed for Java - set(CMAKE_C_STANDARD 99) +@@ -18,6 +18,7 @@ cmake_policy(SET CMP0141 NEW) + # Project + project(onnxruntime C CXX ASM) +include(GNUInstallDirs) - include(CheckCXXCompilerFlag) - include(CheckLanguage) - include(CMakeDependentOption) -@@ -743,9 +744,9 @@ endif() - if (NOT WIN32) - if (onnxruntime_PREFER_SYSTEM_LIB) -- find_package(nsync) -+ find_package(unofficial-nsync CONFIG REQUIRED) # unofficial::nsync::nsync_cpp + # Disable fast-math for Intel oneAPI compiler + if("${CMAKE_CXX_COMPILER_ID}" MATCHES "IntelLLVM") +@@ -355,8 +356,8 @@ endif() + # Single output director for all binaries + set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Single output directory for all binaries.") + +- +-include(FetchContent) ++# Using vcpkg. Disable source download/build with CMake ++# include(FetchContent) + + function(set_msvc_c_cpp_compiler_warning_level warning_level) + if (NOT "${warning_level}" MATCHES "^[0-4]$") +@@ -783,6 +784,7 @@ if (onnxruntime_USE_COREML) + list(APPEND ONNXRUNTIME_PROVIDER_NAMES coreml) + endif() + if (onnxruntime_USE_XNNPACK) ++ find_package(xnnpack CONFIG REQUIRED) # xnnpack + list(APPEND ORT_PROVIDER_FLAGS -DUSE_XNNPACK=1) + list(APPEND ORT_PROVIDER_CMAKE_FLAGS -Donnxruntime_USE_XNNPACK=1) + list(APPEND ONNXRUNTIME_PROVIDER_NAMES xnnpack) +@@ -1335,12 +1337,6 @@ endif() + set(ORT_BUILD_INFO "ORT Build Info: ") + find_package(Git) + if (Git_FOUND) +- execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --format=%h +- OUTPUT_VARIABLE ORT_GIT_COMMIT) +- string(STRIP "${ORT_GIT_COMMIT}" ORT_GIT_COMMIT) +- execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD +- 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() + string(APPEND ORT_BUILD_INFO "build type=${CMAKE_BUILD_TYPE}") +@@ -1436,7 +1432,8 @@ if (onnxruntime_USE_DML) + message(FATAL_ERROR "The DirectML execution provider is only supported when building for Windows.") endif() -- if (TARGET nsync_cpp) # linking error with nsync_FOUND (why?) -+ if (TARGET unofficial::nsync::nsync_cpp) # linking error with nsync_FOUND (why?) - message("Use nsync from preinstalled system lib") - else() - message("Use nsync from submodule") -@@ -869,8 +870,7 @@ add_library(safeint_interface INTERFACE) - target_include_directories(safeint_interface INTERFACE ${SAFEINT_INCLUDE_DIR}) - - if (onnxruntime_PREFER_SYSTEM_LIB) -- find_package(boost_mp11) -- find_package(Boost) -+ find_package(Boost REQUIRED) - if (TARGET Boost::boost AND NOT TARGET Boost::mp11) - add_library(Boost::mp11 ALIAS Boost::boost) + +- include(dml) ++ find_path(dml_INCLUDE_DIR NAMES "DirectML.h" REQUIRED) ++ include_directories(${dml_INCLUDE_DIR}) + endif() + + if (onnxruntime_ENABLE_TRAINING_APIS) +@@ -1689,6 +1686,8 @@ if (WIN32 AND NOT GDK_PLATFORM) endif() -@@ -942,6 +942,8 @@ if (onnxruntime_ENABLE_CPUINFO) - ) - set(CPUINFO_SUPPORTED FALSE) - endif() -+ # patched in https://github.com/luncliff/vcpkg-registry -+ set(CPUINFO_SUPPORTED TRUE) + endif() + ++# see cmake/external/ ++include(external/protobuf_function.cmake) + foreach(target_name ${ONNXRUNTIME_CMAKE_FILES}) + include(${target_name}.cmake) + endforeach() +diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake +index 8e412c7..53ab9d9 100644 +--- a/cmake/external/onnxruntime_external_deps.cmake ++++ b/cmake/external/onnxruntime_external_deps.cmake +@@ -20,16 +20,12 @@ endforeach() + message("Loading Dependencies ...") + # ABSL should be included before protobuf because protobuf may use absl + if(NOT onnxruntime_DISABLE_ABSEIL) +- include(external/abseil-cpp.cmake) ++ find_package(absl CONFIG REQUIRED) ++ list(APPEND onnxruntime_EXTERNAL_LIBRARIES absl::base) + endif() + +-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 +-) ++find_package(re2 CONFIG REQUIRED) # re2::re2 ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES re2::re2) + + if (onnxruntime_BUILD_UNIT_TESTS) + # WebAssembly threading support in Node.js is still an experimental feature and +@@ -43,12 +39,7 @@ if (onnxruntime_BUILD_UNIT_TESTS) + set(GTEST_HAS_ABSL OFF CACHE BOOL "" FORCE) + endif() + # gtest and gmock +- FetchContent_Declare( +- googletest +- URL ${DEP_URL_googletest} +- FIND_PACKAGE_ARGS 1.13.0...<2.0.0 NAMES GTest +- URL_HASH SHA1=${DEP_SHA1_googletest} +- ) ++ find_package(GTest CONFIG REQUIRED) # GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main + endif() + + if (onnxruntime_BUILD_BENCHMARKS) +@@ -57,158 +48,42 @@ if (onnxruntime_BUILD_BENCHMARKS) + # 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(benchmark CONFIG REQUIRED) # benchmark::benchmark benchmark::benchmark_main + 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 +- ) +-endif() + list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/external) + +-FetchContent_Declare( +- mimalloc +- URL ${DEP_URL_mimalloc} +- URL_HASH SHA1=${DEP_SHA1_mimalloc} +-) +- +- +- + # 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 1.12.0...<2.0.0 NAMES Flatbuffers +-) +- +-# Download a protoc binary from Internet if needed +-if(CMAKE_CROSSCOMPILING AND 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. +- message("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("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("Use prebuilt protoc") +- set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc) +- set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE}) +- endif() +- elseif ((CMAKE_SYSTEM_NAME STREQUAL "Emscripten" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "iOS") AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") +- 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") +- set(ONNX_CUSTOM_PROTOC_EXECUTABLE ${protoc_binary_SOURCE_DIR}/bin/protoc) +- set(PROTOC_EXECUTABLE ${ONNX_CUSTOM_PROTOC_EXECUTABLE}) +- endif() +- endif() +-endif() ++find_package(flatbuffers CONFIG REQUIRED) # flatbuffers::flatbuffers ++list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES flatbuffers::flatbuffers) + + #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() +-FetchContent_Declare( +- Protobuf +- URL ${DEP_URL_protobuf} +- URL_HASH SHA1=${DEP_SHA1_protobuf} +- PATCH_COMMAND ${ONNXRUNTIME_PROTOBUF_PATCH_COMMAND} +- FIND_PACKAGE_ARGS 3.21.12 NAMES Protobuf +-) +-set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests" FORCE) +-if (CMAKE_SYSTEM_NAME STREQUAL "Android") +- set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "Build protobuf tests" FORCE) +- set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build 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() ++find_package(protobuf CONFIG REQUIRED) # protobuf::libprotobuf protobuf::libprotobuf-lite ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES protobuf::libprotobuf) + + include(protobuf_function) + #protobuf end + +-set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE) +-set(USE_SYSTEM_TZ_DB ON CACHE BOOL "" FORCE) ++find_package(date CONFIG REQUIRED) # date::date date::date-tz ++list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES date::date) + +-FetchContent_Declare( +- date +- URL ${DEP_URL_date} +- URL_HASH SHA1=${DEP_SHA1_date} +- ) +-onnxruntime_fetchcontent_makeavailable(date) + + +- +-FetchContent_Declare( +- mp11 +- URL ${DEP_URL_mp11} +- URL_HASH SHA1=${DEP_SHA1_mp11} +-) ++find_package(Boost REQUIRED) ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES Boost::headers) ++find_path(BOOST_INCLUDEDIR "boost/mp11.hpp" REQUIRED) ++add_library(Boost::mp11 ALIAS Boost::headers) # note: replace Boost::mp11 to Boost::headers + + set(JSON_BuildTests OFF CACHE INTERNAL "") + set(JSON_Install OFF CACHE INTERNAL "") + 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 +-) ++find_package(nlohmann_json CONFIG REQUIRED) # nlohmann_json::nlohmann_json ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES nlohmann_json::nlohmann_json) + + #TODO: include clog first + if (onnxruntime_ENABLE_CPUINFO) +@@ -265,59 +140,22 @@ if (CPUINFO_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 "") +- +- FetchContent_Declare( +- pytorch_cpuinfo +- URL ${DEP_URL_pytorch_cpuinfo} +- URL_HASH SHA1=${DEP_SHA1_pytorch_cpuinfo} +- FIND_PACKAGE_ARGS NAMES cpuinfo +- ) +- ++ find_package(cpuinfo CONFIG REQUIRED) # cpuinfo::cpuinfo ++ list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo) + 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) +- endif() ++ find_package(nsync CONFIG REQUIRED) ++ list(APPEND onnxruntime_EXTERNAL_DEPENDENCIES nsync::nsync_cpp) + 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 +- ) +-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() +- +-FetchContent_Declare( +- safeint +- URL ${DEP_URL_safeint} +- URL_HASH SHA1=${DEP_SHA1_safeint} +-) ++find_package(Microsoft.GSL CONFIG REQUIRED) # Microsoft.GSL::GSL ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES Microsoft.GSL::GSL) + + # The next line will generate an error message "fatal: not a git repository", but it is ok. It is from flatbuffers +-onnxruntime_fetchcontent_makeavailable(Protobuf nlohmann_json mp11 re2 safeint GSL flatbuffers) + if(NOT flatbuffers_FOUND) + if(NOT TARGET flatbuffers::flatbuffers) + add_library(flatbuffers::flatbuffers ALIAS flatbuffers) +@@ -344,9 +182,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}") +@@ -390,30 +225,15 @@ if (onnxruntime_USE_FULL_PROTOBUF) else() - set(CPUINFO_SUPPORTED FALSE) -@@ -1559,19 +1561,30 @@ else() - set(ONNX_USE_LITE_PROTO OFF CACHE BOOL "" FORCE) + set(PROTOBUF_LIB protobuf::libprotobuf-lite) endif() ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${PROTOBUF_LIB}) + + + # 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(ONNX CONFIG REQUIRED) ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES onnx onnx_proto) + + +-if (CPUINFO_SUPPORTED) ++if (false) + onnxruntime_fetchcontent_makeavailable(pytorch_cpuinfo) + if (pytorch_cpuinfo_SOURCE_DIR) + # shouldn't need to define these aliases after we use a version of cpuinfo with this commit: +@@ -425,20 +245,19 @@ endif() + + + +-include(eigen) +-include(wil) ++find_package(Eigen3 CONFIG REQUIRED) ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES Eigen3::Eigen) -if (NOT onnxruntime_MINIMAL_BUILD) -- add_subdirectory(external/onnx EXCLUDE_FROM_ALL) +- onnxruntime_fetchcontent_makeavailable(onnx) -else() - include(onnx_minimal) -endif() -+find_path(ONNX_INCLUDE_DIR NAMES "onnx/common/version.h" REQUIRED) -+find_library(ONNX_LIBRARY NAMES onnx REQUIRED) -+find_library(ONNX_PROTO_LIBRARY NAMES onnx_proto REQUIRED) ++find_package(wil CONFIG REQUIRED) ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES WIL::WIL) + set(GSL_TARGET "Microsoft.GSL::GSL") + set(GSL_INCLUDE_DIR "$") + + add_library(safeint_interface INTERFACE) +-target_include_directories(safeint_interface INTERFACE ${safeint_SOURCE_DIR}) ++find_path(SAFEINT_INCLUDE_DIRS "SafeInt.hpp" REQUIRED) ++target_include_directories(safeint_interface INTERFACE ${SAFEINT_INCLUDE_DIRS}) ++list(APPEND onnxruntime_EXTERNAL_LIBRARIES safeint_interface) + + # XNNPACK EP + if (onnxruntime_USE_XNNPACK) +@@ -446,31 +265,18 @@ if (onnxruntime_USE_XNNPACK) + message(FATAL_ERROR "XNNPACK EP requires the internal NHWC contrib ops to be available " + "but onnxruntime_DISABLE_CONTRIB_OPS is ON") + endif() +- include(xnnpack) ++ find_package(xnnpack CONFIG REQUIRED) # xnnpack ++ find_library(PTHREADPOOL_LIBRARY NAMES pthreadpool REQUIRED) ++ list(APPEND onnxruntime_EXTERNAL_LIBRARIES xnnpack ${PTHREADPOOL_LIBRARY}) + 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) ++ find_package(mimalloc CONFIG REQUIRED) # 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_interface) +-# 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) +- -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() --set_target_properties(onnx PROPERTIES FOLDER "External/ONNX") --set_target_properties(onnx_proto PROPERTIES FOLDER "External/ONNX") -+add_library(onnx STATIC IMPORTED GLOBAL) -+set_target_properties(onnx -+PROPERTIES -+ INTERFACE_INCLUDE_DIRECTORIES "${ONNX_INCLUDE_DIR}" -+ INTERFACE_COMPILE_DEFINITIONS "ONNX_ML" -+ IMPORTED_IMPLIB "${ONNX_LIBRARY}" -+ IMPORTED_LOCATION "${ONNX_LIBRARY}" -+) - -+add_library(onnx_proto STATIC IMPORTED GLOBAL) -+set_target_properties(onnx_proto -+PROPERTIES -+ INTERFACE_INCLUDE_DIRECTORIES "${ONNX_INCLUDE_DIR}" -+ INTERFACE_COMPILE_DEFINITIONS "ONNX_ML" -+ IMPORTED_IMPLIB "${ONNX_PROTO_LIBRARY}" -+ IMPORTED_LOCATION "${ONNX_PROTO_LIBRARY}" -+) -+if(TRUE) -+ add_compile_definitions(ONNX_NAMESPACE=onnx ONNX_ML=1) -+endif() - # fix a warning in onnx code we can't do anything about - if (MSVC) -@@ -1999,7 +2012,7 @@ if (onnxruntime_ENABLE_EAGER_MODE) - list(APPEND ONNXRUNTIME_TARGETS onnxruntime_eager) + if (onnxruntime_RUN_ONNX_TESTS) + add_definitions(-DORT_RUN_EXTERNAL_ONNX_TESTS) +@@ -492,14 +298,8 @@ 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} +- ) +- set(CXXOPTS_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +- set(CXXOPTS_BUILD_TESTS OFF CACHE BOOL "" FORCE) +- onnxruntime_fetchcontent_makeavailable(cxxopts) ++ find_package(cxxopts CONFIG REQUIRED) ++ list(APPEND onnxruntime_EXTERNAL_LIBRARIES cxxopts::cxxopts) endif() - foreach(target_name ${ONNXRUNTIME_TARGETS}) -- include(${target_name}.cmake) -+ include(${target_name}.cmake) # - endforeach() - if (CMAKE_SYSTEM_NAME STREQUAL "Android") -@@ -2010,7 +2023,7 @@ if (WIN32) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${SYS_PATH_LIB}) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES debug Dbghelp) - else() -- list(APPEND onnxruntime_EXTERNAL_LIBRARIES nsync_cpp) -+ list(APPEND onnxruntime_EXTERNAL_LIBRARIES unofficial::nsync::nsync_cpp) - list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${CMAKE_DL_LIBS} Threads::Threads) - endif() - -diff --git a/cmake/external/xnnpack.cmake b/cmake/external/xnnpack.cmake -index 25e63ea..98a7c08 100644 ---- a/cmake/external/xnnpack.cmake -+++ b/cmake/external/xnnpack.cmake -@@ -1,27 +1,11 @@ --set(XNNPACK_DIR external/XNNPACK) --set(XNNPACK_INCLUDE_DIR ${XNNPACK_DIR}/include) --set(XNNPACK_USE_SYSTEM_LIBS ON CACHE INTERNAL "") --set(XNNPACK_BUILD_TESTS OFF CACHE INTERNAL "") --set(XNNPACK_BUILD_BENCHMARKS OFF CACHE INTERNAL "") --set(FP16_BUILD_TESTS OFF CACHE INTERNAL "") --set(FP16_BUILD_BENCHMARKS OFF CACHE INTERNAL "") --set(CLOG_SOURCE_DIR "${PYTORCH_CPUINFO_DIR}/deps/clog") --set(CPUINFO_SOURCE_DIR ${PYTORCH_CPUINFO_DIR}) -- - if (onnxruntime_BUILD_WEBASSEMBLY) - execute_process(COMMAND git apply --ignore-space-change --ignore-whitespace ${PROJECT_SOURCE_DIR}/patches/xnnpack/AddEmscriptenSupport.patch WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/${XNNPACK_DIR}) - endif() + message("Finished fetching external dependencies") +diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake +index 59ebf8e..c83e6a2 100644 +--- a/cmake/onnxruntime.cmake ++++ b/cmake/onnxruntime.cmake +@@ -255,7 +255,7 @@ install(TARGETS onnxruntime + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/onnxruntime + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +- RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}) + --add_subdirectory(external/FP16) --add_subdirectory(external/pthreadpool) --add_subdirectory(external/XNNPACK) -- --set_target_properties(fp16 PROPERTIES FOLDER "External/Xnnpack") --set_target_properties(pthreadpool PROPERTIES FOLDER "External/Xnnpack") --set_target_properties(XNNPACK PROPERTIES FOLDER "External/Xnnpack") -+find_package(unofficial-pthreadpool CONFIG REQUIRED) # unofficial::pthreadpool -+find_package(xnnpack CONFIG REQUIRED) # xnnpack - --set(onnxruntime_EXTERNAL_LIBRARIES_XNNPACK XNNPACK pthreadpool) --list(APPEND onnxruntime_EXTERNAL_LIBRARIES ${onnxruntime_EXTERNAL_LIBRARIES_XNNPACK}) -+list(APPEND onnxruntime_EXTERNAL_LIBRARIES xnnpack unofficial::pthreadpool) - - # the XNNPACK CMake setup doesn't include the WASM kernels so we have to manually set those up - if (onnxruntime_BUILD_WEBASSEMBLY) diff --git a/cmake/onnxruntime_common.cmake b/cmake/onnxruntime_common.cmake -index a8ca9c9..0f083c9 100644 +index 687a231..f44f4f9 100644 --- a/cmake/onnxruntime_common.cmake +++ b/cmake/onnxruntime_common.cmake -@@ -211,14 +211,17 @@ if (ARM64 OR ARM OR X86 OR X64 OR X86_64) - if((WIN32 AND NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib) OR ((ARM64 OR ARM) AND MSVC)) - # msvc compiler report syntax error with cpuinfo arm source files - # and cpuinfo does not have code for getting arm uarch info under windows -+ # patched in https://github.com/luncliff/vcpkg-registry -+ target_link_libraries(onnxruntime_common cpuinfo::cpuinfo) -+ list(APPEND onnxruntime_EXTERNAL_LIBRARIES kernel32 cpuinfo::cpuinfo cpuinfo::clog) - else() - # Link cpuinfo if supported - # Using it mainly in ARM with Android. +@@ -208,7 +208,7 @@ if (ARM64 OR ARM OR X86 OR X64 OR X86_64) # Its functionality in detecting x86 cpu features are lacking, so is support for Windows. - if (CPUINFO_SUPPORTED) -- target_link_libraries(onnxruntime_common cpuinfo) -- list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo clog) -+ target_link_libraries(onnxruntime_common cpuinfo::cpuinfo) -+ list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo cpuinfo::clog) + onnxruntime_add_include_to_target(onnxruntime_common cpuinfo::cpuinfo) +- list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo cpuinfo::clog) ++ list(APPEND onnxruntime_EXTERNAL_LIBRARIES cpuinfo::cpuinfo) endif() endif() endif() +diff --git a/cmake/onnxruntime_mlas.cmake b/cmake/onnxruntime_mlas.cmake +index e0ccc50..819ffba 100644 +--- a/cmake/onnxruntime_mlas.cmake ++++ b/cmake/onnxruntime_mlas.cmake +@@ -609,7 +609,7 @@ if (NOT onnxruntime_ORT_MINIMAL_BUILD) + + target_link_libraries(onnxruntime_mlas_q4dq PRIVATE ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common) + if (CPUINFO_SUPPORTED AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") +- target_link_libraries(onnxruntime_mlas_q4dq PRIVATE cpuinfo) ++ target_link_libraries(onnxruntime_mlas_q4dq PRIVATE cpuinfo::cpuinfo) + endif() + if(NOT WIN32) + target_link_libraries(onnxruntime_mlas_q4dq PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS}) diff --git a/cmake/onnxruntime_providers.cmake b/cmake/onnxruntime_providers.cmake -index 77eac4b..6fe1263 100644 +index 03360ff..8a0c937 100644 --- a/cmake/onnxruntime_providers.cmake +++ b/cmake/onnxruntime_providers.cmake -@@ -521,10 +521,10 @@ if (onnxruntime_USE_CUDA) - - if(APPLE) - set_property(TARGET onnxruntime_providers_cuda APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker -exported_symbols_list ${ONNXRUNTIME_ROOT}/core/providers/cuda/exported_symbols.lst") -- target_link_libraries(onnxruntime_providers_cuda PRIVATE nsync_cpp) -+ target_link_libraries(onnxruntime_providers_cuda PRIVATE unofficial::nsync::nsync_cpp) - elseif(UNIX) - set_property(TARGET onnxruntime_providers_cuda APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/core/providers/cuda/version_script.lds -Xlinker --gc-sections") -- target_link_libraries(onnxruntime_providers_cuda PRIVATE nsync_cpp) -+ target_link_libraries(onnxruntime_providers_cuda PRIVATE unofficial::nsync::nsync_cpp) - elseif(WIN32) - set_property(TARGET onnxruntime_providers_cuda APPEND_STRING PROPERTY LINK_FLAGS "-DEF:${ONNXRUNTIME_ROOT}/core/providers/cuda/symbols.def") - else() -@@ -577,10 +577,10 @@ if (onnxruntime_USE_DNNL) - INSTALL_RPATH "@loader_path" - BUILD_WITH_INSTALL_RPATH TRUE - INSTALL_RPATH_USE_LINK_PATH FALSE) -- target_link_libraries(onnxruntime_providers_dnnl PRIVATE nsync_cpp) -+ target_link_libraries(onnxruntime_providers_dnnl PRIVATE unofficial::nsync::nsync_cpp) - elseif(UNIX) - set_property(TARGET onnxruntime_providers_dnnl APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/core/providers/dnnl/version_script.lds -Xlinker --gc-sections -Xlinker -rpath=\$ORIGIN") -- target_link_libraries(onnxruntime_providers_dnnl PRIVATE nsync_cpp) -+ target_link_libraries(onnxruntime_providers_dnnl PRIVATE unofficial::nsync::nsync_cpp) - elseif(WIN32) - set_property(TARGET onnxruntime_providers_dnnl APPEND_STRING PROPERTY LINK_FLAGS "-DEF:${ONNXRUNTIME_ROOT}/core/providers/dnnl/symbols.def") - else() -@@ -673,11 +673,11 @@ if (onnxruntime_USE_TENSORRT) - - if(APPLE) - set_property(TARGET onnxruntime_providers_tensorrt APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker -exported_symbols_list ${ONNXRUNTIME_ROOT}/core/providers/tensorrt/exported_symbols.lst") -- target_link_libraries(onnxruntime_providers_tensorrt PRIVATE nsync_cpp) -+ target_link_libraries(onnxruntime_providers_tensorrt PRIVATE unofficial::nsync::nsync_cpp) - elseif(UNIX) - set_property(TARGET onnxruntime_providers_tensorrt APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations") - set_property(TARGET onnxruntime_providers_tensorrt APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/core/providers/tensorrt/version_script.lds -Xlinker --gc-sections") -- target_link_libraries(onnxruntime_providers_tensorrt PRIVATE nsync_cpp stdc++fs) -+ target_link_libraries(onnxruntime_providers_tensorrt PRIVATE unofficial::nsync::nsync_cpp stdc++fs) - elseif(WIN32) - set_property(TARGET onnxruntime_providers_tensorrt APPEND_STRING PROPERTY LINK_FLAGS "-DEF:${ONNXRUNTIME_ROOT}/core/providers/tensorrt/symbols.def") - else() -@@ -1217,7 +1217,7 @@ if (onnxruntime_USE_MIGRAPHX) - target_compile_options(onnxruntime_providers_migraphx PRIVATE -Wno-error=sign-compare) - set_property(TARGET onnxruntime_providers_migraphx APPEND_STRING PROPERTY COMPILE_FLAGS "-Wno-deprecated-declarations") - set_property(TARGET onnxruntime_providers_migraphx APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/core/providers/migraphx/version_script.lds -Xlinker --gc-sections") -- target_link_libraries(onnxruntime_providers_migraphx PRIVATE nsync_cpp stdc++fs) -+ target_link_libraries(onnxruntime_providers_migraphx PRIVATE unofficial::nsync::nsync_cpp stdc++fs) - - install(TARGETS onnxruntime_providers_migraphx +@@ -366,7 +366,7 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD + install(TARGETS onnxruntime_providers_shared ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -@@ -1445,7 +1445,7 @@ if (onnxruntime_USE_ROCM) - - if(UNIX) - set_property(TARGET onnxruntime_providers_rocm APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${ONNXRUNTIME_ROOT}/core/providers/rocm/version_script.lds -Xlinker --gc-sections") -- target_link_libraries(onnxruntime_providers_rocm PRIVATE nsync_cpp) -+ target_link_libraries(onnxruntime_providers_rocm PRIVATE unofficial::nsync::nsync_cpp) - else() - message(FATAL_ERROR "onnxruntime_providers_rocm unknown platform, need to specify shared library exports for it") - endif() -@@ -1521,8 +1521,9 @@ if (onnxruntime_USE_XNNPACK) + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +- RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) + endif() + +@@ -1786,6 +1786,7 @@ endif() + + if (onnxruntime_USE_XNNPACK) + add_compile_definitions(USE_XNNPACK=1) ++ find_package(xnnpack CONFIG REQUIRED) # xnnpack + + file(GLOB_RECURSE onnxruntime_providers_xnnpack_cc_srcs CONFIGURE_DEPENDS + "${ONNXRUNTIME_INCLUDE_DIR}/core/providers/xnnpack/*.h" +@@ -1799,7 +1800,7 @@ if (onnxruntime_USE_XNNPACK) source_group(TREE ${REPO_ROOT} FILES ${onnxruntime_providers_xnnpack_cc_srcs}) onnxruntime_add_static_library(onnxruntime_providers_xnnpack ${onnxruntime_providers_xnnpack_cc_srcs}) onnxruntime_add_include_to_target(onnxruntime_providers_xnnpack -- onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} XNNPACK pthreadpool -+ onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} xnnpack unofficial::pthreadpool +- onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} XNNPACK pthreadpool Boost::mp11 safeint_interface ++ onnxruntime_common onnxruntime_framework onnx onnx_proto ${PROTOBUF_LIB} xnnpack pthreadpool Boost::mp11 safeint_interface ) -+ target_link_libraries(onnxruntime_providers_xnnpack PUBLIC xnnpack unofficial::pthreadpool) add_dependencies(onnxruntime_providers_xnnpack onnx ${onnxruntime_EXTERNAL_DEPENDENCIES}) - set_target_properties(onnxruntime_providers_xnnpack PROPERTIES FOLDER "ONNXRuntime") +diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake +index 695e218..008bdf3 100644 +--- a/cmake/onnxruntime_unittests.cmake ++++ b/cmake/onnxruntime_unittests.cmake +@@ -1122,7 +1122,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) + target_link_libraries(onnxruntime_mlas_benchmark PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS}) + endif() + if (CPUINFO_SUPPORTED AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") +- target_link_libraries(onnxruntime_mlas_benchmark PRIVATE cpuinfo) ++ target_link_libraries(onnxruntime_mlas_benchmark PRIVATE cpuinfo::cpuinfo) + endif() + set_target_properties(onnxruntime_mlas_benchmark PROPERTIES FOLDER "ONNXRuntimeTest") + endif() +@@ -1365,7 +1365,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) + ${CMAKE_CURRENT_BINARY_DIR}) + target_link_libraries(onnxruntime_mlas_test PRIVATE GTest::gtest GTest::gmock ${ONNXRUNTIME_MLAS_LIBS} onnxruntime_common) + if (CPUINFO_SUPPORTED AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") +- target_link_libraries(onnxruntime_mlas_test PRIVATE cpuinfo) ++ target_link_libraries(onnxruntime_mlas_test PRIVATE cpuinfo::cpuinfo) + endif() + if(NOT WIN32) + target_link_libraries(onnxruntime_mlas_test PRIVATE nsync::nsync_cpp ${CMAKE_DL_LIBS}) +diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt +index ab5ed03..8cf6dd1 100644 +--- a/cmake/CMakeLists.txt ++++ b/cmake/CMakeLists.txt +@@ -861,7 +861,7 @@ function(onnxruntime_set_compile_flags target_name) + if (onnxruntime_ENABLE_ATEN) + target_compile_definitions(${target_name} PRIVATE ENABLE_ATEN) + endif() +- set_target_properties(${target_name} PROPERTIES COMPILE_WARNING_AS_ERROR ON) ++ set_target_properties(${target_name} PROPERTIES COMPILE_WARNING_AS_ERROR OFF) + if (onnxruntime_USE_CUDA) + # Suppress a "conversion_function_not_usable" warning in gsl/span + target_compile_options(${target_name} PRIVATE "$<$:SHELL:-Xcudafe \"--diag_suppress=conversion_function_not_usable\">") +diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake +index c83e6a2..d2d43ed 100644 +--- a/cmake/onnxruntime.cmake ++++ b/cmake/onnxruntime.cmake +@@ -305,6 +305,9 @@ if(onnxruntime_BUILD_APPLE_FRAMEWORK) + + # Go through all the static libraries, and create symbolic links + foreach(_LIB ${onnxruntime_INTERNAL_LIBRARIES} ${onnxruntime_EXTERNAL_LIBRARIES}) ++ if(NOT TARGET ${_LIB}) ++ continue() ++ endif() + GET_TARGET_PROPERTY(_LIB_TYPE ${_LIB} TYPE) + if(_LIB_TYPE STREQUAL "STATIC_LIBRARY") + add_custom_command(TARGET onnxruntime POST_BUILD COMMAND ${CMAKE_COMMAND} -E create_symlink $ ${STATIC_LIB_DIR}/$) +diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake +index 067b5ce..f02412f 100644 +--- a/cmake/onnxruntime_unittests.cmake ++++ b/cmake/onnxruntime_unittests.cmake +@@ -662,6 +662,7 @@ if(onnxruntime_USE_COREML) + endif() + + if(onnxruntime_USE_XNNPACK) ++ find_package(xnnpack CONFIG REQUIRED) + list(APPEND onnxruntime_test_framework_src_patterns ${TEST_SRC_DIR}/providers/xnnpack/*) + list(APPEND onnxruntime_test_framework_libs onnxruntime_providers_xnnpack) + list(APPEND onnxruntime_test_providers_dependencies onnxruntime_providers_xnnpack) +@@ -698,6 +699,7 @@ else() + target_compile_definitions(onnxruntime_test_utils PUBLIC -DNSYNC_ATOMIC_CPP11) + target_include_directories(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${ONNXRUNTIME_ROOT}) + onnxruntime_add_include_to_target(onnxruntime_test_utils nsync::nsync_cpp) ++ target_link_libraries(onnxruntime_test_utils PUBLIC nsync::nsync_cpp) + endif() + if (onnxruntime_USE_NCCL) + target_include_directories(onnxruntime_test_utils PRIVATE ${NCCL_INCLUDE_DIRS}) +@@ -706,7 +708,9 @@ if (onnxruntime_USE_ROCM) + target_include_directories(onnxruntime_test_utils PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/amdgpu/orttraining) + endif() + onnxruntime_add_include_to_target(onnxruntime_test_utils onnxruntime_common onnxruntime_framework onnxruntime_session GTest::gtest GTest::gmock onnx onnx_proto flatbuffers::flatbuffers nlohmann_json::nlohmann_json Boost::mp11 safeint_interface) +- ++if(NOT WIN32) ++ target_link_libraries(onnxruntime_test_utils PUBLIC GTest::gtest_main) ++endif() + + + if (onnxruntime_USE_DML) diff --git a/ports/onnxruntime/fix-source-flatbuffers.patch b/ports/onnxruntime/fix-source-flatbuffers.patch new file mode 100644 index 00000000..b861828a --- /dev/null +++ b/ports/onnxruntime/fix-source-flatbuffers.patch @@ -0,0 +1,162 @@ +diff --git a/onnxruntime/core/framework/kernel_type_str_resolver_utils.h b/onnxruntime/core/framework/kernel_type_str_resolver_utils.h +index 3d06013..4121534 100644 +--- a/onnxruntime/core/framework/kernel_type_str_resolver_utils.h ++++ b/onnxruntime/core/framework/kernel_type_str_resolver_utils.h +@@ -10,9 +10,7 @@ + #include "core/framework/kernel_type_str_resolver.h" + #include "core/graph/op_identifier.h" + +-namespace flatbuffers { +-class DetachedBuffer; +-} ++#include + + namespace onnxruntime::kernel_type_str_resolver_utils { + +diff --git a/include/onnxruntime/core/graph/graph.h b/include/onnxruntime/core/graph/graph.h +index 81015b2..a683a57 100644 +--- a/include/onnxruntime/core/graph/graph.h ++++ b/include/onnxruntime/core/graph/graph.h +@@ -43,11 +43,7 @@ + #include "core/graph/node_arg.h" + #include "core/graph/ort_format_load_options.h" + +-namespace flatbuffers { +-class FlatBufferBuilder; +-template +-struct Offset; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + class Graph; +diff --git a/onnxruntime/core/flatbuffers/flatbuffers_utils.h b/onnxruntime/core/flatbuffers/flatbuffers_utils.h +index 4e7db4d..5f21a8c 100644 +--- a/onnxruntime/core/flatbuffers/flatbuffers_utils.h ++++ b/onnxruntime/core/flatbuffers/flatbuffers_utils.h +@@ -13,17 +13,7 @@ namespace ONNX_NAMESPACE { + class ValueInfoProto; + } + +-namespace flatbuffers { +-class FlatBufferBuilder; +- +-template +-struct Offset; +- +-struct String; +- +-template +-class Vector; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + +diff --git a/onnxruntime/core/framework/kernel_type_str_resolver.h b/onnxruntime/core/framework/kernel_type_str_resolver.h +index 75fc2fa..046cce1 100644 +--- a/onnxruntime/core/framework/kernel_type_str_resolver.h ++++ b/onnxruntime/core/framework/kernel_type_str_resolver.h +@@ -18,11 +18,7 @@ + #include "core/graph/graph.h" + #include "core/platform/ort_mutex.h" + +-namespace flatbuffers { +-class FlatBufferBuilder; +-template +-struct Offset; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + +diff --git a/onnxruntime/core/framework/session_state.h b/onnxruntime/core/framework/session_state.h +index d546f26..1d8d928 100644 +--- a/onnxruntime/core/framework/session_state.h ++++ b/onnxruntime/core/framework/session_state.h +@@ -43,11 +43,7 @@ + #include "core/framework/program_region.h" + #endif + +-namespace flatbuffers { +-class FlatBufferBuilder; +-template +-struct Offset; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + +diff --git a/onnxruntime/core/graph/graph_flatbuffers_utils.h b/onnxruntime/core/graph/graph_flatbuffers_utils.h +index f4899ff..1027e07 100644 +--- a/onnxruntime/core/graph/graph_flatbuffers_utils.h ++++ b/onnxruntime/core/graph/graph_flatbuffers_utils.h +@@ -18,11 +18,7 @@ class SparseTensorProto; + #endif // !defined(DISABLE_SPARSE_TENSORS) + } // namespace ONNX_NAMESPACE + +-namespace flatbuffers { +-class FlatBufferBuilder; +-template +-struct Offset; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + +diff --git a/onnxruntime/core/graph/model.h b/onnxruntime/core/graph/model.h +index 5337211..bccbda7 100644 +--- a/onnxruntime/core/graph/model.h ++++ b/onnxruntime/core/graph/model.h +@@ -15,11 +15,7 @@ + #include "core/graph/function_template.h" + #endif + +-namespace flatbuffers { +-class FlatBufferBuilder; +-template +-struct Offset; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + +diff --git a/onnxruntime/core/graph/op_identifier_utils.h b/onnxruntime/core/graph/op_identifier_utils.h +index 265364a..f91bb5f 100644 +--- a/onnxruntime/core/graph/op_identifier_utils.h ++++ b/onnxruntime/core/graph/op_identifier_utils.h +@@ -9,14 +9,7 @@ + #include "core/graph/graph.h" + #include "core/graph/onnx_protobuf.h" + +-namespace flatbuffers { +-class FlatBufferBuilder; +- +-template +-struct Offset; +- +-struct String; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + +diff --git a/onnxruntime/core/graph/runtime_optimization_record_container.h b/onnxruntime/core/graph/runtime_optimization_record_container.h +index 5db784f..00f6598 100644 +--- a/onnxruntime/core/graph/runtime_optimization_record_container.h ++++ b/onnxruntime/core/graph/runtime_optimization_record_container.h +@@ -12,13 +12,7 @@ + #include "core/common/common.h" + #include "core/graph/runtime_optimization_record.h" + +-namespace flatbuffers { +-class FlatBufferBuilder; +-template +-struct Offset; +-template +-class Vector; +-} // namespace flatbuffers ++#include + + namespace onnxruntime { + diff --git a/ports/onnxruntime/fix-sources.patch b/ports/onnxruntime/fix-sources.patch deleted file mode 100644 index 2c9c0c53..00000000 --- a/ports/onnxruntime/fix-sources.patch +++ /dev/null @@ -1,187 +0,0 @@ -diff --git a/onnxruntime/core/common/safeint.h b/onnxruntime/core/common/safeint.h -index 263e936..3ee70f3 100644 ---- a/onnxruntime/core/common/safeint.h -+++ b/onnxruntime/core/common/safeint.h -@@ -32,7 +32,7 @@ class SafeIntExceptionHandler { - #pragma GCC diagnostic ignored "-Wunused-but-set-parameter" - #endif - #endif --#include "safeint/SafeInt.hpp" -+#include "SafeInt.hpp" - #if defined(__GNUC__) - #pragma GCC diagnostic pop - #endif -diff --git a/onnxruntime/core/flatbuffers/flatbuffers_utils.cc b/onnxruntime/core/flatbuffers/flatbuffers_utils.cc -index 8382c42..dedee5f 100644 ---- a/onnxruntime/core/flatbuffers/flatbuffers_utils.cc -+++ b/onnxruntime/core/flatbuffers/flatbuffers_utils.cc -@@ -35,9 +35,9 @@ static flatbuffers::Offset SaveTensorDimensionOrtFormat( - auto denotation = SaveStringToOrtFormat(builder, tensor_shape_dim.has_denotation(), tensor_shape_dim.denotation()); - flatbuffers::Offset dim_val; - if (tensor_shape_dim.has_dim_param()) { -- dim_val = fbs::CreateDimensionValueDirect(builder, fbs::DimensionValueType::PARAM, 0, tensor_shape_dim.dim_param().c_str()); -+ dim_val = fbs::CreateDimensionValueDirect(builder, fbs::DimensionValueType::DimensionValueType_PARAM, 0, tensor_shape_dim.dim_param().c_str()); - } else if (tensor_shape_dim.has_dim_value()) { -- dim_val = fbs::CreateDimensionValueDirect(builder, fbs::DimensionValueType::VALUE, tensor_shape_dim.dim_value()); -+ dim_val = fbs::CreateDimensionValueDirect(builder, fbs::DimensionValueType::DimensionValueType_VALUE, tensor_shape_dim.dim_value()); - } else { - dim_val = fbs::CreateDimensionValueDirect(builder); - } -@@ -96,7 +96,7 @@ static Status SaveTypeInfoOrtFormat(flatbuffers::FlatBufferBuilder& builder, - const TypeProto& type_proto, - flatbuffers::Offset& fbs_type_info) { - auto denotation = SaveStringToOrtFormat(builder, type_proto.has_denotation(), type_proto.denotation()); -- auto value_type = fbs::TypeInfoValue::tensor_type; -+ auto value_type = fbs::TypeInfoValue_tensor_type; - flatbuffers::Offset value; - auto value_case = type_proto.value_case(); - switch (value_case) { -@@ -107,14 +107,14 @@ static Status SaveTypeInfoOrtFormat(flatbuffers::FlatBufferBuilder& builder, - value = fbs_tensor_type.Union(); - } break; - case TypeProto::kSequenceType: { -- value_type = fbs::TypeInfoValue::sequence_type; -+ value_type = fbs::TypeInfoValue_sequence_type; - flatbuffers::Offset fbs_sequence_type; - ORT_RETURN_IF_ERROR( - SaveSequenceTypeOrtFormat(builder, type_proto.sequence_type(), fbs_sequence_type)); - value = fbs_sequence_type.Union(); - } break; - case TypeProto::kMapType: { -- value_type = fbs::TypeInfoValue::map_type; -+ value_type = fbs::TypeInfoValue_map_type; - flatbuffers::Offset fbs_map_type; - ORT_RETURN_IF_ERROR( - SaveMapTypeOrtFormat(builder, type_proto.map_type(), fbs_map_type)); -@@ -176,9 +176,9 @@ static Status LoadTensorDimensionOrtFormat(const fbs::Dimension& fbs_dim, - auto fbs_dim_val = fbs_dim.value(); - if (fbs_dim_val) { - auto type = fbs_dim_val->dim_type(); -- if (type == fbs::DimensionValueType::VALUE) -+ if (type == fbs::DimensionValueType::DimensionValueType_VALUE) - dim.set_dim_value(fbs_dim_val->dim_value()); -- else if (type == fbs::DimensionValueType::PARAM) { -+ else if (type == fbs::DimensionValueType::DimensionValueType_PARAM) { - auto fbs_dim_param = fbs_dim_val->dim_param(); - ORT_RETURN_IF(nullptr == fbs_dim_param, "dim_param value with no name. Invalid ORT format model."); - dim.set_dim_param(fbs_dim_param->str()); -@@ -237,15 +237,15 @@ static Status LoadTypeInfoOrtFormat(const fbs::TypeInfo& fbs_type_info, - TypeProto& type_proto) { - LOAD_STR_FROM_ORT_FORMAT(type_proto, denotation, fbs_type_info.denotation()); - auto value_type = fbs_type_info.value_type(); -- if (value_type == fbs::TypeInfoValue::tensor_type) { -+ if (value_type == fbs::TypeInfoValue_tensor_type) { - auto fbs_tensor_type = fbs_type_info.value_as_tensor_type(); - ORT_RETURN_IF(nullptr == fbs_tensor_type, "Null tensor type info. Invalid ORT format model."); - ORT_RETURN_IF_ERROR(LoadTensorTypeAndShapeOrtFormat(*fbs_tensor_type, *type_proto.mutable_tensor_type())); -- } else if (value_type == fbs::TypeInfoValue::sequence_type) { -+ } else if (value_type == fbs::TypeInfoValue_sequence_type) { - auto fbs_sequence_type = fbs_type_info.value_as_sequence_type(); - ORT_RETURN_IF(nullptr == fbs_sequence_type, "Null sequence type info. Invalid ORT format model."); - ORT_RETURN_IF_ERROR(LoadSequenceTypeOrtFormat(*fbs_sequence_type, *type_proto.mutable_sequence_type())); -- } else if (value_type == fbs::TypeInfoValue::map_type) { -+ } else if (value_type == fbs::TypeInfoValue_map_type) { - auto fbs_map_type = fbs_type_info.value_as_map_type(); - ORT_RETURN_IF(nullptr == fbs_map_type, "Null map type info. Invalid ORT format model."); - ORT_RETURN_IF_ERROR(LoadMapTypeOrtFormat(*fbs_map_type, *type_proto.mutable_map_type())); -diff --git a/onnxruntime/core/graph/graph_flatbuffers_utils.cc b/onnxruntime/core/graph/graph_flatbuffers_utils.cc -index d89bae6..225ef33 100644 ---- a/onnxruntime/core/graph/graph_flatbuffers_utils.cc -+++ b/onnxruntime/core/graph/graph_flatbuffers_utils.cc -@@ -108,44 +108,44 @@ Status SaveAttributeOrtFormat(flatbuffers::FlatBufferBuilder& builder, - auto doc_string = SaveStringToOrtFormat(builder, attr_proto.has_doc_string(), attr_proto.doc_string()); - auto type = static_cast(attr_proto.type()); - switch (type) { -- case fbs::AttributeType::FLOAT: { -+ case fbs::AttributeType::AttributeType_FLOAT: { - GET_FBS_ATTR(builder, type, f, attr_proto.f()); - } break; -- case fbs::AttributeType::INT: { -+ case fbs::AttributeType::AttributeType_INT: { - GET_FBS_ATTR(builder, type, i, attr_proto.i()); - } break; -- case fbs::AttributeType::STRING: { -+ case fbs::AttributeType::AttributeType_STRING: { - auto s = builder.CreateString(attr_proto.s()); - GET_FBS_ATTR(builder, type, s, s); - } break; -- case fbs::AttributeType::TENSOR: { -+ case fbs::AttributeType::AttributeType_TENSOR: { - flatbuffers::Offset fbs_tensor; - ORT_RETURN_IF_ERROR( - SaveInitializerOrtFormat(builder, attr_proto.t(), model_path, fbs_tensor)); - GET_FBS_ATTR(builder, type, t, fbs_tensor); - } break; -- case fbs::AttributeType::GRAPH: { -+ case fbs::AttributeType::AttributeType_GRAPH: { - ORT_RETURN_IF(nullptr == subgraph, "Graph attribute value was null. Invalid ORT format model."); - flatbuffers::Offset fbs_graph; - ORT_RETURN_IF_ERROR(subgraph->SaveToOrtFormat(builder, fbs_graph)); - GET_FBS_ATTR(builder, type, g, fbs_graph); - } break; -- case fbs::AttributeType::FLOATS: { -+ case fbs::AttributeType::AttributeType_FLOATS: { - GET_DATA_VEC(float, floats_vec_, attr_proto.floats()); - auto floats = builder.CreateVector(floats_vec_); - GET_FBS_ATTR(builder, type, floats, floats); - } break; -- case fbs::AttributeType::INTS: { -+ case fbs::AttributeType::AttributeType_INTS: { - GET_DATA_VEC(int64_t, ints_vec_, attr_proto.ints()); - auto ints = builder.CreateVector(ints_vec_); - GET_FBS_ATTR(builder, type, ints, ints); - } break; -- case fbs::AttributeType::STRINGS: { -+ case fbs::AttributeType::AttributeType_STRINGS: { - GET_DATA_VEC(std::string, strings_vec_, attr_proto.strings()); - auto strings = builder.CreateVectorOfStrings(strings_vec_); - GET_FBS_ATTR(builder, type, strings, strings); - } break; -- case fbs::AttributeType::TENSORS: { -+ case fbs::AttributeType::AttributeType_TENSORS: { - std::vector> fbs_tensors_vec; - fbs_tensors_vec.reserve(attr_proto.tensors().size()); - for (const auto& tensor : attr_proto.tensors()) { -@@ -184,7 +184,7 @@ Status LoadInitializerOrtFormat(const fbs::Tensor& fbs_tensor, - - auto fbs_data_type = fbs_tensor.data_type(); - initializer.set_data_type(static_cast(fbs_data_type)); -- if (fbs_data_type == fbs::TensorDataType::STRING) { -+ if (fbs_data_type == fbs::TensorDataType::TensorDataType_STRING) { - auto fbs_str_data = fbs_tensor.string_data(); - ORT_RETURN_IF(nullptr == fbs_str_data, "Missing string data for initializer. Invalid ORT format model."); - auto mutable_str_data = initializer.mutable_string_data(); -diff --git a/onnxruntime/core/framework/session_options.h b/onnxruntime/core/framework/session_options.h -index c301229..50e5e63 100644 ---- a/onnxruntime/core/framework/session_options.h -+++ b/onnxruntime/core/framework/session_options.h -@@ -11,6 +11,7 @@ - #include "core/optimizer/graph_transformer_level.h" - #include "core/util/thread_utils.h" - #include "core/framework/config_options.h" -+#include "core/framework/ort_value.h" - - namespace onnxruntime { - -diff --git a/onnxruntime/core/providers/xnnpack/nn/conv.cc b/onnxruntime/core/providers/xnnpack/nn/conv.cc -index d9f6134..8003d10 100644 ---- a/onnxruntime/core/providers/xnnpack/nn/conv.cc -+++ b/onnxruntime/core/providers/xnnpack/nn/conv.cc -@@ -60,7 +60,7 @@ Status CreateXnnpackKernel(const ConvAttributes& conv_attrs, - gsl::narrow(conv_attrs.group), 1, group_output_channels, - C, M, // input channel stride, output channel stride - W_data, B_data, -- output_min, output_max, flags, &p); -+ output_min, output_max, flags, xnn_caches_t{}, &p); - - } else { - status = xnn_create_convolution2d_nhwc_f32( -@@ -71,7 +71,7 @@ Status CreateXnnpackKernel(const ConvAttributes& conv_attrs, - gsl::narrow(conv_attrs.group), C, M, // groups, group_input_channels, group_output_channels - C, M, // input channel stride, output channel stride - W_data, B_data, -- output_min, output_max, flags, &p); -+ output_min, output_max, flags, xnn_caches_t{}, &p); - } - - if (status != xnn_status_success) { diff --git a/ports/onnxruntime/portfile.cmake b/ports/onnxruntime/portfile.cmake index 6bf8a062..aad5125a 100644 --- a/ports/onnxruntime/portfile.cmake +++ b/ports/onnxruntime/portfile.cmake @@ -1,19 +1,27 @@ if(NOT VCPKG_TARGET_IS_IOS) vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY) endif() +if(VCPKG_TARGET_IS_OSX AND ("framework" IN_LIST FEATURES)) + vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY) +endif() +vcpkg_find_acquire_program(NUGET) vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO microsoft/onnxruntime - REF v1.12.1 - SHA512 fc2e8be54fbeb32744c8882e61aa514be621eb621a073d05a85c6e2deac8c9bf1103e746711f5c33a4fa55a257807ba0159d9f23684f4926ff38b40591575d91 + REF v1.16.0 # e7a0495a874251e9747b2ce0683e0580282c54df + SHA512 ff448f7bcd0d91f129ff7d5bf54ab0ed8f4aed79c79a6e52043138d5cba180099fce5aaf00e7f959e2b3e9a3376bf4ec933428c076b097a2e4a96e1adfd9b05f PATCHES fix-cmake.patch - fix-sources.patch - # https://learn.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt - # support-windows10.patch + fix-source-flatbuffers.patch ) +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 @@ -22,106 +30,131 @@ message(STATUS "Using flatc: ${FLATC}") set(SCHEMA_DIR "${SOURCE_PATH}/onnxruntime/core/flatbuffers/schema") vcpkg_execute_required_process( - COMMAND ${FLATC} --cpp ort.fbs + COMMAND ${FLATC} --cpp --scoped-enums --filename-suffix ".fbs" ort.fbs LOGNAME codegen-flatc-cpp WORKING_DIRECTORY "${SCHEMA_DIR}" ) -file(REMOVE "${SCHEMA_DIR}/ort.fbs.h") -file(RENAME "${SCHEMA_DIR}/ort_generated.h" "${SCHEMA_DIR}/ort.fbs.h") - -if("xnnpack" IN_LIST FEATURES) - # see https://github.com/microsoft/onnxruntime/pull/11798 - set(PROVIDERS_DIR "${SOURCE_PATH}/include/onnxruntime/core/providers") - file(MAKE_DIRECTORY "${PROVIDERS_DIR}/xnnpack") - file(WRITE "${PROVIDERS_DIR}/xnnpack/xnnpack_provider_factory.h" "#pragma once") -endif() vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS FEATURES + python onnxruntime_ENABLE_PYTHON + python onnxruntime_ENABLE_LANGUAGE_INTEROP_OPS training onnxruntime_ENABLE_TRAINING - training onnxruntime_ENABLE_TRAINING_OPS + training onnxruntime_ENABLE_TRAINING_OPS # todo: port `tensorboard` cuda onnxruntime_USE_CUDA cuda onnxruntime_USE_NCCL tensorrt onnxruntime_USE_TENSORRT - tensorrt onnxruntime_TENSORRT_PLACEHOLDER_BUILDER + 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 test onnxruntime_BUILD_UNIT_TESTS + test onnxruntime_BUILD_BENCHMARKS + test onnxruntime_RUN_ONNX_TESTS framework onnxruntime_BUILD_APPLE_FRAMEWORK + framework onnxruntime_BUILD_OBJC INVERTED_FEATURES abseil onnxruntime_DISABLE_ABSEIL - ) -if(VCPKG_TARGET_IS_UWP) - set(CONFIG_OPTIONS WINDOWS_USE_MSBUILD) +if(VCPKG_TARGET_IS_WINDOWS OR VCPKG_TARGET_IS_UWP) + set(GENERATOR_OPTIONS WINDOWS_USE_MSBUILD) +elseif(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS) + set(GENERATOR_OPTIONS GENERATOR Xcode) else() - set(CONFIG_OPTIONS GENERATOR Ninja) + set(GENERATOR_OPTIONS GENERATOR Ninja) endif() if(VCPKG_TARGET_IS_WINDOWS) # target platform should be informed to activate SIMD properly if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") - list(APPEND GENERATOR_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="x64") + list(APPEND ARCH_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="x64") elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") - list(APPEND GENERATOR_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="Win32") + list(APPEND ARCH_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="Win32") elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") - list(APPEND GENERATOR_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="ARM64") + list(APPEND ARCH_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="ARM64") elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") - list(APPEND GENERATOR_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="ARM") + list(APPEND ARCH_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="ARM") else() message(WARNING "Unexpected architecture: ${VCPKG_TARGET_ARCHITECTURE}") - list(APPEND GENERATOR_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="${VCPKG_TARGET_ARCHITECTURE}") + list(APPEND ARCH_OPTIONS -DCMAKE_SYSTEM_PROCESSOR="${VCPKG_TARGET_ARCHITECTURE}") endif() endif() string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED) -vcpkg_find_acquire_program(PYTHON3) -message(STATUS "Using Python3: ${PYTHON3}") +if("python" IN_LIST FEATURES) + x_vcpkg_get_python_packages( + PYTHON_VERSION 3 + PACKAGES numpy sympy # flatbuffers protobuf + OUT_PYTHON_VAR PYTHON3 + ) + get_filename_component(PYTHON_PATH "${PYTHON3}" PATH) +else() + vcpkg_find_acquire_program(PYTHON3) + get_filename_component(PYTHON_PATH "${PYTHON3}" PATH) +endif() +message(STATUS "Using python3: ${PYTHON3}") +vcpkg_add_to_path(PREPEND "${PYTHON_PATH}") vcpkg_cmake_configure( SOURCE_PATH "${SOURCE_PATH}/cmake" - ${CONFIG_OPTIONS} + ${GENERATOR_OPTIONS} OPTIONS - ${GENERATOR_OPTIONS} + ${ARCH_OPTIONS} ${FEATURE_OPTIONS} + -DNUGET_EXE:FILEPATH:=${NUGET} -DPython_EXECUTABLE:FILEPATH=${PYTHON3} + -DProtobuf_PROTOC_EXECUTABLE:FILEPATH=${PROTOC} # -DProtobuf_USE_STATIC_LIBS=OFF -DBUILD_PKGCONFIG_FILES=ON -Donnxruntime_BUILD_SHARED_LIB=${BUILD_SHARED} - -Donnxruntime_BUILD_OBJC=${VCPKG_TARGET_IS_IOS} - -Donnxruntime_BUILD_NODEJS=OFF - -Donnxruntime_BUILD_JAVA=OFF - -Donnxruntime_BUILD_CSHARP=OFF -Donnxruntime_BUILD_WEBASSEMBLY=OFF -Donnxruntime_CROSS_COMPILING=${VCPKG_CROSSCOMPILING} - -Donnxruntime_PREFER_SYSTEM_LIB=ON -Donnxruntime_USE_FULL_PROTOBUF=ON - -Donnxruntime_USE_PREINSTALLED_EIGEN=ON -Deigen_SOURCE_PATH="${CURRENT_INSTALLED_DIR}/include" + -Donnxruntime_USE_PREINSTALLED_EIGEN=ON -Donnxruntime_USE_EXTENSIONS=OFF -Donnxruntime_USE_MPI=OFF # ${VCPKG_TARGET_IS_LINUX} -Donnxruntime_ENABLE_CPUINFO=ON - -Donnxruntime_ENABLE_MICROSOFT_INTERNAL=${VCPKG_TARGET_IS_WINDOWS} + -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 + # for ORT_BUILD_INFO + -DORT_GIT_COMMIT:STRING="e7a0495a874251e9747b2ce0683e0580282c54df" + -DORT_GIT_BRANCH:STRING="v1.16.0" OPTIONS_DEBUG -Donnxruntime_ENABLE_MEMLEAK_CHECKER=OFF -Donnxruntime_ENABLE_MEMORY_PROFILE=OFF -Donnxruntime_ENABLE_CUDA_PROFILING=ON -Donnxruntime_DEBUG_NODE_INPUTS_OUTPUTS=ON + MAYBE_UNUSED_VARIABLES + NUGET_EXE + onnxruntime_BUILD_WEBASSEMBLY + onnxruntime_TENSORRT_PLACEHOLDER_BUILDER + onnxruntime_USE_CUSTOM_DIRECTML ) -vcpkg_cmake_build(TARGET onnxruntime) +if("training" IN_LIST FEATURES) + vcpkg_cmake_build(TARGET onnxruntime_training LOGFILE_BASE build-training) +endif() +vcpkg_cmake_build(TARGET onnxruntime LOGFILE_BASE build-onnxruntime) vcpkg_cmake_install() +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/onnxruntime PACKAGE_NAME onnxruntime) vcpkg_copy_pdbs() vcpkg_fixup_pkgconfig() # pkg_check_modules(libonnxruntime) -if(VCPKG_TARGET_IS_IOS) +if("test" IN_LIST FEATURES) + vcpkg_copy_tools(TOOL_NAMES onnx_test_runner AUTO_CLEAN) +endif() +if("framework" IN_LIST FEATURES) set(FRAMEWORK_NAME "onnxruntime.framework") file(RENAME "${CURRENT_PACKAGES_DIR}/debug/bin/${FRAMEWORK_NAME}" "${CURRENT_PACKAGES_DIR}/debug/lib/${FRAMEWORK_NAME}" diff --git a/ports/onnxruntime/support-windows10.patch b/ports/onnxruntime/support-windows10.patch deleted file mode 100644 index 2476559c..00000000 --- a/ports/onnxruntime/support-windows10.patch +++ /dev/null @@ -1,16 +0,0 @@ -diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt -index 4b86657..4a53ecf 100644 ---- a/cmake/CMakeLists.txt -+++ b/cmake/CMakeLists.txt -@@ -2031,9 +2031,9 @@ endif() - if (WIN32 AND NOT GDK_PLATFORM) - add_compile_definitions(WINAPI_FAMILY=100) # Desktop app - if (onnxruntime_USE_WINML) -- add_compile_definitions(WINVER=0x0602 _WIN32_WINNT=0x0602 NTDDI_VERSION=0x06020000) # Support Windows 8 and newer -+ add_compile_definitions(WINVER=0x0A00 _WIN32_WINNT=0x0A00 NTDDI_VERSION=0x06020000) # Support Windows 10 and newer - else() -- add_compile_definitions(WINVER=0x0601 _WIN32_WINNT=0x0601 NTDDI_VERSION=0x06010000) # Support Windows 7 and newer -+ add_compile_definitions(WINVER=0x0A00 _WIN32_WINNT=0x0A00 NTDDI_VERSION=0x06010000) # Support Windows 10 and newer - endif() - if (NOT CMAKE_CXX_STANDARD_LIBRARIES MATCHES kernel32.lib) - # On onecore, link to the onecore build of the MSVC runtime diff --git a/ports/onnxruntime/vcpkg.json b/ports/onnxruntime/vcpkg.json index b644ac94..e8329da2 100644 --- a/ports/onnxruntime/vcpkg.json +++ b/ports/onnxruntime/vcpkg.json @@ -1,9 +1,8 @@ { "name": "onnxruntime", - "version-semver": "1.12.1", - "port-version": 2, + "version-semver": "1.16.0", "description": "ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator", - "homepage": "www.onnxruntime.ai", + "homepage": "https://www.onnxruntime.ai", "dependencies": [ "boost-config", "boost-mp11", @@ -16,6 +15,7 @@ "name": "flatbuffers", "host": true }, + "ms-gsl", "nlohmann-json", { "name": "nsync", @@ -24,6 +24,10 @@ "onnx", "optional-lite", "protobuf", + { + "name": "protobuf", + "host": true + }, "re2", "safeint", { @@ -31,17 +35,22 @@ "host": true }, { - "name": "wil", - "platform": "windows" + "name": "vcpkg-cmake-config", + "host": true }, + "wil", "zlib" ], "features": { "coreml": { - "description": "Build with CoreML support" + "description": "Build with CoreML support", + "supports": "osx | ios" }, "cuda": { - "description": "Build with CUDA/NCCL support" + "description": "Build with CUDA/NCCL support", + "dependencies": [ + "cuda" + ] }, "directml": { "description": "Build with DirectML support", @@ -50,11 +59,31 @@ "directml" ] }, + "framework": { + "description": "Artifact will be Apple framework", + "supports": "osx | ios" + }, + "python": { + "description": "Enable python buildings", + "dependencies": [ + { + "name": "vcpkg-get-python-packages", + "host": true + } + ] + }, "tensorrt": { "description": "Build with NVIDIA TensorRT support" }, - "training": { - "description": "Turn on build options for ML training" + "test": { + "description": "Build ONNXRuntime unit tests", + "dependencies": [ + "benchmark", + "gtest" + ] + }, + "winml": { + "description": "Build with WinML support" }, "xnnpack": { "description": "Build with XNNPack support", diff --git a/versions/baseline.json b/versions/baseline.json index ec730572..429edb3d 100644 --- a/versions/baseline.json +++ b/versions/baseline.json @@ -70,11 +70,11 @@ }, "onnx": { "baseline": "1.14.1", - "port-version": 0 + "port-version": 1 }, "onnxruntime": { - "baseline": "1.12.1", - "port-version": 2 + "baseline": "1.16.0", + "port-version": 0 }, "openssl1": { "baseline": "1.1.1u", diff --git a/versions/o-/onnx.json b/versions/o-/onnx.json index 027c18b8..4f0de92b 100644 --- a/versions/o-/onnx.json +++ b/versions/o-/onnx.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "7011da9a989a72143c55f0894c8014be136caada", + "version-semver": "1.14.1", + "port-version": 1 + }, { "git-tree": "7b3356ece5980df538926a7429f2fdff883f4cae", "version-semver": "1.14.1", diff --git a/versions/o-/onnxruntime.json b/versions/o-/onnxruntime.json index afb8e0de..df640eda 100644 --- a/versions/o-/onnxruntime.json +++ b/versions/o-/onnxruntime.json @@ -1,5 +1,10 @@ { "versions": [ + { + "git-tree": "01b085df61589562b3cc8d14cc36c2c21cb2cd27", + "version-semver": "1.16.0", + "port-version": 0 + }, { "git-tree": "841dd3e72c199db01da439b0f5ed06c0481c6371", "version-semver": "1.12.1",