1# CUDA {#cuda}
2
3CUDA-only packages are stored in the `cudaPackages` packages set. This set
4includes the `cudatoolkit`, portions of the toolkit in separate derivations,
5`cudnn`, `cutensor` and `nccl`.
6
7A package set is available for each CUDA version, so for example
8`cudaPackages_11_6`. Within each set is a matching version of the above listed
9packages. Additionally, other versions of the packages that are packaged and
10compatible are available as well. For example, there can be a
11`cudaPackages.cudnn_8_3` package.
12
13To use one or more CUDA packages in an expression, give the expression a `cudaPackages` parameter, and in case CUDA is optional
14```nix
15cudaSupport ? false
16cudaPackages ? {}
17```
18
19When using `callPackage`, you can choose to pass in a different variant, e.g.
20when a different version of the toolkit suffices
21```nix
22mypkg = callPackage { cudaPackages = cudaPackages_11_5; }
23```
24
25If another version of say `cudnn` or `cutensor` is needed, you can override the
26package set to make it the default. This guarantees you get a consistent package
27set.
28```nix
29mypkg = let
30 cudaPackages = cudaPackages_11_5.overrideScope' (final: prev: {
31 cudnn = prev.cudnn_8_3;
32 }});
33in callPackage { inherit cudaPackages; };
34```
35
36The CUDA NVCC compiler requires flags to determine which hardware you
37want to target for in terms of SASS (real hardware) or PTX (JIT kernels).
38
39Nixpkgs tries to target support real architecture defaults based on the
40CUDA toolkit version with PTX support for future hardware. Experienced
41users may optimize this configuration for a variety of reasons such as
42reducing binary size and compile time, supporting legacy hardware, or
43optimizing for specific hardware.
44
45You may provide capabilities to add support or reduce binary size through
46`config` using `cudaCapabilities = [ "6.0" "7.0" ];` and
47`cudaForwardCompat = true;` if you want PTX support for future hardware.
48
49Please consult [GPUs supported](https://en.wikipedia.org/wiki/CUDA#GPUs_supported)
50for your specific card(s).
51
52Library maintainers should consult [NVCC Docs](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/)
53and release notes for their software package.