about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/cuda-modules
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2024-01-06 02:12:23 +0100
committerAlyssa Ross <hi@alyssa.is>2024-01-06 02:12:23 +0100
commitf34a1b70eb86e4a63cfb88ea460345bb1aed88e3 (patch)
tree32834d23912250e0c4b86aa4420baacf8091c0fe /nixpkgs/pkgs/development/cuda-modules
parent003ab91dd67b093890db1dd0bab564345db6e496 (diff)
parent7a7cfff8915e06365bc2365ff33d4d413184fa9f (diff)
downloadnixlib-f34a1b70eb86e4a63cfb88ea460345bb1aed88e3.tar
nixlib-f34a1b70eb86e4a63cfb88ea460345bb1aed88e3.tar.gz
nixlib-f34a1b70eb86e4a63cfb88ea460345bb1aed88e3.tar.bz2
nixlib-f34a1b70eb86e4a63cfb88ea460345bb1aed88e3.tar.lz
nixlib-f34a1b70eb86e4a63cfb88ea460345bb1aed88e3.tar.xz
nixlib-f34a1b70eb86e4a63cfb88ea460345bb1aed88e3.tar.zst
nixlib-f34a1b70eb86e4a63cfb88ea460345bb1aed88e3.zip
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Conflicts:
	nixpkgs/pkgs/build-support/go/module.nix
Diffstat (limited to 'nixpkgs/pkgs/development/cuda-modules')
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/cuda/overrides.nix86
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/cudatoolkit/releases.nix6
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/flags.nix11
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix59
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/generic-builders/multiplex.nix27
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix1
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/setup-hooks/setup-cuda-hook.sh20
-rw-r--r--nixpkgs/pkgs/development/cuda-modules/tensorrt/fixup.nix21
8 files changed, 169 insertions, 62 deletions
diff --git a/nixpkgs/pkgs/development/cuda-modules/cuda/overrides.nix b/nixpkgs/pkgs/development/cuda-modules/cuda/overrides.nix
index fd32978bfb59..d92e07bb1b0b 100644
--- a/nixpkgs/pkgs/development/cuda-modules/cuda/overrides.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/cuda/overrides.nix
@@ -1,4 +1,4 @@
-{cudaVersion, lib}:
+{cudaVersion, lib, addDriverRunpath}:
 let
   inherit (lib) attrsets lists strings;
   # cudaVersionOlder : Version -> Boolean
@@ -42,6 +42,31 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) {
     lists.optionals (cudaVersionAtLeast "12.0") [final.libnvjitlink.lib]
   );
 
