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