push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,273 @@
{ lib }:
{
/**
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/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";
};
# 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";
};
};
}

View File

@@ -0,0 +1,30 @@
{ lib }:
{
# See ./cuda.nix for documentation.
inherit (import ./cuda.nix { inherit lib; })
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 = ./../../..;
}

View File

@@ -0,0 +1,70 @@
{
/**
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/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";
};
};
};
}

View File

@@ -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";
}

View File

@@ -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;
}

View File

@@ -0,0 +1,31 @@
# The _cuda attribute set is a fixed-point which contains the static functionality required to construct CUDA package
# 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
# 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;
};
extensions = [ ]; # Extensions applied to every CUDA package set.
fixups = import ./fixups { inherit lib; };
lib = import ./lib {
_cuda = final;
inherit lib;
};
})

View File

@@ -0,0 +1,12 @@
{ flags, lib }:
prevAttrs: {
autoPatchelfIgnoreMissingDeps = prevAttrs.autoPatchelfIgnoreMissingDeps or [ ] ++ [
"libnvrm_gpu.so"
"libnvrm_mem.so"
"libnvdla_runtime.so"
];
# `cuda_compat` only works on aarch64-linux, and only when building for Jetson devices.
badPlatformsConditions = prevAttrs.badPlatformsConditions or { } // {
"Trying to use cuda_compat on aarch64-linux targeting non-Jetson devices" = !flags.isJetsonBuild;
};
}

View File

@@ -0,0 +1,37 @@
# TODO(@connorbaker): cuda_cudart.dev depends on crt/host_config.h, which is from
# (getDev cuda_nvcc). It would be nice to be able to encode that.
{ addDriverRunpath, lib }:
prevAttrs: {
# Remove once cuda-find-redist-features has a special case for libcuda
outputs =
prevAttrs.outputs or [ ]
++ lib.lists.optionals (!(builtins.elem "stubs" prevAttrs.outputs)) [ "stubs" ];
allowFHSReferences = false;
# The libcuda stub's pkg-config doesn't follow the general pattern:
postPatch =
prevAttrs.postPatch or ""
+ ''
while IFS= read -r -d $'\0' path; do
sed -i \
-e "s|^libdir\s*=.*/lib\$|libdir=''${!outputLib}/lib/stubs|" \
-e "s|^Libs\s*:\(.*\)\$|Libs: \1 -Wl,-rpath,${addDriverRunpath.driverLink}/lib|" \
"$path"
done < <(find -iname 'cuda-*.pc' -print0)
''
# Namelink may not be enough, add a soname.
# Cf. https://gitlab.kitware.com/cmake/cmake/-/issues/25536
+ ''
if [[ -f lib/stubs/libcuda.so && ! -f lib/stubs/libcuda.so.1 ]]; then
ln -s libcuda.so lib/stubs/libcuda.so.1
fi
'';
postFixup = prevAttrs.postFixup or "" + ''
mv "''${!outputDev}/share" "''${!outputDev}/lib"
moveToOutput lib/stubs "$stubs"
ln -s "$stubs"/lib/stubs/* "$stubs"/lib/
ln -s "$stubs"/lib/stubs "''${!outputLib}/lib/stubs"
'';
}

View File

@@ -0,0 +1,18 @@
{
libglut,
libcufft,
libcurand,
libGLU,
libglvnd,
libgbm,
}:
prevAttrs: {
buildInputs = prevAttrs.buildInputs or [ ] ++ [
libglut
libcufft
libcurand
libGLU
libglvnd
libgbm
];
}

View File

@@ -0,0 +1,35 @@
{
cudaAtLeast,
gmp,
expat,
libxcrypt-legacy,
ncurses6,
python310,
python311,
python312,
stdenv,
lib,
}:
prevAttrs: {
buildInputs =
prevAttrs.buildInputs or [ ]
++ [
gmp
libxcrypt-legacy
ncurses6
python310
python311
python312
]
# aarch64,sbsa needs expat
++ lib.lists.optionals (stdenv.hostPlatform.isAarch64) [ expat ];
installPhase =
prevAttrs.installPhase or ""
# Python 3.8 is not in nixpkgs anymore, delete Python 3.8 cuda-gdb support
# to avoid autopatchelf failing to find libpython3.8.so.
+ ''
find $bin -name '*python3.8*' -delete
find $bin -name '*python3.9*' -delete
'';
}

View File

@@ -0,0 +1,62 @@
{
lib,
backendStdenv,
setupCudaHook,
}:
prevAttrs: {
# Merge "bin" and "dev" into "out" to avoid circular references
outputs = builtins.filter (
x:
!(builtins.elem x [
"dev"
"bin"
])
) prevAttrs.outputs or [ ];
# Patch the nvcc.profile.
# Syntax:
# - `=` for assignment,
# - `?=` for conditional assignment,
# - `+=` to "prepend",
# - `=+` to "append".
# Cf. https://web.archive.org/web/20230308044351/https://arcb.csc.ncsu.edu/~mueller/cluster/nvidia/2.0/nvcc_2.0.pdf
# We set all variables with the lowest priority (=+), but we do force
# nvcc to use the fixed backend toolchain. Cf. comments in
# backend-stdenv.nix
postPatch =
prevAttrs.postPatch or ""
+ ''
substituteInPlace bin/nvcc.profile \
--replace-fail \
'$(TOP)/$(_TARGET_DIR_)/include' \
"''${!outputDev}/include"
''
+ ''
cat << EOF >> bin/nvcc.profile
# Fix a compatible backend compiler
PATH += "${backendStdenv.cc}/bin":
# Expose the split-out nvvm
LIBRARIES =+ "-L''${!outputBin}/nvvm/lib"
INCLUDES =+ "-I''${!outputBin}/nvvm/include"
EOF
'';
# Entries here will be in nativeBuildInputs when cuda_nvcc is in nativeBuildInputs.
propagatedBuildInputs = prevAttrs.propagatedBuildInputs or [ ] ++ [ setupCudaHook ];
postInstall = prevAttrs.postInstall or "" + ''
moveToOutput "nvvm" "''${!outputBin}"
'';
# The nvcc and cicc binaries contain hard-coded references to /usr
allowFHSReferences = true;
meta = prevAttrs.meta or { } // {
mainProgram = "nvcc";
};
}

View File

@@ -0,0 +1 @@
{ cuda_cupti }: prevAttrs: { buildInputs = prevAttrs.buildInputs or [ ] ++ [ cuda_cupti ]; }

View File

@@ -0,0 +1 @@
_: _: { outputs = [ "out" ]; }

View File

@@ -0,0 +1,75 @@
{
cudaOlder,
cudaMajorMinorVersion,
fetchurl,
lib,
libcublas,
patchelf,
zlib,
}:
let
inherit (lib)
attrsets
maintainers
meta
strings
;
in
finalAttrs: prevAttrs: {
src = fetchurl { inherit (finalAttrs.passthru.redistribRelease) hash url; };
# Useful for inspecting why something went wrong.
badPlatformsConditions =
let
cudaTooOld = cudaOlder finalAttrs.passthru.featureRelease.minCudaVersion;
cudaTooNew =
(finalAttrs.passthru.featureRelease.maxCudaVersion != null)
&& strings.versionOlder finalAttrs.passthru.featureRelease.maxCudaVersion cudaMajorMinorVersion;
in
prevAttrs.badPlatformsConditions or { }
// {
"CUDA version is too old" = cudaTooOld;
"CUDA version is too new" = cudaTooNew;
};
buildInputs = prevAttrs.buildInputs or [ ] ++ [
zlib
(attrsets.getLib libcublas)
];
# Tell autoPatchelf about runtime dependencies. *_infer* libraries only
# exist in CuDNN 8.
# NOTE: Versions from CUDNN releases have four components.
postFixup =
prevAttrs.postFixup or ""
+
strings.optionalString
(
strings.versionAtLeast finalAttrs.version "8.0.5.0"
&& strings.versionOlder finalAttrs.version "9.0.0.0"
)
''
${meta.getExe patchelf} $lib/lib/libcudnn.so --add-needed libcudnn_cnn_infer.so
${meta.getExe patchelf} $lib/lib/libcudnn_ops_infer.so --add-needed libcublas.so --add-needed libcublasLt.so
'';
meta = prevAttrs.meta or { } // {
homepage = "https://developer.nvidia.com/cudnn";
maintainers =
prevAttrs.meta.maintainers or [ ]
++ (with maintainers; [
mdaiter
samuela
connorbaker
]);
# TODO(@connorbaker): Temporary workaround to avoid changing the derivation hash since introducing more
# brokenConditions would change the derivation as they're top-level and __structuredAttrs is set.
teams = prevAttrs.meta.teams or [ ];
license = {
shortName = "cuDNN EULA";
fullName = "NVIDIA cuDNN Software License Agreement (EULA)";
url = "https://docs.nvidia.com/deeplearning/sdk/cudnn-sla/index.html#supplement";
free = false;
};
};
}

View File

@@ -0,0 +1,11 @@
{ lib }:
lib.concatMapAttrs (
fileName: _type:
let
# Fixup is in `./${attrName}.nix` or in `./${fileName}/default.nix`:
attrName = lib.removeSuffix ".nix" fileName;
fixup = import (./. + "/${fileName}");
isFixup = fileName != "default.nix";
in
lib.optionalAttrs isFixup { ${attrName} = fixup; }
) (builtins.readDir ./.)

View File

@@ -0,0 +1,5 @@
_: prevAttrs: {
badPlatformsConditions = prevAttrs.badPlatformsConditions or { } // {
"Package is not supported; use drivers from linuxPackages" = true;
};
}

View File

@@ -0,0 +1 @@
{ zlib }: prevAttrs: { buildInputs = prevAttrs.buildInputs or [ ] ++ [ zlib ]; }

View File

@@ -0,0 +1 @@
{ zlib }: prevAttrs: { buildInputs = prevAttrs.buildInputs or [ ] ++ [ zlib ]; }

View File

@@ -0,0 +1,12 @@
{
libcublas,
numactl,
rdma-core,
}:
prevAttrs: {
buildInputs = prevAttrs.buildInputs or [ ] ++ [
libcublas
numactl
rdma-core
];
}

View File

@@ -0,0 +1,19 @@
{
cudaAtLeast,
lib,
libcublas,
libcusparse ? null,
libnvjitlink ? null,
}:
prevAttrs: {
buildInputs = prevAttrs.buildInputs or [ ] ++ [
libcublas
libnvjitlink
libcusparse
];
brokenConditions = prevAttrs.brokenConditions or { } // {
"libnvjitlink missing (CUDA >= 12.0)" = libnvjitlink == null;
"libcusparse missing (CUDA >= 12.1)" = libcusparse == null;
};
}

View File

@@ -0,0 +1,12 @@
{
cudaAtLeast,
lib,
libnvjitlink ? null,
}:
prevAttrs: {
buildInputs = prevAttrs.buildInputs or [ ] ++ [ libnvjitlink ];
brokenConditions = prevAttrs.brokenConditions or { } // {
"libnvjitlink missing (CUDA >= 12.0)" = libnvjitlink == null;
};
}

View File

@@ -0,0 +1,23 @@
{
cuda_cudart,
lib,
libcublas,
}:
finalAttrs: prevAttrs: {
buildInputs =
prevAttrs.buildInputs or [ ]
++ [ (lib.getLib libcublas) ]
# For some reason, the 1.4.x release of cusparselt requires the cudart library.
++ lib.optionals (lib.hasPrefix "1.4" finalAttrs.version) [ (lib.getLib cuda_cudart) ];
meta = prevAttrs.meta or { } // {
description = "cuSPARSELt: A High-Performance CUDA Library for Sparse Matrix-Matrix Multiplication";
homepage = "https://developer.nvidia.com/cusparselt-downloads";
maintainers = prevAttrs.meta.maintainers or [ ] ++ [ lib.maintainers.sepiabrown ];
teams = prevAttrs.meta.teams or [ ];
license = lib.licenses.unfreeRedistributable // {
shortName = "cuSPARSELt EULA";
fullName = "cuSPARSELt SUPPLEMENT TO SOFTWARE LICENSE AGREEMENT FOR NVIDIA SOFTWARE DEVELOPMENT KITS";
url = "https://docs.nvidia.com/cuda/cusparselt/license.html";
};
};
}

View File

@@ -0,0 +1,23 @@
{
cuda_cudart,
lib,
libcublas,
}:
finalAttrs: prevAttrs: {
buildInputs =
prevAttrs.buildInputs or [ ]
++ [ (lib.getLib libcublas) ]
# For some reason, the 1.4.x release of cuTENSOR requires the cudart library.
++ lib.optionals (lib.hasPrefix "1.4" finalAttrs.version) [ (lib.getLib cuda_cudart) ];
meta = prevAttrs.meta or { } // {
description = "cuTENSOR: A High-Performance CUDA Library For Tensor Primitives";
homepage = "https://developer.nvidia.com/cutensor";
maintainers = prevAttrs.meta.maintainers or [ ] ++ [ lib.maintainers.obsidian-systems-maintenance ];
teams = prevAttrs.meta.teams;
license = lib.licenses.unfreeRedistributable // {
shortName = "cuTENSOR EULA";
fullName = "cuTENSOR SUPPLEMENT TO SOFTWARE LICENSE AGREEMENT FOR NVIDIA SOFTWARE DEVELOPMENT KITS";
url = "https://docs.nvidia.com/cuda/cutensor/license.html";
};
};
}

View File

@@ -0,0 +1,86 @@
{
cudaAtLeast,
cudaMajorMinorVersion,
cudaOlder,
e2fsprogs,
elfutils,
flags,
gst_all_1,
lib,
libjpeg8,
qt6,
rdma-core,
stdenv,
ucx,
}:
prevAttrs:
let
qtwayland = lib.getLib qt6.qtwayland;
inherit (qt6) wrapQtAppsHook qtwebview;
archDir =
{
aarch64-linux = "linux-" + (if flags.isJetsonBuild then "v4l_l4t" else "desktop") + "-t210-a64";
x86_64-linux = "linux-desktop-glibc_2_11_3-x64";
}
.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
in
{
outputs = [ "out" ]; # NOTE(@connorbaker): Force a single output so relative lookups work.
nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ wrapQtAppsHook ];
buildInputs =
prevAttrs.buildInputs or [ ]
++ [
qtwayland
qtwebview
(qt6.qtwebengine or qt6.full)
rdma-core
]
++ lib.optionals (cudaOlder "12.7") [
e2fsprogs
ucx
]
++ lib.optionals (cudaMajorMinorVersion == "12.9") [
elfutils
];
dontWrapQtApps = true;
preInstall = prevAttrs.preInstall or "" + ''
if [[ -d nsight-compute ]]; then
nixLog "Lifting components of Nsight Compute to the top level"
mv -v nsight-compute/*/* .
nixLog "Removing empty directories"
rmdir -pv nsight-compute/*
fi
rm -rf host/${archDir}/Mesa/
'';
postInstall =
prevAttrs.postInstall or ""
+ ''
moveToOutput 'ncu' "''${!outputBin}/bin"
moveToOutput 'ncu-ui' "''${!outputBin}/bin"
moveToOutput 'host/${archDir}' "''${!outputBin}/bin"
moveToOutput 'target/${archDir}' "''${!outputBin}/bin"
wrapQtApp "''${!outputBin}/bin/host/${archDir}/ncu-ui.bin"
''
# NOTE(@connorbaker): No idea what this platform is or how to patchelf for it.
+ lib.optionalString (flags.isJetsonBuild && cudaOlder "12.9") ''
nixLog "Removing QNX 700 target directory for Jetson builds"
rm -rfv "''${!outputBin}/target/qnx-700-t210-a64"
''
+ lib.optionalString (flags.isJetsonBuild && cudaAtLeast "12.8") ''
nixLog "Removing QNX 800 target directory for Jetson builds"
rm -rfv "''${!outputBin}/target/qnx-800-tegra-a64"
'';
# lib needs libtiff.so.5, but nixpkgs provides libtiff.so.6
preFixup = prevAttrs.preFixup or "" + ''
patchelf --replace-needed libtiff.so.5 libtiff.so "''${!outputBin}/bin/host/${archDir}/Plugins/imageformats/libqtiff.so"
'';
autoPatchelfIgnoreMissingDeps = prevAttrs.autoPatchelfIgnoreMissingDeps or [ ] ++ [
"libnvidia-ml.so.1"
];
# NOTE(@connorbaker): It might be a problem that when nsight_compute contains hosts and targets of different
# architectures, that we patchelf just the binaries matching the builder's platform; autoPatchelfHook prints
# messages like
# skipping [$out]/host/linux-desktop-glibc_2_11_3-x64/libQt6Core.so.6 because its architecture (x64) differs from
# target (AArch64)
}

View File

@@ -0,0 +1,136 @@
{
boost178,
cuda_cudart,
cudaAtLeast,
e2fsprogs,
gst_all_1,
lib,
nss,
numactl,
pulseaudio,
qt6,
rdma-core,
stdenv,
ucx,
wayland,
xorg,
}:
prevAttrs:
let
qtwayland = lib.getLib qt6.qtwayland;
qtWaylandPlugins = "${qtwayland}/${qt6.qtbase.qtPluginPrefix}";
# NOTE(@connorbaker): nsight_systems doesn't support Jetson, so no need for case splitting on aarch64-linux.
hostDir =
{
aarch64-linux = "host-linux-armv8";
x86_64-linux = "host-linux-x64";
}
.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
targetDir =
{
aarch64-linux = "target-linux-sbsa-armv8";
x86_64-linux = "target-linux-x64";
}
.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
in
{
outputs = [ "out" ]; # NOTE(@connorbaker): Force a single output so relative lookups work.
# An ad hoc replacement for
# https://github.com/ConnorBaker/cuda-redist-find-features/issues/11
env = prevAttrs.env or { } // {
rmPatterns =
prevAttrs.env.rmPatterns or ""
+ toString [
"${hostDir}/lib{arrow,jpeg}*"
"${hostDir}/lib{ssl,ssh,crypto}*"
"${hostDir}/libboost*"
"${hostDir}/libexec"
"${hostDir}/libstdc*"
"${hostDir}/python/bin/python"
"${hostDir}/Mesa"
];
};
# NOTE(@connorbaker): nsight-exporter and nsight-sys are deprecated scripts wrapping nsys, it's fine to remove them.
prePatch = prevAttrs.prePatch or "" + ''
if [[ -d bin ]]; then
nixLog "Removing bin wrapper scripts"
for knownWrapper in bin/{nsys{,-ui},nsight-{exporter,sys}}; do
[[ -e $knownWrapper ]] && rm -v "$knownWrapper"
done
unset -v knownWrapper
nixLog "Removing empty bin directory"
rmdir -v bin
fi
if [[ -d nsight-systems ]]; then
nixLog "Lifting components of Nsight System to the top level"
mv -v nsight-systems/*/* .
nixLog "Removing empty nsight-systems directory"
rmdir -pv nsight-systems/*
fi
'';
postPatch = prevAttrs.postPatch or "" + ''
for path in $rmPatterns; do
rm -r "$path"
done
patchShebangs nsight-systems
'';
nativeBuildInputs = prevAttrs.nativeBuildInputs or [ ] ++ [ qt6.wrapQtAppsHook ];
dontWrapQtApps = true;
buildInputs =
prevAttrs.buildInputs or [ ]
++ [
(qt6.qtdeclarative or qt6.full)
(qt6.qtsvg or qt6.full)
(qt6.qtimageformats or qt6.full)
(qt6.qtpositioning or qt6.full)
(qt6.qtscxml or qt6.full)
(qt6.qttools or qt6.full)
(qt6.qtwebengine or qt6.full)
(qt6.qtwayland or qt6.full)
boost178
cuda_cudart.stubs
e2fsprogs
gst_all_1.gst-plugins-base
gst_all_1.gstreamer
nss
numactl
pulseaudio
qt6.qtbase
qtWaylandPlugins
rdma-core
ucx
wayland
xorg.libXcursor
xorg.libXdamage
xorg.libXrandr
xorg.libXtst
]
# NOTE(@connorbaker): Seems to be required only for aarch64-linux.
++ lib.optionals stdenv.hostPlatform.isAarch64 [
gst_all_1.gst-plugins-bad
];
postInstall = prevAttrs.postInstall or "" + ''
moveToOutput '${hostDir}' "''${!outputBin}"
moveToOutput '${targetDir}' "''${!outputBin}"
moveToOutput 'bin' "''${!outputBin}"
wrapQtApp "''${!outputBin}/${hostDir}/nsys-ui.bin"
'';
# lib needs libtiff.so.5, but nixpkgs provides libtiff.so.6
preFixup = prevAttrs.preFixup or "" + ''
patchelf --replace-needed libtiff.so.5 libtiff.so "''${!outputBin}/${hostDir}/Plugins/imageformats/libqtiff.so"
'';
autoPatchelfIgnoreMissingDeps = prevAttrs.autoPatchelfIgnoreMissingDeps or [ ] ++ [
"libnvidia-ml.so.1"
];
}

View File

@@ -0,0 +1,5 @@
_: prevAttrs: {
badPlatformsConditions = prevAttrs.badPlatformsConditions or { } // {
"Package is not supported; use drivers from linuxPackages" = true;
};
}

View File

@@ -0,0 +1,128 @@
{
_cuda,
cudaOlder,
cudaPackages,
cudaMajorMinorVersion,
lib,
patchelf,
requireFile,
stdenv,
}:
let
inherit (lib)
attrsets
maintainers
meta
strings
versions
;
inherit (stdenv) hostPlatform;
# targetArch :: String
targetArch = attrsets.attrByPath [ hostPlatform.system ] "unsupported" {
x86_64-linux = "x86_64-linux-gnu";
aarch64-linux = "aarch64-linux-gnu";
};
in
finalAttrs: prevAttrs: {
# Useful for inspecting why something went wrong.
brokenConditions =
let
cudaTooOld = cudaOlder finalAttrs.passthru.featureRelease.minCudaVersion;
cudaTooNew =
(finalAttrs.passthru.featureRelease.maxCudaVersion != null)
&& strings.versionOlder finalAttrs.passthru.featureRelease.maxCudaVersion cudaMajorMinorVersion;
cudnnVersionIsSpecified = finalAttrs.passthru.featureRelease.cudnnVersion != null;
cudnnVersionSpecified = versions.majorMinor finalAttrs.passthru.featureRelease.cudnnVersion;
cudnnVersionProvided = versions.majorMinor finalAttrs.passthru.cudnn.version;
cudnnTooOld =
cudnnVersionIsSpecified && (strings.versionOlder cudnnVersionProvided cudnnVersionSpecified);
cudnnTooNew =
cudnnVersionIsSpecified && (strings.versionOlder cudnnVersionSpecified cudnnVersionProvided);
in
prevAttrs.brokenConditions or { }
// {
"CUDA version is too old" = cudaTooOld;
"CUDA version is too new" = cudaTooNew;
"CUDNN version is too old" = cudnnTooOld;
"CUDNN version is too new" = cudnnTooNew;
};
src = requireFile {
name = finalAttrs.passthru.redistribRelease.filename;
inherit (finalAttrs.passthru.redistribRelease) hash;
message = ''
To use the TensorRT derivation, you must join the NVIDIA Developer Program and
download the ${finalAttrs.version} TAR package for CUDA ${cudaMajorMinorVersion} from
${finalAttrs.meta.homepage}.
Once you have downloaded the file, add it to the store with the following
command, and try building this derivation again.
$ nix-store --add-fixed sha256 ${finalAttrs.passthru.redistribRelease.filename}
'';
};
# We need to look inside the extracted output to get the files we need.
sourceRoot = "TensorRT-${finalAttrs.version}";
buildInputs = prevAttrs.buildInputs or [ ] ++ [ (finalAttrs.passthru.cudnn.lib or null) ];
preInstall =
prevAttrs.preInstall or ""
+ strings.optionalString (targetArch != "unsupported") ''
# Replace symlinks to bin and lib with the actual directories from targets.
for dir in bin lib; do
rm "$dir"
mv "targets/${targetArch}/$dir" "$dir"
done
# Remove broken symlinks
for dir in include samples; do
rm "targets/${targetArch}/$dir" || :
done
'';
# Tell autoPatchelf about runtime dependencies.
postFixup =
let
versionTriple = "${versions.majorMinor finalAttrs.version}.${versions.patch finalAttrs.version}";
in
prevAttrs.postFixup or ""
+ ''
${meta.getExe' patchelf "patchelf"} --add-needed libnvinfer.so \
"$lib/lib/libnvinfer.so.${versionTriple}" \
"$lib/lib/libnvinfer_plugin.so.${versionTriple}" \
"$lib/lib/libnvinfer_builder_resource.so.${versionTriple}"
'';
passthru = prevAttrs.passthru or { } // {
# The CUDNN used with TensorRT.
# If null, the default cudnn derivation will be used.
# If a version is specified, the cudnn derivation with that version will be used,
# unless it is not available, in which case the default cudnn derivation will be used.
cudnn =
let
desiredName = _cuda.lib.mkVersionedName "cudnn" (
lib.versions.majorMinor finalAttrs.passthru.featureRelease.cudnnVersion
);
in
if finalAttrs.passthru.featureRelease.cudnnVersion == null || (cudaPackages ? desiredName) then
cudaPackages.cudnn
else
cudaPackages.${desiredName};
};
meta = prevAttrs.meta or { } // {
badPlatforms =
prevAttrs.meta.badPlatforms or [ ]
++ lib.optionals (targetArch == "unsupported") [ hostPlatform.system ];
homepage = "https://developer.nvidia.com/tensorrt";
maintainers = prevAttrs.meta.maintainers or [ ] ++ [ maintainers.aidalgol ];
teams = prevAttrs.meta.teams or [ ];
# Building TensorRT on Hydra is impossible because of the non-redistributable
# license and because the source needs to be manually downloaded from the
# NVIDIA Developer Program (see requireFile above).
hydraPlatforms = lib.platforms.none;
};
}

View File

@@ -0,0 +1,139 @@
{ _cuda, 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 = _cuda.lib._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}
## `_cuda.lib._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}
## `_cuda.lib._mkMissingPackagesAssertions` usage examples
```nix
{
lib,
libcal ? null,
libcublas,
utils,
}:
let
inherit (lib.attrsets) recursiveUpdate;
inherit (_cuda.lib) _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;
}))
];
}

View File

@@ -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}
## `_cuda.lib._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);
}

View File

@@ -0,0 +1,52 @@
{
_cuda,
lib,
}:
{
# See ./assertions.nix for documentation.
inherit (import ./assertions.nix { inherit _cuda 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 _cuda lib; })
_mkMetaBadPlatforms
_mkMetaBroken
;
# See ./redist.nix for documentation.
inherit (import ./redist.nix { inherit _cuda lib; })
_redistSystemIsSupported
getNixSystems
getRedistSystem
mkRedistUrl
;
# See ./strings.nix for documentation.
inherit (import ./strings.nix { inherit _cuda lib; })
dotsToUnderscores
dropDots
formatCapabilities
mkCmakeCudaArchitecturesString
mkGencodeFlag
mkRealArchitecture
mkVersionedName
mkVirtualArchitecture
;
# See ./versions.nix for documentation.
inherit (import ./versions.nix { inherit _cuda lib; })
majorMinorPatch
trimComponents
;
}

View File

@@ -0,0 +1,71 @@
{ _cuda, 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 = _cuda.lib._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 = _cuda.lib._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;
}

View File

@@ -0,0 +1,196 @@
{ _cuda, 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._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.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.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 "/" (
[ _cuda.db.redistUrlPrefix ]
++ (
if redistName != "tensorrt" then
[
redistName
"redist"
]
else
[ "machine-learning" ]
)
++ [ relativePath ]
);
}

View File

@@ -0,0 +1,382 @@
{ _cuda, lib }:
let
cudaLib = _cuda.lib;
in
{
/**
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.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.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.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.mkVirtualArchitecture cudaCapabilities;
/**
The gencode flags for the given CUDA capabilities.
# Type
```
gencode :: List String
```
*/
gencode =
let
base = lib.map (cudaLib.mkGencodeFlag "sm") cudaCapabilities;
forward = cudaLib.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.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.mkCmakeCudaArchitecturesString` usage examples
```nix
mkCmakeCudaArchitecturesString [ "8.9" "10.0a" ]
=> "89;100a"
```
:::
*/
mkCmakeCudaArchitecturesString = lib.concatMapStringsSep ";" cudaLib.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.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.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.mkRealArchitecture` usage examples
```nix
mkRealArchitecture "8.9"
=> "sm_89"
```
```nix
mkRealArchitecture "10.0a"
=> "sm_100a"
```
:::
*/
mkRealArchitecture = cudaCapability: "sm_" + cudaLib.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.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.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.mkVirtualArchitecture` usage examples
```nix
mkVirtualArchitecture "8.9"
=> "compute_89"
```
```nix
mkVirtualArchitecture "10.0a"
=> "compute_100a"
```
:::
*/
mkVirtualArchitecture = cudaCapability: "compute_" + cudaLib.dropDots cudaCapability;
}

View File

@@ -0,0 +1,79 @@
{ _cuda, lib }:
let
cudaLib = _cuda.lib;
in
{
/**
Extracts the major, minor, and patch version from a string.
# Type
```
majorMinorPatch :: (version :: String) -> String
```
# Inputs
`version`
: The version string
# Examples
:::{.example}
## `_cuda.lib.majorMinorPatch` usage examples
```nix
majorMinorPatch "11.0.3.4"
=> "11.0.3"
```
:::
*/
majorMinorPatch = cudaLib.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}
## `_cuda.lib.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 ".")
];
}