about summary refs log tree commit diff
path: root/pkgs/development/cuda-modules
diff options
context:
space:
mode:
authorSomeone <sergei.kozlukov@aalto.fi>2023-12-26 04:54:10 +0000
committerGitHub <noreply@github.com>2023-12-26 04:54:10 +0000
commit86b7775ff38a6f12529691d8bc39ffb7d219f5a2 (patch)
tree3e26fa72015cde28913567abd693cbafe91d40a2 /pkgs/development/cuda-modules
parentbc2c8e8ed1a665131ecdfc43e979e07dc8e45bc4 (diff)
parentcf214375c9bc03f458dc6dad04990fd5774c6bb7 (diff)
Merge pull request #276800 from SomeoneSerge/fix/cuda-no-throw
cudaPackages: eliminate exceptions
Diffstat (limited to 'pkgs/development/cuda-modules')
-rw-r--r--pkgs/development/cuda-modules/cuda/overrides.nix2
-rw-r--r--pkgs/development/cuda-modules/flags.nix9
-rw-r--r--pkgs/development/cuda-modules/generic-builders/manifest.nix22
-rw-r--r--pkgs/development/cuda-modules/generic-builders/multiplex.nix27
-rw-r--r--pkgs/development/cuda-modules/tensorrt/fixup.nix21
5 files changed, 46 insertions, 35 deletions
diff --git a/pkgs/development/cuda-modules/cuda/overrides.nix b/pkgs/development/cuda-modules/cuda/overrides.nix
index 3f68c7be724ff..d92e07bb1b0bf 100644
--- a/pkgs/development/cuda-modules/cuda/overrides.nix
+++ b/pkgs/development/cuda-modules/cuda/overrides.nix
@@ -87,7 +87,7 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) {
   cuda_nvcc = prev.cuda_nvcc.overrideAttrs (
     oldAttrs: {
 
-      outputs = oldAttrs.outputs ++ [ "lib" ];
+      outputs = oldAttrs.outputs ++ lists.optionals (!(builtins.elem "lib" oldAttrs.outputs)) [ "lib" ];
 
       # Patch the nvcc.profile.
       # Syntax:
diff --git a/pkgs/development/cuda-modules/flags.nix b/pkgs/development/cuda-modules/flags.nix
index ab44ced452329..a123c7bce5a16 100644
--- a/pkgs/development/cuda-modules/flags.nix
+++ b/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
diff --git a/pkgs/development/cuda-modules/generic-builders/manifest.nix b/pkgs/development/cuda-modules/generic-builders/manifest.nix
index 67f6e93559c4f..5a4c5280d7dbd 100644
--- a/pkgs/development/cuda-modules/generic-builders/manifest.nix
+++ b/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,8 +86,10 @@ 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;
 
@@ -115,10 +117,14 @@ 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 = ''
@@ -283,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/pkgs/development/cuda-modules/generic-builders/multiplex.nix b/pkgs/development/cuda-modules/generic-builders/multiplex.nix
index b8053094bcc82..5480da7307261 100644
--- a/pkgs/development/cuda-modules/generic-builders/multiplex.nix
+++ b/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/pkgs/development/cuda-modules/tensorrt/fixup.nix b/pkgs/development/cuda-modules/tensorrt/fixup.nix
index d713189328ed7..43a7dfb817840 100644
--- a/pkgs/development/cuda-modules/tensorrt/fixup.nix
+++ b/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];
   };