From 626aa6834fcb4845f39f0b55bb7b4f8c78d9bf2f Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Sat, 10 May 2025 00:06:32 +0000 Subject: [PATCH 01/11] cudaPackages: add cudaNamePrefix Signed-off-by: Connor Baker (cherry picked from commit 646bebe3be8004e578842745136b8196f4f1fced) --- pkgs/top-level/cuda-packages.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/top-level/cuda-packages.nix b/pkgs/top-level/cuda-packages.nix index 740efe03b346..70aaf15362f0 100644 --- a/pkgs/top-level/cuda-packages.nix +++ b/pkgs/top-level/cuda-packages.nix @@ -64,6 +64,9 @@ let nvccCompatibilities pkgs ; + + cudaNamePrefix = "cuda${cudaMajorMinorVersion}"; + cudaMajorVersion = versions.major cudaMajorMinorVersion; cudaOlder = strings.versionOlder cudaMajorMinorVersion; cudaAtLeast = strings.versionAtLeast cudaMajorMinorVersion; From a3d81cb05760bbbc052e5df6fd007b5a2bdd9c2c Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Sat, 10 May 2025 15:01:52 +0000 Subject: [PATCH 02/11] cudaPackages.driver_assistant: mark as unsupported Signed-off-by: Connor Baker (cherry picked from commit a018d736978adf55e1b8f7bf79e736cd6d042573) --- pkgs/development/cuda-modules/fixups/driver_assistant.nix | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 pkgs/development/cuda-modules/fixups/driver_assistant.nix diff --git a/pkgs/development/cuda-modules/fixups/driver_assistant.nix b/pkgs/development/cuda-modules/fixups/driver_assistant.nix new file mode 100644 index 000000000000..e9c50b2f4eaf --- /dev/null +++ b/pkgs/development/cuda-modules/fixups/driver_assistant.nix @@ -0,0 +1,5 @@ +_: prevAttrs: { + badPlatformsConditions = prevAttrs.badPlatformsConditions or { } // { + "Package is not supported; use drivers from linuxPackages" = true; + }; +} From a2368c42d5d1054907c4fc33770f1cb2dcb0bec0 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Fri, 9 May 2025 21:54:54 +0000 Subject: [PATCH 03/11] cudaLib: init Signed-off-by: Connor Baker (cherry picked from commit 0ac3a73b6a997ea5e05067577a17c613ecddcd7d) --- .../cuda-modules/lib/data/cuda.nix | 357 +++++++++++++++++ .../cuda-modules/lib/data/default.nix | 32 ++ .../cuda-modules/lib/data/nvcc.nix | 268 +++++++++++++ .../cuda-modules/lib/data/redist.nix | 56 +++ pkgs/development/cuda-modules/lib/default.nix | 13 + .../cuda-modules/lib/utils/assertions.nix | 139 +++++++ .../cuda-modules/lib/utils/cuda.nix | 129 ++++++ .../cuda-modules/lib/utils/default.nix | 49 +++ .../cuda-modules/lib/utils/meta.nix | 71 ++++ .../cuda-modules/lib/utils/redist.nix | 196 +++++++++ .../cuda-modules/lib/utils/strings.nix | 379 ++++++++++++++++++ .../cuda-modules/lib/utils/versions.nix | 76 ++++ pkgs/top-level/all-packages.nix | 2 + 13 files changed, 1767 insertions(+) create mode 100644 pkgs/development/cuda-modules/lib/data/cuda.nix create mode 100644 pkgs/development/cuda-modules/lib/data/default.nix create mode 100644 pkgs/development/cuda-modules/lib/data/nvcc.nix create mode 100644 pkgs/development/cuda-modules/lib/data/redist.nix create mode 100644 pkgs/development/cuda-modules/lib/default.nix create mode 100644 pkgs/development/cuda-modules/lib/utils/assertions.nix create mode 100644 pkgs/development/cuda-modules/lib/utils/cuda.nix create mode 100644 pkgs/development/cuda-modules/lib/utils/default.nix create mode 100644 pkgs/development/cuda-modules/lib/utils/meta.nix create mode 100644 pkgs/development/cuda-modules/lib/utils/redist.nix create mode 100644 pkgs/development/cuda-modules/lib/utils/strings.nix create mode 100644 pkgs/development/cuda-modules/lib/utils/versions.nix diff --git a/pkgs/development/cuda-modules/lib/data/cuda.nix b/pkgs/development/cuda-modules/lib/data/cuda.nix new file mode 100644 index 000000000000..0b97645c420d --- /dev/null +++ b/pkgs/development/cuda-modules/lib/data/cuda.nix @@ -0,0 +1,357 @@ +{ cudaLib, lib }: +{ + /** + All CUDA capabilities, sorted by version. + + NOTE: Since the capabilities are sorted by version and architecture/family-specific features are + appended to the minor version component, the sorted list groups capabilities by baseline feature + set. + + # Type + + ``` + allSortedCudaCapabilities :: [CudaCapability] + ``` + + # Example + + ``` + allSortedCudaCapabilities = [ + "5.0" + "5.2" + "6.0" + "6.1" + "7.0" + "7.2" + "7.5" + "8.0" + "8.6" + "8.7" + "8.9" + "9.0" + "9.0a" + "10.0" + "10.0a" + "10.0f" + "10.1" + "10.1a" + "10.1f" + "10.3" + "10.3a" + "10.3f" + ]; + ``` + */ + allSortedCudaCapabilities = lib.sort lib.versionOlder ( + lib.attrNames cudaLib.data.cudaCapabilityToInfo + ); + + /** + Mapping of CUDA micro-architecture name to capabilities belonging to that micro-architecture. + + # Type + + ``` + cudaArchNameToCapabilities :: AttrSet NonEmptyStr (NonEmptyListOf CudaCapability) + ``` + */ + cudaArchNameToCapabilities = lib.groupBy ( + cudaCapability: cudaLib.data.cudaCapabilityToInfo.${cudaCapability}.archName + ) cudaLib.data.allSortedCudaCapabilities; + + /** + Attribute set of supported CUDA capability mapped to information about that capability. + + NOTE: For more on baseline, architecture-specific, and family-specific feature sets, see + https://developer.nvidia.com/blog/nvidia-blackwell-and-nvidia-cuda-12-9-introduce-family-specific-architecture-features. + + NOTE: For information on when support for a given architecture was added, see + https://docs.nvidia.com/cuda/parallel-thread-execution/#release-notes + + NOTE: For baseline feature sets, `dontDefaultAfterCudaMajorMinorVersion` is generally set to the CUDA release + immediately prior to TensorRT removing support for that architecture. + + 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/ + + # Type + + ``` + cudaCapabilityToInfo :: + AttrSet + CudaCapability + { archName :: String + , cudaCapability :: CudaCapability + , isJetson :: Bool + , isArchitectureSpecific :: Bool + , isFamilySpecific :: Bool + , minCudaMajorMinorVersion :: MajorMinorVersion + , maxCudaMajorMinorVersion :: MajorMinorVersion + , dontDefaultAfterCudaMajorMinorVersion :: Null | MajorMinorVersion + } + ``` + + `archName` + + : The name of the microarchitecture + + `cudaCapability` + + : The CUDA capability + + `isJetson` + + : Whether this capability 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. + + `isArchitectureSpecific` + + : Whether this capability is an architecture-specific feature set. + NOTE: These architectures are only built upon request. + + `isFamilySpecific` + + : Whether this capability is a family-specific feature set. + NOTE: These architectures are only built upon request. + + `minCudaMajorMinorVersion` + + : The minimum (inclusive) CUDA version that supports this capability. + + `maxCudaMajorMinorVersion` + + : The maximum (exclusive) CUDA version that supports this capability. + `null` means there is no maximum. + + `dontDefaultAfterCudaMajorMinorVersion` + + : The CUDA version after which to exclude this capability from the list of default capabilities we build. + */ + cudaCapabilityToInfo = + lib.mapAttrs + ( + cudaCapability: + # Supplies default values. + { + archName, + isJetson ? false, + isArchitectureSpecific ? (lib.hasSuffix "a" cudaCapability), + isFamilySpecific ? (lib.hasSuffix "f" cudaCapability), + minCudaMajorMinorVersion, + maxCudaMajorMinorVersion ? null, + dontDefaultAfterCudaMajorMinorVersion ? null, + }: + { + inherit + archName + cudaCapability + isJetson + isArchitectureSpecific + isFamilySpecific + minCudaMajorMinorVersion + maxCudaMajorMinorVersion + dontDefaultAfterCudaMajorMinorVersion + ; + } + ) + { + # Tesla K40 + "3.5" = { + archName = "Kepler"; + minCudaMajorMinorVersion = "10.0"; + dontDefaultAfterCudaMajorMinorVersion = "11.0"; + maxCudaMajorMinorVersion = "11.8"; + }; + + # Tesla K80 + "3.7" = { + archName = "Kepler"; + minCudaMajorMinorVersion = "10.0"; + dontDefaultAfterCudaMajorMinorVersion = "11.0"; + maxCudaMajorMinorVersion = "11.8"; + }; + + # Tesla/Quadro M series + "5.0" = { + archName = "Maxwell"; + minCudaMajorMinorVersion = "10.0"; + dontDefaultAfterCudaMajorMinorVersion = "11.0"; + }; + + # Quadro M6000 , GeForce 900, GTX-970, GTX-980, GTX Titan X + "5.2" = { + archName = "Maxwell"; + minCudaMajorMinorVersion = "10.0"; + dontDefaultAfterCudaMajorMinorVersion = "11.0"; + }; + + # Quadro GP100, Tesla P100, DGX-1 (Generic Pascal) + "6.0" = { + archName = "Pascal"; + minCudaMajorMinorVersion = "10.0"; + # Removed from TensorRT 10.0, which corresponds to CUDA 12.4 release. + # https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-1001/support-matrix/index.html + dontDefaultAfterCudaMajorMinorVersion = "12.3"; + }; + + # 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 + "6.1" = { + archName = "Pascal"; + minCudaMajorMinorVersion = "10.0"; + # Removed from TensorRT 10.0, which corresponds to CUDA 12.4 release. + # https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-1001/support-matrix/index.html + dontDefaultAfterCudaMajorMinorVersion = "12.3"; + }; + + # DGX-1 with Volta, Tesla V100, GTX 1180 (GV104), Titan V, Quadro GV100 + "7.0" = { + archName = "Volta"; + minCudaMajorMinorVersion = "10.0"; + # Removed from TensorRT 10.5, which corresponds to CUDA 12.6 release. + # https://docs.nvidia.com/deeplearning/tensorrt/archives/tensorrt-1050/support-matrix/index.html + dontDefaultAfterCudaMajorMinorVersion = "12.5"; + }; + + # Jetson AGX Xavier, Drive AGX Pegasus, Xavier NX + "7.2" = { + archName = "Volta"; + minCudaMajorMinorVersion = "10.0"; + # Note: without `cuda_compat`, maxCudaMajorMinorVersion is 11.8 + # https://docs.nvidia.com/cuda/cuda-for-tegra-appnote/index.html#deployment-considerations-for-cuda-upgrade-package + maxCudaMajorMinorVersion = "12.2"; + isJetson = true; + }; + + # 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 + "7.5" = { + archName = "Turing"; + minCudaMajorMinorVersion = "10.0"; + }; + + # NVIDIA A100 (the name “Tesla” has been dropped – GA100), NVIDIA DGX-A100 + "8.0" = { + archName = "Ampere"; + minCudaMajorMinorVersion = "11.2"; + }; + + # 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 + "8.6" = { + archName = "Ampere"; + minCudaMajorMinorVersion = "11.2"; + }; + + # Jetson AGX Orin and Drive AGX Orin only + "8.7" = { + archName = "Ampere"; + minCudaMajorMinorVersion = "11.5"; + isJetson = true; + }; + + # NVIDIA GeForce RTX 4090, RTX 4080, RTX 6000, Tesla L40 + "8.9" = { + archName = "Ada"; + minCudaMajorMinorVersion = "11.8"; + }; + + # NVIDIA H100 (GH100) + "9.0" = { + archName = "Hopper"; + minCudaMajorMinorVersion = "11.8"; + }; + + "9.0a" = { + archName = "Hopper"; + minCudaMajorMinorVersion = "12.0"; + }; + + # NVIDIA B100 + "10.0" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.7"; + }; + + "10.0a" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.7"; + }; + + "10.0f" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + + # NVIDIA Jetson Thor Blackwell + "10.1" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.7"; + isJetson = true; + }; + + "10.1a" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.7"; + isJetson = true; + }; + + "10.1f" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + isJetson = true; + }; + + # NVIDIA ??? + "10.3" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + + "10.3a" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + + "10.3f" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + + # NVIDIA GeForce RTX 5090 (GB202) etc. + "12.0" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.8"; + }; + + "12.0a" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.8"; + }; + + "12.0f" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + + # NVIDIA ??? + "12.1" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + + "12.1a" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + + "12.1f" = { + archName = "Blackwell"; + minCudaMajorMinorVersion = "12.9"; + }; + }; +} diff --git a/pkgs/development/cuda-modules/lib/data/default.nix b/pkgs/development/cuda-modules/lib/data/default.nix new file mode 100644 index 000000000000..60924cbb4f9e --- /dev/null +++ b/pkgs/development/cuda-modules/lib/data/default.nix @@ -0,0 +1,32 @@ +{ cudaLib, lib }: +{ + # See ./cuda.nix for documentation. + inherit (import ./cuda.nix { inherit cudaLib lib; }) + allSortedCudaCapabilities + cudaArchNameToCapabilities + cudaCapabilityToInfo + ; + + # See ./nvcc.nix for documentation. + inherit (import ./nvcc.nix) + nvccCompatibilities + ; + + # See ./redist.nix for documentation. + inherit (import ./redist.nix) + redistNames + redistSystems + redistUrlPrefix + ; + + /** + The path to the CUDA packages root directory, for use with `callPackage` to create new package sets. + + # Type + + ``` + cudaPackagesPath :: Path + ``` + */ + cudaPackagesPath = ./..; +} diff --git a/pkgs/development/cuda-modules/lib/data/nvcc.nix b/pkgs/development/cuda-modules/lib/data/nvcc.nix new file mode 100644 index 000000000000..535f64b40991 --- /dev/null +++ b/pkgs/development/cuda-modules/lib/data/nvcc.nix @@ -0,0 +1,268 @@ +{ + /** + Mapping of CUDA versions to NVCC compatibilities + + 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 + + ``` + nvccCompatibilities :: + AttrSet + String + { clang :: { maxMajorVersion :: String, minMajorVersion :: String } + , gcc :: { maxMajorVersion :: String, minMajorVersion :: String } + } + ``` + */ + nvccCompatibilities = { + # Our baseline + # https://docs.nvidia.com/cuda/archive/11.0/cuda-toolkit-release-notes/index.html#cuda-compiler-new-features + "11.0" = { + clang = { + maxMajorVersion = "9"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "9"; + minMajorVersion = "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" = { + clang = { + maxMajorVersion = "10"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "10"; + minMajorVersion = "6"; + }; + }; + + # Added support for Clang 11 + # https://docs.nvidia.com/cuda/archive/11.2.2/cuda-installation-guide-linux/index.html#system-requirements + "11.2" = { + clang = { + maxMajorVersion = "11"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "10"; + minMajorVersion = "6"; + }; + }; + + # No changes from 11.2 to 11.3 + "11.3" = { + clang = { + maxMajorVersion = "11"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "10"; + minMajorVersion = "6"; + }; + }; + + # 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 + # 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 + "11.4" = { + clang = { + maxMajorVersion = "12"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "10"; + minMajorVersion = "6"; + }; + }; + + # No changes from 11.4 to 11.5 + "11.5" = { + clang = { + maxMajorVersion = "12"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "10"; + minMajorVersion = "6"; + }; + }; + + # No changes from 11.5 to 11.6 + # However, as mentioned above, we add GCC 11 this release. + "11.6" = { + clang = { + maxMajorVersion = "12"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "11"; + minMajorVersion = "6"; + }; + }; + + # 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" = { + clang = { + maxMajorVersion = "13"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "11"; + minMajorVersion = "6"; + }; + }; + + # Added support for Clang 14 + # https://docs.nvidia.com/cuda/archive/11.8.0/cuda-installation-guide-linux/index.html#system-requirements + "11.8" = { + clang = { + maxMajorVersion = "14"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "11"; + minMajorVersion = "6"; + }; + }; + + # Added support for GCC 12 + # https://docs.nvidia.com/cuda/archive/12.0.1/cuda-installation-guide-linux/index.html#system-requirements + "12.0" = { + clang = { + maxMajorVersion = "14"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "12"; + minMajorVersion = "6"; + }; + }; + + # 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" = { + clang = { + maxMajorVersion = "15"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "12"; + minMajorVersion = "6"; + }; + }; + + # 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" = { + clang = { + maxMajorVersion = "16"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "12"; + minMajorVersion = "6"; + }; + }; + + # No changes from 12.2 to 12.3 + # https://docs.nvidia.com/cuda/archive/12.3.2/cuda-installation-guide-linux/index.html#host-compiler-support-policy + "12.3" = { + clang = { + maxMajorVersion = "16"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "12"; + minMajorVersion = "6"; + }; + }; + + # Maximum Clang version is 17 + # Minimum GCC version is still 6, but all versions prior to GCC 7.3 are deprecated. + # Maximum GCC version is 13.2 + # https://docs.nvidia.com/cuda/archive/12.4.1/cuda-installation-guide-linux/index.html#host-compiler-support-policy + "12.4" = { + clang = { + maxMajorVersion = "17"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "13"; + minMajorVersion = "6"; + }; + }; + + # No changes from 12.4 to 12.5 + # https://docs.nvidia.com/cuda/archive/12.5.1/cuda-installation-guide-linux/index.html#host-compiler-support-policy + "12.5" = { + clang = { + maxMajorVersion = "17"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "13"; + minMajorVersion = "6"; + }; + }; + + # Maximum Clang version is 18 + # https://docs.nvidia.com/cuda/archive/12.6.0/cuda-installation-guide-linux/index.html#host-compiler-support-policy + "12.6" = { + clang = { + maxMajorVersion = "18"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "13"; + minMajorVersion = "6"; + }; + }; + + # Maximum Clang version is 19, maximum GCC version is 14 + # https://docs.nvidia.com/cuda/archive/12.8.1/cuda-installation-guide-linux/index.html#host-compiler-support-policy + "12.8" = { + clang = { + maxMajorVersion = "19"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "14"; + minMajorVersion = "6"; + }; + }; + + # No changes from 12.8 to 12.9 + # https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#host-compiler-support-policy + "12.9" = { + clang = { + maxMajorVersion = "19"; + minMajorVersion = "7"; + }; + gcc = { + maxMajorVersion = "14"; + minMajorVersion = "6"; + }; + }; + }; +} diff --git a/pkgs/development/cuda-modules/lib/data/redist.nix b/pkgs/development/cuda-modules/lib/data/redist.nix new file mode 100644 index 000000000000..52e91f81c35c --- /dev/null +++ b/pkgs/development/cuda-modules/lib/data/redist.nix @@ -0,0 +1,56 @@ +{ + /** + A list of redistributable names to use in creation of the `redistName` option type. + + # Type + + ``` + redistNames :: [String] + ``` + */ + redistNames = [ + "cublasmp" + "cuda" + "cudnn" + "cudss" + "cuquantum" + "cusolvermp" + "cusparselt" + "cutensor" + "nppplus" + "nvcomp" + # "nvidia-driver", # NOTE: Some of the earlier manifests don't follow our scheme. + "nvjpeg2000" + "nvpl" + "nvtiff" + "tensorrt" # NOTE: not truly a redist; uses different naming convention + ]; + + /** + A list of redistributable systems to use in creation of the `redistSystem` option type. + + # Type + + ``` + redistSystems :: [String] + ``` + */ + redistSystems = [ + "linux-aarch64" + "linux-all" # Taken to mean all other linux systems + "linux-sbsa" + "linux-x86_64" + "source" # Source-agnostic platform + ]; + + /** + The prefix of the URL for redistributable files. + + # Type + + ``` + redistUrlPrefix :: String + ``` + */ + redistUrlPrefix = "https://developer.download.nvidia.com/compute"; +} diff --git a/pkgs/development/cuda-modules/lib/default.nix b/pkgs/development/cuda-modules/lib/default.nix new file mode 100644 index 000000000000..6918d9ca5053 --- /dev/null +++ b/pkgs/development/cuda-modules/lib/default.nix @@ -0,0 +1,13 @@ +let + lib = import ../../../../lib; +in +lib.fixedPoints.makeExtensible (final: { + data = import ./data { + inherit lib; + cudaLib = final; + }; + utils = import ./utils { + inherit lib; + cudaLib = final; + }; +}) diff --git a/pkgs/development/cuda-modules/lib/utils/assertions.nix b/pkgs/development/cuda-modules/lib/utils/assertions.nix new file mode 100644 index 000000000000..5fc940889b7f --- /dev/null +++ b/pkgs/development/cuda-modules/lib/utils/assertions.nix @@ -0,0 +1,139 @@ +{ cudaLib, lib }: +{ + /** + Evaluate assertions and add error context to return value. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + # Type + + ``` + _evaluateAssertions + :: (assertions :: List { assertion :: Bool, message :: String }) + -> Bool + ``` + */ + _evaluateAssertions = + assertions: + let + failedAssertionsString = cudaLib.utils._mkFailedAssertionsString assertions; + in + if failedAssertionsString == "" then + true + else + lib.addErrorContext "with failed assertions:${failedAssertionsString}" false; + + /** + Function to generate a string of failed assertions. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + # Type + + ``` + _mkFailedAssertionsString + :: (assertions :: List { assertion :: Bool, message :: String }) + -> String + ``` + + # Inputs + + `assertions` + + : A list of assertions to evaluate + + # Examples + + :::{.example} + ## `cudaLib.utils._mkFailedAssertionsString` usage examples + + ```nix + _mkFailedAssertionsString [ + { assertion = false; message = "Assertion 1 failed"; } + { assertion = true; message = "Assertion 2 failed"; } + ] + => "\n- Assertion 1 failed" + ``` + + ```nix + _mkFailedAssertionsString [ + { assertion = false; message = "Assertion 1 failed"; } + { assertion = false; message = "Assertion 2 failed"; } + ] + => "\n- Assertion 1 failed\n- Assertion 2 failed" + ``` + ::: + */ + _mkFailedAssertionsString = lib.foldl' ( + failedAssertionsString: + { assertion, message }: + failedAssertionsString + lib.optionalString (!assertion) ("\n- " + message) + ) ""; + + /** + Utility function to generate assertions for missing packages. + + Used to mark a package as unsupported if any of its required packages are missing (null). + + Expects a set of attributes. + + Most commonly used in overrides files on a callPackage-provided attribute set of packages. + + NOTE: We typically use platfromAssertions instead of brokenAssertions because the presence of packages set to null + means evaluation will fail if package attributes are accessed without checking for null first. OfBorg evaluation + sets allowBroken to true, which means we can't rely on brokenAssertions to prevent evaluation of a package with + missing dependencies. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + # Type + + ``` + _mkMissingPackagesAssertions + :: (attrs :: AttrSet) + -> (assertions :: List { assertion :: Bool, message :: String }) + ``` + + # Inputs + + `attrs` + + : The attributes to check for null + + # Examples + + :::{.example} + ## `cudaLib.utils._mkMissingPackagesAssertions` usage examples + + ```nix + { + lib, + libcal ? null, + libcublas, + utils, + }: + let + inherit (lib.attrsets) recursiveUpdate; + inherit (cudaLib.utils) _mkMissingPackagesAssertions; + in + prevAttrs: { + passthru = prevAttrs.passthru or { } // { + platformAssertions = + prevAttrs.passthru.platformAssertions or [ ] + ++ _mkMissingPackagesAssertions { inherit libcal; }; + }; + } + ``` + ::: + */ + _mkMissingPackagesAssertions = lib.flip lib.pipe [ + # Take the attributes that are null. + (lib.filterAttrs (_: value: value == null)) + lib.attrNames + # Map them to assertions. + (lib.map (name: { + message = "${name} is available"; + assertion = false; + })) + ]; +} diff --git a/pkgs/development/cuda-modules/lib/utils/cuda.nix b/pkgs/development/cuda-modules/lib/utils/cuda.nix new file mode 100644 index 000000000000..e372fda0d1b5 --- /dev/null +++ b/pkgs/development/cuda-modules/lib/utils/cuda.nix @@ -0,0 +1,129 @@ +{ lib }: +{ + /** + Returns whether a capability should be built by default for a particular CUDA version. + + Capabilities built by default are baseline, non-Jetson capabilities with relatively recent CUDA support. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + # Type + + ``` + _cudaCapabilityIsDefault + :: (cudaMajorMinorVersion :: Version) + -> (cudaCapabilityInfo :: CudaCapabilityInfo) + -> Bool + ``` + + # Inputs + + `cudaMajorMinorVersion` + + : The CUDA version to check + + `cudaCapabilityInfo` + + : The capability information to check + */ + _cudaCapabilityIsDefault = + cudaMajorMinorVersion: cudaCapabilityInfo: + let + recentCapability = + cudaCapabilityInfo.dontDefaultAfterCudaMajorMinorVersion == null + || lib.versionAtLeast cudaCapabilityInfo.dontDefaultAfterCudaMajorMinorVersion cudaMajorMinorVersion; + in + recentCapability + && !cudaCapabilityInfo.isJetson + && !cudaCapabilityInfo.isArchitectureSpecific + && !cudaCapabilityInfo.isFamilySpecific; + + /** + Returns whether a capability is supported for a particular CUDA version. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + # Type + + ``` + _cudaCapabilityIsSupported + :: (cudaMajorMinorVersion :: Version) + -> (cudaCapabilityInfo :: CudaCapabilityInfo) + -> Bool + ``` + + # Inputs + + `cudaMajorMinorVersion` + + : The CUDA version to check + + `cudaCapabilityInfo` + + : The capability information to check + */ + _cudaCapabilityIsSupported = + cudaMajorMinorVersion: cudaCapabilityInfo: + let + lowerBoundSatisfied = lib.versionAtLeast cudaMajorMinorVersion cudaCapabilityInfo.minCudaMajorMinorVersion; + upperBoundSatisfied = + cudaCapabilityInfo.maxCudaMajorMinorVersion == null + || lib.versionAtLeast cudaCapabilityInfo.maxCudaMajorMinorVersion cudaMajorMinorVersion; + in + lowerBoundSatisfied && upperBoundSatisfied; + + /** + Generates a CUDA variant name from a version. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + # Type + + ``` + _mkCudaVariant :: (version :: String) -> String + ``` + + # Inputs + + `version` + + : The version string + + # Examples + + :::{.example} + ## `cudaLib.utils._mkCudaVariant` usage examples + + ```nix + _mkCudaVariant "11.0" + => "cuda11" + ``` + ::: + */ + _mkCudaVariant = version: "cuda${lib.versions.major version}"; + + /** + A predicate which, given a package, returns true if the package has a free license or one of NVIDIA's licenses. + + This function is intended to be provided as `config.allowUnfreePredicate` when `import`-ing Nixpkgs. + + # Type + + ``` + allowUnfreeCudaPredicate :: (package :: Package) -> Bool + ``` + */ + allowUnfreeCudaPredicate = + package: + lib.all ( + license: + license.free + || lib.elem license.shortName [ + "CUDA EULA" + "cuDNN EULA" + "cuSPARSELt EULA" + "cuTENSOR EULA" + "NVidia OptiX EULA" + ] + ) (lib.toList package.meta.license); +} diff --git a/pkgs/development/cuda-modules/lib/utils/default.nix b/pkgs/development/cuda-modules/lib/utils/default.nix new file mode 100644 index 000000000000..ee9ace015fae --- /dev/null +++ b/pkgs/development/cuda-modules/lib/utils/default.nix @@ -0,0 +1,49 @@ +{ cudaLib, lib }: +{ + # See ./assertions.nix for documentation. + inherit (import ./assertions.nix { inherit cudaLib lib; }) + _evaluateAssertions + _mkFailedAssertionsString + _mkMissingPackagesAssertions + ; + + # See ./cuda.nix for documentation. + inherit (import ./cuda.nix { inherit lib; }) + _cudaCapabilityIsDefault + _cudaCapabilityIsSupported + _mkCudaVariant + allowUnfreeCudaPredicate + ; + + # See ./meta.nix for documentation. + inherit (import ./meta.nix { inherit cudaLib lib; }) + _mkMetaBadPlatforms + _mkMetaBroken + ; + + # See ./redist.nix for documentation. + inherit (import ./redist.nix { inherit cudaLib lib; }) + _redistSystemIsSupported + getNixSystems + getRedistSystem + mkRedistUrl + ; + + # See ./strings.nix for documentation. + inherit (import ./strings.nix { inherit cudaLib lib; }) + dotsToUnderscores + dropDots + formatCapabilities + mkCmakeCudaArchitecturesString + mkGencodeFlag + mkRealArchitecture + mkVersionedName + mkVirtualArchitecture + ; + + # See ./versions.nix for documentation. + inherit (import ./versions.nix { inherit cudaLib lib; }) + majorMinorPatch + trimComponents + ; +} diff --git a/pkgs/development/cuda-modules/lib/utils/meta.nix b/pkgs/development/cuda-modules/lib/utils/meta.nix new file mode 100644 index 000000000000..327d4ae97d95 --- /dev/null +++ b/pkgs/development/cuda-modules/lib/utils/meta.nix @@ -0,0 +1,71 @@ +{ cudaLib, lib }: +{ + /** + Returns a list of bad platforms for a given package if assertsions in `finalAttrs.passthru.platformAssertions` + fail, optionally logging evaluation warnings for each reason. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + NOTE: This function requires `finalAttrs.passthru.platformAssertions` to be a list of assertions and + `finalAttrs.finalPackage.name` and `finalAttrs.finalPackage.stdenv` to be available. + + # Type + + ``` + _mkMetaBadPlatforms :: (warn :: Bool) -> (finalAttrs :: AttrSet) -> List String + ``` + */ + _mkMetaBadPlatforms = + warn: finalAttrs: + let + failedAssertionsString = cudaLib.utils._mkFailedAssertionsString finalAttrs.passthru.platformAssertions; + hasFailedAssertions = failedAssertionsString != ""; + finalStdenv = finalAttrs.finalPackage.stdenv; + in + lib.warnIf (warn && hasFailedAssertions) + "Package ${finalAttrs.finalPackage.name} is unsupported on this platform due to the following failed assertions:${failedAssertionsString}" + ( + lib.optionals hasFailedAssertions ( + lib.unique [ + finalStdenv.buildPlatform.system + finalStdenv.hostPlatform.system + finalStdenv.targetPlatform.system + ] + ) + ); + + /** + Returns a boolean indicating whether the package is broken as a result of `finalAttrs.passthru.brokenAssertions`, + optionally logging evaluation warnings for each reason. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + NOTE: This function requires `finalAttrs.passthru.brokenAssertions` to be a list of assertions and + `finalAttrs.finalPackage.name` to be available. + + # Type + + ``` + _mkMetaBroken :: (warn :: Bool) -> (finalAttrs :: AttrSet) -> Bool + ``` + + # Inputs + + `warn` + + : A boolean indicating whether to log warnings + + `finalAttrs` + + : The final attributes of the package + */ + _mkMetaBroken = + warn: finalAttrs: + let + failedAssertionsString = cudaLib.utils._mkFailedAssertionsString finalAttrs.passthru.brokenAssertions; + hasFailedAssertions = failedAssertionsString != ""; + in + lib.warnIf (warn && hasFailedAssertions) + "Package ${finalAttrs.finalPackage.name} is marked as broken due to the following failed assertions:${failedAssertionsString}" + hasFailedAssertions; +} diff --git a/pkgs/development/cuda-modules/lib/utils/redist.nix b/pkgs/development/cuda-modules/lib/utils/redist.nix new file mode 100644 index 000000000000..b9cd2a3b1e0d --- /dev/null +++ b/pkgs/development/cuda-modules/lib/utils/redist.nix @@ -0,0 +1,196 @@ +{ cudaLib, lib }: +{ + /** + Returns a boolean indicating whether the provided redist system is supported by any of the provided redist systems. + + NOTE: No guarantees are made about this function's stability. You may use it at your own risk. + + # Type + + ``` + _redistSystemIsSupported + :: (redistSystem :: RedistSystem) + -> (redistSystems :: List RedistSystem) + -> Bool + ``` + + # Inputs + + `redistSystem` + + : The redist system to check + + `redistSystems` + + : The list of redist systems to check against + + # Examples + + :::{.example} + ## `cudaLib.utils._redistSystemIsSupported` usage examples + + ```nix + _redistSystemIsSupported "linux-x86_64" [ "linux-x86_64" ] + => true + ``` + + ```nix + _redistSystemIsSupported "linux-x86_64" [ "linux-aarch64" ] + => false + ``` + + ```nix + _redistSystemIsSupported "linux-x86_64" [ "linux-aarch64" "linux-x86_64" ] + => true + ``` + + ```nix + _redistSystemIsSupported "linux-x86_64" [ "linux-aarch64" "linux-all" ] + => true + ``` + ::: + */ + _redistSystemIsSupported = + redistSystem: redistSystems: + lib.findFirst ( + redistSystem': + redistSystem' == redistSystem || redistSystem' == "linux-all" || redistSystem' == "source" + ) null redistSystems != null; + + /** + Maps a NVIDIA redistributable system to Nix systems. + + NOTE: This function returns a list of systems because the redistributable systems `"linux-all"` and `"source"` can + be built on multiple systems. + + NOTE: This function *will* be called by unsupported systems because `cudaPackages` is evaluated on all systems. As + such, we need to handle unsupported systems gracefully. + + # Type + + ``` + getNixSystems :: (redistSystem :: RedistSystem) -> [String] + ``` + + # Inputs + + `redistSystem` + + : The NVIDIA redistributable system + + # Examples + + :::{.example} + ## `cudaLib.utils.getNixSystems` usage examples + + ```nix + getNixSystems "linux-sbsa" + => [ "aarch64-linux" ] + ``` + + ```nix + getNixSystems "linux-aarch64" + => [ "aarch64-linux" ] + ``` + ::: + */ + getNixSystems = + redistSystem: + if redistSystem == "linux-x86_64" then + [ "x86_64-linux" ] + else if redistSystem == "linux-sbsa" || redistSystem == "linux-aarch64" then + [ "aarch64-linux" ] + else if redistSystem == "linux-all" || redistSystem == "source" then + [ + "aarch64-linux" + "x86_64-linux" + ] + else + [ ]; + + /** + Maps a Nix system to a NVIDIA redistributable system. + + 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 evaluated on all systems. As + such, we need to handle unsupported systems gracefully. + + # Type + + ``` + getRedistSystem :: (hasJetsonCudaCapability :: Bool) -> (nixSystem :: String) -> String + ``` + + # Inputs + + `hasJetsonCudaCapability` + + : If configured for a Jetson device + + `nixSystem` + + : The Nix system + + # Examples + + :::{.example} + ## `cudaLib.utils.getRedistSystem` usage examples + + ```nix + getRedistSystem true "aarch64-linux" + => "linux-aarch64" + ``` + + ```nix + getRedistSystem false "aarch64-linux" + => "linux-sbsa" + ``` + ::: + */ + getRedistSystem = + hasJetsonCudaCapability: nixSystem: + if nixSystem == "x86_64-linux" then + "linux-x86_64" + else if nixSystem == "aarch64-linux" then + if hasJetsonCudaCapability then "linux-aarch64" else "linux-sbsa" + else + "unsupported"; + + /** + Function to generate a URL for something in the redistributable tree. + + # Type + + ``` + mkRedistUrl :: (redistName :: RedistName) -> (relativePath :: NonEmptyStr) -> RedistUrl + ``` + + # Inputs + + `redistName` + + : The name of the redistributable + + `relativePath` + + : The relative path to a file in the redistributable tree + */ + mkRedistUrl = + redistName: relativePath: + lib.concatStringsSep "/" ( + [ cudaLib.data.redistUrlPrefix ] + ++ ( + if redistName != "tensorrt" then + [ + redistName + "redist" + ] + else + [ "machine-learning" ] + ) + ++ [ relativePath ] + ); +} diff --git a/pkgs/development/cuda-modules/lib/utils/strings.nix b/pkgs/development/cuda-modules/lib/utils/strings.nix new file mode 100644 index 000000000000..47a71b395f4f --- /dev/null +++ b/pkgs/development/cuda-modules/lib/utils/strings.nix @@ -0,0 +1,379 @@ +{ cudaLib, lib }: +{ + /** + Replaces dots in a string with underscores. + + # Type + + ``` + dotsToUnderscores :: (str :: String) -> String + ``` + + # Inputs + + `str` + + : The string for which dots shall be replaced by underscores + + # Examples + + :::{.example} + ## `cudaLib.utils.dotsToUnderscores` usage examples + + ```nix + dotsToUnderscores "1.2.3" + => "1_2_3" + ``` + ::: + */ + dotsToUnderscores = lib.replaceStrings [ "." ] [ "_" ]; + + /** + Removes the dots from a string. + + # Type + + ``` + dropDots :: (str :: String) -> String + ``` + + # Inputs + + `str` + + : The string to remove dots from + + # Examples + + :::{.example} + ## `cudaLib.utils.dropDots` usage examples + + ```nix + dropDots "1.2.3" + => "123" + ``` + ::: + */ + dropDots = lib.replaceStrings [ "." ] [ "" ]; + + /** + Produces an attribute set of useful data and functionality for packaging CUDA software within Nixpkgs. + + # Type + + ``` + formatCapabilities + :: { cudaCapabilityToInfo :: AttrSet CudaCapability CudaCapabilityInfo + , cudaCapabilities :: List CudaCapability + , cudaForwardCompat :: Bool + } + -> { cudaCapabilities :: List CudaCapability + , cudaForwardCompat :: Bool + , gencode :: List String + , realArches :: List String + , virtualArches :: List String + , archNames :: List String + , arches :: List String + , gencodeString :: String + , cmakeCudaArchitecturesString :: String + } + ``` + + # Inputs + + `cudaCapabilityToInfo` + + : A mapping of CUDA capabilities to their information + + `cudaCapabilities` + + : A list of CUDA capabilities to use + + `cudaForwardCompat` + + : A boolean indicating whether to include the forward compatibility gencode (+PTX) to support future GPU + generations + */ + formatCapabilities = + { + cudaCapabilityToInfo, + cudaCapabilities, + cudaForwardCompat, + }: + let + /** + The real architectures for the given CUDA capabilities. + + # Type + + ``` + realArches :: List String + ``` + */ + realArches = lib.map cudaLib.utils.mkRealArchitecture cudaCapabilities; + + /** + The virtual architectures for the given CUDA capabilities. + + These are typically used for forward compatibility, when trying to support an architecture newer than the CUDA + version allows. + + # Type + + ``` + virtualArches :: List String + ``` + */ + virtualArches = lib.map cudaLib.utils.mkVirtualArchitecture cudaCapabilities; + + /** + The gencode flags for the given CUDA capabilities. + + # Type + + ``` + gencode :: List String + ``` + */ + gencode = + let + base = lib.map (cudaLib.utils.mkGencodeFlag "sm") cudaCapabilities; + forward = cudaLib.utils.mkGencodeFlag "compute" (lib.last cudaCapabilities); + in + base ++ lib.optionals cudaForwardCompat [ forward ]; + in + { + inherit + cudaCapabilities + cudaForwardCompat + gencode + realArches + virtualArches + ; + + /** + The architecture names for the given CUDA capabilities. + + # Type + + ``` + archNames :: List String + ``` + */ + # E.g. [ "Ampere" "Turing" ] + archNames = lib.pipe cudaCapabilities [ + (lib.map (cudaCapability: cudaCapabilityToInfo.${cudaCapability}.archName)) + lib.unique + lib.naturalSort + ]; + + /** + The architectures for the given CUDA capabilities, including both real and virtual architectures. + + When `cudaForwardCompat` is enabled, the last architecture in the list is used as the forward compatibility architecture. + + # Type + + ``` + arches :: List String + ``` + */ + # E.g. [ "sm_75" "sm_86" "compute_86" ] + arches = realArches ++ lib.optionals cudaForwardCompat [ (lib.last virtualArches) ]; + + /** + The CMake-compatible CUDA architectures string for the given CUDA capabilities. + + # Type + + ``` + cmakeCudaArchitecturesString :: String + ``` + */ + cmakeCudaArchitecturesString = cudaLib.utils.mkCmakeCudaArchitecturesString cudaCapabilities; + + /** + The gencode string for the given CUDA capabilities. + + # Type + + ``` + gencodeString :: String + ``` + */ + gencodeString = lib.concatStringsSep " " gencode; + }; + + /** + Produces a CMake-compatible CUDA architecture string from a list of CUDA capabilities. + + # Type + + ``` + mkCmakeCudaArchitecturesString :: (cudaCapabilities :: List String) -> String + ``` + + # Inputs + + `cudaCapabilities` + + : The CUDA capabilities to convert + + # Examples + + :::{.example} + ## `cudaLib.utils.mkCmakeCudaArchitecturesString` usage examples + + ```nix + mkCmakeCudaArchitecturesString [ "8.9" "10.0a" ] + => "89;100a" + ``` + ::: + */ + mkCmakeCudaArchitecturesString = lib.concatMapStringsSep ";" cudaLib.utils.dropDots; + + /** + Produces a gencode flag from a CUDA capability. + + # Type + + ``` + mkGencodeFlag :: (archPrefix :: String) -> (cudaCapability :: String) -> String + ``` + + # Inputs + + `archPrefix` + + : The architecture prefix to use for the `code` field + + `cudaCapability` + + : The CUDA capability to convert + + # Examples + + :::{.example} + ## `cudaLib.utils.mkGencodeFlag` usage examples + + ```nix + mkGencodeFlag "sm" "8.9" + => "-gencode=arch=compute_89,code=sm_89" + ``` + + ```nix + mkGencodeFlag "compute" "10.0a" + => "-gencode=arch=compute_100a,code=compute_100a" + ``` + ::: + */ + mkGencodeFlag = + archPrefix: cudaCapability: + let + cap = cudaLib.utils.dropDots cudaCapability; + in + "-gencode=arch=compute_${cap},code=${archPrefix}_${cap}"; + + /** + Produces a real architecture string from a CUDA capability. + + # Type + + ``` + mkRealArchitecture :: (cudaCapability :: String) -> String + ``` + + # Inputs + + `cudaCapability` + + : The CUDA capability to convert + + # Examples + + :::{.example} + ## `cudaLib.utils.mkRealArchitecture` usage examples + + ```nix + mkRealArchitecture "8.9" + => "sm_89" + ``` + + ```nix + mkRealArchitecture "10.0a" + => "sm_100a" + ``` + ::: + */ + mkRealArchitecture = cudaCapability: "sm_" + cudaLib.utils.dropDots cudaCapability; + + /** + Create a versioned attribute name from a version by replacing dots with underscores. + + # Type + + ``` + mkVersionedName :: (name :: String) -> (version :: Version) -> String + ``` + + # Inputs + + `name` + + : The name to use + + `version` + + : The version to use + + # Examples + + :::{.example} + ## `cudaLib.utils.mkVersionedName` usage examples + + ```nix + mkVersionedName "hello" "1.2.3" + => "hello_1_2_3" + ``` + + ```nix + mkVersionedName "cudaPackages" "12.8" + => "cudaPackages_12_8" + ``` + ::: + */ + mkVersionedName = name: version: "${name}_${cudaLib.utils.dotsToUnderscores version}"; + + /** + Produces a virtual architecture string from a CUDA capability. + + # Type + + ``` + mkVirtualArchitecture :: (cudaCapability :: String) -> String + ``` + + # Inputs + + `cudaCapability` + + : The CUDA capability to convert + + # Examples + + :::{.example} + ## `cudaLib.utils.mkVirtualArchitecture` usage examples + + ```nix + mkVirtualArchitecture "8.9" + => "compute_89" + ``` + + ```nix + mkVirtualArchitecture "10.0a" + => "compute_100a" + ``` + ::: + */ + mkVirtualArchitecture = cudaCapability: "compute_" + cudaLib.utils.dropDots cudaCapability; +} diff --git a/pkgs/development/cuda-modules/lib/utils/versions.nix b/pkgs/development/cuda-modules/lib/utils/versions.nix new file mode 100644 index 000000000000..976ad65b2b65 --- /dev/null +++ b/pkgs/development/cuda-modules/lib/utils/versions.nix @@ -0,0 +1,76 @@ +{ cudaLib, lib }: +{ + /** + Extracts the major, minor, and patch version from a string. + + # Type + + ``` + majorMinorPatch :: (version :: String) -> String + ``` + + # Inputs + + `version` + + : The version string + + # Examples + + :::{.example} + ## `cudaLib.utils.majorMinorPatch` usage examples + + ```nix + majorMinorPatch "11.0.3.4" + => "11.0.3" + ``` + ::: + */ + majorMinorPatch = cudaLib.utils.trimComponents 3; + + /** + Get a version string with no more than than the specified number of components. + + # Type + + ``` + trimComponents :: (numComponents :: Integer) -> (version :: String) -> String + ``` + + # Inputs + + `numComponents` + : A positive integer corresponding to the maximum number of components to keep + + `version` + : A version string + + # Examples + + :::{.example} + ## `cudaLib.utils.trimComponents` usage examples + + ```nix + trimComponents 1 "1.2.3.4" + => "1" + ``` + + ```nix + trimComponents 3 "1.2.3.4" + => "1.2.3" + ``` + + ```nix + trimComponents 9 "1.2.3.4" + => "1.2.3.4" + ``` + ::: + */ + trimComponents = + n: v: + lib.pipe v [ + lib.splitVersion + (lib.take n) + (lib.concatStringsSep ".") + ]; +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index c112851029c1..54ef290488f5 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2723,6 +2723,8 @@ with pkgs; cron = isc-cron; + cudaLib = import ../development/cuda-modules/lib; + cudaPackages_11_0 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.0"; }; cudaPackages_11_1 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.1"; }; cudaPackages_11_2 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.2"; }; From fd906c82526aee6deed02acb4a292ca39b2680b7 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Fri, 9 May 2025 23:07:38 +0000 Subject: [PATCH 04/11] cudaPackages: rewrite backendStdenv Signed-off-by: Connor Baker (cherry picked from commit 629ae4e42c4764f1e56cd64746a3f19e28ff62a0) --- .../cuda-modules/packages/backendStdenv.nix | 148 ++++++++++++++++-- 1 file changed, 135 insertions(+), 13 deletions(-) diff --git a/pkgs/development/cuda-modules/packages/backendStdenv.nix b/pkgs/development/cuda-modules/packages/backendStdenv.nix index b3595835fe38..ac9a8ebaf44f 100644 --- a/pkgs/development/cuda-modules/packages/backendStdenv.nix +++ b/pkgs/development/cuda-modules/packages/backendStdenv.nix @@ -1,4 +1,3 @@ -# Exposed as cudaPackages.backendStdenv. # This is what nvcc uses as a backend, # and it has to be an officially supported one (e.g. gcc11 for cuda11). # @@ -7,26 +6,149 @@ # E.g. for cudaPackages_11_8 we use gcc11 with gcc12's libstdc++ # Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context { + config, + cudaLib, cudaMajorMinorVersion, lib, - nvccCompatibilities, pkgs, stdenv, stdenvAdapters, }: - let - gccMajorVersion = nvccCompatibilities.${cudaMajorMinorVersion}.gccMaxMajorVersion; - cudaStdenv = stdenvAdapters.useLibsFrom stdenv pkgs."gcc${gccMajorVersion}Stdenv"; + inherit (builtins) toJSON; + inherit (cudaLib.data) allSortedCudaCapabilities cudaCapabilityToInfo nvccCompatibilities; + inherit (cudaLib.utils) + _cudaCapabilityIsDefault + _cudaCapabilityIsSupported + _evaluateAssertions + getRedistSystem + mkVersionedName + ; + inherit (lib) addErrorContext; + inherit (lib.customisation) extendDerivation; + inherit (lib.lists) filter intersectLists subtractLists; + + # NOTE: By virtue of processing a sorted list (allSortedCudaCapabilities), our groups will be sorted. + + architectureSpecificCudaCapabilities = filter ( + cudaCapability: cudaCapabilityToInfo.${cudaCapability}.isArchitectureSpecific + ) allSortedCudaCapabilities; + + familySpecificCudaCapabilities = filter ( + cudaCapability: cudaCapabilityToInfo.${cudaCapability}.isFamilySpecific + ) allSortedCudaCapabilities; + + jetsonCudaCapabilities = filter ( + cudaCapability: cudaCapabilityToInfo.${cudaCapability}.isJetson + ) allSortedCudaCapabilities; + passthruExtra = { - # cudaPackages.backendStdenv.nixpkgsCompatibleLibstdcxx has been removed, - # if you need it you're likely doing something wrong. There has been a - # warning here for a month or so. Now we can no longer return any - # meaningful value in its place and drop the attribute entirely. + nvccHostCCMatchesStdenvCC = backendStdenv.cc == stdenv.cc; + + # The Nix system of the host platform. + hostNixSystem = stdenv.hostPlatform.system; + + # The Nix system of the host platform for the CUDA redistributable. + hostRedistSystem = getRedistSystem passthruExtra.hasJetsonCudaCapability stdenv.hostPlatform.system; + + # Sets whether packages should be built with forward compatibility. + # TODO(@connorbaker): If the requested CUDA capabilities are not supported by the current CUDA version, + # should we throw an evaluation warning and build with forward compatibility? + cudaForwardCompat = config.cudaForwardCompat or true; + + # CUDA capabilities which are supported by the current CUDA version. + supportedCudaCapabilities = filter ( + cudaCapability: + _cudaCapabilityIsSupported cudaMajorMinorVersion cudaCapabilityToInfo.${cudaCapability} + ) allSortedCudaCapabilities; + + # Find the default set of capabilities for this CUDA version using the list of supported capabilities. + # Includes only baseline capabilities. + defaultCudaCapabilities = filter ( + cudaCapability: + _cudaCapabilityIsDefault cudaMajorMinorVersion cudaCapabilityToInfo.${cudaCapability} + ) passthruExtra.supportedCudaCapabilities; + + # The resolved requested or default CUDA capabilities. + cudaCapabilities = + if config.cudaCapabilities or [ ] != [ ] then + config.cudaCapabilities + else + passthruExtra.defaultCudaCapabilities; + + # Requested architecture-specific CUDA capabilities. + requestedArchitectureSpecificCudaCapabilities = intersectLists architectureSpecificCudaCapabilities passthruExtra.cudaCapabilities; + + # Whether the requested CUDA capabilities include architecture-specific CUDA capabilities. + hasArchitectureSpecificCudaCapability = + passthruExtra.requestedArchitectureSpecificCudaCapabilities != [ ]; + + # Requested family-specific CUDA capabilities. + requestedFamilySpecificCudaCapabilities = intersectLists familySpecificCudaCapabilities passthruExtra.cudaCapabilities; + + # Whether the requested CUDA capabilities include family-specific CUDA capabilities. + hasFamilySpecificCudaCapability = passthruExtra.requestedFamilySpecificCudaCapabilities != [ ]; + + # Requested Jetson CUDA capabilities. + requestedJetsonCudaCapabilities = intersectLists jetsonCudaCapabilities passthruExtra.cudaCapabilities; + + # Whether the requested CUDA capabilities include Jetson CUDA capabilities. + hasJetsonCudaCapability = passthruExtra.requestedJetsonCudaCapabilities != [ ]; }; - assertCondition = true; + + assertions = + let + # 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. + jetsonMesssagePrefix = "Jetson CUDA capabilities (${toJSON passthruExtra.requestedJetsonCudaCapabilities})"; + + # Remove all known capabilities from the user's list to find unrecognized capabilities. + unrecognizedCudaCapabilities = subtractLists allSortedCudaCapabilities passthruExtra.cudaCapabilities; + + # Remove all supported capabilities from the user's list to find unsupported capabilities. + unsupportedCudaCapabilities = subtractLists passthruExtra.supportedCudaCapabilities passthruExtra.cudaCapabilities; + in + [ + { + message = "Unrecognized CUDA capabilities: ${toJSON unrecognizedCudaCapabilities}"; + assertion = unrecognizedCudaCapabilities == [ ]; + } + { + message = "Unsupported CUDA capabilities: ${toJSON unsupportedCudaCapabilities}"; + assertion = unsupportedCudaCapabilities == [ ]; + } + { + message = + "${jetsonMesssagePrefix} require hostPlatform (currently ${passthruExtra.hostNixSystem}) " + + "to be aarch64-linux"; + assertion = passthruExtra.hasJetsonCudaCapability -> passthruExtra.hostNixSystem == "aarch64-linux"; + } + { + message = + let + # Find the capabilities which are not Jetson capabilities. + requestedNonJetsonCudaCapabilities = subtractLists ( + passthruExtra.requestedJetsonCudaCapabilities + ++ passthruExtra.requestedArchitectureSpecificCudaCapabilities + ++ passthruExtra.requestedFamilySpecificCudaCapabilities + ) passthruExtra.cudaCapabilities; + in + "${jetsonMesssagePrefix} cannot be specified with non-Jetson capabilities " + + "(${toJSON requestedNonJetsonCudaCapabilities})"; + assertion = + passthruExtra.hasJetsonCudaCapability + -> passthruExtra.requestedJetsonCudaCapabilities == passthruExtra.cudaCapabilities; + } + ]; + + assertCondition = addErrorContext "while evaluating ${mkVersionedName "cudaPackages" cudaMajorMinorVersion}.backendStdenv" ( + _evaluateAssertions assertions + ); + + backendStdenv = + stdenvAdapters.useLibsFrom stdenv + pkgs."gcc${nvccCompatibilities.${cudaMajorMinorVersion}.gcc.maxMajorVersion}Stdenv"; in - # TODO: Consider testing whether we in fact use the newer libstdc++ - -lib.extendDerivation assertCondition passthruExtra cudaStdenv +extendDerivation assertCondition passthruExtra backendStdenv From 9e09b547947672c1be01766de0cfc7346f39adc0 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Fri, 9 May 2025 22:16:23 +0000 Subject: [PATCH 05/11] cudaPackages: switch to cudaLib Signed-off-by: Connor Baker (cherry picked from commit c5dad2886a5623fc5e41054ab9ed9ff8e5f7ac91) --- doc/languages-frameworks/cuda.section.md | 4 +- pkgs/development/cuda-modules/README.md | 3 - pkgs/development/cuda-modules/aliases.nix | 5 +- .../cuda-modules/cuda/extension.nix | 2 +- pkgs/development/cuda-modules/cudnn/shims.nix | 6 +- .../cuda-modules/cusparselt/extension.nix | 18 +- .../cuda-modules/cutensor/extension.nix | 14 +- .../cuda-modules/fixups/tensorrt.nix | 6 +- pkgs/development/cuda-modules/flags.nix | 399 ------------------ .../generic-builders/manifest.nix | 40 +- .../generic-builders/multiplex.nix | 21 +- pkgs/development/cuda-modules/gpus.nix | 244 ----------- .../cuda-modules/nvcc-compatibilities.nix | 125 ------ .../cuda-modules/tensorrt/shims.nix | 6 +- pkgs/development/cuda-modules/tests/flags.nix | 78 ++++ pkgs/top-level/cuda-packages.nix | 82 ++-- pkgs/top-level/release-cuda.nix | 17 +- 17 files changed, 186 insertions(+), 884 deletions(-) delete mode 100644 pkgs/development/cuda-modules/flags.nix delete mode 100644 pkgs/development/cuda-modules/gpus.nix delete mode 100644 pkgs/development/cuda-modules/nvcc-compatibilities.nix create mode 100644 pkgs/development/cuda-modules/tests/flags.nix 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 356ec5196b69..4ddda47a766d 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; From a818a59d9fd813bf007c1d55c050bf54b93fd557 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Thu, 15 May 2025 21:00:40 +0000 Subject: [PATCH 06/11] cudaPackages.fixups -> pkgs.cudaFixups (cherry picked from commit 765529dfff5cb04cd8ebf9275c9bccc9473fcbb5) --- .../cuda-modules/fixups/default.nix | 5 +++-- .../cuda-modules/generic-builders/manifest.nix | 4 ++-- pkgs/top-level/all-packages.nix | 2 ++ pkgs/top-level/cuda-packages.nix | 18 +++++------------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/pkgs/development/cuda-modules/fixups/default.nix b/pkgs/development/cuda-modules/fixups/default.nix index 9166e413bb71..a5ec4a90e817 100644 --- a/pkgs/development/cuda-modules/fixups/default.nix +++ b/pkgs/development/cuda-modules/fixups/default.nix @@ -1,5 +1,6 @@ -{ lib }: - +let + lib = import ../../../../lib; +in lib.concatMapAttrs ( fileName: _type: let diff --git a/pkgs/development/cuda-modules/generic-builders/manifest.nix b/pkgs/development/cuda-modules/generic-builders/manifest.nix index f4eecc29f4dc..712db3bd5b99 100644 --- a/pkgs/development/cuda-modules/generic-builders/manifest.nix +++ b/pkgs/development/cuda-modules/generic-builders/manifest.nix @@ -5,9 +5,9 @@ autoPatchelfHook, backendStdenv, callPackage, + cudaFixups, cudaLib, fetchurl, - fixups, lib, markForCudatoolkitRootHook, flags, @@ -45,7 +45,7 @@ let # Last step before returning control to `callPackage` (adds the `.override` method) # we'll apply (`overrideAttrs`) necessary package-specific "fixup" functions. # Order is significant. - maybeFixup = fixups.${pname} or null; + maybeFixup = cudaFixups.${pname} or null; fixup = if maybeFixup != null then callPackage maybeFixup { } else { }; # Get the redist systems for which package provides distributables. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 54ef290488f5..7499ad9b62b1 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2725,6 +2725,8 @@ with pkgs; cudaLib = import ../development/cuda-modules/lib; + cudaFixups = import ../development/cuda-modules/fixups; + cudaPackages_11_0 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.0"; }; cudaPackages_11_1 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.1"; }; cudaPackages_11_2 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.2"; }; diff --git a/pkgs/top-level/cuda-packages.nix b/pkgs/top-level/cuda-packages.nix index 60bc5c0dd953..5870d383291e 100644 --- a/pkgs/top-level/cuda-packages.nix +++ b/pkgs/top-level/cuda-packages.nix @@ -26,7 +26,6 @@ cudaMajorMinorVersion, lib, newScope, - pkgs, stdenv, }: let @@ -39,9 +38,6 @@ let versions ; - # MUST be defined outside fix-point (cf. "NAMESET STRICTNESS" above) - fixups = import ../development/cuda-modules/fixups { inherit lib; }; - # 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. @@ -54,19 +50,15 @@ let 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: + # It is important that cudaLib and cudaFixups 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 - lib - pkgs - ; + # This decision is driven both by a separation of concerns and by "NAMESET STRICTNESS" (see above). + + inherit cudaMajorMinorVersion; cudaNamePrefix = "cuda${cudaMajorMinorVersion}"; From a92ac4cd5a206609c46441ed3890306652b07fb2 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Thu, 15 May 2025 20:49:17 +0000 Subject: [PATCH 07/11] tree-wide: cudaPackages.flags updates Signed-off-by: Connor Baker (cherry picked from commit ead65813623f92f8630811b1b3616877a727b1d9) --- pkgs/applications/science/misc/colmap/default.nix | 2 +- pkgs/by-name/dl/dlib/package.nix | 2 +- pkgs/by-name/gp/gpu-burn/package.nix | 4 ++-- pkgs/by-name/mi/mistral-rs/package.nix | 2 +- pkgs/by-name/mo/moshi/package.nix | 2 +- pkgs/by-name/ti/tiny-cuda-nn/package.nix | 2 +- pkgs/development/libraries/science/math/magma/generic.nix | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkgs/applications/science/misc/colmap/default.nix b/pkgs/applications/science/misc/colmap/default.nix index c28c1b15b96e..39c5798ff096 100644 --- a/pkgs/applications/science/misc/colmap/default.nix +++ b/pkgs/applications/science/misc/colmap/default.nix @@ -46,7 +46,7 @@ stdenv'.mkDerivation rec { cmakeFlags = lib.optionals cudaSupport [ (lib.cmakeBool "CUDA_ENABLED" true) (lib.cmakeFeature "CMAKE_CUDA_ARCHITECTURES" ( - lib.strings.concatStringsSep ";" (map cudaPackages.flags.dropDot cudaCapabilities) + lib.strings.concatStringsSep ";" (map cudaPackages.flags.dropDots cudaCapabilities) )) ]; diff --git a/pkgs/by-name/dl/dlib/package.nix b/pkgs/by-name/dl/dlib/package.nix index 16c34f2168dc..c37e2f7c8889 100644 --- a/pkgs/by-name/dl/dlib/package.nix +++ b/pkgs/by-name/dl/dlib/package.nix @@ -42,7 +42,7 @@ ] ++ lib.optionals cudaSupport [ (lib.cmakeFeature "DLIB_USE_CUDA_COMPUTE_CAPABILITIES" ( - builtins.concatStringsSep "," (with cudaPackages.flags; map dropDot cudaCapabilities) + builtins.concatStringsSep "," (with cudaPackages.flags; map dropDots cudaCapabilities) )) ]; diff --git a/pkgs/by-name/gp/gpu-burn/package.nix b/pkgs/by-name/gp/gpu-burn/package.nix index 2028427c96c1..8f95db66b43c 100644 --- a/pkgs/by-name/gp/gpu-burn/package.nix +++ b/pkgs/by-name/gp/gpu-burn/package.nix @@ -17,7 +17,7 @@ let cuda_nvcc libcublas ; - inherit (cudaPackages.flags) cudaCapabilities dropDot isJetsonBuild; + inherit (cudaPackages.flags) cudaCapabilities dropDots isJetsonBuild; in backendStdenv.mkDerivation { pname = "gpu-burn"; @@ -53,7 +53,7 @@ backendStdenv.mkDerivation { makeFlags = [ "CUDAPATH=${getBin cuda_nvcc}" - "COMPUTE=${last (map dropDot cudaCapabilities)}" + "COMPUTE=${last (map dropDots cudaCapabilities)}" "IS_JETSON=${boolToString isJetsonBuild}" ]; diff --git a/pkgs/by-name/mi/mistral-rs/package.nix b/pkgs/by-name/mi/mistral-rs/package.nix index 18d3eccf6e3f..a3c22e807014 100644 --- a/pkgs/by-name/mi/mistral-rs/package.nix +++ b/pkgs/by-name/mi/mistral-rs/package.nix @@ -60,7 +60,7 @@ let )) else cudaCapability; - cudaCapability' = lib.toInt (cudaPackages.flags.dropDot cudaCapabilityString); + cudaCapability' = lib.toInt (cudaPackages.flags.dropDots cudaCapabilityString); mklSupport = assert accelIsValid; diff --git a/pkgs/by-name/mo/moshi/package.nix b/pkgs/by-name/mo/moshi/package.nix index 94fd6af59326..f0e2b3db2235 100644 --- a/pkgs/by-name/mo/moshi/package.nix +++ b/pkgs/by-name/mo/moshi/package.nix @@ -38,7 +38,7 @@ let )) else cudaCapability; - cudaCapability' = lib.toInt (cudaPackages.flags.dropDot cudaCapabilityString); + cudaCapability' = lib.toInt (cudaPackages.flags.dropDots cudaCapabilityString); in rustPlatform.buildRustPackage (finalAttrs: { pname = "moshi"; diff --git a/pkgs/by-name/ti/tiny-cuda-nn/package.nix b/pkgs/by-name/ti/tiny-cuda-nn/package.nix index 924d691e52bd..e2c2f75d13da 100644 --- a/pkgs/by-name/ti/tiny-cuda-nn/package.nix +++ b/pkgs/by-name/ti/tiny-cuda-nn/package.nix @@ -43,7 +43,7 @@ let cudaCapabilities = lists.subtractLists unsupportedCudaCapabilities flags.cudaCapabilities; - cudaArchitecturesString = strings.concatMapStringsSep ";" flags.dropDot cudaCapabilities; + cudaArchitecturesString = strings.concatMapStringsSep ";" flags.dropDots cudaCapabilities; in stdenv.mkDerivation (finalAttrs: { pname = "tiny-cuda-nn"; diff --git a/pkgs/development/libraries/science/math/magma/generic.nix b/pkgs/development/libraries/science/math/magma/generic.nix index 53407ebe7bcb..c7938b98368a 100644 --- a/pkgs/development/libraries/science/math/magma/generic.nix +++ b/pkgs/development/libraries/science/math/magma/generic.nix @@ -94,7 +94,7 @@ let minArch = let # E.g. [ "80" "86" "90" ] - cudaArchitectures = (builtins.map flags.dropDot flags.cudaCapabilities); + cudaArchitectures = (builtins.map flags.dropDots flags.cudaCapabilities); minArch' = builtins.head (builtins.sort strings.versionOlder cudaArchitectures); in # "75" -> "750" Cf. https://github.com/icl-utk-edu/magma/blob/v2.9.0/CMakeLists.txt#L200-L201 From 420ef69fa8589533cf8c5d4b26363cb0255bd3e5 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Sat, 10 May 2025 02:51:30 +0000 Subject: [PATCH 08/11] cudaPackages: doc fixup Signed-off-by: Connor Baker (cherry picked from commit 8fcff2390e3224e970291975cedcbd23f743c6da) --- pkgs/development/cuda-modules/README.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/pkgs/development/cuda-modules/README.md b/pkgs/development/cuda-modules/README.md index 3e6168e52be8..4d4e14eb5af8 100644 --- a/pkgs/development/cuda-modules/README.md +++ b/pkgs/development/cuda-modules/README.md @@ -8,15 +8,6 @@ The files in this directory are added (in some way) to the `cudaPackages` package set by [cuda-packages.nix](../../top-level/cuda-packages.nix). -## Top-level files - -Top-level nix files are included in the initial creation of the `cudaPackages` -scope. These are typically required for the creation of the finalized -`cudaPackages` scope: - -- `backend-stdenv.nix`: Standard environment for CUDA packages. -- `flags.nix`: Flags set, or consumed by, NVCC in order to build packages. - ## Top-level directories - `cuda`: CUDA redistributables! Provides extension to `cudaPackages` scope. @@ -38,6 +29,8 @@ scope. These are typically required for the creation of the finalized short, the Multiplex builder adds multiple versions of a single package to single instance of the CUDA Packages package set. It is used primarily for packages like `cudnn` and `cutensor`. +- `lib`: A library of functions and data used by and for the CUDA package set. + This library is exposed at the top-level as `pkgs.cudaLib`. - `modules`: Nixpkgs modules to check the shape and content of CUDA redistributable and feature manifests. These modules additionally use shims provided by some CUDA packages to allow them to re-use the @@ -45,9 +38,8 @@ scope. These are typically required for the creation of the finalized own. `cudnn` and `tensorrt` are examples of packages which provide such shims. These modules are further described in the [Modules](./modules/README.md) documentation. -- `nccl`: NVIDIA NCCL library. -- `nccl-tests`: NVIDIA NCCL tests. -- `saxpy`: Example CMake project that uses CUDA. +- `packages`: Contains packages which exist in every instance of the CUDA + package set. These packages are built in a `by-name` fashion. - `setup-hooks`: Nixpkgs setup hooks for CUDA. - `tensorrt`: NVIDIA TensorRT library. From c3fdb7a77c0147481149df3636593bd4dfe96ae4 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Tue, 20 May 2025 09:32:03 -0700 Subject: [PATCH 09/11] _cuda: introduce to organize CUDA package set backbone Signed-off-by: Connor Baker (cherry picked from commit 688e14d21a38135270544bfdfcc793d25dea2802) --- doc/languages-frameworks/cuda.section.md | 4 +- .../{lib/data => _cuda/db/bootstrap}/cuda.nix | 60 +---------------- .../data => _cuda/db/bootstrap}/default.nix | 8 +-- .../{lib/data => _cuda/db/bootstrap}/nvcc.nix | 0 .../data => _cuda/db/bootstrap}/redist.nix | 0 .../cuda-modules/_cuda/db/default.nix | 65 +++++++++++++++++++ .../cuda-modules/_cuda/default.nix | 30 +++++++++ .../{ => _cuda}/fixups/cuda_compat.nix | 0 .../{ => _cuda}/fixups/cuda_cudart.nix | 0 .../{ => _cuda}/fixups/cuda_demo_suite.nix | 0 .../{ => _cuda}/fixups/cuda_gdb.nix | 0 .../{ => _cuda}/fixups/cuda_nvcc.nix | 0 .../{ => _cuda}/fixups/cuda_nvprof.nix | 0 .../{ => _cuda}/fixups/cuda_sanitizer_api.nix | 0 .../cuda-modules/{ => _cuda}/fixups/cudnn.nix | 0 .../{ => _cuda}/fixups/default.nix | 4 +- .../{ => _cuda}/fixups/driver_assistant.nix | 0 .../{ => _cuda}/fixups/fabricmanager.nix | 0 .../cuda-modules/{ => _cuda}/fixups/imex.nix | 0 .../{ => _cuda}/fixups/libcufile.nix | 0 .../{ => _cuda}/fixups/libcusolver.nix | 0 .../{ => _cuda}/fixups/libcusparse.nix | 0 .../{ => _cuda}/fixups/libcusparse_lt.nix | 0 .../{ => _cuda}/fixups/libcutensor.nix | 0 .../{ => _cuda}/fixups/nsight_compute.nix | 0 .../{ => _cuda}/fixups/nsight_systems.nix | 0 .../{ => _cuda}/fixups/nvidia_driver.nix | 0 .../{ => _cuda}/fixups/tensorrt.nix | 4 +- .../{lib/utils => _cuda/lib}/assertions.nix | 10 +-- .../{lib/utils => _cuda/lib}/cuda.nix | 2 +- .../{lib/utils => _cuda/lib}/default.nix | 15 +++-- .../{lib/utils => _cuda/lib}/meta.nix | 6 +- .../{lib/utils => _cuda/lib}/redist.nix | 10 +-- .../{lib/utils => _cuda/lib}/strings.nix | 39 ++++++----- .../{lib/utils => _cuda/lib}/versions.nix | 11 ++-- .../cuda-modules/cusparselt/extension.nix | 2 +- .../cuda-modules/cutensor/extension.nix | 2 +- .../generic-builders/manifest.nix | 11 ++-- .../generic-builders/multiplex.nix | 3 +- pkgs/development/cuda-modules/lib/default.nix | 13 ---- .../cuda-modules/packages/backendStdenv.nix | 6 +- pkgs/development/cuda-modules/tests/flags.nix | 5 +- pkgs/top-level/all-packages.nix | 5 +- pkgs/top-level/cuda-packages.nix | 23 ++++--- pkgs/top-level/release-cuda.nix | 4 +- 45 files changed, 186 insertions(+), 156 deletions(-) rename pkgs/development/cuda-modules/{lib/data => _cuda/db/bootstrap}/cuda.nix (88%) rename pkgs/development/cuda-modules/{lib/data => _cuda/db/bootstrap}/default.nix (74%) rename pkgs/development/cuda-modules/{lib/data => _cuda/db/bootstrap}/nvcc.nix (100%) rename pkgs/development/cuda-modules/{lib/data => _cuda/db/bootstrap}/redist.nix (100%) create mode 100644 pkgs/development/cuda-modules/_cuda/db/default.nix create mode 100644 pkgs/development/cuda-modules/_cuda/default.nix rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cuda_compat.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cuda_cudart.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cuda_demo_suite.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cuda_gdb.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cuda_nvcc.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cuda_nvprof.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cuda_sanitizer_api.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/cudnn.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/default.nix (89%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/driver_assistant.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/fabricmanager.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/imex.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/libcufile.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/libcusolver.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/libcusparse.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/libcusparse_lt.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/libcutensor.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/nsight_compute.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/nsight_systems.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/nvidia_driver.nix (100%) rename pkgs/development/cuda-modules/{ => _cuda}/fixups/tensorrt.nix (98%) rename pkgs/development/cuda-modules/{lib/utils => _cuda/lib}/assertions.nix (91%) rename pkgs/development/cuda-modules/{lib/utils => _cuda/lib}/cuda.nix (98%) rename pkgs/development/cuda-modules/{lib/utils => _cuda/lib}/default.nix (73%) rename pkgs/development/cuda-modules/{lib/utils => _cuda/lib}/meta.nix (90%) rename pkgs/development/cuda-modules/{lib/utils => _cuda/lib}/redist.nix (95%) rename pkgs/development/cuda-modules/{lib/utils => _cuda/lib}/strings.nix (84%) rename pkgs/development/cuda-modules/{lib/utils => _cuda/lib}/versions.nix (84%) delete mode 100644 pkgs/development/cuda-modules/lib/default.nix diff --git a/doc/languages-frameworks/cuda.section.md b/doc/languages-frameworks/cuda.section.md index 7e489acdbd64..535ce02efbc6 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 `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. +1. Update `nvccCompatibilities` in `pkgs/development/cuda-modules/_cuda/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/_cuda/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/lib/data/cuda.nix b/pkgs/development/cuda-modules/_cuda/db/bootstrap/cuda.nix similarity index 88% rename from pkgs/development/cuda-modules/lib/data/cuda.nix rename to pkgs/development/cuda-modules/_cuda/db/bootstrap/cuda.nix index 0b97645c420d..e852bc85b639 100644 --- a/pkgs/development/cuda-modules/lib/data/cuda.nix +++ b/pkgs/development/cuda-modules/_cuda/db/bootstrap/cuda.nix @@ -1,63 +1,5 @@ -{ cudaLib, lib }: +{ lib }: { - /** - All CUDA capabilities, sorted by version. - - NOTE: Since the capabilities are sorted by version and architecture/family-specific features are - appended to the minor version component, the sorted list groups capabilities by baseline feature - set. - - # Type - - ``` - allSortedCudaCapabilities :: [CudaCapability] - ``` - - # Example - - ``` - allSortedCudaCapabilities = [ - "5.0" - "5.2" - "6.0" - "6.1" - "7.0" - "7.2" - "7.5" - "8.0" - "8.6" - "8.7" - "8.9" - "9.0" - "9.0a" - "10.0" - "10.0a" - "10.0f" - "10.1" - "10.1a" - "10.1f" - "10.3" - "10.3a" - "10.3f" - ]; - ``` - */ - allSortedCudaCapabilities = lib.sort lib.versionOlder ( - lib.attrNames cudaLib.data.cudaCapabilityToInfo - ); - - /** - Mapping of CUDA micro-architecture name to capabilities belonging to that micro-architecture. - - # Type - - ``` - cudaArchNameToCapabilities :: AttrSet NonEmptyStr (NonEmptyListOf CudaCapability) - ``` - */ - cudaArchNameToCapabilities = lib.groupBy ( - cudaCapability: cudaLib.data.cudaCapabilityToInfo.${cudaCapability}.archName - ) cudaLib.data.allSortedCudaCapabilities; /** Attribute set of supported CUDA capability mapped to information about that capability. diff --git a/pkgs/development/cuda-modules/lib/data/default.nix b/pkgs/development/cuda-modules/_cuda/db/bootstrap/default.nix similarity index 74% rename from pkgs/development/cuda-modules/lib/data/default.nix rename to pkgs/development/cuda-modules/_cuda/db/bootstrap/default.nix index 60924cbb4f9e..8cfea1406934 100644 --- a/pkgs/development/cuda-modules/lib/data/default.nix +++ b/pkgs/development/cuda-modules/_cuda/db/bootstrap/default.nix @@ -1,9 +1,7 @@ -{ cudaLib, lib }: +{ lib }: { # See ./cuda.nix for documentation. - inherit (import ./cuda.nix { inherit cudaLib lib; }) - allSortedCudaCapabilities - cudaArchNameToCapabilities + inherit (import ./cuda.nix { inherit lib; }) cudaCapabilityToInfo ; @@ -28,5 +26,5 @@ cudaPackagesPath :: Path ``` */ - cudaPackagesPath = ./..; + cudaPackagesPath = ./../../..; } diff --git a/pkgs/development/cuda-modules/lib/data/nvcc.nix b/pkgs/development/cuda-modules/_cuda/db/bootstrap/nvcc.nix similarity index 100% rename from pkgs/development/cuda-modules/lib/data/nvcc.nix rename to pkgs/development/cuda-modules/_cuda/db/bootstrap/nvcc.nix diff --git a/pkgs/development/cuda-modules/lib/data/redist.nix b/pkgs/development/cuda-modules/_cuda/db/bootstrap/redist.nix similarity index 100% rename from pkgs/development/cuda-modules/lib/data/redist.nix rename to pkgs/development/cuda-modules/_cuda/db/bootstrap/redist.nix diff --git a/pkgs/development/cuda-modules/_cuda/db/default.nix b/pkgs/development/cuda-modules/_cuda/db/default.nix new file mode 100644 index 000000000000..e6d404102aab --- /dev/null +++ b/pkgs/development/cuda-modules/_cuda/db/default.nix @@ -0,0 +1,65 @@ +{ + lib, + bootstrapData, + db, +}: + +bootstrapData +// { + /** + All CUDA capabilities, sorted by version. + + NOTE: Since the capabilities are sorted by version and architecture/family-specific features are + appended to the minor version component, the sorted list groups capabilities by baseline feature + set. + + # Type + + ``` + allSortedCudaCapabilities :: [CudaCapability] + ``` + + # Example + + ``` + allSortedCudaCapabilities = [ + "5.0" + "5.2" + "6.0" + "6.1" + "7.0" + "7.2" + "7.5" + "8.0" + "8.6" + "8.7" + "8.9" + "9.0" + "9.0a" + "10.0" + "10.0a" + "10.0f" + "10.1" + "10.1a" + "10.1f" + "10.3" + "10.3a" + "10.3f" + ]; + ``` + */ + allSortedCudaCapabilities = lib.sort lib.versionOlder (lib.attrNames db.cudaCapabilityToInfo); + + /** + Mapping of CUDA micro-architecture name to capabilities belonging to that micro-architecture. + + # Type + + ``` + cudaArchNameToCapabilities :: AttrSet NonEmptyStr (NonEmptyListOf CudaCapability) + ``` + */ + cudaArchNameToCapabilities = lib.groupBy ( + cudaCapability: db.cudaCapabilityToInfo.${cudaCapability}.archName + ) db.allSortedCudaCapabilities; +} diff --git a/pkgs/development/cuda-modules/_cuda/default.nix b/pkgs/development/cuda-modules/_cuda/default.nix new file mode 100644 index 000000000000..4d0c3c4b5d6a --- /dev/null +++ b/pkgs/development/cuda-modules/_cuda/default.nix @@ -0,0 +1,30 @@ +# The _cuda attribute set is a fixed-point which contains the static functionality required to construct CUDA package +# sets. For example, `_cuda.cudaData` includes information about NVIDIA's redistributables (such as the names NVIDIA +# uses for different systems), `_cuda.cudaLib` contains utility functions like `formatCapabilities` (which generate +# common arguments passed to NVCC and `cmakeFlags`), and `_cuda.cudaFixups` contains `callPackage`-able functions +# which are provided to the corresponding package's `overrideAttrs` attribute to provide package-specific fixups +# out of scope of the generic redistributable builder. +# +# Since this attribute set is used to construct the CUDA package sets, it must exist outside the fixed point of the +# package sets. Make these attributes available directly in the package set construction could cause confusion if +# users override the attribute set with the expection that changes will be reflected in the enclosing CUDA package +# set. To avoid this, we declare `_cuda` and inherit its members here, at top-level. (This also allows us to benefit +# from import caching, as it should be evaluated once per system, rather than per-system and CUDA package set.) + +let + lib = import ../../../../lib; +in +lib.fixedPoints.makeExtensible (final: { + bootstrapData = import ./db/bootstrap { + inherit lib; + }; + db = import ./db { + inherit (final) bootstrapData db; + inherit lib; + }; + fixups = import ./fixups { inherit lib; }; + lib = import ./lib { + _cuda = final; + inherit lib; + }; +}) diff --git a/pkgs/development/cuda-modules/fixups/cuda_compat.nix b/pkgs/development/cuda-modules/_cuda/fixups/cuda_compat.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cuda_compat.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cuda_compat.nix diff --git a/pkgs/development/cuda-modules/fixups/cuda_cudart.nix b/pkgs/development/cuda-modules/_cuda/fixups/cuda_cudart.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cuda_cudart.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cuda_cudart.nix diff --git a/pkgs/development/cuda-modules/fixups/cuda_demo_suite.nix b/pkgs/development/cuda-modules/_cuda/fixups/cuda_demo_suite.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cuda_demo_suite.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cuda_demo_suite.nix diff --git a/pkgs/development/cuda-modules/fixups/cuda_gdb.nix b/pkgs/development/cuda-modules/_cuda/fixups/cuda_gdb.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cuda_gdb.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cuda_gdb.nix diff --git a/pkgs/development/cuda-modules/fixups/cuda_nvcc.nix b/pkgs/development/cuda-modules/_cuda/fixups/cuda_nvcc.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cuda_nvcc.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cuda_nvcc.nix diff --git a/pkgs/development/cuda-modules/fixups/cuda_nvprof.nix b/pkgs/development/cuda-modules/_cuda/fixups/cuda_nvprof.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cuda_nvprof.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cuda_nvprof.nix diff --git a/pkgs/development/cuda-modules/fixups/cuda_sanitizer_api.nix b/pkgs/development/cuda-modules/_cuda/fixups/cuda_sanitizer_api.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cuda_sanitizer_api.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cuda_sanitizer_api.nix diff --git a/pkgs/development/cuda-modules/fixups/cudnn.nix b/pkgs/development/cuda-modules/_cuda/fixups/cudnn.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/cudnn.nix rename to pkgs/development/cuda-modules/_cuda/fixups/cudnn.nix diff --git a/pkgs/development/cuda-modules/fixups/default.nix b/pkgs/development/cuda-modules/_cuda/fixups/default.nix similarity index 89% rename from pkgs/development/cuda-modules/fixups/default.nix rename to pkgs/development/cuda-modules/_cuda/fixups/default.nix index a5ec4a90e817..0c9874672ce4 100644 --- a/pkgs/development/cuda-modules/fixups/default.nix +++ b/pkgs/development/cuda-modules/_cuda/fixups/default.nix @@ -1,6 +1,4 @@ -let - lib = import ../../../../lib; -in +{ lib }: lib.concatMapAttrs ( fileName: _type: let diff --git a/pkgs/development/cuda-modules/fixups/driver_assistant.nix b/pkgs/development/cuda-modules/_cuda/fixups/driver_assistant.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/driver_assistant.nix rename to pkgs/development/cuda-modules/_cuda/fixups/driver_assistant.nix diff --git a/pkgs/development/cuda-modules/fixups/fabricmanager.nix b/pkgs/development/cuda-modules/_cuda/fixups/fabricmanager.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/fabricmanager.nix rename to pkgs/development/cuda-modules/_cuda/fixups/fabricmanager.nix diff --git a/pkgs/development/cuda-modules/fixups/imex.nix b/pkgs/development/cuda-modules/_cuda/fixups/imex.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/imex.nix rename to pkgs/development/cuda-modules/_cuda/fixups/imex.nix diff --git a/pkgs/development/cuda-modules/fixups/libcufile.nix b/pkgs/development/cuda-modules/_cuda/fixups/libcufile.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/libcufile.nix rename to pkgs/development/cuda-modules/_cuda/fixups/libcufile.nix diff --git a/pkgs/development/cuda-modules/fixups/libcusolver.nix b/pkgs/development/cuda-modules/_cuda/fixups/libcusolver.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/libcusolver.nix rename to pkgs/development/cuda-modules/_cuda/fixups/libcusolver.nix diff --git a/pkgs/development/cuda-modules/fixups/libcusparse.nix b/pkgs/development/cuda-modules/_cuda/fixups/libcusparse.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/libcusparse.nix rename to pkgs/development/cuda-modules/_cuda/fixups/libcusparse.nix diff --git a/pkgs/development/cuda-modules/fixups/libcusparse_lt.nix b/pkgs/development/cuda-modules/_cuda/fixups/libcusparse_lt.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/libcusparse_lt.nix rename to pkgs/development/cuda-modules/_cuda/fixups/libcusparse_lt.nix diff --git a/pkgs/development/cuda-modules/fixups/libcutensor.nix b/pkgs/development/cuda-modules/_cuda/fixups/libcutensor.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/libcutensor.nix rename to pkgs/development/cuda-modules/_cuda/fixups/libcutensor.nix diff --git a/pkgs/development/cuda-modules/fixups/nsight_compute.nix b/pkgs/development/cuda-modules/_cuda/fixups/nsight_compute.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/nsight_compute.nix rename to pkgs/development/cuda-modules/_cuda/fixups/nsight_compute.nix diff --git a/pkgs/development/cuda-modules/fixups/nsight_systems.nix b/pkgs/development/cuda-modules/_cuda/fixups/nsight_systems.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/nsight_systems.nix rename to pkgs/development/cuda-modules/_cuda/fixups/nsight_systems.nix diff --git a/pkgs/development/cuda-modules/fixups/nvidia_driver.nix b/pkgs/development/cuda-modules/_cuda/fixups/nvidia_driver.nix similarity index 100% rename from pkgs/development/cuda-modules/fixups/nvidia_driver.nix rename to pkgs/development/cuda-modules/_cuda/fixups/nvidia_driver.nix diff --git a/pkgs/development/cuda-modules/fixups/tensorrt.nix b/pkgs/development/cuda-modules/_cuda/fixups/tensorrt.nix similarity index 98% rename from pkgs/development/cuda-modules/fixups/tensorrt.nix rename to pkgs/development/cuda-modules/_cuda/fixups/tensorrt.nix index c55844eac0d9..2b73e8c2d4be 100644 --- a/pkgs/development/cuda-modules/fixups/tensorrt.nix +++ b/pkgs/development/cuda-modules/_cuda/fixups/tensorrt.nix @@ -1,5 +1,5 @@ { - cudaLib, + _cuda, cudaOlder, cudaPackages, cudaMajorMinorVersion, @@ -103,7 +103,7 @@ finalAttrs: prevAttrs: { # unless it is not available, in which case the default cudnn derivation will be used. cudnn = let - desiredName = cudaLib.utils.mkVersionedName "cudnn" ( + desiredName = _cuda.lib.mkVersionedName "cudnn" ( lib.versions.majorMinor finalAttrs.passthru.featureRelease.cudnnVersion ); in diff --git a/pkgs/development/cuda-modules/lib/utils/assertions.nix b/pkgs/development/cuda-modules/_cuda/lib/assertions.nix similarity index 91% rename from pkgs/development/cuda-modules/lib/utils/assertions.nix rename to pkgs/development/cuda-modules/_cuda/lib/assertions.nix index 5fc940889b7f..f4413b28e4f3 100644 --- a/pkgs/development/cuda-modules/lib/utils/assertions.nix +++ b/pkgs/development/cuda-modules/_cuda/lib/assertions.nix @@ -1,4 +1,4 @@ -{ cudaLib, lib }: +{ _cuda, lib }: { /** Evaluate assertions and add error context to return value. @@ -16,7 +16,7 @@ _evaluateAssertions = assertions: let - failedAssertionsString = cudaLib.utils._mkFailedAssertionsString assertions; + failedAssertionsString = _cuda.lib._mkFailedAssertionsString assertions; in if failedAssertionsString == "" then true @@ -45,7 +45,7 @@ # Examples :::{.example} - ## `cudaLib.utils._mkFailedAssertionsString` usage examples + ## `_cuda.lib._mkFailedAssertionsString` usage examples ```nix _mkFailedAssertionsString [ @@ -103,7 +103,7 @@ # Examples :::{.example} - ## `cudaLib.utils._mkMissingPackagesAssertions` usage examples + ## `_cuda.lib._mkMissingPackagesAssertions` usage examples ```nix { @@ -114,7 +114,7 @@ }: let inherit (lib.attrsets) recursiveUpdate; - inherit (cudaLib.utils) _mkMissingPackagesAssertions; + inherit (_cuda.lib) _mkMissingPackagesAssertions; in prevAttrs: { passthru = prevAttrs.passthru or { } // { diff --git a/pkgs/development/cuda-modules/lib/utils/cuda.nix b/pkgs/development/cuda-modules/_cuda/lib/cuda.nix similarity index 98% rename from pkgs/development/cuda-modules/lib/utils/cuda.nix rename to pkgs/development/cuda-modules/_cuda/lib/cuda.nix index e372fda0d1b5..16f99e57709a 100644 --- a/pkgs/development/cuda-modules/lib/utils/cuda.nix +++ b/pkgs/development/cuda-modules/_cuda/lib/cuda.nix @@ -92,7 +92,7 @@ # Examples :::{.example} - ## `cudaLib.utils._mkCudaVariant` usage examples + ## `_cuda.lib._mkCudaVariant` usage examples ```nix _mkCudaVariant "11.0" diff --git a/pkgs/development/cuda-modules/lib/utils/default.nix b/pkgs/development/cuda-modules/_cuda/lib/default.nix similarity index 73% rename from pkgs/development/cuda-modules/lib/utils/default.nix rename to pkgs/development/cuda-modules/_cuda/lib/default.nix index ee9ace015fae..b2fe9838de61 100644 --- a/pkgs/development/cuda-modules/lib/utils/default.nix +++ b/pkgs/development/cuda-modules/_cuda/lib/default.nix @@ -1,7 +1,10 @@ -{ cudaLib, lib }: +{ + _cuda, + lib, +}: { # See ./assertions.nix for documentation. - inherit (import ./assertions.nix { inherit cudaLib lib; }) + inherit (import ./assertions.nix { inherit _cuda lib; }) _evaluateAssertions _mkFailedAssertionsString _mkMissingPackagesAssertions @@ -16,13 +19,13 @@ ; # See ./meta.nix for documentation. - inherit (import ./meta.nix { inherit cudaLib lib; }) + inherit (import ./meta.nix { inherit _cuda lib; }) _mkMetaBadPlatforms _mkMetaBroken ; # See ./redist.nix for documentation. - inherit (import ./redist.nix { inherit cudaLib lib; }) + inherit (import ./redist.nix { inherit _cuda lib; }) _redistSystemIsSupported getNixSystems getRedistSystem @@ -30,7 +33,7 @@ ; # See ./strings.nix for documentation. - inherit (import ./strings.nix { inherit cudaLib lib; }) + inherit (import ./strings.nix { inherit _cuda lib; }) dotsToUnderscores dropDots formatCapabilities @@ -42,7 +45,7 @@ ; # See ./versions.nix for documentation. - inherit (import ./versions.nix { inherit cudaLib lib; }) + inherit (import ./versions.nix { inherit _cuda lib; }) majorMinorPatch trimComponents ; diff --git a/pkgs/development/cuda-modules/lib/utils/meta.nix b/pkgs/development/cuda-modules/_cuda/lib/meta.nix similarity index 90% rename from pkgs/development/cuda-modules/lib/utils/meta.nix rename to pkgs/development/cuda-modules/_cuda/lib/meta.nix index 327d4ae97d95..72f71973b0cd 100644 --- a/pkgs/development/cuda-modules/lib/utils/meta.nix +++ b/pkgs/development/cuda-modules/_cuda/lib/meta.nix @@ -1,4 +1,4 @@ -{ cudaLib, lib }: +{ _cuda, lib }: { /** Returns a list of bad platforms for a given package if assertsions in `finalAttrs.passthru.platformAssertions` @@ -18,7 +18,7 @@ _mkMetaBadPlatforms = warn: finalAttrs: let - failedAssertionsString = cudaLib.utils._mkFailedAssertionsString finalAttrs.passthru.platformAssertions; + failedAssertionsString = _cuda.lib._mkFailedAssertionsString finalAttrs.passthru.platformAssertions; hasFailedAssertions = failedAssertionsString != ""; finalStdenv = finalAttrs.finalPackage.stdenv; in @@ -62,7 +62,7 @@ _mkMetaBroken = warn: finalAttrs: let - failedAssertionsString = cudaLib.utils._mkFailedAssertionsString finalAttrs.passthru.brokenAssertions; + failedAssertionsString = _cuda.lib._mkFailedAssertionsString finalAttrs.passthru.brokenAssertions; hasFailedAssertions = failedAssertionsString != ""; in lib.warnIf (warn && hasFailedAssertions) diff --git a/pkgs/development/cuda-modules/lib/utils/redist.nix b/pkgs/development/cuda-modules/_cuda/lib/redist.nix similarity index 95% rename from pkgs/development/cuda-modules/lib/utils/redist.nix rename to pkgs/development/cuda-modules/_cuda/lib/redist.nix index b9cd2a3b1e0d..a7053dc582c4 100644 --- a/pkgs/development/cuda-modules/lib/utils/redist.nix +++ b/pkgs/development/cuda-modules/_cuda/lib/redist.nix @@ -1,4 +1,4 @@ -{ cudaLib, lib }: +{ _cuda, lib }: { /** Returns a boolean indicating whether the provided redist system is supported by any of the provided redist systems. @@ -27,7 +27,7 @@ # Examples :::{.example} - ## `cudaLib.utils._redistSystemIsSupported` usage examples + ## `cudaLib._redistSystemIsSupported` usage examples ```nix _redistSystemIsSupported "linux-x86_64" [ "linux-x86_64" ] @@ -81,7 +81,7 @@ # Examples :::{.example} - ## `cudaLib.utils.getNixSystems` usage examples + ## `cudaLib.getNixSystems` usage examples ```nix getNixSystems "linux-sbsa" @@ -137,7 +137,7 @@ # Examples :::{.example} - ## `cudaLib.utils.getRedistSystem` usage examples + ## `cudaLib.getRedistSystem` usage examples ```nix getRedistSystem true "aarch64-linux" @@ -181,7 +181,7 @@ mkRedistUrl = redistName: relativePath: lib.concatStringsSep "/" ( - [ cudaLib.data.redistUrlPrefix ] + [ _cuda.db.redistUrlPrefix ] ++ ( if redistName != "tensorrt" then [ diff --git a/pkgs/development/cuda-modules/lib/utils/strings.nix b/pkgs/development/cuda-modules/_cuda/lib/strings.nix similarity index 84% rename from pkgs/development/cuda-modules/lib/utils/strings.nix rename to pkgs/development/cuda-modules/_cuda/lib/strings.nix index 47a71b395f4f..f25157b4da4c 100644 --- a/pkgs/development/cuda-modules/lib/utils/strings.nix +++ b/pkgs/development/cuda-modules/_cuda/lib/strings.nix @@ -1,4 +1,7 @@ -{ cudaLib, lib }: +{ _cuda, lib }: +let + cudaLib = _cuda.lib; +in { /** Replaces dots in a string with underscores. @@ -18,7 +21,7 @@ # Examples :::{.example} - ## `cudaLib.utils.dotsToUnderscores` usage examples + ## `cudaLib.dotsToUnderscores` usage examples ```nix dotsToUnderscores "1.2.3" @@ -46,7 +49,7 @@ # Examples :::{.example} - ## `cudaLib.utils.dropDots` usage examples + ## `cudaLib.dropDots` usage examples ```nix dropDots "1.2.3" @@ -110,7 +113,7 @@ realArches :: List String ``` */ - realArches = lib.map cudaLib.utils.mkRealArchitecture cudaCapabilities; + realArches = lib.map cudaLib.mkRealArchitecture cudaCapabilities; /** The virtual architectures for the given CUDA capabilities. @@ -124,7 +127,7 @@ virtualArches :: List String ``` */ - virtualArches = lib.map cudaLib.utils.mkVirtualArchitecture cudaCapabilities; + virtualArches = lib.map cudaLib.mkVirtualArchitecture cudaCapabilities; /** The gencode flags for the given CUDA capabilities. @@ -137,8 +140,8 @@ */ gencode = let - base = lib.map (cudaLib.utils.mkGencodeFlag "sm") cudaCapabilities; - forward = cudaLib.utils.mkGencodeFlag "compute" (lib.last cudaCapabilities); + base = lib.map (cudaLib.mkGencodeFlag "sm") cudaCapabilities; + forward = cudaLib.mkGencodeFlag "compute" (lib.last cudaCapabilities); in base ++ lib.optionals cudaForwardCompat [ forward ]; in @@ -190,7 +193,7 @@ cmakeCudaArchitecturesString :: String ``` */ - cmakeCudaArchitecturesString = cudaLib.utils.mkCmakeCudaArchitecturesString cudaCapabilities; + cmakeCudaArchitecturesString = cudaLib.mkCmakeCudaArchitecturesString cudaCapabilities; /** The gencode string for the given CUDA capabilities. @@ -222,7 +225,7 @@ # Examples :::{.example} - ## `cudaLib.utils.mkCmakeCudaArchitecturesString` usage examples + ## `cudaLib.mkCmakeCudaArchitecturesString` usage examples ```nix mkCmakeCudaArchitecturesString [ "8.9" "10.0a" ] @@ -230,7 +233,7 @@ ``` ::: */ - mkCmakeCudaArchitecturesString = lib.concatMapStringsSep ";" cudaLib.utils.dropDots; + mkCmakeCudaArchitecturesString = lib.concatMapStringsSep ";" cudaLib.dropDots; /** Produces a gencode flag from a CUDA capability. @@ -254,7 +257,7 @@ # Examples :::{.example} - ## `cudaLib.utils.mkGencodeFlag` usage examples + ## `cudaLib.mkGencodeFlag` usage examples ```nix mkGencodeFlag "sm" "8.9" @@ -270,7 +273,7 @@ mkGencodeFlag = archPrefix: cudaCapability: let - cap = cudaLib.utils.dropDots cudaCapability; + cap = cudaLib.dropDots cudaCapability; in "-gencode=arch=compute_${cap},code=${archPrefix}_${cap}"; @@ -292,7 +295,7 @@ # Examples :::{.example} - ## `cudaLib.utils.mkRealArchitecture` usage examples + ## `cudaLib.mkRealArchitecture` usage examples ```nix mkRealArchitecture "8.9" @@ -305,7 +308,7 @@ ``` ::: */ - mkRealArchitecture = cudaCapability: "sm_" + cudaLib.utils.dropDots cudaCapability; + mkRealArchitecture = cudaCapability: "sm_" + cudaLib.dropDots cudaCapability; /** Create a versioned attribute name from a version by replacing dots with underscores. @@ -329,7 +332,7 @@ # Examples :::{.example} - ## `cudaLib.utils.mkVersionedName` usage examples + ## `cudaLib.mkVersionedName` usage examples ```nix mkVersionedName "hello" "1.2.3" @@ -342,7 +345,7 @@ ``` ::: */ - mkVersionedName = name: version: "${name}_${cudaLib.utils.dotsToUnderscores version}"; + mkVersionedName = name: version: "${name}_${cudaLib.dotsToUnderscores version}"; /** Produces a virtual architecture string from a CUDA capability. @@ -362,7 +365,7 @@ # Examples :::{.example} - ## `cudaLib.utils.mkVirtualArchitecture` usage examples + ## `cudaLib.mkVirtualArchitecture` usage examples ```nix mkVirtualArchitecture "8.9" @@ -375,5 +378,5 @@ ``` ::: */ - mkVirtualArchitecture = cudaCapability: "compute_" + cudaLib.utils.dropDots cudaCapability; + mkVirtualArchitecture = cudaCapability: "compute_" + cudaLib.dropDots cudaCapability; } diff --git a/pkgs/development/cuda-modules/lib/utils/versions.nix b/pkgs/development/cuda-modules/_cuda/lib/versions.nix similarity index 84% rename from pkgs/development/cuda-modules/lib/utils/versions.nix rename to pkgs/development/cuda-modules/_cuda/lib/versions.nix index 976ad65b2b65..e231f795f13f 100644 --- a/pkgs/development/cuda-modules/lib/utils/versions.nix +++ b/pkgs/development/cuda-modules/_cuda/lib/versions.nix @@ -1,4 +1,7 @@ -{ cudaLib, lib }: +{ _cuda, lib }: +let + cudaLib = _cuda.lib; +in { /** Extracts the major, minor, and patch version from a string. @@ -18,7 +21,7 @@ # Examples :::{.example} - ## `cudaLib.utils.majorMinorPatch` usage examples + ## `_cuda.lib.majorMinorPatch` usage examples ```nix majorMinorPatch "11.0.3.4" @@ -26,7 +29,7 @@ ``` ::: */ - majorMinorPatch = cudaLib.utils.trimComponents 3; + majorMinorPatch = cudaLib.trimComponents 3; /** Get a version string with no more than than the specified number of components. @@ -48,7 +51,7 @@ # Examples :::{.example} - ## `cudaLib.utils.trimComponents` usage examples + ## `_cuda.lib.trimComponents` usage examples ```nix trimComponents 1 "1.2.3.4" diff --git a/pkgs/development/cuda-modules/cusparselt/extension.nix b/pkgs/development/cuda-modules/cusparselt/extension.nix index 56308973c341..f53405e3d099 100644 --- a/pkgs/development/cuda-modules/cusparselt/extension.nix +++ b/pkgs/development/cuda-modules/cusparselt/extension.nix @@ -69,7 +69,7 @@ let # Patch version changes should not break the build, so we only use major and minor # computeName :: RedistribRelease -> String computeName = - { version, ... }: cudaLib.utils.mkVersionedName redistName (lib.versions.majorMinor version); + { version, ... }: cudaLib.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 5f59cfb15bb6..57de518aa7ac 100644 --- a/pkgs/development/cuda-modules/cutensor/extension.nix +++ b/pkgs/development/cuda-modules/cutensor/extension.nix @@ -108,7 +108,7 @@ let # Patch version changes should not break the build, so we only use major and minor # computeName :: RedistribRelease -> String computeName = - { version, ... }: cudaLib.utils.mkVersionedName redistName (lib.versions.majorMinor version); + { version, ... }: cudaLib.mkVersionedName redistName (lib.versions.majorMinor version); in final: _: let diff --git a/pkgs/development/cuda-modules/generic-builders/manifest.nix b/pkgs/development/cuda-modules/generic-builders/manifest.nix index 712db3bd5b99..36872cf9682f 100644 --- a/pkgs/development/cuda-modules/generic-builders/manifest.nix +++ b/pkgs/development/cuda-modules/generic-builders/manifest.nix @@ -5,8 +5,7 @@ autoPatchelfHook, backendStdenv, callPackage, - cudaFixups, - cudaLib, + _cuda, fetchurl, lib, markForCudatoolkitRootHook, @@ -45,7 +44,7 @@ let # Last step before returning control to `callPackage` (adds the `.override` method) # we'll apply (`overrideAttrs`) necessary package-specific "fixup" functions. # Order is significant. - maybeFixup = cudaFixups.${pname} or null; + maybeFixup = _cuda.fixups.${pname} or null; fixup = if maybeFixup != null then callPackage maybeFixup { } else { }; # Get the redist systems for which package provides distributables. @@ -54,9 +53,9 @@ let # 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; + redistSystem = _cuda.lib.getRedistSystem backendStdenv.hasJetsonCudaCapability hostPlatform.system; - sourceMatchesHost = lib.elem hostPlatform.system (cudaLib.utils.getNixSystems redistSystem); + sourceMatchesHost = lib.elem hostPlatform.system (_cuda.lib.getNixSystems redistSystem); in (backendStdenv.mkDerivation (finalAttrs: { # NOTE: Even though there's no actual buildPhase going on here, the derivations of the @@ -327,7 +326,7 @@ in broken = lists.any trivial.id (attrsets.attrValues finalAttrs.brokenConditions); platforms = trivial.pipe supportedRedistSystems [ # Map each redist system to the equivalent nix systems. - (lib.concatMap cudaLib.utils.getNixSystems) + (lib.concatMap _cuda.lib.getNixSystems) # Take all the unique values. lib.unique # Sort the list. diff --git a/pkgs/development/cuda-modules/generic-builders/multiplex.nix b/pkgs/development/cuda-modules/generic-builders/multiplex.nix index 0a6d101eaf9d..3085ae3e4610 100644 --- a/pkgs/development/cuda-modules/generic-builders/multiplex.nix +++ b/pkgs/development/cuda-modules/generic-builders/multiplex.nix @@ -64,8 +64,7 @@ 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 :: Package -> String - computeName = - { version, ... }: cudaLib.utils.mkVersionedName pname (lib.versions.majorMinor version); + computeName = { version, ... }: cudaLib.mkVersionedName pname (lib.versions.majorMinor version); # The newest package for each major-minor version, with newest first. # newestPackages :: List Package diff --git a/pkgs/development/cuda-modules/lib/default.nix b/pkgs/development/cuda-modules/lib/default.nix deleted file mode 100644 index 6918d9ca5053..000000000000 --- a/pkgs/development/cuda-modules/lib/default.nix +++ /dev/null @@ -1,13 +0,0 @@ -let - lib = import ../../../../lib; -in -lib.fixedPoints.makeExtensible (final: { - data = import ./data { - inherit lib; - cudaLib = final; - }; - utils = import ./utils { - inherit lib; - cudaLib = final; - }; -}) diff --git a/pkgs/development/cuda-modules/packages/backendStdenv.nix b/pkgs/development/cuda-modules/packages/backendStdenv.nix index ac9a8ebaf44f..7122ad2da319 100644 --- a/pkgs/development/cuda-modules/packages/backendStdenv.nix +++ b/pkgs/development/cuda-modules/packages/backendStdenv.nix @@ -7,7 +7,7 @@ # Cf. https://github.com/NixOS/nixpkgs/pull/218265 for context { config, - cudaLib, + _cuda, cudaMajorMinorVersion, lib, pkgs, @@ -16,8 +16,8 @@ }: let inherit (builtins) toJSON; - inherit (cudaLib.data) allSortedCudaCapabilities cudaCapabilityToInfo nvccCompatibilities; - inherit (cudaLib.utils) + inherit (_cuda.db) allSortedCudaCapabilities cudaCapabilityToInfo nvccCompatibilities; + inherit (_cuda.lib) _cudaCapabilityIsDefault _cudaCapabilityIsSupported _evaluateAssertions diff --git a/pkgs/development/cuda-modules/tests/flags.nix b/pkgs/development/cuda-modules/tests/flags.nix index d9ae72231c6c..314f69d1b90a 100644 --- a/pkgs/development/cuda-modules/tests/flags.nix +++ b/pkgs/development/cuda-modules/tests/flags.nix @@ -1,4 +1,5 @@ { + cudaData, cudaLib, cudaNamePrefix, lib, @@ -6,8 +7,8 @@ }: let inherit (builtins) deepSeq toJSON tryEval; - inherit (cudaLib.data) cudaCapabilityToInfo; - inherit (cudaLib.utils) formatCapabilities; + inherit (cudaData) cudaCapabilityToInfo; + inherit (cudaLib) formatCapabilities; inherit (lib.asserts) assertMsg; in # When changing names or formats: pause, validate, and update the assert diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 7499ad9b62b1..4a82d04d231e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -2723,9 +2723,8 @@ with pkgs; cron = isc-cron; - cudaLib = import ../development/cuda-modules/lib; - - cudaFixups = import ../development/cuda-modules/fixups; + # Top-level fix-point used in `cudaPackages`' internals + _cuda = import ../development/cuda-modules/_cuda; cudaPackages_11_0 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.0"; }; cudaPackages_11_1 = callPackage ./cuda-packages.nix { cudaMajorMinorVersion = "11.1"; }; diff --git a/pkgs/top-level/cuda-packages.nix b/pkgs/top-level/cuda-packages.nix index 5870d383291e..53dd4b6029ea 100644 --- a/pkgs/top-level/cuda-packages.nix +++ b/pkgs/top-level/cuda-packages.nix @@ -22,7 +22,7 @@ # I've (@connorbaker) attempted to do that, though I'm unsure of how this will interact with overrides. { config, - cudaLib, + _cuda, cudaMajorMinorVersion, lib, newScope, @@ -38,25 +38,28 @@ let versions ; + cudaLib = _cuda.lib; + # 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; + cudaCapability: _cuda.db.cudaCapabilityToInfo.${cudaCapability}.isJetson + ) _cuda.db.allSortedCudaCapabilities; hasJetsonCudaCapability = lib.intersectLists jetsonCudaCapabilities (config.cudaCapabilities or [ ]) != [ ]; - redistSystem = cudaLib.utils.getRedistSystem hasJetsonCudaCapability stdenv.hostPlatform.system; + redistSystem = _cuda.lib.getRedistSystem hasJetsonCudaCapability stdenv.hostPlatform.system; passthruFunction = final: { # NOTE: - # It is important that cudaLib and cudaFixups are not part of the package set fixed-point. As described by + # It is important that _cuda is 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. # This decision is driven both by a separation of concerns and by "NAMESET STRICTNESS" (see above). + # Also see the comment in `pkgs/top-level/all-packages.nix` about the `_cuda` attribute. inherit cudaMajorMinorVersion; @@ -77,17 +80,17 @@ let }; flags = - cudaLib.utils.formatCapabilities { + cudaLib.formatCapabilities { inherit (final.backendStdenv) cudaCapabilities cudaForwardCompat; - inherit (cudaLib.data) cudaCapabilityToInfo; + inherit (_cuda.db) 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; + inherit (cudaLib) dropDots; cudaComputeCapabilityToName = - cudaCapability: cudaLib.data.cudaCapabilityToInfo.${cudaCapability}.archName; - dropDot = cudaLib.utils.dropDots; + cudaCapability: _cuda.db.cudaCapabilityToInfo.${cudaCapability}.archName; + dropDot = cudaLib.dropDots; isJetsonBuild = final.backendStdenv.hasJetsonCudaCapability; }; diff --git a/pkgs/top-level/release-cuda.nix b/pkgs/top-level/release-cuda.nix index 4ddda47a766d..6e6e4811604a 100644 --- a/pkgs/top-level/release-cuda.nix +++ b/pkgs/top-level/release-cuda.nix @@ -14,7 +14,7 @@ let lib = import ../../lib; - cudaLib = import ../development/cuda-modules/lib; + inherit (import ../development/cuda-modules/_cuda) cudaLib; in { @@ -27,7 +27,7 @@ in # Attributes passed to nixpkgs. nixpkgsArgs ? { config = { - allowUnfreePredicate = cudaLib.utils.allowUnfreeCudaPredicate; + allowUnfreePredicate = cudaLib.allowUnfreeCudaPredicate; "${variant}Support" = true; inHydra = true; From af0b7004b54d728b2ac9f21efdbce0e4ad634104 Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Tue, 27 May 2025 23:51:13 +0000 Subject: [PATCH 10/11] _cuda: missed fixups Signed-off-by: Connor Baker (cherry picked from commit 816a644da5883579b0dcff9d8068862ad398d40e) --- pkgs/development/cuda-modules/README.md | 2 -- pkgs/development/cuda-modules/_cuda/default.nix | 8 ++++---- pkgs/development/cuda-modules/tests/flags.nix | 8 ++++---- pkgs/top-level/release-cuda.nix | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pkgs/development/cuda-modules/README.md b/pkgs/development/cuda-modules/README.md index 4d4e14eb5af8..1a88761c4d51 100644 --- a/pkgs/development/cuda-modules/README.md +++ b/pkgs/development/cuda-modules/README.md @@ -29,8 +29,6 @@ package set by [cuda-packages.nix](../../top-level/cuda-packages.nix). short, the Multiplex builder adds multiple versions of a single package to single instance of the CUDA Packages package set. It is used primarily for packages like `cudnn` and `cutensor`. -- `lib`: A library of functions and data used by and for the CUDA package set. - This library is exposed at the top-level as `pkgs.cudaLib`. - `modules`: Nixpkgs modules to check the shape and content of CUDA redistributable and feature manifests. These modules additionally use shims provided by some CUDA packages to allow them to re-use the diff --git a/pkgs/development/cuda-modules/_cuda/default.nix b/pkgs/development/cuda-modules/_cuda/default.nix index 4d0c3c4b5d6a..0f6f80506616 100644 --- a/pkgs/development/cuda-modules/_cuda/default.nix +++ b/pkgs/development/cuda-modules/_cuda/default.nix @@ -1,8 +1,8 @@ # The _cuda attribute set is a fixed-point which contains the static functionality required to construct CUDA package -# sets. For example, `_cuda.cudaData` includes information about NVIDIA's redistributables (such as the names NVIDIA -# uses for different systems), `_cuda.cudaLib` contains utility functions like `formatCapabilities` (which generate -# common arguments passed to NVCC and `cmakeFlags`), and `_cuda.cudaFixups` contains `callPackage`-able functions -# which are provided to the corresponding package's `overrideAttrs` attribute to provide package-specific fixups +# sets. For example, `_cuda.bootstrapData` includes information about NVIDIA's redistributables (such as the names +# NVIDIA uses for different systems), `_cuda.lib` contains utility functions like `formatCapabilities` (which generate +# common arguments passed to NVCC and `cmakeFlags`), and `_cuda.fixups` contains `callPackage`-able functions which +# are provided to the corresponding package's `overrideAttrs` attribute to provide package-specific fixups # out of scope of the generic redistributable builder. # # Since this attribute set is used to construct the CUDA package sets, it must exist outside the fixed point of the diff --git a/pkgs/development/cuda-modules/tests/flags.nix b/pkgs/development/cuda-modules/tests/flags.nix index 314f69d1b90a..926a9be5220f 100644 --- a/pkgs/development/cuda-modules/tests/flags.nix +++ b/pkgs/development/cuda-modules/tests/flags.nix @@ -1,14 +1,13 @@ { - cudaData, - cudaLib, + _cuda, cudaNamePrefix, lib, runCommand, }: let inherit (builtins) deepSeq toJSON tryEval; - inherit (cudaData) cudaCapabilityToInfo; - inherit (cudaLib) formatCapabilities; + inherit (_cuda.bootstrapData) cudaCapabilityToInfo; + inherit (_cuda.lib) formatCapabilities; inherit (lib.asserts) assertMsg; in # When changing names or formats: pause, validate, and update the assert @@ -62,6 +61,7 @@ assert "7.5" "8.6" ]; + cudaForwardCompat = true; }; actualWrapped = (tryEval (deepSeq actual actual)).value; in diff --git a/pkgs/top-level/release-cuda.nix b/pkgs/top-level/release-cuda.nix index 6e6e4811604a..e9d64e74cd70 100644 --- a/pkgs/top-level/release-cuda.nix +++ b/pkgs/top-level/release-cuda.nix @@ -14,7 +14,7 @@ let lib = import ../../lib; - inherit (import ../development/cuda-modules/_cuda) cudaLib; + cudaLib = (import ../development/cuda-modules/_cuda).lib; in { From 574561de38776186d9f683164fbc5de6d032979d Mon Sep 17 00:00:00 2001 From: Connor Baker Date: Wed, 11 Jun 2025 17:20:44 +0000 Subject: [PATCH 11/11] doc: correct paths in CUDA update section Signed-off-by: Connor Baker (cherry picked from commit 3f0d99c733524382fa6951505b3c0faa3831e2bb) --- doc/languages-frameworks/cuda.section.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/languages-frameworks/cuda.section.md b/doc/languages-frameworks/cuda.section.md index 535ce02efbc6..1a40f4cc1a24 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 `nvccCompatibilities` in `pkgs/development/cuda-modules/_cuda/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/_cuda/data/cuda.nix` to include any new GPUs supported by the new release of CUDA. +1. Update `nvccCompatibilities` in `pkgs/development/cuda-modules/_cuda/db/bootstrap/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/_cuda/db/bootstrap/cuda.nix` to include any new GPUs supported by the new release of CUDA. ### Updating the CUDA Toolkit runfile installer {#updating-the-cuda-toolkit}