diff --git a/doc/languages-frameworks/cuda.section.md b/doc/languages-frameworks/cuda.section.md index 091fc57a53a0..7e489acdbd64 100644 --- a/doc/languages-frameworks/cuda.section.md +++ b/doc/languages-frameworks/cuda.section.md @@ -115,8 +115,8 @@ All new projects should use the CUDA redistributables available in [`cudaPackage ### Updating supported compilers and GPUs {#updating-supported-compilers-and-gpus} -1. Update `nvcc-compatibilities.nix` in `pkgs/development/cuda-modules/` to include the newest release of NVCC, as well as any newly supported host compilers. -2. Update `gpus.nix` in `pkgs/development/cuda-modules/` to include any new GPUs supported by the new release of CUDA. +1. Update `nvccCompatibilities` in `pkgs/development/cuda-modules/lib/data/nvcc.nix` to include the newest release of NVCC, as well as any newly supported host compilers. +2. Update `cudaCapabilityToInfo` in `pkgs/development/cuda-modules/lib/data/cuda.nix` to include any new GPUs supported by the new release of CUDA. ### Updating the CUDA Toolkit runfile installer {#updating-the-cuda-toolkit} diff --git a/pkgs/development/cuda-modules/README.md b/pkgs/development/cuda-modules/README.md index d79f5bede0bb..3e6168e52be8 100644 --- a/pkgs/development/cuda-modules/README.md +++ b/pkgs/development/cuda-modules/README.md @@ -16,9 +16,6 @@ scope. These are typically required for the creation of the finalized - `backend-stdenv.nix`: Standard environment for CUDA packages. - `flags.nix`: Flags set, or consumed by, NVCC in order to build packages. -- `gpus.nix`: A list of supported NVIDIA GPUs. -- `nvcc-compatibilities.nix`: NVCC releases and the version range of GCC/Clang - they support. ## Top-level directories diff --git a/pkgs/development/cuda-modules/aliases.nix b/pkgs/development/cuda-modules/aliases.nix index 14975410d378..1c8e9c1d5fab 100644 --- a/pkgs/development/cuda-modules/aliases.nix +++ b/pkgs/development/cuda-modules/aliases.nix @@ -1,11 +1,12 @@ # Packages which have been deprecated or removed from cudaPackages -final: _: +{ lib }: let mkRenamed = oldName: { path, package }: - final.lib.warn "cudaPackages.${oldName} is deprecated, use ${path} instead" package; + lib.warn "cudaPackages.${oldName} is deprecated, use ${path} instead" package; in +final: _: builtins.mapAttrs mkRenamed { # A comment to prevent empty { } from collapsing into a single line diff --git a/pkgs/development/cuda-modules/cuda/extension.nix b/pkgs/development/cuda-modules/cuda/extension.nix index 09d8999270a2..c46c39dcea2d 100644 --- a/pkgs/development/cuda-modules/cuda/extension.nix +++ b/pkgs/development/cuda-modules/cuda/extension.nix @@ -43,7 +43,7 @@ let }; # Generally we prefer to do things involving getting attribute names with feature_manifest instead - # of redistrib_manifest because the feature manifest will have *only* the redist architecture + # of redistrib_manifest because the feature manifest will have *only* the redist system # names as the keys, whereas the redistrib manifest will also have things like version, name, license, # and license_path. featureManifest = evaluatedModules.config.cuda.manifests.feature; diff --git a/pkgs/development/cuda-modules/cudnn/shims.nix b/pkgs/development/cuda-modules/cudnn/shims.nix index 0a7f09bc9f0f..01918e88f07b 100644 --- a/pkgs/development/cuda-modules/cudnn/shims.nix +++ b/pkgs/development/cuda-modules/cudnn/shims.nix @@ -1,14 +1,14 @@ # Shims to mimic the shape of ../modules/generic/manifests/{feature,redistrib}/release.nix { package, - # redistArch :: String + # redistSystem :: String # String is "unsupported" if the given architecture is unsupported. - redistArch, + redistSystem, }: { featureRelease = { inherit (package) minCudaVersion maxCudaVersion; - ${redistArch}.outputs = { + ${redistSystem}.outputs = { lib = true; static = true; dev = true; diff --git a/pkgs/development/cuda-modules/cusparselt/extension.nix b/pkgs/development/cuda-modules/cusparselt/extension.nix index e72be0d7cb99..56308973c341 100644 --- a/pkgs/development/cuda-modules/cusparselt/extension.nix +++ b/pkgs/development/cuda-modules/cusparselt/extension.nix @@ -1,11 +1,9 @@ # Support matrix can be found at # https://docs.nvidia.com/deeplearning/cudnn/archives/cudnn-880/support-matrix/index.html { + cudaLib, lib, - stdenv, - cudaMajorMinorVersion, - flags, - mkVersionedPackageName, + redistSystem, }: let inherit (lib) @@ -15,8 +13,6 @@ let trivial ; - inherit (stdenv) hostPlatform; - redistName = "cusparselt"; pname = "libcusparse_lt"; @@ -54,17 +50,12 @@ let releaseGrabber ]) cusparseltVersions; - # A release is supported if it has a libPath that matches our CUDA version for our platform. - # LibPath are not constant across the same release -- one platform may support fewer - # CUDA versions than another. - # redistArch :: String - redistArch = flags.getRedistArch hostPlatform.system; # platformIsSupported :: Manifests -> Boolean platformIsSupported = { feature, redistrib, ... }: (attrsets.attrByPath [ pname - redistArch + redistSystem ] null feature) != null; # TODO(@connorbaker): With an auxiliary file keeping track of the CUDA versions each release supports, @@ -77,7 +68,8 @@ let # 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 # computeName :: RedistribRelease -> String - computeName = { version, ... }: mkVersionedPackageName redistName version; + computeName = + { version, ... }: cudaLib.utils.mkVersionedName redistName (lib.versions.majorMinor version); in final: _: let diff --git a/pkgs/development/cuda-modules/cutensor/extension.nix b/pkgs/development/cuda-modules/cutensor/extension.nix index deb6cc7e8e51..5f59cfb15bb6 100644 --- a/pkgs/development/cuda-modules/cutensor/extension.nix +++ b/pkgs/development/cuda-modules/cutensor/extension.nix @@ -13,11 +13,10 @@ # - Instead of providing different releases for each version of CUDA, CuTensor has multiple subdirectories in `lib` # -- one for each version of CUDA. { + cudaLib, cudaMajorMinorVersion, - flags, lib, - mkVersionedPackageName, - stdenv, + redistSystem, }: let inherit (lib) @@ -28,8 +27,6 @@ let trivial ; - inherit (stdenv) hostPlatform; - redistName = "cutensor"; pname = "libcutensor"; @@ -92,14 +89,12 @@ let # A release is supported if it has a libPath that matches our CUDA version for our platform. # LibPath are not constant across the same release -- one platform may support fewer # CUDA versions than another. - # redistArch :: String - redistArch = flags.getRedistArch hostPlatform.system; # platformIsSupported :: Manifests -> Boolean platformIsSupported = { feature, redistrib, ... }: (attrsets.attrByPath [ pname - redistArch + redistSystem ] null feature) != null; # TODO(@connorbaker): With an auxiliary file keeping track of the CUDA versions each release supports, @@ -112,7 +107,8 @@ let # 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 # computeName :: RedistribRelease -> String - computeName = { version, ... }: mkVersionedPackageName redistName version; + computeName = + { version, ... }: cudaLib.utils.mkVersionedName redistName (lib.versions.majorMinor version); in final: _: let diff --git a/pkgs/development/cuda-modules/fixups/tensorrt.nix b/pkgs/development/cuda-modules/fixups/tensorrt.nix index a836debf0604..c55844eac0d9 100644 --- a/pkgs/development/cuda-modules/fixups/tensorrt.nix +++ b/pkgs/development/cuda-modules/fixups/tensorrt.nix @@ -1,9 +1,9 @@ { + cudaLib, cudaOlder, cudaPackages, cudaMajorMinorVersion, lib, - mkVersionedPackageName, patchelf, requireFile, stdenv, @@ -103,7 +103,9 @@ finalAttrs: prevAttrs: { # unless it is not available, in which case the default cudnn derivation will be used. cudnn = let - desiredName = mkVersionedPackageName "cudnn" finalAttrs.passthru.featureRelease.cudnnVersion; + desiredName = cudaLib.utils.mkVersionedName "cudnn" ( + lib.versions.majorMinor finalAttrs.passthru.featureRelease.cudnnVersion + ); in if finalAttrs.passthru.featureRelease.cudnnVersion == null || (cudaPackages ? desiredName) then cudaPackages.cudnn diff --git a/pkgs/development/cuda-modules/flags.nix b/pkgs/development/cuda-modules/flags.nix deleted file mode 100644 index 980f33c7863f..000000000000 --- a/pkgs/development/cuda-modules/flags.nix +++ /dev/null @@ -1,399 +0,0 @@ -# Type aliases -# Gpu :: AttrSet -# - See the documentation in ./gpus.nix. -{ - config, - cudaCapabilities ? (config.cudaCapabilities or [ ]), - cudaForwardCompat ? (config.cudaForwardCompat or true), - lib, - cudaMajorMinorVersion, - stdenv, - # gpus :: List Gpu - gpus, -}: -let - inherit (lib) - asserts - attrsets - lists - strings - trivial - ; - - inherit (stdenv) hostPlatform; - - # Flags are determined based on your CUDA toolkit by default. You may benefit - # from improved performance, reduced file size, or greater hardware support by - # passing a configuration based on your specific GPU environment. - # - # cudaCapabilities :: List Capability - # List of hardware generations to build. - # E.g. [ "8.0" ] - # Currently, the last item is considered the optional forward-compatibility arch, - # but this may change in the future. - # - # cudaForwardCompat :: Bool - # Whether to include the forward compatibility gencode (+PTX) - # to support future GPU generations. - # E.g. true - # - # Please see the accompanying documentation or https://github.com/NixOS/nixpkgs/pull/205351 - - # isSupported :: Gpu -> Bool - isSupported = - gpu: - let - inherit (gpu) minCudaVersion maxCudaVersion; - lowerBoundSatisfied = strings.versionAtLeast cudaMajorMinorVersion minCudaVersion; - upperBoundSatisfied = - (maxCudaVersion == null) || !(strings.versionOlder maxCudaVersion cudaMajorMinorVersion); - in - lowerBoundSatisfied && upperBoundSatisfied; - - # NOTE: Jetson is never built by default. - # isDefault :: Gpu -> Bool - isDefault = - gpu: - let - inherit (gpu) dontDefaultAfter isJetson; - newGpu = dontDefaultAfter == null; - recentGpu = newGpu || strings.versionAtLeast dontDefaultAfter cudaMajorMinorVersion; - in - recentGpu && !isJetson; - - # supportedGpus :: List Gpu - # GPUs which are supported by the provided CUDA version. - supportedGpus = builtins.filter isSupported gpus; - - # defaultGpus :: List Gpu - # GPUs which are supported by the provided CUDA version and we want to build for by default. - defaultGpus = builtins.filter isDefault supportedGpus; - - # supportedCapabilities :: List Capability - supportedCapabilities = lists.map (gpu: gpu.computeCapability) supportedGpus; - - # defaultCapabilities :: List Capability - # The default capabilities to target, if not overridden by the user. - defaultCapabilities = lists.map (gpu: gpu.computeCapability) defaultGpus; - - # cudaArchNameToVersions :: AttrSet String (List String) - # Maps the name of a GPU architecture to different versions of that architecture. - # For example, "Ampere" maps to [ "8.0" "8.6" "8.7" ]. - cudaArchNameToVersions = lists.groupBy' (versions: gpu: versions ++ [ gpu.computeCapability ]) [ ] ( - gpu: gpu.archName - ) supportedGpus; - - # cudaComputeCapabilityToName :: AttrSet String String - # Maps the version of a GPU architecture to the name of that architecture. - # For example, "8.0" maps to "Ampere". - cudaComputeCapabilityToName = builtins.listToAttrs ( - lists.map (gpu: attrsets.nameValuePair gpu.computeCapability gpu.archName) supportedGpus - ); - - # cudaComputeCapabilityToIsJetson :: AttrSet String Boolean - cudaComputeCapabilityToIsJetson = builtins.listToAttrs ( - lists.map (attrs: attrsets.nameValuePair attrs.computeCapability attrs.isJetson) supportedGpus - ); - - # jetsonComputeCapabilities :: List String - jetsonComputeCapabilities = trivial.pipe cudaComputeCapabilityToIsJetson [ - (attrsets.filterAttrs (_: isJetson: isJetson)) - builtins.attrNames - ]; - - # Find the intersection with the user-specified list of cudaCapabilities. - # NOTE: Jetson devices are never built by default because they cannot be targeted along with - # non-Jetson devices and require an aarch64 host platform. As such, if they're present anywhere, - # they must be in the user-specified cudaCapabilities. - # NOTE: We don't need to worry about mixes of Jetson and non-Jetson devices here -- there's - # sanity-checking for all that in below. - jetsonTargets = lists.intersectLists jetsonComputeCapabilities cudaCapabilities; - - # dropDot :: String -> String - dropDot = ver: builtins.replaceStrings [ "." ] [ "" ] ver; - - # archMapper :: String -> List String -> List String - # Maps a feature across a list of architecture versions to produce a list of architectures. - # For example, "sm" and [ "8.0" "8.6" "8.7" ] produces [ "sm_80" "sm_86" "sm_87" ]. - archMapper = feat: lists.map (computeCapability: "${feat}_${dropDot computeCapability}"); - - # gencodeMapper :: String -> List String -> List String - # Maps a feature across a list of architecture versions to produce a list of gencode arguments. - # For example, "sm" and [ "8.0" "8.6" "8.7" ] produces [ "-gencode=arch=compute_80,code=sm_80" - # "-gencode=arch=compute_86,code=sm_86" "-gencode=arch=compute_87,code=sm_87" ]. - gencodeMapper = - feat: - lists.map ( - computeCapability: - "-gencode=arch=compute_${dropDot computeCapability},code=${feat}_${dropDot computeCapability}" - ); - - # Maps Nix system to NVIDIA redist arch. - # NOTE: We swap out the default `linux-sbsa` redist (for server-grade ARM chips) with the - # `linux-aarch64` redist (which is for Jetson devices) if we're building any Jetson devices. - # Since both are based on aarch64, we can only have one or the other, otherwise there's an - # ambiguity as to which should be used. - # NOTE: This function *will* be called by unsupported systems because `cudaPackages` is part of - # `all-packages.nix`, which is evaluated on all systems. As such, we need to handle unsupported - # systems gracefully. - # getRedistArch :: String -> String - getRedistArch = - nixSystem: - attrsets.attrByPath [ nixSystem ] "unsupported" { - aarch64-linux = if jetsonTargets != [ ] then "linux-aarch64" else "linux-sbsa"; - x86_64-linux = "linux-x86_64"; - ppc64le-linux = "linux-ppc64le"; - x86_64-windows = "windows-x86_64"; - }; - - # Maps NVIDIA redist arch to Nix system. - # NOTE: This function *will* be called by unsupported systems because `cudaPackages` is part of - # `all-packages.nix`, which is evaluated on all systems. As such, we need to handle unsupported - # systems gracefully. - # getNixSystem :: String -> String - getNixSystem = - redistArch: - attrsets.attrByPath [ redistArch ] "unsupported-${redistArch}" { - linux-sbsa = "aarch64-linux"; - linux-aarch64 = "aarch64-linux"; - linux-x86_64 = "x86_64-linux"; - linux-ppc64le = "ppc64le-linux"; - windows-x86_64 = "x86_64-windows"; - }; - - formatCapabilities = - { - cudaCapabilities, - enableForwardCompat ? true, - }: - rec { - inherit cudaCapabilities enableForwardCompat; - - # 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 "sm_${dropDot cap}") cudaCapabilities - ); - - # realArches :: List String - # The real architectures are physical architectures supported by the CUDA version. - # E.g. [ "sm_75" "sm_86" ] - realArches = archMapper "sm" cudaCapabilities; - - # virtualArches :: List String - # The virtual architectures are typically used for forward compatibility, when trying to support - # an architecture newer than the CUDA version allows. - # E.g. [ "compute_75" "compute_86" ] - virtualArches = archMapper "compute" cudaCapabilities; - - # arches :: List String - # By default, build for all supported architectures and forward compatibility via a virtual - # architecture for the newest supported architecture. - # E.g. [ "sm_75" "sm_86" "compute_86" ] - arches = realArches ++ lists.optional enableForwardCompat (lists.last virtualArches); - - # gencode :: List String - # A list of CUDA gencode arguments to pass to NVCC. - # E.g. [ "-gencode=arch=compute_75,code=sm_75" ... "-gencode=arch=compute_86,code=compute_86" ] - gencode = - let - base = gencodeMapper "sm" cudaCapabilities; - forward = gencodeMapper "compute" [ (lists.last cudaCapabilities) ]; - in - base ++ lib.optionals enableForwardCompat forward; - - # gencodeString :: String - # A space-separated string of CUDA gencode arguments to pass to NVCC. - # E.g. "-gencode=arch=compute_75,code=sm_75 ... -gencode=arch=compute_86,code=compute_86" - gencodeString = strings.concatStringsSep " " gencode; - - # cmakeCudaArchitecturesString :: String - # A semicolon-separated string of CUDA capabilities without dots, suitable for passing to CMake. - # E.g. "75;86" - cmakeCudaArchitecturesString = strings.concatMapStringsSep ";" dropDot cudaCapabilities; - - # Jetson devices cannot be targeted by the same binaries which target non-Jetson devices. While - # NVIDIA provides both `linux-aarch64` and `linux-sbsa` packages, which both target `aarch64`, - # they are built with different settings and cannot be mixed. - # isJetsonBuild :: Boolean - isJetsonBuild = - let - requestedJetsonDevices = lists.filter ( - cap: cudaComputeCapabilityToIsJetson.${cap} or false - ) cudaCapabilities; - requestedNonJetsonDevices = lists.filter ( - cap: !(builtins.elem cap requestedJetsonDevices) - ) cudaCapabilities; - jetsonBuildSufficientCondition = requestedJetsonDevices != [ ]; - jetsonBuildNecessaryCondition = requestedNonJetsonDevices == [ ] && hostPlatform.isAarch64; - in - trivial.throwIf (jetsonBuildSufficientCondition && !jetsonBuildNecessaryCondition) '' - Jetson devices cannot be targeted with non-Jetson devices. Additionally, they require hostPlatform to be aarch64. - You requested ${builtins.toJSON cudaCapabilities} for host platform ${hostPlatform.system}. - Requested Jetson devices: ${builtins.toJSON requestedJetsonDevices}. - Requested non-Jetson devices: ${builtins.toJSON requestedNonJetsonDevices}. - Exactly one of the following must be true: - - All CUDA capabilities belong to Jetson devices and hostPlatform is aarch64. - - No CUDA capabilities belong to Jetson devices. - See ${./gpus.nix} for a list of architectures supported by this version of Nixpkgs. - '' jetsonBuildSufficientCondition - && jetsonBuildNecessaryCondition; - }; -in -# When changing names or formats: pause, validate, and update the assert -assert - let - expected = { - cudaCapabilities = [ - "7.5" - "8.6" - ]; - enableForwardCompat = true; - - archNames = [ - "Turing" - "Ampere" - ]; - realArches = [ - "sm_75" - "sm_86" - ]; - virtualArches = [ - "compute_75" - "compute_86" - ]; - arches = [ - "sm_75" - "sm_86" - "compute_86" - ]; - - gencode = [ - "-gencode=arch=compute_75,code=sm_75" - "-gencode=arch=compute_86,code=sm_86" - "-gencode=arch=compute_86,code=compute_86" - ]; - gencodeString = "-gencode=arch=compute_75,code=sm_75 -gencode=arch=compute_86,code=sm_86 -gencode=arch=compute_86,code=compute_86"; - - cmakeCudaArchitecturesString = "75;86"; - - isJetsonBuild = false; - }; - actual = formatCapabilities { - cudaCapabilities = [ - "7.5" - "8.6" - ]; - }; - actualWrapped = (builtins.tryEval (builtins.deepSeq actual actual)).value; - in - asserts.assertMsg - ((strings.versionAtLeast cudaMajorMinorVersion "11.2") -> (expected == actualWrapped)) - '' - This test should only fail when using a version of CUDA older than 11.2, the first to support - 8.6. - Expected: ${builtins.toJSON expected} - Actual: ${builtins.toJSON actualWrapped} - ''; -# Check mixed Jetson and non-Jetson devices -assert - let - expected = false; - actual = formatCapabilities { - cudaCapabilities = [ - "7.2" - "7.5" - ]; - }; - actualWrapped = (builtins.tryEval (builtins.deepSeq actual actual)).value; - in - asserts.assertMsg (expected == actualWrapped) '' - Jetson devices capabilities cannot be mixed with non-jetson devices. - Capability 7.5 is non-Jetson and should not be allowed with Jetson 7.2. - Expected: ${builtins.toJSON expected} - Actual: ${builtins.toJSON actualWrapped} - ''; -# Check Jetson-only -assert - let - expected = { - cudaCapabilities = [ - "6.2" - "7.2" - ]; - enableForwardCompat = true; - - archNames = [ - "Pascal" - "Volta" - ]; - realArches = [ - "sm_62" - "sm_72" - ]; - virtualArches = [ - "compute_62" - "compute_72" - ]; - arches = [ - "sm_62" - "sm_72" - "compute_72" - ]; - - gencode = [ - "-gencode=arch=compute_62,code=sm_62" - "-gencode=arch=compute_72,code=sm_72" - "-gencode=arch=compute_72,code=compute_72" - ]; - gencodeString = "-gencode=arch=compute_62,code=sm_62 -gencode=arch=compute_72,code=sm_72 -gencode=arch=compute_72,code=compute_72"; - - cmakeCudaArchitecturesString = "62;72"; - - isJetsonBuild = true; - }; - actual = formatCapabilities { - cudaCapabilities = [ - "6.2" - "7.2" - ]; - }; - actualWrapped = (builtins.tryEval (builtins.deepSeq actual actual)).value; - in - asserts.assertMsg - # We can't do this test unless we're targeting aarch64 - (hostPlatform.isAarch64 -> (expected == actualWrapped)) - '' - Jetson devices can only be built with other Jetson devices. - Both 6.2 and 7.2 are Jetson devices. - Expected: ${builtins.toJSON expected} - Actual: ${builtins.toJSON actualWrapped} - ''; -{ - # formatCapabilities :: { cudaCapabilities: List Capability, enableForwardCompat: Boolean } -> { ... } - inherit formatCapabilities; - - # cudaArchNameToVersions :: String => String - inherit cudaArchNameToVersions; - - # cudaComputeCapabilityToName :: String => String - inherit cudaComputeCapabilityToName; - - # dropDot :: String -> String - inherit dropDot; - - inherit - defaultCapabilities - supportedCapabilities - jetsonComputeCapabilities - jetsonTargets - getNixSystem - getRedistArch - ; -} -// formatCapabilities { - cudaCapabilities = if cudaCapabilities == [ ] then defaultCapabilities else cudaCapabilities; - enableForwardCompat = cudaForwardCompat; -} diff --git a/pkgs/development/cuda-modules/generic-builders/manifest.nix b/pkgs/development/cuda-modules/generic-builders/manifest.nix index f36cc2d989ad..f4eecc29f4dc 100644 --- a/pkgs/development/cuda-modules/generic-builders/manifest.nix +++ b/pkgs/development/cuda-modules/generic-builders/manifest.nix @@ -5,6 +5,7 @@ autoPatchelfHook, backendStdenv, callPackage, + cudaLib, fetchurl, fixups, lib, @@ -47,15 +48,15 @@ let maybeFixup = fixups.${pname} or null; fixup = if maybeFixup != null then callPackage maybeFixup { } else { }; - # Get the redist architectures for which package provides distributables. + # Get the redist systems for which package provides distributables. # These are used by meta.platforms. - supportedRedistArchs = builtins.attrNames featureRelease; - # redistArch :: String - # The redistArch is the name of the architecture for which the redistributable is built. - # It is `"unsupported"` if the redistributable is not supported on the target platform. - redistArch = flags.getRedistArch hostPlatform.system; + supportedRedistSystems = builtins.attrNames featureRelease; + # redistSystem :: String + # The redistSystem is the name of the system for which the redistributable is built. + # It is `"unsupported"` if the redistributable is not supported on the target system. + redistSystem = cudaLib.utils.getRedistSystem backendStdenv.hasJetsonCudaCapability hostPlatform.system; - sourceMatchesHost = flags.getNixSystem redistArch == hostPlatform.system; + sourceMatchesHost = lib.elem hostPlatform.system (cudaLib.utils.getNixSystems redistSystem); in (backendStdenv.mkDerivation (finalAttrs: { # NOTE: Even though there's no actual buildPhase going on here, the derivations of the @@ -81,7 +82,7 @@ in hasOutput = output: attrsets.attrByPath [ - redistArch + redistSystem "outputs" output ] false featureRelease; @@ -99,12 +100,15 @@ in # NOTE: In the case the redistributable isn't supported on the target platform, # we will have `outputs = [ "out" ] ++ possibleOutputs`. This is of note because platforms which # aren't supported would otherwise have evaluation errors when trying to access outputs other than `out`. - # The alternative would be to have `outputs = [ "out" ]` when`redistArch = "unsupported"`, but that would + # The alternative would be to have `outputs = [ "out" ]` when`redistSystem = "unsupported"`, but that would # require adding guards throughout the entirety of the CUDA package set to ensure `cudaSupport` is true -- # recall that OfBorg will evaluate packages marked as broken and that `cudaPackages` will be evaluated with # `cudaSupport = false`! additionalOutputs = - if redistArch == "unsupported" then possibleOutputs else builtins.filter hasOutput possibleOutputs; + if redistSystem == "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; in @@ -155,14 +159,14 @@ in }; # src :: Optional Derivation - # If redistArch doesn't exist in redistribRelease, return null. + # If redistSystem doesn't exist in redistribRelease, return null. src = trivial.mapNullable ( { relative_path, sha256, ... }: fetchurl { url = "https://developer.download.nvidia.com/compute/${redistName}/redist/${relative_path}"; inherit sha256; } - ) (redistribRelease.${redistArch} or null); + ) (redistribRelease.${redistSystem} or null); postPatch = # Pkg-config's setup hook expects configuration files in $out/share/pkgconfig @@ -321,11 +325,13 @@ in description = "${redistribRelease.name}. By downloading and using the packages you accept the terms and conditions of the ${finalAttrs.meta.license.shortName}"; sourceProvenance = [ sourceTypes.binaryNativeCode ]; broken = lists.any trivial.id (attrsets.attrValues finalAttrs.brokenConditions); - platforms = trivial.pipe supportedRedistArchs [ - # Map each redist arch to the equivalent nix system or null if there is no equivalent. - (builtins.map flags.getNixSystem) - # Filter out unsupported systems - (builtins.filter (nixSystem: !(strings.hasPrefix "unsupported-" nixSystem))) + platforms = trivial.pipe supportedRedistSystems [ + # Map each redist system to the equivalent nix systems. + (lib.concatMap cudaLib.utils.getNixSystems) + # Take all the unique values. + lib.unique + # Sort the list. + lib.naturalSort ]; badPlatforms = let diff --git a/pkgs/development/cuda-modules/generic-builders/multiplex.nix b/pkgs/development/cuda-modules/generic-builders/multiplex.nix index 816a375e620f..0a6d101eaf9d 100644 --- a/pkgs/development/cuda-modules/generic-builders/multiplex.nix +++ b/pkgs/development/cuda-modules/generic-builders/multiplex.nix @@ -1,11 +1,9 @@ { - # callPackage-provided arguments lib, + cudaLib, cudaMajorMinorVersion, - flags, + redistSystem, stdenv, - # Expected to be passed by the caller - mkVersionedPackageName, # Builder-specific arguments # Short package name (e.g., "cuda_cccl") # pname : String @@ -26,7 +24,7 @@ # The featureRelease is used to populate meta.platforms (by way of looking at the attribute names), determine the # outputs of the package, and provide additional package-specific constraints (e.g., min/max supported CUDA versions, # required versions of other packages, etc.). - # shimFn :: {package, redistArch} -> AttrSet + # shimFn :: {package, redistSystem} -> AttrSet shimsFn ? (throw "shimsFn must be provided"), }: let @@ -41,10 +39,6 @@ let # - Releases: ../modules/${pname}/releases/releases.nix # - Package: ../modules/${pname}/releases/package.nix - # redistArch :: String - # Value is `"unsupported"` if the platform is not supported. - redistArch = flags.getRedistArch stdenv.hostPlatform.system; - # Check whether a package supports our CUDA version. # satisfiesCudaVersion :: Package -> Bool satisfiesCudaVersion = @@ -53,7 +47,7 @@ let && lib.versionAtLeast package.maxCudaVersion cudaMajorMinorVersion; # FIXME: do this at the module system level - propagatePlatforms = lib.mapAttrs (redistArch: lib.map (p: { inherit redistArch; } // p)); + propagatePlatforms = lib.mapAttrs (redistSystem: lib.map (p: { inherit redistSystem; } // p)); # Releases for all platforms and all CUDA versions. allReleases = propagatePlatforms evaluatedModules.config.${pname}.releases; @@ -65,12 +59,13 @@ let allPackages = lib.concatLists (lib.attrValues allReleases'); packageOlder = p1: p2: lib.versionOlder p1.version p2.version; - packageSupportedPlatform = p: p.redistArch == redistArch; + packageSupportedPlatform = p: p.redistSystem == redistSystem; # 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 # computeName :: Package -> String - computeName = package: mkVersionedPackageName pname package.version; + computeName = + { version, ... }: cudaLib.utils.mkVersionedName pname (lib.versions.majorMinor version); # The newest package for each major-minor version, with newest first. # newestPackages :: List Package @@ -113,7 +108,7 @@ let buildPackage = package: let - shims = final.callPackage shimsFn { inherit package redistArch; }; + shims = final.callPackage shimsFn { inherit package redistSystem; }; name = computeName package; drv = final.callPackage ./manifest.nix { inherit pname redistName; diff --git a/pkgs/development/cuda-modules/gpus.nix b/pkgs/development/cuda-modules/gpus.nix deleted file mode 100644 index a5466a2ef15f..000000000000 --- a/pkgs/development/cuda-modules/gpus.nix +++ /dev/null @@ -1,244 +0,0 @@ -# Type aliases -# -# Gpu = { -# archName: String -# - The name of the microarchitecture. -# computeCapability: String -# - The compute capability of the GPU. -# isJetson: Boolean -# - Whether a GPU is part of NVIDIA's line of Jetson embedded computers. This field is -# notable because it tells us what architecture to build for (as Jetson devices are -# aarch64). -# More on Jetson devices here: -# https://www.nvidia.com/en-us/autonomous-machines/embedded-systems/ -# NOTE: These architectures are only built upon request. -# minCudaVersion: String -# - The minimum (inclusive) CUDA version that supports this GPU. -# dontDefaultAfter: null | String -# - The CUDA version after which to exclude this GPU from the list of default capabilities -# we build. null means we always include this GPU in the default capabilities if it is -# supported. -# maxCudaVersion: null | String -# - The maximum (exclusive) CUDA version that supports this GPU. null means there is no -# maximum. -# } -# -# Many thanks to Arnon Shimoni for maintaining a list of these architectures and capabilities. -# Without your work, this would have been much more difficult. -# https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/ -# -# https://en.wikipedia.org/wiki/CUDA#GPUs_supported - -[ - { - # Tesla K40 - archName = "Kepler"; - computeCapability = "3.5"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = "11.0"; - maxCudaVersion = "11.8"; - } - { - # Tesla K80 - archName = "Kepler"; - computeCapability = "3.7"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = "11.0"; - maxCudaVersion = "11.8"; - } - { - # Tesla/Quadro M series - archName = "Maxwell"; - computeCapability = "5.0"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = "11.0"; - maxCudaVersion = null; - } - { - # Quadro M6000, GeForce 900, GTX-970, GTX-980, GTX Titan X - archName = "Maxwell"; - computeCapability = "5.2"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = "11.0"; - maxCudaVersion = null; - } - { - # Tegra (Jetson) TX1 / Tegra X1, Drive CX, Drive PX, Jetson Nano - archName = "Maxwell"; - computeCapability = "5.3"; - isJetson = true; - minCudaVersion = "10.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # Quadro GP100, Tesla P100, DGX-1 (Generic Pascal) - archName = "Pascal"; - computeCapability = "6.0"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # GTX 1080, GTX 1070, GTX 1060, GTX 1050, GTX 1030 (GP108), GT 1010 (GP108) Titan Xp, Tesla - # P40, Tesla P4, Discrete GPU on the NVIDIA Drive PX2 - archName = "Pascal"; - computeCapability = "6.1"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # Integrated GPU on the NVIDIA Drive PX2, Tegra (Jetson) TX2 - archName = "Pascal"; - computeCapability = "6.2"; - isJetson = true; - minCudaVersion = "10.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # DGX-1 with Volta, Tesla V100, GTX 1180 (GV104), Titan V, Quadro GV100 - archName = "Volta"; - computeCapability = "7.0"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # Jetson AGX Xavier, Drive AGX Pegasus, Xavier NX - archName = "Volta"; - computeCapability = "7.2"; - isJetson = true; - minCudaVersion = "10.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # GTX/RTX Turing – GTX 1660 Ti, RTX 2060, RTX 2070, RTX 2080, Titan RTX, Quadro RTX 4000, - # Quadro RTX 5000, Quadro RTX 6000, Quadro RTX 8000, Quadro T1000/T2000, Tesla T4 - archName = "Turing"; - computeCapability = "7.5"; - isJetson = false; - minCudaVersion = "10.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # NVIDIA A100 (the name “Tesla” has been dropped – GA100), NVIDIA DGX-A100 - archName = "Ampere"; - computeCapability = "8.0"; - isJetson = false; - minCudaVersion = "11.2"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # Tesla GA10x cards, RTX Ampere – RTX 3080, GA102 – RTX 3090, RTX A2000, A3000, RTX A4000, - # A5000, A6000, NVIDIA A40, GA106 – RTX 3060, GA104 – RTX 3070, GA107 – RTX 3050, RTX A10, RTX - # A16, RTX A40, A2 Tensor Core GPU - archName = "Ampere"; - computeCapability = "8.6"; - isJetson = false; - minCudaVersion = "11.2"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # Jetson AGX Orin and Drive AGX Orin only - archName = "Ampere"; - computeCapability = "8.7"; - isJetson = true; - minCudaVersion = "11.5"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # NVIDIA GeForce RTX 4090, RTX 4080, RTX 6000, Tesla L40 - archName = "Ada"; - computeCapability = "8.9"; - isJetson = false; - minCudaVersion = "11.8"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # NVIDIA H100 (GH100) - archName = "Hopper"; - computeCapability = "9.0"; - isJetson = false; - minCudaVersion = "11.8"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # NVIDIA H100 (GH100) (Thor) - archName = "Hopper"; - computeCapability = "9.0a"; - isJetson = false; - minCudaVersion = "12.0"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # NVIDIA B100 - archName = "Blackwell"; - computeCapability = "10.0"; - isJetson = false; - minCudaVersion = "12.8"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # NVIDIA B100 Accelerated - archName = "Blackwell"; - computeCapability = "10.0a"; - isJetson = false; - minCudaVersion = "12.8"; - dontDefaultAfter = "12.0"; # disable to reduce size of OnnxRuntime and Torch CUDA binaries - maxCudaVersion = null; - } - { - # NVIDIA Blackwell - archName = "Blackwell"; - computeCapability = "10.1"; - isJetson = false; - minCudaVersion = "12.8"; - dontDefaultAfter = "12.0"; # disable to reduce size of OnnxRuntime and Torch CUDA binaries - maxCudaVersion = null; - } - { - # NVIDIA Blackwell Accelerated - archName = "Blackwell"; - computeCapability = "10.1a"; - isJetson = false; - minCudaVersion = "12.8"; - dontDefaultAfter = "12.0"; # disable to reduce size of OnnxRuntime and Torch CUDA binaries - maxCudaVersion = null; - } - { - # NVIDIA GeForce RTX 5090 (GB202), RTX 5080 (GB203), RTX 5070 (GB205) - archName = "Blackwell"; - computeCapability = "12.0"; - isJetson = false; - minCudaVersion = "12.8"; - dontDefaultAfter = null; - maxCudaVersion = null; - } - { - # NVIDIA Blackwell Accelerated - archName = "Blackwell"; - computeCapability = "12.0a"; - isJetson = false; - minCudaVersion = "12.8"; - dontDefaultAfter = "12.0"; # disable to reduce size of OnnxRuntime and Torch CUDA binaries - maxCudaVersion = null; - } -] diff --git a/pkgs/development/cuda-modules/nvcc-compatibilities.nix b/pkgs/development/cuda-modules/nvcc-compatibilities.nix deleted file mode 100644 index e4be18ea85ab..000000000000 --- a/pkgs/development/cuda-modules/nvcc-compatibilities.nix +++ /dev/null @@ -1,125 +0,0 @@ -# Taken from -# https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#host-compiler-support-policy -# -# NVCC performs a version check on the host compiler’s major version and so newer minor versions -# of the compilers listed below will be supported, but major versions falling outside the range -# will not be supported. -# -# NOTE: These constraints don't apply to Jetson, which uses something else. -# NOTE: NVIDIA can and will add support for newer compilers even during patch releases. -# E.g.: CUDA 12.2.1 maxxed out with support for Clang 15.0; 12.2.2 added support for Clang 16.0. -# NOTE: Because all platforms NVIDIA supports use GCC and Clang, we omit the architectures here. -# Type Aliases -# CudaVersion = String (two-part version number, e.g. "11.2") -# Platform = String (e.g. "x86_64-linux") -# CompilerCompatibilities = { -# clangMaxMajorVersion = String (e.g. "15") -# clangMinMajorVersion = String (e.g. "7") -# gccMaxMajorVersion = String (e.g. "11") -# gccMinMajorVersion = String (e.g. "6") -# } -let - # attrs :: AttrSet CudaVersion CompilerCompatibilities - attrs = { - # Our baseline - # https://docs.nvidia.com/cuda/archive/11.0/cuda-toolkit-release-notes/index.html#cuda-compiler-new-features - "11.0" = { - clangMaxMajorVersion = "9"; - clangMinMajorVersion = "7"; - gccMaxMajorVersion = "9"; - gccMinMajorVersion = "6"; - }; - - # Added support for Clang 10 and GCC 10 - # https://docs.nvidia.com/cuda/archive/11.1.1/cuda-toolkit-release-notes/index.html#cuda-compiler-new-features - "11.1" = attrs."11.0" // { - clangMaxMajorVersion = "10"; - gccMaxMajorVersion = "10"; - }; - - # Added support for Clang 11 - # https://docs.nvidia.com/cuda/archive/11.2.2/cuda-installation-guide-linux/index.html#system-requirements - "11.2" = attrs."11.1" // { - clangMaxMajorVersion = "11"; - }; - - # No changes from 11.2 to 11.3 - "11.3" = attrs."11.2"; - - # Added support for Clang 12 and GCC 11 - # https://docs.nvidia.com/cuda/archive/11.4.4/cuda-toolkit-release-notes/index.html#cuda-general-new-features - "11.4" = attrs."11.3" // { - clangMaxMajorVersion = "12"; - # NOTE: There is a bug in the version of GLIBC that GCC 11 uses which causes it to fail to compile some CUDA - # code. As such, we skip it for this release, and do the bump in 11.6 (skipping 11.5). - # https://forums.developer.nvidia.com/t/cuda-11-5-samples-throw-multiple-error-attribute-malloc-does-not-take-arguments/192750/15 - # gccMaxMajorVersion = "11"; - }; - - # No changes from 11.4 to 11.5 - "11.5" = attrs."11.4"; - - # No changes from 11.5 to 11.6 - # However, as mentioned above, we add GCC 11 this release. - "11.6" = attrs."11.5" // { - gccMaxMajorVersion = "11"; - }; - - # Added support for Clang 13 - # https://docs.nvidia.com/cuda/archive/11.7.1/cuda-toolkit-release-notes/index.html#cuda-compiler-new-features - "11.7" = attrs."11.6" // { - clangMaxMajorVersion = "13"; - }; - - # Added support for Clang 14 - # https://docs.nvidia.com/cuda/archive/11.8.0/cuda-installation-guide-linux/index.html#system-requirements - "11.8" = attrs."11.7" // { - clangMaxMajorVersion = "14"; - }; - - # Added support for GCC 12 - # https://docs.nvidia.com/cuda/archive/12.0.1/cuda-installation-guide-linux/index.html#system-requirements - "12.0" = attrs."11.8" // { - gccMaxMajorVersion = "12"; - }; - - # Added support for Clang 15 - # https://docs.nvidia.com/cuda/archive/12.1.1/cuda-toolkit-release-notes/index.html#cuda-compilers-new-features - "12.1" = attrs."12.0" // { - clangMaxMajorVersion = "15"; - }; - - # Added support for Clang 16 - # https://docs.nvidia.com/cuda/archive/12.2.2/cuda-installation-guide-linux/index.html#host-compiler-support-policy - "12.2" = attrs."12.1" // { - clangMaxMajorVersion = "16"; - }; - - # No changes from 12.2 to 12.3 - "12.3" = attrs."12.2"; - - # Added support for Clang 17 and GCC 13 - # https://docs.nvidia.com/cuda/archive/12.4.0/cuda-installation-guide-linux/index.html#host-compiler-support-policy - "12.4" = attrs."12.3" // { - clangMaxMajorVersion = "17"; - gccMaxMajorVersion = "13"; - }; - - # No changes from 12.4 to 12.5 - "12.5" = attrs."12.4"; - - # Added support for Clang 18 - # https://docs.nvidia.com/cuda/archive/12.6.0/cuda-installation-guide-linux/index.html#host-compiler-support-policy - "12.6" = attrs."12.4" // { - clangMaxMajorVersion = "18"; - }; - - # Added support for Clang 19 and GCC 14 - # https://docs.nvidia.com/cuda/archive/12.8.0/cuda-installation-guide-linux/index.html#host-compiler-support-policy - "12.8" = attrs."12.6" // { - clangMaxMajorVersion = "19"; - gccMaxMajorVersion = "14"; - }; - }; -in -attrs diff --git a/pkgs/development/cuda-modules/tensorrt/shims.nix b/pkgs/development/cuda-modules/tensorrt/shims.nix index d347ef7e294c..b452a515404c 100644 --- a/pkgs/development/cuda-modules/tensorrt/shims.nix +++ b/pkgs/development/cuda-modules/tensorrt/shims.nix @@ -1,14 +1,14 @@ # Shims to mimic the shape of ../modules/generic/manifests/{feature,redistrib}/release.nix { package, - # redistArch :: String + # redistSystem :: String # String is `"unsupported"` if the given architecture is unsupported. - redistArch, + redistSystem, }: { featureRelease = { inherit (package) cudnnVersion minCudaVersion maxCudaVersion; - ${redistArch}.outputs = { + ${redistSystem}.outputs = { bin = true; lib = true; static = true; diff --git a/pkgs/development/cuda-modules/tests/flags.nix b/pkgs/development/cuda-modules/tests/flags.nix new file mode 100644 index 000000000000..d9ae72231c6c --- /dev/null +++ b/pkgs/development/cuda-modules/tests/flags.nix @@ -0,0 +1,78 @@ +{ + cudaLib, + cudaNamePrefix, + lib, + runCommand, +}: +let + inherit (builtins) deepSeq toJSON tryEval; + inherit (cudaLib.data) cudaCapabilityToInfo; + inherit (cudaLib.utils) formatCapabilities; + inherit (lib.asserts) assertMsg; +in +# When changing names or formats: pause, validate, and update the assert +assert assertMsg ( + cudaCapabilityToInfo ? "7.5" && cudaCapabilityToInfo ? "8.6" +) "The following test requires both 7.5 and 8.6 be known CUDA capabilities"; +assert + let + expected = { + cudaCapabilities = [ + "7.5" + "8.6" + ]; + cudaForwardCompat = true; + + # Sorted alphabetically + archNames = [ + "Ampere" + "Turing" + ]; + + realArches = [ + "sm_75" + "sm_86" + ]; + + virtualArches = [ + "compute_75" + "compute_86" + ]; + + arches = [ + "sm_75" + "sm_86" + "compute_86" + ]; + + gencode = [ + "-gencode=arch=compute_75,code=sm_75" + "-gencode=arch=compute_86,code=sm_86" + "-gencode=arch=compute_86,code=compute_86" + ]; + + gencodeString = "-gencode=arch=compute_75,code=sm_75 -gencode=arch=compute_86,code=sm_86 -gencode=arch=compute_86,code=compute_86"; + + cmakeCudaArchitecturesString = "75;86"; + }; + actual = formatCapabilities { + inherit cudaCapabilityToInfo; + cudaCapabilities = [ + "7.5" + "8.6" + ]; + }; + actualWrapped = (tryEval (deepSeq actual actual)).value; + in + assertMsg (expected == actualWrapped) '' + Expected: ${toJSON expected} + Actual: ${toJSON actualWrapped} + ''; +runCommand "${cudaNamePrefix}-tests-flags" + { + __structuredAttrs = true; + strictDeps = true; + } + '' + touch "$out" + '' diff --git a/pkgs/top-level/cuda-packages.nix b/pkgs/top-level/cuda-packages.nix index 70aaf15362f0..60bc5c0dd953 100644 --- a/pkgs/top-level/cuda-packages.nix +++ b/pkgs/top-level/cuda-packages.nix @@ -22,6 +22,7 @@ # I've (@connorbaker) attempted to do that, though I'm unsure of how this will interact with overrides. { config, + cudaLib, cudaMajorMinorVersion, lib, newScope, @@ -37,31 +38,33 @@ let strings versions ; + # MUST be defined outside fix-point (cf. "NAMESET STRICTNESS" above) fixups = import ../development/cuda-modules/fixups { inherit lib; }; - gpus = import ../development/cuda-modules/gpus.nix; - nvccCompatibilities = import ../development/cuda-modules/nvcc-compatibilities.nix; - flags = import ../development/cuda-modules/flags.nix { - inherit - config - cudaMajorMinorVersion - gpus - lib - stdenv - ; - }; - mkVersionedPackageName = - name: version: name + "_" + strings.replaceStrings [ "." ] [ "_" ] (versions.majorMinor version); + # Since Jetson capabilities are never built by default, we can check if any of them were requested + # through final.config.cudaCapabilities and use that to determine if we should change some manifest versions. + # Copied from backendStdenv. + jetsonCudaCapabilities = lib.filter ( + cudaCapability: cudaLib.data.cudaCapabilityToInfo.${cudaCapability}.isJetson + ) cudaLib.data.allSortedCudaCapabilities; + hasJetsonCudaCapability = + lib.intersectLists jetsonCudaCapabilities (config.cudaCapabilities or [ ]) != [ ]; + redistSystem = cudaLib.utils.getRedistSystem hasJetsonCudaCapability stdenv.hostPlatform.system; passthruFunction = final: { + # NOTE: + # It is important that cudaLib (and fixups, which will be addressed later) are not part of the package set + # fixed-point. + # As described by @SomeoneSerge: + # > The layering should be: configuration -> (identifies/is part of) cudaPackages -> (is built using) cudaLib. + # > No arrows should point in the reverse directions. + # That is to say that cudaLib should only know about package sets and configurations, because it implements + # functionality for interpreting configurations, resolving them against data, and constructing package sets. inherit cudaMajorMinorVersion fixups - flags - gpus lib - nvccCompatibilities pkgs ; @@ -71,10 +74,6 @@ let cudaOlder = strings.versionOlder cudaMajorMinorVersion; cudaAtLeast = strings.versionAtLeast cudaMajorMinorVersion; - # NOTE: mkVersionedPackageName is an internal, implementation detail and should not be relied on by outside consumers. - # It may be removed in the future. - inherit mkVersionedPackageName; - # Maintain a reference to the final cudaPackages. # Without this, if we use `final.callPackage` and a package accepts `cudaPackages` as an # argument, it's provided with `cudaPackages` from the top-level scope, which is not what we @@ -85,6 +84,21 @@ let __attrsFailEvaluation = true; }; + flags = + cudaLib.utils.formatCapabilities { + inherit (final.backendStdenv) cudaCapabilities cudaForwardCompat; + inherit (cudaLib.data) cudaCapabilityToInfo; + } + # TODO(@connorbaker): Enable the corresponding warnings in `../development/cuda-modules/aliases.nix` after some + # time to allow users to migrate to cudaLib and backendStdenv. + // { + inherit (cudaLib.utils) dropDots; + cudaComputeCapabilityToName = + cudaCapability: cudaLib.data.cudaCapabilityToInfo.${cudaCapability}.archName; + dropDot = cudaLib.utils.dropDots; + isJetsonBuild = final.backendStdenv.hasJetsonCudaCapability; + }; + # Loose packages # Barring packages which share a home (e.g., cudatoolkit and cudatoolkit-legacy-runfile), new packages # should be added to ../development/cuda-modules/packages in "by-name" style, where they will be automatically @@ -131,7 +145,10 @@ let value = final.callPackage ../development/cuda-modules/tests/opencv-and-torch config; }; in - attrsets.listToAttrs (attrsets.mapCartesianProduct builder configs); + attrsets.listToAttrs (attrsets.mapCartesianProduct builder configs) + // { + flags = final.callPackage ../development/cuda-modules/tests/flags.nix { }; + }; }; composedExtension = fixedPoints.composeManyExtensions ( @@ -146,10 +163,10 @@ let (import ../development/cuda-modules/cuda/extension.nix { inherit cudaMajorMinorVersion lib; }) (import ../development/cuda-modules/generic-builders/multiplex.nix { inherit + cudaLib cudaMajorMinorVersion - flags lib - mkVersionedPackageName + redistSystem stdenv ; pname = "cudnn"; @@ -159,28 +176,25 @@ let }) (import ../development/cuda-modules/cutensor/extension.nix { inherit + cudaLib cudaMajorMinorVersion - flags lib - mkVersionedPackageName - stdenv + redistSystem ; }) (import ../development/cuda-modules/cusparselt/extension.nix { inherit - cudaMajorMinorVersion - flags + cudaLib lib - mkVersionedPackageName - stdenv + redistSystem ; }) (import ../development/cuda-modules/generic-builders/multiplex.nix { inherit + cudaLib cudaMajorMinorVersion - flags lib - mkVersionedPackageName + redistSystem stdenv ; pname = "tensorrt"; @@ -193,7 +207,9 @@ let }) (import ../development/cuda-modules/cuda-library-samples/extension.nix { inherit lib stdenv; }) ] - ++ lib.optionals config.allowAliases [ (import ../development/cuda-modules/aliases.nix) ] + ++ lib.optionals config.allowAliases [ + (import ../development/cuda-modules/aliases.nix { inherit lib; }) + ] ); cudaPackages = customisation.makeScope newScope ( diff --git a/pkgs/top-level/release-cuda.nix b/pkgs/top-level/release-cuda.nix index d2e515556bb7..68bec74c9530 100644 --- a/pkgs/top-level/release-cuda.nix +++ b/pkgs/top-level/release-cuda.nix @@ -14,20 +14,7 @@ let lib = import ../../lib; - ensureList = x: if builtins.isList x then x else [ x ]; - allowUnfreePredicate = - p: - builtins.all ( - license: - license.free - || builtins.elem license.shortName [ - "CUDA EULA" - "cuDNN EULA" - "cuSPARSELt EULA" - "cuTENSOR EULA" - "NVidia OptiX EULA" - ] - ) (ensureList p.meta.license); + cudaLib = import ../development/cuda-modules/lib; in { @@ -40,7 +27,7 @@ in # Attributes passed to nixpkgs. nixpkgsArgs ? { config = { - inherit allowUnfreePredicate; + allowUnfreePredicate = cudaLib.utils.allowUnfreeCudaPredicate; "${variant}Support" = true; inHydra = true;