-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cudaPackages: overhaul of how we package cuda packages
There are many different versions of the `cudatoolkit` and related cuda packages, and it can be tricky to ensure they remain compatible. - `cudaPackages` is now a package set with `cudatoolkit`, `cudnn`, `cutensor`, `nccl`, as well as `cudatoolkit` split into smaller packages ("redist"); - expressions should now use `cudaPackages` as parameter instead of the individual cuda packages; - `makeScope` is now used, so it is possible to use `.overrideScope'` to set e.g. a different `cudnn` version; - `release-cuda.nix` is introduced to easily evaluate cuda packages using hydra.
- Loading branch information
Showing
50 changed files
with
3,352 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# CUDA {#cuda} | ||
|
||
CUDA-only packages are stored in the `cudaPackages` packages set. This set | ||
includes the `cudatoolkit`, portions of the toolkit in separate derivations, | ||
`cudnn`, `cutensor` and `nccl`. | ||
|
||
A package set is available for each CUDA version, so for example | ||
`cudaPackages_11_6`. Within each set is a matching version of the above listed | ||
packages. Additionally, other versions of the packages that are packaged and | ||
compatible are available as well. For example, there can be a | ||
`cudaPackages.cudnn_8_3_2` package. | ||
|
||
To use one or more CUDA packages in an expression, give the expression a `cudaPackages` parameter, and in case CUDA is optional | ||
```nix | ||
cudaSupport ? false | ||
cudaPackages ? {} | ||
``` | ||
|
||
When using `callPackage`, you can choose to pass in a different variant, e.g. | ||
when a different version of the toolkit suffices | ||
```nix | ||
mypkg = callPackage { cudaPackages = cudaPackages_11_5; } | ||
``` | ||
|
||
If another version of say `cudnn` or `cutensor` is needed, you can override the | ||
package set to make it the default. This guarantees you get a consistent package | ||
set. | ||
```nix | ||
mypkg = let | ||
cudaPackages = cudaPackages_11_5.overrideScope' (final: prev { | ||
cudnn = prev.cudnn_8_3_2; | ||
}}); | ||
in callPackage { inherit cudaPackages; }; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
pkgs/development/compilers/cudatoolkit/auto-add-opengl-runpath-hook.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Run autoOpenGLRunpath on all files | ||
echo "Sourcing auto-add-opengl-runpath-hook" | ||
|
||
autoAddOpenGLRunpathPhase () { | ||
# TODO: support multiple outputs | ||
for file in $(find ${out,lib,bin} -type f); do | ||
addOpenGLRunpath $file | ||
done | ||
} | ||
|
||
if [ -z "${dontUseAutoAddOpenGLRunpath-}" ]; then | ||
echo "Using autoAddOpenGLRunpathPhase" | ||
postFixupHooks+=(autoAddOpenGLRunpathPhase) | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
final: prev: let | ||
### Cuda Toolkit | ||
|
||
# Function to build the class cudatoolkit package | ||
buildCudaToolkitPackage = final.callPackage ./common.nix; | ||
|
||
# Version info for the classic cudatoolkit packages that contain everything that is in redist. | ||
cudatoolkitVersions = final.lib.importTOML ./versions.toml; | ||
|
||
### Add classic cudatoolkit package | ||
cudatoolkit = buildCudaToolkitPackage ((attrs: attrs // { gcc = prev.pkgs.${attrs.gcc}; }) cudatoolkitVersions.${final.cudaVersion}); | ||
|
||
in { | ||
inherit cudatoolkit; | ||
} |
51 changes: 51 additions & 0 deletions
51
pkgs/development/compilers/cudatoolkit/redist/build-cuda-redist-package.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ lib | ||
, stdenv | ||
, fetchurl | ||
, autoPatchelfHook | ||
, autoAddOpenGLRunpathHook | ||
}: | ||
|
||
pname: | ||
attrs: | ||
|
||
let | ||
arch = "linux-x86_64"; | ||
in stdenv.mkDerivation { | ||
inherit pname; | ||
inherit (attrs) version; | ||
|
||
src = assert (lib.hasAttr arch attrs); fetchurl { | ||
url = "https://developer.download.nvidia.com/compute/cuda/redist/${attrs.${arch}.relative_path}"; | ||
inherit (attrs.${arch}) sha256; | ||
}; | ||
|
||
nativeBuildInputs = [ | ||
autoPatchelfHook | ||
# This hook will make sure libcuda can be found | ||
# in typically /lib/opengl-driver by adding that | ||
# directory to the rpath of all ELF binaries. | ||
# Check e.g. with `patchelf --print-rpath path/to/my/binary | ||
autoAddOpenGLRunpathHook | ||
]; | ||
|
||
buildInputs = [ | ||
stdenv.cc.cc.lib | ||
]; | ||
|
||
dontBuild = true; | ||
|
||
# TODO: choose whether to install static/dynamic libs | ||
installPhase = '' | ||
runHook preInstall | ||
rm LICENSE | ||
mkdir -p $out | ||
mv * $out | ||
runHook postInstall | ||
''; | ||
|
||
meta = { | ||
description = attrs.name; | ||
license = lib.licenses.unfree; | ||
platforms = lib.optionals (lib.hasAttr arch attrs) [ "x86_64-linux" ]; | ||
}; | ||
} |
32 changes: 32 additions & 0 deletions
32
pkgs/development/compilers/cudatoolkit/redist/extension.nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
final: prev: let | ||
|
||
inherit (final) callPackage; | ||
inherit (prev) cudaVersion lib pkgs; | ||
|
||
### Cuda Toolkit Redist | ||
|
||
# Manifest files for redist cudatoolkit. These can be found at | ||
# https://developer.download.nvidia.com/compute/cuda/redist/ | ||
cudaToolkitRedistManifests = { | ||
"11.4" = ./manifests/redistrib_11.4.4.json; | ||
"11.5" = ./manifests/redistrib_11.5.2.json; | ||
"11.6" = ./manifests/redistrib_11.6.2.json; | ||
}; | ||
|
||
# Function to build a single cudatoolkit redist package | ||
buildCudaToolkitRedistPackage = callPackage ./build-cuda-redist-package.nix { }; | ||
|
||
# Function that builds all cudatoolkit redist packages given a cuda version and manifest file | ||
buildCudaToolkitRedistPackages = { version, manifest }: let | ||
attrs = lib.filterAttrs (key: value: key != "release_date") (lib.importJSON manifest); | ||
in lib.mapAttrs buildCudaToolkitRedistPackage attrs; | ||
|
||
redistExists = cudaToolkitRedistManifests ? "${cudaVersion}"; | ||
|
||
# All cudatoolkit redist packages for the current cuda version | ||
cudaToolkitRedistPackages = if | ||
lib.hasAttr cudaVersion cudaToolkitRedistManifests | ||
then buildCudaToolkitRedistPackages { version = cudaVersion; manifest = cudaToolkitRedistManifests.${cudaVersion}; } | ||
else {}; | ||
|
||
in cudaToolkitRedistPackages |
Oops, something went wrong.