nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
fork

Configure Feed

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

cudaPackages.cudnn: migrate to redist cuda, fix missing zlib (#168748)

* cudaPackages.cudnn: migrate to redist cudaPackages

* cudaPackages.cudnn: fix missing zlib in rpath

* cudaPackages.cudnn: remove the propagated cudatoolkit

* cudaPackages.cudnn: use autoPatchelfHook

instead of custom find ... -exec ldd | grep routine
mark libcudnn_cnn_infer.so as needed for libcudnn.so on cudnn>=8.0.5
- a hint for autoPatchelf, as an alternative to manually adding $ORIGIN

* cudaPackages.cudnn: use automatic hooks for rpath

as a more common way to use addOpenGLRunpath and autoPatchelf with cudaPackages

* cudaPackages.cudnn: consume individual cuda packages

...since cudnn is part of the cuda package set

- introduces the scary useCudatoolkitRunfile function argument
to discourage usage of the runfile-based cudatoolkit
- instead of the rather hidden useRedist term in let ... in
- repeats cudatoolkit_root pattern after cuda_joined in pytorch &c
(the "toolchain view")
- redist packages are marked optional to support cuda<11.4 where the
attributes for redist packages do not exist

* cudaPackages.cudnn: update to pname+version

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>

authored by

Serge K
Sandro
and committed by
GitHub
d924de58 047473aa

+54 -33
+5 -1
pkgs/development/libraries/science/math/cudnn/extension.nix
··· 5 5 6 6 ### CuDNN 7 7 8 - buildCuDnnPackage = args: callPackage ./generic.nix {} args; 8 + buildCuDnnPackage = args: 9 + let 10 + useCudatoolkitRunfile = lib.versionOlder cudaVersion "11.3.999"; 11 + in 12 + callPackage ./generic.nix { inherit useCudatoolkitRunfile; } args; 9 13 10 14 toUnderscore = str: lib.replaceStrings ["."] ["_"] str; 11 15
+48 -32
pkgs/development/libraries/science/math/cudnn/generic.nix
··· 1 1 { stdenv 2 2 , lib 3 - , cudatoolkit 3 + , zlib 4 + , useCudatoolkitRunfile ? false 5 + , cudaVersion 6 + , cudaMajorVersion 7 + , cudatoolkit # if cuda>=11: only used for .cc 8 + , libcublas ? null # cuda <11 doesn't ship redist packages 9 + , autoPatchelfHook 10 + , autoAddOpenGLRunpathHook 4 11 , fetchurl 5 - , addOpenGLRunpath 6 12 , # The distributed version of CUDNN includes both dynamically liked .so files, 7 13 # as well as statically linked .a files. However, CUDNN is quite large 8 14 # (multiple gigabytes), so you can save some space in your nix store by ··· 23 17 , url 24 18 , hash ? null 25 19 , sha256 ? null 26 - , supportedCudaVersions ? [] 20 + , supportedCudaVersions ? [ ] 27 21 }: 28 22 29 23 assert (hash != null) || (sha256 != null); 30 24 25 + assert useCudatoolkitRunfile || (libcublas != null); 26 + 31 27 let 28 + inherit (cudatoolkit) cc; 29 + 32 30 majorMinorPatch = version: lib.concatStringsSep "." (lib.take 3 (lib.splitVersion version)); 33 31 version = majorMinorPatch fullVersion; 34 - in stdenv.mkDerivation { 35 - name = "cudatoolkit-${cudatoolkit.majorVersion}-cudnn-${version}"; 36 32 33 + cudatoolkit_root = 34 + if useCudatoolkitRunfile 35 + then cudatoolkit 36 + else libcublas; 37 + in 38 + stdenv.mkDerivation { 39 + pname = "cudatoolkit-${cudaMajorVersion}-cudnn"; 37 40 inherit version; 38 - # It's often the case that the src depends on the version of cudatoolkit it's 39 - # being linked against, so we pass in `cudatoolkit` as an argument to `mkSrc`. 41 + 40 42 src = fetchurl { 41 43 inherit url hash sha256; 42 44 }; 43 45 44 - nativeBuildInputs = [ addOpenGLRunpath ]; 46 + # Check and normalize Runpath against DT_NEEDED using autoPatchelf. 47 + # Prepend /run/opengl-driver/lib using addOpenGLRunpath for dlopen("libcudacuda.so") 48 + nativeBuildInputs = [ 49 + autoPatchelfHook 50 + autoAddOpenGLRunpathHook 51 + ]; 45 52 46 - # Some cuDNN libraries depend on things in cudatoolkit, eg. 47 - # libcudnn_ops_infer.so.8 tries to load libcublas.so.11. So we need to patch 48 - # cudatoolkit into RPATH. See also https://github.com/NixOS/nixpkgs/blob/88a2ad974692a5c3638fcdc2c772e5770f3f7b21/pkgs/development/python-modules/jaxlib/bin.nix#L78-L98. 53 + # Used by autoPatchelfHook 54 + buildInputs = [ 55 + cc.cc.lib # libstdc++ 56 + zlib 57 + cudatoolkit_root 58 + ]; 59 + 60 + # We used to patch Runpath here, but now we use autoPatchelfHook 49 61 # 50 62 # Note also that version <=8.3.0 contained a subdirectory "lib64/" but in 51 63 # version 8.3.2 it seems to have been renamed to simply "lib/". 52 64 installPhase = '' 53 65 runHook preInstall 54 - 55 - function fixRunPath { 56 - p=$(patchelf --print-rpath $1) 57 - patchelf --set-rpath "''${p:+$p:}${lib.makeLibraryPath [ stdenv.cc.cc cudatoolkit.lib ]}:${cudatoolkit}/lib:\$ORIGIN/" $1 58 - } 59 - 60 - for sofile in {lib,lib64}/lib*.so; do 61 - fixRunPath $sofile 62 - done 63 66 64 67 mkdir -p $out 65 68 cp -a include $out/include ··· 81 66 runHook postInstall 82 67 ''; 83 68 84 - # Set RUNPATH so that libcuda in /run/opengl-driver(-32)/lib can be found. 85 - # See the explanation in addOpenGLRunpath. 86 - postFixup = '' 87 - for lib in $out/lib/lib*.so; do 88 - addOpenGLRunpath $lib 89 - done 69 + # Without --add-needed autoPatchelf forgets $ORIGIN on cuda>=8.0.5. 70 + postFixup = lib.optionalString (lib.versionAtLeast fullVersion "8.0.5") '' 71 + patchelf $out/lib/libcudnn.so --add-needed libcudnn_cnn_infer.so 90 72 ''; 91 73 92 - propagatedBuildInputs = [ 93 - cudatoolkit 94 - ]; 95 - 96 74 passthru = { 97 - inherit cudatoolkit; 75 + inherit useCudatoolkitRunfile; 76 + 77 + cudatoolkit = lib.warn '' 78 + cudnn.cudatoolkit passthru attribute is deprecated; 79 + if your derivation uses cudnn directly, it should probably consume cudaPackages instead 80 + '' 81 + cudatoolkit; 82 + 98 83 majorVersion = lib.versions.major version; 99 84 }; 100 85 ··· 104 89 # official version constraints (as recorded in default.nix). In some cases 105 90 # you _may_ be able to smudge version constraints, just know that you're 106 91 # embarking into unknown and unsupported territory when doing so. 107 - broken = !(elem cudatoolkit.majorMinorVersion supportedCudaVersions); 92 + broken = !(elem cudaVersion supportedCudaVersions); 108 93 description = "NVIDIA CUDA Deep Neural Network library (cuDNN)"; 109 94 homepage = "https://developer.nvidia.com/cudnn"; 95 + # TODO: consider marking unfreRedistributable when not using runfile 110 96 license = licenses.unfree; 111 97 platforms = [ "x86_64-linux" ]; 112 98 maintainers = with maintainers; [ mdaiter samuela ];
+1
pkgs/games/katago/default.nix
··· 52 52 eigen 53 53 ] ++ lib.optionals (enableGPU && enableCuda) [ 54 54 cudaPackages.cudnn 55 + cudaPackages.cudatoolkit 55 56 mesa.drivers 56 57 ] ++ lib.optionals (enableGPU && !enableCuda) [ 57 58 opencl-headers