Skip to content

Commit

Permalink
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 203 deletions.
73 changes: 29 additions & 44 deletions pkgs/development/libraries/onnxruntime/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
, stdenv
, lib
, fetchFromGitHub
, fetchpatch2
, Foundation
, abseil-cpp_202401
, abseil-cpp_202407
, cmake
, cpuinfo
, eigen
, flatbuffers_23
, gbenchmark
, glibcLocales
, gtest
, howard-hinnant-date
, libpng
, nlohmann_json
, nsync
Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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}")
Expand Down
26 changes: 6 additions & 20 deletions pkgs/development/libraries/onnxruntime/nvcc-gsl.patch
Original file line number Diff line number Diff line change
@@ -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}
Expand All @@ -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}
132 changes: 0 additions & 132 deletions pkgs/development/libraries/onnxruntime/update-re2.patch

This file was deleted.

0 comments on commit 8af8086

Please sign in to comment.