Merge pull request #276800 from SomeoneSerge/fix/cuda-no-throw

cudaPackages: eliminate exceptions

authored by Someone and committed by GitHub 86b7775f bc2c8e8e

+47 -35
+1 -1
pkgs/development/cuda-modules/cuda/overrides.nix
··· 87 87 cuda_nvcc = prev.cuda_nvcc.overrideAttrs ( 88 88 oldAttrs: { 89 89 90 - outputs = oldAttrs.outputs ++ [ "lib" ]; 90 + outputs = oldAttrs.outputs ++ lists.optionals (!(builtins.elem "lib" oldAttrs.outputs)) [ "lib" ]; 91 91 92 92 # Patch the nvcc.profile. 93 93 # Syntax:
+5 -4
pkgs/development/cuda-modules/flags.nix
··· 143 143 else if nixSystem == "x86_64-windows" then 144 144 "windows-x86_64" 145 145 else 146 - builtins.throw "Unsupported Nix system: ${nixSystem}"; 146 + "unsupported"; 147 147 148 148 # Maps NVIDIA redist arch to Nix system. 149 149 # It is imperative that we include the boolean condition based on jetsonTargets to ensure ··· 163 163 else if redistArch == "windows-x86_64" then 164 164 "x86_64-windows" 165 165 else 166 - builtins.throw "Unsupported NVIDIA redist arch: ${redistArch}"; 166 + "unsupported-${redistArch}"; 167 167 168 168 formatCapabilities = 169 169 { ··· 175 175 176 176 # archNames :: List String 177 177 # E.g. [ "Turing" "Ampere" ] 178 + # 179 + # Unknown architectures are rendered as sm_XX gencode flags. 178 180 archNames = lists.unique ( 179 - lists.map (cap: cudaComputeCapabilityToName.${cap} or (throw "missing cuda compute capability")) 180 - cudaCapabilities 181 + lists.map (cap: cudaComputeCapabilityToName.${cap} or "sm_${dropDot cap}") cudaCapabilities 181 182 ); 182 183 183 184 # realArches :: List String
+14 -8
pkgs/development/cuda-modules/generic-builders/manifest.nix
··· 77 77 false 78 78 featureRelease; 79 79 # Order is important here so we use a list. 80 - additionalOutputs = builtins.filter hasOutput [ 80 + possibleOutputs = [ 81 81 "bin" 82 82 "lib" 83 83 "static" ··· 86 86 "sample" 87 87 "python" 88 88 ]; 89 + additionalOutputs = 90 + if redistArch == "unsupported" then possibleOutputs else builtins.filter hasOutput possibleOutputs; 89 91 # The out output is special -- it's the default output and we always include it. 90 - outputs = ["out"] ++ additionalOutputs; 92 + outputs = [ "out" ] ++ additionalOutputs; 91 93 in 92 94 outputs; 93 95 ··· 115 117 brokenConditions = {}; 116 118 117 119 src = fetchurl { 118 - url = "https://developer.download.nvidia.com/compute/${redistName}/redist/${ 119 - redistribRelease.${redistArch}.relative_path 120 - }"; 121 - inherit (redistribRelease.${redistArch}) sha256; 120 + url = 121 + if (builtins.hasAttr redistArch redistribRelease) then 122 + "https://developer.download.nvidia.com/compute/${redistName}/redist/${ 123 + redistribRelease.${redistArch}.relative_path 124 + }" 125 + else 126 + "cannot-construct-an-url-for-the-${redistArch}-platform"; 127 + sha256 = redistribRelease.${redistArch}.sha256 or lib.fakeHash; 122 128 }; 123 129 124 130 postPatch = '' ··· 283 289 ( 284 290 redistArch: 285 291 let 286 - nixSystem = builtins.tryEval (flags.getNixSystem redistArch); 292 + nixSystem = flags.getNixSystem redistArch; 287 293 in 288 - if nixSystem.success then [nixSystem.value] else [] 294 + lists.optionals (!(strings.hasPrefix "unsupported-" nixSystem)) [ nixSystem ] 289 295 ) 290 296 supportedRedistArchs; 291 297 broken = lists.any trivial.id (attrsets.attrValues finalAttrs.brokenConditions);
+15 -12
pkgs/development/cuda-modules/generic-builders/multiplex.nix
··· 59 59 # - Releases: ../modules/${pname}/releases/releases.nix 60 60 # - Package: ../modules/${pname}/releases/package.nix 61 61 62 + # FIXME: do this at the module system level 63 + propagatePlatforms = lib.mapAttrs (platform: subset: map (r: r // { inherit platform; }) subset); 64 + 62 65 # All releases across all platforms 63 66 # See ../modules/${pname}/releases/releases.nix 64 - allReleases = evaluatedModules.config.${pname}.releases; 67 + releaseSets = propagatePlatforms evaluatedModules.config.${pname}.releases; 65 68 66 69 # Compute versioned attribute name to be used in this package set 67 70 # Patch version changes should not break the build, so we only use major and minor ··· 72 75 # isSupported :: Package -> Bool 73 76 isSupported = 74 77 package: 75 - strings.versionAtLeast cudaVersion package.minCudaVersion 78 + !(strings.hasPrefix "unsupported" package.platform) 79 + && strings.versionAtLeast cudaVersion package.minCudaVersion 76 80 && strings.versionAtLeast package.maxCudaVersion cudaVersion; 77 81 78 82 # Get all of the packages for our given platform. 79 83 redistArch = flags.getRedistArch hostPlatform.system; 80 84 85 + allReleases = builtins.concatMap (xs: xs) (builtins.attrValues releaseSets); 86 + 81 87 # All the supported packages we can build for our platform. 82 - # supportedPackages :: List (AttrSet Packages) 83 - supportedPackages = builtins.filter isSupported (allReleases.${redistArch} or []); 88 + # perSystemReleases :: List Package 89 + perSystemReleases = releaseSets.${redistArch} or [ ]; 84 90 85 - # newestToOldestSupportedPackage :: List (AttrSet Packages) 86 - newestToOldestSupportedPackage = lists.reverseList supportedPackages; 87 - 88 - nameOfNewest = computeName (builtins.head newestToOldestSupportedPackage); 91 + preferable = 92 + p1: p2: (isSupported p2 -> isSupported p1) && (strings.versionAtLeast p1.version p2.version); 93 + newest = builtins.head (builtins.sort preferable allReleases); 89 94 90 95 # A function which takes the `final` overlay and the `package` being built and returns 91 96 # a function to be consumed via `overrideAttrs`. ··· 120 125 attrsets.nameValuePair name fixedDrv; 121 126 122 127 # versionedDerivations :: AttrSet Derivation 123 - versionedDerivations = builtins.listToAttrs (lists.map buildPackage newestToOldestSupportedPackage); 128 + versionedDerivations = builtins.listToAttrs (lists.map buildPackage perSystemReleases); 124 129 125 - defaultDerivation = attrsets.optionalAttrs (versionedDerivations != {}) { 126 - ${pname} = versionedDerivations.${nameOfNewest}; 127 - }; 130 + defaultDerivation = { ${pname} = (buildPackage newest).value; }; 128 131 in 129 132 versionedDerivations // defaultDerivation; 130 133 in
+11 -10
pkgs/development/cuda-modules/tensorrt/fixup.nix
··· 16 16 strings 17 17 versions 18 18 ; 19 + targetArch = 20 + if hostPlatform.isx86_64 then 21 + "x86_64-linux-gnu" 22 + else if hostPlatform.isAarch64 then 23 + "aarch64-linux-gnu" 24 + else 25 + "unsupported"; 19 26 in 20 27 finalAttrs: prevAttrs: { 21 28 # Useful for inspecting why something went wrong. ··· 58 65 # We need to look inside the extracted output to get the files we need. 59 66 sourceRoot = "TensorRT-${finalAttrs.version}"; 60 67 61 - buildInputs = prevAttrs.buildInputs ++ [finalAttrs.passthru.cudnn.lib]; 68 + buildInputs = prevAttrs.buildInputs ++ [ finalAttrs.passthru.cudnn.lib ]; 62 69 63 70 preInstall = 64 - let 65 - targetArch = 66 - if hostPlatform.isx86_64 then 67 - "x86_64-linux-gnu" 68 - else if hostPlatform.isAarch64 then 69 - "aarch64-linux-gnu" 70 - else 71 - throw "Unsupported architecture"; 72 - in 73 71 (prevAttrs.preInstall or "") 74 72 + '' 75 73 # Replace symlinks to bin and lib with the actual directories from targets. ··· 107 105 }; 108 106 109 107 meta = prevAttrs.meta // { 108 + badPlatforms = 109 + prevAttrs.meta.badPlatforms or [ ] 110 + ++ lib.optionals (targetArch == "unsupported") [ hostPlatform.system ]; 110 111 homepage = "https://developer.nvidia.com/tensorrt"; 111 112 maintainers = prevAttrs.meta.maintainers ++ [maintainers.aidalgol]; 112 113 };
+1
pkgs/development/python-modules/tensorflow/default.nix
··· 480 480 }; 481 481 482 482 meta = with lib; { 483 + badPlatforms = lib.optionals cudaSupport lib.platforms.darwin; 483 484 changelog = "https://github.com/tensorflow/tensorflow/releases/tag/v${version}"; 484 485 description = "Computation using data flow graphs for scalable machine learning"; 485 486 homepage = "http://tensorflow.org";