diff --git a/pkgs/development/libraries/onnxruntime/default.nix b/pkgs/development/libraries/onnxruntime/default.nix index 66d1dd309a68d2..0c177ff6c828e5 100644 --- a/pkgs/development/libraries/onnxruntime/default.nix +++ b/pkgs/development/libraries/onnxruntime/default.nix @@ -2,9 +2,8 @@ , stdenv , lib , fetchFromGitHub -, fetchpatch2 , Foundation -, abseil-cpp_202401 +, abseil-cpp_202407 , cmake , cpuinfo , eigen @@ -12,6 +11,7 @@ , gbenchmark , glibcLocales , gtest +, howard-hinnant-date , libpng , nlohmann_json , nsync @@ -30,34 +30,33 @@ let - version = "1.18.1"; + version = "1.20.1"; - abseil-cpp = abseil-cpp_202401; + src = fetchFromGitHub { + owner = "microsoft"; + repo = "onnxruntime"; + tag = "v${version}"; + hash = "sha256-xIjR2HsVIqc78ojSXzoTGIxk7VndGYa8o4pVB8U8oXI="; + fetchSubmodules = true; + }; stdenv = throw "Use effectiveStdenv instead"; effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else inputs.stdenv; cudaArchitecturesString = cudaPackages.flags.cmakeCudaArchitecturesString; - howard-hinnant-date = fetchFromGitHub { - owner = "HowardHinnant"; - repo = "date"; - rev = "v3.0.1"; - sha256 = "sha256-ZSjeJKAcT7mPym/4ViDvIR9nFMQEBCSUtPEuMO27Z+I="; - }; - mp11 = fetchFromGitHub { owner = "boostorg"; repo = "mp11"; - rev = "boost-1.82.0"; + tag = "boost-1.82.0"; hash = "sha256-cLPvjkf2Au+B19PJNrUkTW/VPxybi1MpPxnIl4oo4/o="; }; safeint = fetchFromGitHub { owner = "dcleblanc"; repo = "safeint"; - rev = "ff15c6ada150a5018c5ef2172401cb4529eac9c0"; - hash = "sha256-PK1ce4C0uCR4TzLFg+elZdSk5DdPCRhhwT3LvEwWnPU="; + tag = "3.0.28"; + hash = "sha256-pjwjrqq6dfiVsXIhbBtbolhiysiFlFTnx5XcX77f+C0="; }; pytorch_clog = effectiveStdenv.mkDerivation { @@ -78,28 +77,26 @@ let onnx = fetchFromGitHub { owner = "onnx"; repo = "onnx"; - rev = "refs/tags/v1.16.1"; - hash = "sha256-I1wwfn91hdH3jORIKny0Xc73qW2P04MjkVCgcaNnQUE="; + tag = "v1.16.1"; + hash = "sha256-+NmWoZDXNJ8YQIWlUXV+czHyI8UtJedu2VG+1aR5L7s="; + # Apply backport of https://github.com/onnx/onnx/pull/6195 from 1.17.0 + postFetch = '' + pushd $out + patch -p1 < ${src}/cmake/patches/onnx/onnx.patch + popd + ''; }; cutlass = fetchFromGitHub { owner = "NVIDIA"; repo = "cutlass"; - rev = "v3.1.0"; - hash = "sha256-mpaiCxiYR1WaSSkcEPTzvcREenJWklD+HRdTT5/pD54="; + tag = "v3.5.1"; + hash = "sha256-sTGYN+bjtEqQ7Ootr/wvx3P9f8MCDSSj3qyCWjfdLEA="; }; in effectiveStdenv.mkDerivation rec { pname = "onnxruntime"; - inherit version; - - src = fetchFromGitHub { - owner = "microsoft"; - repo = "onnxruntime"; - rev = "refs/tags/v${version}"; - hash = "sha256-+zWtbLKekGhwdBU3bm1u2F7rYejQ62epE+HcHj05/8A="; - fetchSubmodules = true; - }; + inherit src version; patches = [ # If you stumble on these patches trying to update onnxruntime, check @@ -109,20 +106,7 @@ effectiveStdenv.mkDerivation rec { # - always try find_package first (FIND_PACKAGE_ARGS), # - use MakeAvailable instead of the low-level Populate, # - use Eigen3::Eigen as the target name (as declared by libeigen/eigen). - ./0001-eigen-allow-dependency-injection.patch - # Incorporate a patch that has landed upstream which exposes new - # 'abseil-cpp' libraries & modifies the 're2' CMakeLists to fix a - # configuration error that around missing 'gmock' exports. - # - # TODO: Check if it can be dropped after 1.19.0 - # https://github.com/microsoft/onnxruntime/commit/b522df0ae477e59f60acbe6c92c8a64eda96cace - ./update-re2.patch - # fix `error: template-id not allowed for constructor in C++20` - (fetchpatch2 { - name = "suppress-gcc-warning-in-TreeEnsembleAggregator.patch"; - url = "https://github.com/microsoft/onnxruntime/commit/10883d7997ed4b53f989a49bd4387c5769fbd12f.patch?full_index=1"; - hash = "sha256-NgvuCHE7axaUtZIjtQvDpagr+QtHdyL7xXkPQwZbhvY="; - }) + ./eigen.patch ] ++ lib.optionals cudaSupport [ # We apply the referenced 1064.patch ourselves to our nix dependency. # FIND_PACKAGE_ARGS for CUDA was added in https://github.com/microsoft/onnxruntime/commit/87744e5 so it might be possible to delete this patch after upgrading to 1.17.0 @@ -142,12 +126,14 @@ effectiveStdenv.mkDerivation rec { wheel ]) ++ lib.optionals cudaSupport [ cudaPackages.cuda_nvcc + cudaPackages.cudnn-frontend ]; buildInputs = [ cpuinfo eigen glibcLocales + howard-hinnant-date libpng nlohmann_json microsoft-gsl @@ -192,10 +178,8 @@ effectiveStdenv.mkDerivation rec { "-DABSL_ENABLE_INSTALL=ON" "-DFETCHCONTENT_FULLY_DISCONNECTED=ON" "-DFETCHCONTENT_QUIET=OFF" - "-DFETCHCONTENT_SOURCE_DIR_ABSEIL_CPP=${abseil-cpp.src}" - "-DFETCHCONTENT_SOURCE_DIR_DATE=${howard-hinnant-date}" + "-DFETCHCONTENT_SOURCE_DIR_ABSEIL_CPP=${abseil-cpp_202407.src}" "-DFETCHCONTENT_SOURCE_DIR_FLATBUFFERS=${flatbuffers_23.src}" - "-DFETCHCONTENT_SOURCE_DIR_GOOGLETEST=${gtest.src}" "-DFETCHCONTENT_SOURCE_DIR_GOOGLE_NSYNC=${nsync.src}" "-DFETCHCONTENT_SOURCE_DIR_MP11=${mp11}" "-DFETCHCONTENT_SOURCE_DIR_ONNX=${onnx}" @@ -233,6 +217,7 @@ effectiveStdenv.mkDerivation rec { postPatch = '' substituteInPlace cmake/libonnxruntime.pc.cmake.in \ --replace-fail '$'{prefix}/@CMAKE_INSTALL_ @CMAKE_INSTALL_ + echo "find_package(cudnn_frontend REQUIRED)" > cmake/external/cudnn_frontend.cmake '' + lib.optionalString (effectiveStdenv.hostPlatform.system == "aarch64-linux") '' # https://github.com/NixOS/nixpkgs/pull/226734#issuecomment-1663028691 rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc diff --git a/pkgs/development/libraries/onnxruntime/0001-eigen-allow-dependency-injection.patch b/pkgs/development/libraries/onnxruntime/eigen.patch similarity index 50% rename from pkgs/development/libraries/onnxruntime/0001-eigen-allow-dependency-injection.patch rename to pkgs/development/libraries/onnxruntime/eigen.patch index 0092ea4d1e8ef0..3a58755812d4ce 100644 --- a/pkgs/development/libraries/onnxruntime/0001-eigen-allow-dependency-injection.patch +++ b/pkgs/development/libraries/onnxruntime/eigen.patch @@ -1,13 +1,21 @@ diff --git a/cmake/external/eigen.cmake b/cmake/external/eigen.cmake -index b123adb..aab2483 100644 +index 339cded091..6264c8da69 100644 --- a/cmake/external/eigen.cmake +++ b/cmake/external/eigen.cmake -@@ -7,8 +7,13 @@ else () - eigen - URL ${DEP_URL_eigen} - URL_HASH SHA1=${DEP_SHA1_eigen} -+ FIND_PACKAGE_ARGS NAMES Eigen3 - ) +@@ -9,15 +9,21 @@ else () + URL ${DEP_URL_eigen} + URL_HASH SHA1=${DEP_SHA1_eigen} + PATCH_COMMAND ${Patch_EXECUTABLE} --binary --ignore-whitespace -p1 < ${PROJECT_SOURCE_DIR}/patches/eigen/eigen-aix.patch ++ FIND_PACKAGE_ARGS NAMES Eigen3 + ) + else() + FetchContent_Declare( + eigen + URL ${DEP_URL_eigen} + URL_HASH SHA1=${DEP_SHA1_eigen} ++ FIND_PACKAGE_ARGS NAMES Eigen3 + ) + endif() - FetchContent_Populate(eigen) - set(eigen_INCLUDE_DIRS "${eigen_SOURCE_DIR}") diff --git a/pkgs/development/libraries/onnxruntime/nvcc-gsl.patch b/pkgs/development/libraries/onnxruntime/nvcc-gsl.patch index ca94faab93942a..c6ac77602fcad9 100644 --- a/pkgs/development/libraries/onnxruntime/nvcc-gsl.patch +++ b/pkgs/development/libraries/onnxruntime/nvcc-gsl.patch @@ -1,12 +1,11 @@ diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake -index 775576a..ccea13c 100644 +index 85746027d4..346ac37a54 100644 --- a/cmake/external/onnxruntime_external_deps.cmake +++ b/cmake/external/onnxruntime_external_deps.cmake -@@ -367,22 +367,12 @@ if (NOT WIN32) - endif() +@@ -422,14 +422,6 @@ if ((CPUINFO_SUPPORTED OR onnxruntime_USE_XNNPACK) AND NOT ANDROID) endif() --if(onnxruntime_USE_CUDA) + if(onnxruntime_USE_CUDA) - FetchContent_Declare( - GSL - URL ${DEP_URL_microsoft_gsl} @@ -15,19 +14,6 @@ index 775576a..ccea13c 100644 - 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() -+FetchContent_Declare( -+ GSL -+ URL ${DEP_URL_microsoft_gsl} -+ URL_HASH SHA1=${DEP_SHA1_microsoft_gsl} -+ FIND_PACKAGE_ARGS 4.0 NAMES Microsoft.GSL -+) - - FetchContent_Declare( - safeint + FetchContent_Declare( + GSL + URL ${DEP_URL_microsoft_gsl} diff --git a/pkgs/development/libraries/onnxruntime/update-re2.patch b/pkgs/development/libraries/onnxruntime/update-re2.patch deleted file mode 100644 index 7996721f8e111c..00000000000000 --- a/pkgs/development/libraries/onnxruntime/update-re2.patch +++ /dev/null @@ -1,132 +0,0 @@ -From 0d1e631c365944d54e87bdce39beb13b225ba8f8 Mon Sep 17 00:00:00 2001 -From: Changming Sun -Date: Thu, 23 May 2024 14:30:15 -0700 -Subject: [PATCH] Update RE2 to the latest (#20775) - -Update RE2 to the latest. - -To keep the components up to date. - -(cherry picked from commit b522df0ae477e59f60acbe6c92c8a64eda96cace) ---- - cgmanifests/generated/cgmanifest.json | 2 +- - cmake/deps.txt | 4 +-- - cmake/external/abseil-cpp.cmake | 35 ++++++++++++++++++++++----- - cmake/external/helper_functions.cmake | 6 +++++ - 4 files changed, 38 insertions(+), 9 deletions(-) - -diff --git a/cgmanifests/generated/cgmanifest.json b/cgmanifests/generated/cgmanifest.json -index eb74178b3e..e3e9be67ae 100644 ---- a/cgmanifests/generated/cgmanifest.json -+++ b/cgmanifests/generated/cgmanifest.json -@@ -276,7 +276,7 @@ - "component": { - "type": "git", - "git": { -- "commitHash": "5723bb8950318135ed9cf4fc76bed988a087f536", -+ "commitHash": "2b354c6ad0d0479dcff68dab23fb0d1143a482c2", - "repositoryUrl": "https://github.com/google/re2.git" - }, - "comments": "re2" -diff --git a/cmake/deps.txt b/cmake/deps.txt -index d213b09034..d4d19dea08 100644 ---- a/cmake/deps.txt -+++ b/cmake/deps.txt -@@ -50,11 +50,11 @@ psimd;https://github.com/Maratyszcza/psimd/archive/072586a71b55b7f8c584153d223e9 - pthreadpool;https://github.com/Maratyszcza/pthreadpool/archive/4fe0e1e183925bf8cfa6aae24237e724a96479b8.zip;07a0aa91dd9bf86f31b95497e00f31d8a261a4bd - pybind11;https://github.com/pybind/pybind11/archive/refs/tags/v2.10.1.zip;769b6aa67a77f17a770960f604b727645b6f6a13 - pytorch_cpuinfo;https://github.com/pytorch/cpuinfo/archive/959002f82d7962a473d8bf301845f2af720e0aa4.zip;85da3caa60eb2b148613b443fbc2bfdc30689965 --re2;https://github.com/google/re2/archive/refs/tags/2022-06-01.zip;aa77313b76e91b531ee7f3e45f004c6a502a5374 -+re2;https://github.com/google/re2/archive/refs/tags/2024-05-01.tar.gz;206cfee5ee0b4c6844680ba66275e9e8faa77405 - safeint;https://github.com/dcleblanc/SafeInt/archive/refs/tags/3.0.28.zip;23f252040ff6cb9f1fd18575b32fa8fb5928daac - tensorboard;https://github.com/tensorflow/tensorboard/archive/373eb09e4c5d2b3cc2493f0949dc4be6b6a45e81.zip;67b833913605a4f3f499894ab11528a702c2b381 - cutlass;https://github.com/NVIDIA/cutlass/archive/refs/tags/v3.1.0.zip;757f90a795034a89d4f48a79d1f009f7a04c8dee - utf8_range;https://github.com/protocolbuffers/utf8_range/archive/72c943dea2b9240cd09efde15191e144bc7c7d38.zip;9925739c9debc0efa2adcb194d371a35b6a03156 - extensions;https://github.com/microsoft/onnxruntime-extensions/archive/94142d8391c9791ec71c38336436319a2d4ac7a0.zip;4365ac5140338b4cb75a39944a4be276e3829b3c - composable_kernel;https://github.com/ROCmSoftwarePlatform/composable_kernel/archive/5356c4a943a35e74d7cdc69486afcb8703b9a59a.zip;522382c2af437e09124287e5879ab64af5b2e299 --directx_headers;https://github.com/microsoft/DirectX-Headers/archive/refs/tags/v1.613.1.zip;47653509a3371eabb156360f42faf582f314bf2e -\ No newline at end of file -+directx_headers;https://github.com/microsoft/DirectX-Headers/archive/refs/tags/v1.613.1.zip;47653509a3371eabb156360f42faf582f314bf2e -diff --git a/cmake/external/abseil-cpp.cmake b/cmake/external/abseil-cpp.cmake -index 57cfbee464..c01195c99e 100644 ---- a/cmake/external/abseil-cpp.cmake -+++ b/cmake/external/abseil-cpp.cmake -@@ -45,10 +45,8 @@ endif() - - # TODO: since multiple ORT's dependencies depend on Abseil, the list below would vary from version to version. - # We'd better to not manually manage the list. --set(ABSEIL_LIBS absl::base -+set(ABSEIL_LIBS - absl::city --absl::core_headers --absl::fixed_array - absl::flags - absl::flat_hash_map - absl::flat_hash_set -@@ -60,9 +58,34 @@ absl::node_hash_set - absl::optional - absl::raw_hash_set - absl::raw_logging_internal --absl::span - absl::str_format --absl::strings -+absl::str_format_internal -+absl::bits -+absl::fixed_array -+absl::numeric_representation -+absl::utility -+absl::type_traits -+absl::string_view -+absl::core_headers -+absl::nullability -+absl::span -+absl::config - absl::synchronization -+absl::base -+absl::civil_time -+absl::debugging_internal -+absl::demangle_internal -+absl::graphcycles_internal -+absl::int128 -+absl::kernel_timeout_internal -+absl::log_severity -+absl::malloc_internal -+absl::spinlock_wait -+absl::stacktrace -+absl::string_view -+absl::strings -+absl::strings_internal -+absl::symbolize - absl::throw_delegate --absl::time) -+absl::time -+absl::time_zone) -\ No newline at end of file -diff --git a/cmake/external/helper_functions.cmake b/cmake/external/helper_functions.cmake -index 768e807b40..eefb3ba2e8 100644 ---- a/cmake/external/helper_functions.cmake -+++ b/cmake/external/helper_functions.cmake -@@ -159,7 +159,12 @@ macro(onnxruntime_fetchcontent_makeavailable) - endif() - - if(EXISTS ${__cmake_srcdir}/CMakeLists.txt) -+ set(CMAKE_SKIP_INSTALL_RULES TRUE) -+ if (__cmake_arg_SYSTEM) -+ add_subdirectory(${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR} SYSTEM) -+ else() - add_subdirectory(${__cmake_srcdir} ${${__cmake_contentNameLower}_BINARY_DIR} EXCLUDE_FROM_ALL) -+ endif() - get_property(subdir_import_targets DIRECTORY "${__cmake_srcdir}" PROPERTY BUILDSYSTEM_TARGETS) - foreach(subdir_target ${subdir_import_targets}) - if(TARGET ${subdir_target}) -@@ -176,6 +181,7 @@ macro(onnxruntime_fetchcontent_makeavailable) - set_target_properties(${subdir_target} PROPERTIES COMPILE_WARNING_AS_ERROR OFF) - endif() - endforeach() -+ set(CMAKE_SKIP_INSTALL_RULES FALSE) - endif() - - unset(__cmake_srcdir) --- -2.45.2 -