+  cuda_cudart = prev.cuda_cudart.overrideAttrs (
+    prevAttrs: {
+      allowFHSReferences = false;
+
+      # The libcuda stub's pkg-config doesn't follow the general pattern:
+      postPatch =
+        prevAttrs.postPatch or ""
+        + ''
+          while IFS= read -r -d $'\0' path ; do
+            sed -i \
+              -e "s|^libdir\s*=.*/lib\$|libdir=''${!outputLib}/lib/stubs|" \
+              -e "s|^Libs\s*:\(.*\)\$|Libs: \1 -Wl,-rpath,${addDriverRunpath.driverLink}/lib|" \
+              "$path"
+          done < <(find -iname 'cuda-*.pc' -print0)
+        ''
+        + ''
+          # Namelink may not be enough, add a soname.
+          # Cf. https://gitlab.kitware.com/cmake/cmake/-/issues/25536
+          if [[ -f lib/stubs/libcuda.so && ! -f lib/stubs/libcuda.so.1 ]] ; then
+            ln -s libcuda.so lib/stubs/libcuda.so.1
+          fi
+        '';
+    }
+  );
+
   cuda_compat = prev.cuda_compat.overrideAttrs (
     prevAttrs: {
       env.autoPatchelfIgnoreMissingDeps =
@@ -61,9 +86,64 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) {
 
   cuda_nvcc = prev.cuda_nvcc.overrideAttrs (
     oldAttrs: {
-      propagatedBuildInputs = [final.setupCudaHook];
 
-      meta = (oldAttrs.meta or {}) // {
+      outputs = oldAttrs.outputs ++ lists.optionals (!(builtins.elem "lib" oldAttrs.outputs)) [ "lib" ];
+
+      # Patch the nvcc.profile.
+      # Syntax:
+      # - `=` for assignment,
+      # - `?=` for conditional assignment,
+      # - `+=` to "prepend",
+      # - `=+` to "append".
+
+      # Cf. https://web.archive.org/web/20230308044351/https://arcb.csc.ncsu.edu/~mueller/cluster/nvidia/2.0/nvcc_2.0.pdf
+
+      # We set all variables with the lowest priority (=+), but we do force
+      # nvcc to use the fixed backend toolchain. Cf. comments in
+      # backend-stdenv.nix
+
+      postPatch =
+        (oldAttrs.postPatch or "")
+        + ''
+          substituteInPlace bin/nvcc.profile \
+            --replace \
+              '$(TOP)/lib' \
+              "''${!outputLib}/lib" \
+            --replace \
+              '$(TOP)/$(_NVVM_BRANCH_)' \
+              "''${!outputBin}/nvvm" \
+            --replace \
+              '$(TOP)/$(_TARGET_DIR_)/include' \
+              "''${!outputDev}/include"
+
+          cat << EOF >> bin/nvcc.profile
+
+          # Fix a compatible backend compiler
+          PATH += ${lib.getBin final.backendStdenv.cc}/bin:
+          LIBRARIES += "-L${lib.getLib final.backendStdenv.nixpkgsCompatibleLibstdcxx}/lib"
+
+          # Expose the split-out nvvm
+          LIBRARIES =+ -L''${!outputBin}/nvvm/lib
+          INCLUDES =+ -I''${!outputBin}/nvvm/include
+
+          # Expose cudart and the libcuda stubs
+          LIBRARIES =+ -L$static/lib" "-L${final.cuda_cudart.lib}/lib -L${final.cuda_cudart.lib}/lib/stubs
+          INCLUDES =+ -I${final.cuda_cudart.dev}/include
+          EOF
+        '';
+
+      propagatedBuildInputs = [ final.setupCudaHook ];
+
+      postInstall =
+        (oldAttrs.postInstall or "")
+        + ''
+          moveToOutput "nvvm" "''${!outputBin}"
+        '';
+
+      # The nvcc and cicc binaries contain hard-coded references to /usr
+      allowFHSReferences = true;
+
+      meta = (oldAttrs.meta or { }) // {
         mainProgram = "nvcc";
       };
     }
diff --git a/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/releases.nix b/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/releases.nix
index d1f7bf9a12ff..b6828cc1f68c 100644
--- a/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/releases.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/cudatoolkit/releases.nix
@@ -95,9 +95,9 @@
   };
 
   "12.2" = {
-    version = "12.2.0";
-    url = "https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run";
-    sha256 = "sha256-7PPSr63LrAKfD0UFeFgQ1S0AbkuHunn/P5hDNqK79Rg=";
+    version = "12.2.2";
+    url = "https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_535.104.05_linux.run";
+    sha256 = "sha256-Kzmq4+dhjZ9Zo8j6HxvGHynAsODfdfsFB2uts1KVLvI=";
   };
 
   "12.3" = {
diff --git a/nixpkgs/pkgs/development/cuda-modules/flags.nix b/nixpkgs/pkgs/development/cuda-modules/flags.nix
index 139952bc9dfd..a123c7bce5a1 100644
--- a/nixpkgs/pkgs/development/cuda-modules/flags.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/flags.nix
@@ -143,7 +143,7 @@ let
     else if nixSystem == "x86_64-windows" then
       "windows-x86_64"
     else
-      builtins.throw "Unsupported Nix system: ${nixSystem}";
+      "unsupported";
 
   # Maps NVIDIA redist arch to Nix system.
   # It is imperative that we include the boolean condition based on jetsonTargets to ensure
@@ -163,7 +163,7 @@ let
     else if redistArch == "windows-x86_64" then
       "x86_64-windows"
     else
-      builtins.throw "Unsupported NVIDIA redist arch: ${redistArch}";
+      "unsupported-${redistArch}";
 
   formatCapabilities =
     {
@@ -175,9 +175,10 @@ let
 
       # archNames :: List String
       # E.g. [ "Turing" "Ampere" ]
+      #
+      # Unknown architectures are rendered as sm_XX gencode flags.
       archNames = lists.unique (
-        lists.map (cap: cudaComputeCapabilityToName.${cap} or (throw "missing cuda compute capability"))
-          cudaCapabilities
+        lists.map (cap: cudaComputeCapabilityToName.${cap} or "sm_${dropDot cap}") cudaCapabilities
       );
 
       # realArches :: List String
@@ -219,7 +220,7 @@ let
       isJetsonBuild =
         let
           requestedJetsonDevices =
-            lists.filter (cap: cudaComputeCapabilityToIsJetson.${cap})
+            lists.filter (cap: cudaComputeCapabilityToIsJetson.${cap} or false)
               cudaCapabilities;
           requestedNonJetsonDevices =
             lists.filter (cap: !(builtins.elem cap requestedJetsonDevices))
diff --git a/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix b/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix
index 71c914c8c8f2..5a4c5280d7db 100644
--- a/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/generic-builders/manifest.nix
@@ -77,7 +77,7 @@ backendStdenv.mkDerivation (
             false
             featureRelease;
         # Order is important here so we use a list.
-        additionalOutputs = builtins.filter hasOutput [
+        possibleOutputs = [
           "bin"
           "lib"
           "static"
@@ -86,15 +86,22 @@ backendStdenv.mkDerivation (
           "sample"
           "python"
         ];
+        additionalOutputs =
+          if redistArch == "unsupported" then possibleOutputs else builtins.filter hasOutput possibleOutputs;
         # The out output is special -- it's the default output and we always include it.
-        outputs = ["out"] ++ additionalOutputs;
+        outputs = [ "out" ] ++ additionalOutputs;
       in
       outputs;
 
     # Traversed in the order of the outputs speficied in outputs;
     # entries are skipped if they don't exist in outputs.
     outputToPatterns = {
-      bin = ["bin"];
+      bin = [ "bin" ];
+      dev = [
+        "share/pkg-config"
+        "**/*.pc"
+        "**/*.cmake"
+      ];
       lib = [
         "lib"
         "lib64"
@@ -110,12 +117,32 @@ backendStdenv.mkDerivation (
     brokenConditions = {};
 
     src = fetchurl {
-      url = "https://developer.download.nvidia.com/compute/${redistName}/redist/${
-        redistribRelease.${redistArch}.relative_path
-      }";
-      inherit (redistribRelease.${redistArch}) sha256;
+      url =
+        if (builtins.hasAttr redistArch redistribRelease) then
+          "https://developer.download.nvidia.com/compute/${redistName}/redist/${
+            redistribRelease.${redistArch}.relative_path
+          }"
+        else
+          "cannot-construct-an-url-for-the-${redistArch}-platform";
+      sha256 = redistribRelease.${redistArch}.sha256 or lib.fakeHash;
     };
 
+    postPatch = ''
+      if [[ -d pkg-config ]] ; then
+        mkdir -p share/pkg-config
+        mv pkg-config/* share/pkg-config/
+        rmdir pkg-config
+      fi
+
+      for pc in share/pkg-config/*.pc ; do
+        sed -i \
+          -e "s|^cudaroot\s*=.*\$|cudaroot=''${!outputDev}|" \
+          -e "s|^libdir\s*=.*/lib\$|libdir=''${!outputLib}/lib|" \
+          -e "s|^includedir\s*=.*/include\$|includedir=''${!outputDev}/include|" \
+          "$pc"
+      done
+    '';
+
     # We do need some other phases, like configurePhase, so the multiple-output setup hook works.
     dontBuild = true;
 
@@ -197,6 +224,20 @@ backendStdenv.mkDerivation (
         runHook postInstall
       '';
 
+    doInstallCheck = true;
+    allowFHSReferences = true; # TODO: Default to `false`
+    postInstallCheck = ''
+      echo "Executing postInstallCheck"
+
+      if [[ -z "''${allowFHSReferences-}" ]] ; then
+        mapfile -t outputPaths < <(for o in $(getAllOutputNames); do echo "''${!o}"; done)
+        if grep --max-count=5 --recursive --exclude=LICENSE /usr/ "''${outputPaths[@]}" ; then
+          echo "Detected references to /usr" >&2
+          exit 1
+        fi
+      fi
+    '';
+
     # libcuda needs to be resolved during runtime
     # NOTE: Due to the use of __structuredAttrs, we can't use a list for autoPatchelfIgnoreMissingDeps, since it
     # will take only the first value. Instead, we produce a string with the values separated by spaces.
@@ -248,9 +289,9 @@ backendStdenv.mkDerivation (
           (
             redistArch:
             let
-              nixSystem = builtins.tryEval (flags.getNixSystem redistArch);
+              nixSystem = flags.getNixSystem redistArch;
             in
-            if nixSystem.success then [nixSystem.value] else []
+            lists.optionals (!(strings.hasPrefix "unsupported-" nixSystem)) [ nixSystem ]
           )
           supportedRedistArchs;
       broken = lists.any trivial.id (attrsets.attrValues finalAttrs.brokenConditions);
diff --git a/nixpkgs/pkgs/development/cuda-modules/generic-builders/multiplex.nix b/nixpkgs/pkgs/development/cuda-modules/generic-builders/multiplex.nix
index b8053094bcc8..5480da730726 100644
--- a/nixpkgs/pkgs/development/cuda-modules/generic-builders/multiplex.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/generic-builders/multiplex.nix
@@ -59,9 +59,12 @@ let
   # - Releases: ../modules/${pname}/releases/releases.nix
   # - Package: ../modules/${pname}/releases/package.nix
 
+  # FIXME: do this at the module system level
+  propagatePlatforms = lib.mapAttrs (platform: subset: map (r: r // { inherit platform; }) subset);
+
   # All releases across all platforms
   # See ../modules/${pname}/releases/releases.nix
-  allReleases = evaluatedModules.config.${pname}.releases;
+  releaseSets = propagatePlatforms evaluatedModules.config.${pname}.releases;
 
   # Compute versioned attribute name to be used in this package set
   # Patch version changes should not break the build, so we only use major and minor
@@ -72,20 +75,22 @@ let
   # isSupported :: Package -> Bool
   isSupported =
     package:
-    strings.versionAtLeast cudaVersion package.minCudaVersion
+    !(strings.hasPrefix "unsupported" package.platform)
+    && strings.versionAtLeast cudaVersion package.minCudaVersion
     && strings.versionAtLeast package.maxCudaVersion cudaVersion;
 
   # Get all of the packages for our given platform.
   redistArch = flags.getRedistArch hostPlatform.system;
 
-  # All the supported packages we can build for our platform.
-  # supportedPackages :: List (AttrSet Packages)
-  supportedPackages = builtins.filter isSupported (allReleases.${redistArch} or []);
+  allReleases = builtins.concatMap (xs: xs) (builtins.attrValues releaseSets);
 
-  # newestToOldestSupportedPackage :: List (AttrSet Packages)
-  newestToOldestSupportedPackage = lists.reverseList supportedPackages;
+  # All the supported packages we can build for our platform.
+  # perSystemReleases :: List Package
+  perSystemReleases = releaseSets.${redistArch} or [ ];
 
-  nameOfNewest = computeName (builtins.head newestToOldestSupportedPackage);
+  preferable =
+    p1: p2: (isSupported p2 -> isSupported p1) && (strings.versionAtLeast p1.version p2.version);
+  newest = builtins.head (builtins.sort preferable allReleases);
 
   # A function which takes the `final` overlay and the `package` being built and returns
   # a function to be consumed via `overrideAttrs`.
@@ -120,11 +125,9 @@ let
         attrsets.nameValuePair name fixedDrv;
 
       # versionedDerivations :: AttrSet Derivation
-      versionedDerivations = builtins.listToAttrs (lists.map buildPackage newestToOldestSupportedPackage);
+      versionedDerivations = builtins.listToAttrs (lists.map buildPackage perSystemReleases);
 
-      defaultDerivation = attrsets.optionalAttrs (versionedDerivations != {}) {
-        ${pname} = versionedDerivations.${nameOfNewest};
-      };
+      defaultDerivation = { ${pname} = (buildPackage newest).value; };
     in
     versionedDerivations // defaultDerivation;
 in
diff --git a/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix b/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix
index fff52801e3cc..73e17b28757b 100644
--- a/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/saxpy/default.nix
@@ -14,6 +14,7 @@ let
     cudaVersion
     flags
     libcublas
+    setupCudaHook
     ;
 in
 backendStdenv.mkDerivation {
diff --git a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/setup-cuda-hook.sh b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/setup-cuda-hook.sh
index 7b7b3bdde80e..a4a444fcd241 100644
--- a/nixpkgs/pkgs/development/cuda-modules/setup-hooks/setup-cuda-hook.sh
+++ b/nixpkgs/pkgs/development/cuda-modules/setup-hooks/setup-cuda-hook.sh
@@ -93,26 +93,6 @@ setupCUDAToolkitCompilers() {
     if [[ -z "${dontCompressFatbin-}" ]]; then
         export NVCC_PREPEND_FLAGS+=" -Xfatbin=-compress-all"
     fi
-
-    # CMake's enable_language(CUDA) runs a compiler test and it doesn't account for
-    # CUDAToolkit_ROOT. We have to help it locate libcudart
-    if [[ -z "${nvccDontPrependCudartFlags-}" ]] ; then
-        if [[ ! -v cudaOutputToPath["cuda_cudart-out"] ]] ; then
-            echo "setupCUDAToolkitCompilers: missing cudaPackages.cuda_cudart. This may become an an error in the future" >&2
-            # exit 1
-        fi
-        for pkg in "${!cudaOutputToPath[@]}" ; do
-            [[ ! "$pkg" = cuda_cudart* ]] && continue
-
-            local path="${cudaOutputToPath[$pkg]}"
-            if [[ -d "$path/include" ]] ; then
-                export NVCC_PREPEND_FLAGS+=" -I$path/include"
-            fi
-            if [[ -d "$path/lib" ]] ; then
-                export NVCC_PREPEND_FLAGS+=" -L$path/lib"
-            fi
-        done
-    fi
 }
 preConfigureHooks+=(setupCUDAToolkitCompilers)
 
diff --git a/nixpkgs/pkgs/development/cuda-modules/tensorrt/fixup.nix b/nixpkgs/pkgs/development/cuda-modules/tensorrt/fixup.nix
index d713189328ed..43a7dfb81784 100644
--- a/nixpkgs/pkgs/development/cuda-modules/tensorrt/fixup.nix
+++ b/nixpkgs/pkgs/development/cuda-modules/tensorrt/fixup.nix
@@ -16,6 +16,13 @@ let
     strings
     versions
     ;
+  targetArch =
+    if hostPlatform.isx86_64 then
+      "x86_64-linux-gnu"
+    else if hostPlatform.isAarch64 then
+      "aarch64-linux-gnu"
+    else
+      "unsupported";
 in
 finalAttrs: prevAttrs: {
   # Useful for inspecting why something went wrong.
@@ -58,18 +65,9 @@ finalAttrs: prevAttrs: {
   # We need to look inside the extracted output to get the files we need.
   sourceRoot = "TensorRT-${finalAttrs.version}";
 
-  buildInputs = prevAttrs.buildInputs ++ [finalAttrs.passthru.cudnn.lib];
+  buildInputs = prevAttrs.buildInputs ++ [ finalAttrs.passthru.cudnn.lib ];
 
   preInstall =
-    let
-      targetArch =
-        if hostPlatform.isx86_64 then
-          "x86_64-linux-gnu"
-        else if hostPlatform.isAarch64 then
-          "aarch64-linux-gnu"
-        else
-          throw "Unsupported architecture";
-    in
     (prevAttrs.preInstall or "")
     + ''
       # Replace symlinks to bin and lib with the actual directories from targets.
@@ -107,6 +105,9 @@ finalAttrs: prevAttrs: {
   };
 
   meta = prevAttrs.meta // {
+    badPlatforms =
+      prevAttrs.meta.badPlatforms or [ ]
+      ++ lib.optionals (targetArch == "unsupported") [ hostPlatform.system ];
     homepage = "https://developer.nvidia.com/tensorrt";
     maintainers = prevAttrs.meta.maintainers ++ [maintainers.aidalgol];
   };