lol
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 24.11-pre 254 lines 7.8 kB view raw
1{ config 2, stdenv 3, lib 4, fetchFromGitHub 5, Foundation 6, abseil-cpp 7, cmake 8, eigen 9, gtest 10, libpng 11, nlohmann_json 12, nsync 13, pkg-config 14, python3Packages 15, re2 16, zlib 17, microsoft-gsl 18, libiconv 19, protobuf_21 20, pythonSupport ? true 21, cudaSupport ? config.cudaSupport 22, cudaPackages ? {} 23}@inputs: 24 25 26let 27 version = "1.16.3"; 28 29 stdenv = throw "Use effectiveStdenv instead"; 30 effectiveStdenv = if cudaSupport then cudaPackages.backendStdenv else inputs.stdenv; 31 32 cudaCapabilities = cudaPackages.cudaFlags.cudaCapabilities; 33 # E.g. [ "80" "86" "90" ] 34 cudaArchitectures = (builtins.map cudaPackages.cudaFlags.dropDot cudaCapabilities); 35 cudaArchitecturesString = lib.strings.concatStringsSep ";" cudaArchitectures; 36 37 howard-hinnant-date = fetchFromGitHub { 38 owner = "HowardHinnant"; 39 repo = "date"; 40 rev = "v2.4.1"; 41 sha256 = "sha256-BYL7wxsYRI45l8C3VwxYIIocn5TzJnBtU0UZ9pHwwZw="; 42 }; 43 44 mp11 = fetchFromGitHub { 45 owner = "boostorg"; 46 repo = "mp11"; 47 rev = "boost-1.79.0"; 48 hash = "sha256-ZxgPDLvpISrjpEHKpLGBowRKGfSwTf6TBfJD18yw+LM="; 49 }; 50 51 safeint = fetchFromGitHub { 52 owner = "dcleblanc"; 53 repo = "safeint"; 54 rev = "ff15c6ada150a5018c5ef2172401cb4529eac9c0"; 55 hash = "sha256-PK1ce4C0uCR4TzLFg+elZdSk5DdPCRhhwT3LvEwWnPU="; 56 }; 57 58 pytorch_cpuinfo = fetchFromGitHub { 59 owner = "pytorch"; 60 repo = "cpuinfo"; 61 # There are no tags in the repository 62 rev = "5916273f79a21551890fd3d56fc5375a78d1598d"; 63 hash = "sha256-nXBnloVTuB+AVX59VDU/Wc+Dsx94o92YQuHp3jowx2A="; 64 }; 65 66 flatbuffers = fetchFromGitHub { 67 owner = "google"; 68 repo = "flatbuffers"; 69 rev = "v1.12.0"; 70 hash = "sha256-L1B5Y/c897Jg9fGwT2J3+vaXsZ+lfXnskp8Gto1p/Tg="; 71 }; 72 73 onnx = fetchFromGitHub { 74 owner = "onnx"; 75 repo = "onnx"; 76 rev = "refs/tags/v1.14.1"; 77 hash = "sha256-ZVSdk6LeAiZpQrrzLxphMbc1b3rNUMpcxcXPP8s/5tE="; 78 }; 79 80 cutlass = fetchFromGitHub { 81 owner = "NVIDIA"; 82 repo = "cutlass"; 83 rev = "v3.0.0"; 84 sha256 = "sha256-YPD5Sy6SvByjIcGtgeGH80TEKg2BtqJWSg46RvnJChY="; 85 }; 86in 87effectiveStdenv.mkDerivation rec { 88 pname = "onnxruntime"; 89 inherit version; 90 91 src = fetchFromGitHub { 92 owner = "microsoft"; 93 repo = "onnxruntime"; 94 rev = "refs/tags/v${version}"; 95 hash = "sha256-bTW9Pc3rvH+c8VIlDDEtAXyA3sajVyY5Aqr6+SxaMF4="; 96 fetchSubmodules = true; 97 }; 98 99 patches = [ 100 # If you stumble on these patches trying to update onnxruntime, check 101 # `git blame` and ping the introducers. 102 103 # Context: we want the upstream to 104 # - always try find_package first (FIND_PACKAGE_ARGS), 105 # - use MakeAvailable instead of the low-level Populate, 106 # - use Eigen3::Eigen as the target name (as declared by libeigen/eigen). 107 ./0001-eigen-allow-dependency-injection.patch 108 ] ++ lib.optionals cudaSupport [ 109 # We apply the referenced 1064.patch ourselves to our nix dependency. 110 # 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 111 ./nvcc-gsl.patch 112 ]; 113 114 nativeBuildInputs = [ 115 cmake 116 pkg-config 117 python3Packages.python 118 protobuf_21 119 ] ++ lib.optionals pythonSupport (with python3Packages; [ 120 pip 121 python 122 pythonOutputDistHook 123 setuptools 124 wheel 125 ]) ++ lib.optionals cudaSupport [ 126 cudaPackages.cuda_nvcc 127 ]; 128 129 buildInputs = [ 130 eigen 131 libpng 132 zlib 133 nlohmann_json 134 microsoft-gsl 135 ] ++ lib.optionals pythonSupport (with python3Packages; [ 136 numpy 137 pybind11 138 packaging 139 ]) ++ lib.optionals effectiveStdenv.isDarwin [ 140 Foundation 141 libiconv 142 ] ++ lib.optionals cudaSupport (with cudaPackages; [ 143 cuda_cccl # cub/cub.cuh 144 libcublas # cublas_v2.h 145 libcurand # curand.h 146 libcusparse # cusparse.h 147 libcufft # cufft.h 148 cudnn # cudnn.h 149 cuda_cudart 150 ]); 151 152 nativeCheckInputs = [ 153 gtest 154 ] ++ lib.optionals pythonSupport (with python3Packages; [ 155 pytest 156 sympy 157 onnx 158 ]); 159 160 # TODO: build server, and move .so's to lib output 161 # Python's wheel is stored in a separate dist output 162 outputs = [ "out" "dev" ] ++ lib.optionals pythonSupport [ "dist" ]; 163 164 enableParallelBuilding = true; 165 166 cmakeDir = "../cmake"; 167 168 cmakeFlags = [ 169 "-DABSL_ENABLE_INSTALL=ON" 170 "-DFETCHCONTENT_FULLY_DISCONNECTED=ON" 171 "-DFETCHCONTENT_QUIET=OFF" 172 "-DFETCHCONTENT_SOURCE_DIR_ABSEIL_CPP=${abseil-cpp.src}" 173 "-DFETCHCONTENT_SOURCE_DIR_DATE=${howard-hinnant-date}" 174 "-DFETCHCONTENT_SOURCE_DIR_FLATBUFFERS=${flatbuffers}" 175 "-DFETCHCONTENT_SOURCE_DIR_GOOGLE_NSYNC=${nsync.src}" 176 "-DFETCHCONTENT_SOURCE_DIR_MP11=${mp11}" 177 "-DFETCHCONTENT_SOURCE_DIR_ONNX=${onnx}" 178 "-DFETCHCONTENT_SOURCE_DIR_PYTORCH_CPUINFO=${pytorch_cpuinfo}" 179 "-DFETCHCONTENT_SOURCE_DIR_RE2=${re2.src}" 180 "-DFETCHCONTENT_SOURCE_DIR_SAFEINT=${safeint}" 181 "-DFETCHCONTENT_TRY_FIND_PACKAGE_MODE=ALWAYS" 182 "-Donnxruntime_BUILD_SHARED_LIB=ON" 183 (lib.cmakeBool "onnxruntime_BUILD_UNIT_TESTS" doCheck) 184 "-Donnxruntime_ENABLE_LTO=ON" 185 "-Donnxruntime_USE_FULL_PROTOBUF=OFF" 186 (lib.cmakeBool "onnxruntime_USE_CUDA" cudaSupport) 187 (lib.cmakeBool "onnxruntime_USE_NCCL" cudaSupport) 188 ] ++ lib.optionals pythonSupport [ 189 "-Donnxruntime_ENABLE_PYTHON=ON" 190 ] ++ lib.optionals cudaSupport [ 191 (lib.cmakeFeature "FETCHCONTENT_SOURCE_DIR_CUTLASS" "${cutlass}") 192 (lib.cmakeFeature "onnxruntime_CUDNN_HOME" "${cudaPackages.cudnn}") 193 (lib.cmakeFeature "CMAKE_CUDA_ARCHITECTURES" cudaArchitecturesString) 194 (lib.cmakeFeature "onnxruntime_NVCC_THREADS" "1") 195 ]; 196 197 env = lib.optionalAttrs effectiveStdenv.cc.isClang { 198 NIX_CFLAGS_COMPILE = toString [ 199 "-Wno-error=deprecated-declarations" 200 "-Wno-error=unused-but-set-variable" 201 ]; 202 }; 203 204 doCheck = !cudaSupport; 205 206 requiredSystemFeatures = lib.optionals cudaSupport [ "big-parallel" ]; 207 208 postPatch = '' 209 substituteInPlace cmake/libonnxruntime.pc.cmake.in \ 210 --replace-fail '$'{prefix}/@CMAKE_INSTALL_ @CMAKE_INSTALL_ 211 '' + lib.optionalString (effectiveStdenv.hostPlatform.system == "aarch64-linux") '' 212 # https://github.com/NixOS/nixpkgs/pull/226734#issuecomment-1663028691 213 rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc 214 ''; 215 216 postBuild = lib.optionalString pythonSupport '' 217 ${python3Packages.python.interpreter} ../setup.py bdist_wheel 218 ''; 219 220 postInstall = '' 221 # perform parts of `tools/ci_build/github/linux/copy_strip_binary.sh` 222 install -m644 -Dt $out/include \ 223 ../include/onnxruntime/core/framework/provider_options.h \ 224 ../include/onnxruntime/core/providers/cpu/cpu_provider_factory.h \ 225 ../include/onnxruntime/core/session/onnxruntime_*.h 226 ''; 227 228 passthru = { 229 inherit cudaSupport cudaPackages; # for the python module 230 protobuf = protobuf_21; 231 tests = lib.optionalAttrs pythonSupport { 232 python = python3Packages.onnxruntime; 233 }; 234 }; 235 236 meta = with lib; { 237 description = "Cross-platform, high performance scoring engine for ML models"; 238 longDescription = '' 239 ONNX Runtime is a performance-focused complete scoring engine 240 for Open Neural Network Exchange (ONNX) models, with an open 241 extensible architecture to continually address the latest developments 242 in AI and Deep Learning. ONNX Runtime stays up to date with the ONNX 243 standard with complete implementation of all ONNX operators, and 244 supports all ONNX releases (1.2+) with both future and backwards 245 compatibility. 246 ''; 247 homepage = "https://github.com/microsoft/onnxruntime"; 248 changelog = "https://github.com/microsoft/onnxruntime/releases/tag/v${version}"; 249 # https://github.com/microsoft/onnxruntime/blob/master/BUILD.md#architectures 250 platforms = platforms.unix; 251 license = licenses.mit; 252 maintainers = with maintainers; [ jonringer puffnfresh ck3d cbourjau ]; 253 }; 254}