Skip to content

Commit 29b31ad

Browse files
authored
cudaPackages: name and consolidate use of fixups pattern (#404973)
2 parents ffb1838 + eec8903 commit 29b31ad

33 files changed

+842
-821
lines changed

pkgs/development/cuda-modules/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ scope. These are typically required for the creation of the finalized
2727
to `cudaPackages` scope.
2828
- `cudnn`: NVIDIA cuDNN library.
2929
- `cutensor`: NVIDIA cuTENSOR library.
30+
- `fixups`: Each file or directory (excluding `default.nix`) should contain a
31+
`callPackage`-able expression to be provided to the `overrideAttrs` attribute
32+
of a package produced by the generic manifest builder.
33+
These fixups are applied by `pname`, so packages with multiple versions
34+
(e.g., `cudnn`, `cudnn_8_9`, etc.) all share a single fixup function
35+
(i.e., `fixups/cudnn.nix`).
3036
- `generic-builders`:
3137
- Contains a builder `manifest.nix` which operates on the `Manifest` type
3238
defined in `modules/generic/manifests`. Most packages are built using this
Lines changed: 77 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,33 @@
11
{
2-
lib,
3-
backendStdenv,
4-
fetchFromGitHub,
5-
cmake,
62
addDriverRunpath,
73
autoAddDriverRunpath,
4+
autoPatchelfHook,
5+
backendStdenv,
6+
cmake,
7+
cuda_cccl ? null,
8+
cuda_cudart ? null,
9+
cuda_nvcc ? null,
10+
cudaAtLeast,
11+
cudaOlder,
812
cudatoolkit,
9-
cutensor,
10-
cusparselt,
11-
cudaPackages,
13+
cusparselt ? null,
14+
cutensor ? null,
15+
fetchFromGitHub,
16+
lib,
17+
libcusparse ? null,
1218
setupCudaHook,
13-
autoPatchelfHook,
1419
}:
1520

1621
let
17-
inherit (cudaPackages)
18-
cuda_cccl
19-
cuda_cudart
20-
cuda_nvcc
21-
libcusparse
22-
cudaAtLeast
23-
cudaOlder
24-
;
25-
rev = "e57b9c483c5384b7b97b7d129457e5a9bdcdb5e1";
26-
src = fetchFromGitHub {
27-
owner = "NVIDIA";
28-
repo = "CUDALibrarySamples";
29-
inherit rev;
30-
sha256 = "0g17afsmb8am0darxchqgjz1lmkaihmnn7k1x4ahg5gllcmw8k3l";
31-
};
32-
commonAttrs = {
33-
version = lib.strings.substring 0 7 rev + "-" + lib.versions.majorMinor cudatoolkit.version;
22+
base = backendStdenv.mkDerivation (finalAttrs: {
23+
src = fetchFromGitHub {
24+
owner = "NVIDIA";
25+
repo = "CUDALibrarySamples";
26+
rev = "e57b9c483c5384b7b97b7d129457e5a9bdcdb5e1";
27+
sha256 = "0g17afsmb8am0darxchqgjz1lmkaihmnn7k1x4ahg5gllcmw8k3l";
28+
};
29+
version =
30+
lib.strings.substring 0 7 finalAttrs.src.rev + "-" + lib.versions.majorMinor cudatoolkit.version;
3431
nativeBuildInputs = [
3532
cmake
3633
addDriverRunpath
@@ -53,64 +50,63 @@ let
5350
maintainers = with lib.maintainers; [ obsidian-systems-maintenance ];
5451
teams = [ lib.teams.cuda ];
5552
};
56-
};
53+
});
5754
in
5855

5956
{
60-
cublas = backendStdenv.mkDerivation (
61-
commonAttrs
62-
// {
57+
cublas = base.overrideAttrs (
58+
finalAttrs: _: {
6359
pname = "cuda-library-samples-cublas";
64-
65-
src = "${src}/cuBLASLt";
60+
sourceRoot = "${finalAttrs.src.name}/cuBLASLt";
6661
}
6762
);
6863

69-
cusolver = backendStdenv.mkDerivation (
70-
commonAttrs
71-
// {
64+
cusolver = base.overrideAttrs (
65+
finalAttrs: _: {
7266
pname = "cuda-library-samples-cusolver";
73-
74-
src = "${src}/cuSOLVER";
75-
76-
sourceRoot = "cuSOLVER/gesv";
67+
sourceRoot = "${finalAttrs.src.name}/cuSOLVER/gesv";
7768
}
7869
);
7970

80-
cutensor = backendStdenv.mkDerivation (
81-
commonAttrs
82-
// {
71+
cutensor = base.overrideAttrs (
72+
finalAttrs: prevAttrs: {
8373
pname = "cuda-library-samples-cutensor";
8474

85-
src = "${src}/cuTENSOR";
75+
sourceRoot = "${finalAttrs.src.name}/cuTENSOR";
8676

87-
buildInputs = [ cutensor ];
77+
buildInputs = prevAttrs.buildInputs or [ ] ++ [ cutensor ];
8878

89-
cmakeFlags = [ "-DCUTENSOR_EXAMPLE_BINARY_INSTALL_DIR=${builtins.placeholder "out"}/bin" ];
79+
cmakeFlags = prevAttrs.cmakeFlags or [ ] ++ [
80+
"-DCUTENSOR_EXAMPLE_BINARY_INSTALL_DIR=${builtins.placeholder "out"}/bin"
81+
];
9082

9183
# CUTENSOR_ROOT is double escaped
92-
postPatch = ''
93-
substituteInPlace CMakeLists.txt \
94-
--replace-fail "\''${CUTENSOR_ROOT}/include" "${cutensor.dev}/include"
95-
'';
84+
postPatch =
85+
prevAttrs.postPatch or ""
86+
+ ''
87+
substituteInPlace CMakeLists.txt \
88+
--replace-fail "\''${CUTENSOR_ROOT}/include" "${lib.getDev cutensor}/include"
89+
'';
9690

9791
CUTENSOR_ROOT = cutensor;
92+
93+
meta = prevAttrs.meta or { } // {
94+
broken = cutensor == null;
95+
};
9896
}
9997
);
10098

101-
cusparselt = backendStdenv.mkDerivation (
102-
commonAttrs
103-
// {
99+
cusparselt = base.overrideAttrs (
100+
finalAttrs: prevAttrs: {
104101
pname = "cuda-library-samples-cusparselt";
105102

106-
src = "${src}/cuSPARSELt";
103+
sourceRoot = "${finalAttrs.src.name}/cuSPARSELt/matmul";
107104

108-
sourceRoot = "cuSPARSELt/matmul";
109-
110-
buildInputs = lib.optionals (cudaOlder "11.4") [ cudatoolkit ];
105+
buildInputs = prevAttrs.buildInputs or [ ] ++ lib.optionals (cudaOlder "11.4") [ cudatoolkit ];
111106

112107
nativeBuildInputs =
113-
[
108+
prevAttrs.nativeBuildInputs or [ ]
109+
++ [
114110
cmake
115111
addDriverRunpath
116112
(lib.getDev cusparselt)
@@ -125,22 +121,34 @@ in
125121
cuda_cccl # <nv/target>
126122
];
127123

128-
postPatch = ''
129-
substituteInPlace CMakeLists.txt \
130-
--replace-fail "''${CUSPARSELT_ROOT}/lib64/libcusparseLt.so" "${lib.getLib cusparselt}/lib/libcusparseLt.so" \
131-
--replace-fail "''${CUSPARSELT_ROOT}/lib64/libcusparseLt_static.a" "${lib.getStatic cusparselt}/lib/libcusparseLt_static.a"
132-
'';
133-
134-
installPhase = ''
135-
runHook preInstall
136-
mkdir -p $out/bin
137-
cp matmul_example $out/bin/
138-
cp matmul_example_static $out/bin/
139-
runHook postInstall
140-
'';
124+
postPatch =
125+
prevAttrs.postPatch or ""
126+
+ ''
127+
substituteInPlace CMakeLists.txt \
128+
--replace-fail "''${CUSPARSELT_ROOT}/lib64/libcusparseLt.so" "${lib.getLib cusparselt}/lib/libcusparseLt.so" \
129+
--replace-fail "''${CUSPARSELT_ROOT}/lib64/libcusparseLt_static.a" "${lib.getStatic cusparselt}/lib/libcusparseLt_static.a"
130+
'';
131+
132+
postInstall =
133+
prevAttrs.postInstall or ""
134+
+ ''
135+
mkdir -p $out/bin
136+
cp matmul_example $out/bin/
137+
cp matmul_example_static $out/bin/
138+
'';
141139

142140
CUDA_TOOLKIT_PATH = lib.getLib cudatoolkit;
143141
CUSPARSELT_PATH = lib.getLib cusparselt;
142+
143+
meta = prevAttrs.meta or { } // {
144+
broken =
145+
# Base dependencies
146+
(cusparselt == null || libcusparse == null)
147+
# CUDA 11.4+ dependencies
148+
|| (cudaAtLeast "11.4" && (cuda_nvcc == null || cuda_cudart == null))
149+
# CUDA 12.0+ dependencies
150+
|| (cudaAtLeast "12.0" && cuda_cccl == null);
151+
};
144152
}
145153
);
146154
}

pkgs/development/cuda-modules/cuda/extension.nix

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,42 +53,13 @@ let
5353
# buildRedistPackage : callPackage -> PackageName -> Derivation
5454
buildRedistPackage =
5555
callPackage: pname:
56-
let
56+
callPackage ../generic-builders/manifest.nix {
57+
inherit pname redistName;
58+
# We pass the whole release to the builder because it has logic to handle
59+
# the case we're trying to build on an unsupported platform.
5760
redistribRelease = redistribManifest.${pname};
5861
featureRelease = featureManifest.${pname};
59-
drv =
60-
let
61-
# get `autoAddDriverRunpath` from pkgs instead of cudaPackages' alias to avoid warning
62-
inherit (callPackage ({ pkgs }: pkgs) { }) autoAddDriverRunpath;
63-
in
64-
(callPackage ../generic-builders/manifest.nix {
65-
# We pass the whole release to the builder because it has logic to handle
66-
# the case we're trying to build on an unsupported platform.
67-
inherit
68-
pname
69-
redistName
70-
redistribRelease
71-
featureRelease
72-
autoAddDriverRunpath
73-
;
74-
}).overrideAttrs
75-
(prevAttrs: {
76-
# Add the package-specific license.
77-
meta = prevAttrs.meta // {
78-
license =
79-
let
80-
licensePath =
81-
if redistribRelease.license_path != null then
82-
redistribRelease.license_path
83-
else
84-
"${pname}/LICENSE.txt";
85-
url = "https://developer.download.nvidia.com/compute/cuda/redist/${licensePath}";
86-
in
87-
lib.licenses.nvidiaCudaRedist // { inherit url; };
88-
};
89-
});
90-
in
91-
drv;
62+
};
9263

9364
# Build all the redist packages given final and prev.
9465
redistPackages =

0 commit comments

Comments
 (0)