cudaPackages: allow expressions to be used with older versions of CUDA

Signed-off-by: Connor Baker <ConnorBaker01@gmail.com>
This commit is contained in:
Connor Baker
2025-10-23 16:47:29 -07:00
parent 218fe975b3
commit 8af89d0875
11 changed files with 306 additions and 208 deletions
@@ -23,17 +23,17 @@ buildRedist {
allowFHSReferences = true;
buildInputs = [
gmp
]
# aarch64, sbsa needs expat
++ lib.optionals backendStdenv.hostPlatform.isAarch64 [ expat ]
# From 12.5, cuda-gdb comes with Python TUI wrappers
++ lib.optionals (cudaAtLeast "12.5") [
libxcrypt-legacy
ncurses
python3
];
buildInputs =
# only needs gmp from 12.0 and on
lib.optionals (cudaAtLeast "12.0") [ gmp ]
# aarch64, sbsa needs expat
++ lib.optionals backendStdenv.hostPlatform.isAarch64 [ expat ]
# From 12.5, cuda-gdb comes with Python TUI wrappers
++ lib.optionals (cudaAtLeast "12.5") [
libxcrypt-legacy
ncurses
python3
];
# Remove binaries requiring Python3 versions we do not have
postInstall = lib.optionalString (cudaAtLeast "12.5") ''
@@ -1,6 +1,9 @@
{
backendStdenv,
buildRedist,
cuda_cupti,
cudaAtLeast,
lib,
}:
buildRedist {
redistName = "cuda";
@@ -10,6 +13,9 @@ buildRedist {
outputs = [
"out"
]
# The `bin` and `lib` output are only available on SBSA starting with CUDA 11.8.
++ lib.optionals (backendStdenv.hostRedistSystem != "linux-sbsa" || cudaAtLeast "11.8") [
"bin"
"lib"
];
@@ -1,4 +1,8 @@
{ buildRedist }:
{
buildRedist,
cudaAtLeast,
lib,
}:
buildRedist {
redistName = "cuda";
pname = "cuda_nvrtc";
@@ -8,9 +12,9 @@ buildRedist {
"dev"
"include"
"lib"
"static"
"stubs"
];
]
++ lib.optionals (cudaAtLeast "11.5") [ "static" ]
++ [ "stubs" ];
allowFHSReferences = true;
@@ -1,6 +1,7 @@
{
backendStdenv,
buildRedist,
cudaMajorMinorVersion,
lib,
}:
buildRedist {
@@ -17,6 +18,10 @@ buildRedist {
autoPatchelfIgnoreMissingDeps = [
"libnvcudla.so"
]
++ lib.optionals (cudaMajorMinorVersion == "11.8") [
"libcuda.so.1"
"libnvdla_runtime.so"
];
platformAssertions = [
@@ -1,5 +1,7 @@
{
buildRedist,
cudaOlder,
lib,
numactl,
rdma-core,
}:
@@ -17,14 +19,17 @@ buildRedist {
allowFHSReferences = true;
# TODO(@connorbaker): At some point before 12.6, libcufile depends on libcublas.
buildInputs = [
numactl
rdma-core
];
# Before 11.7 libcufile depends on itself for some reason.
autoPatchelfIgnoreMissingDeps = [
"libcuda.so.1"
];
]
++ lib.optionals (cudaOlder "11.7") [ "libcufile.so.0" ];
meta = {
description = "Library to leverage GDS technology";
@@ -1,5 +1,6 @@
{
buildRedist,
cudaAtLeast,
lib,
libcublas,
libcusparse,
@@ -18,11 +19,13 @@ buildRedist {
"stubs"
];
buildInputs = [
(lib.getLib libcublas)
(lib.getLib libcusparse)
libnvjitlink
];
buildInputs =
# Always depends on this
[ (lib.getLib libcublas) ]
# Dependency from 12.0 and on
++ lib.optionals (cudaAtLeast "12.0") [ libnvjitlink ]
# Dependency from 12.1 and on
++ lib.optionals (cudaAtLeast "12.1") [ (lib.getLib libcusparse) ];
meta = {
description = "Collection of dense and sparse direct linear solvers and Eigen solvers";
@@ -1,4 +1,9 @@
{ buildRedist, libnvjitlink }:
{
buildRedist,
cudaAtLeast,
lib,
libnvjitlink,
}:
buildRedist {
redistName = "cuda";
pname = "libcusparse";
@@ -12,7 +17,9 @@ buildRedist {
"stubs"
];
buildInputs = [ libnvjitlink ];
buildInputs =
# Dependency from 12.0 and on
lib.optionals (cudaAtLeast "12.0") [ libnvjitlink ];
meta = {
description = "GPU-accelerated basic linear algebra subroutines for sparse matrix computations for unstructured sparsity";
@@ -1,4 +1,8 @@
{ buildRedist }:
{
buildRedist,
cudaAtLeast,
lib,
}:
buildRedist {
redistName = "cuda";
pname = "libnvjitlink";
@@ -9,8 +13,8 @@ buildRedist {
"include"
"lib"
"static"
"stubs"
];
]
++ lib.optionals (cudaAtLeast "12.2") [ "stubs" ];
meta = {
description = "APIs which can be used at runtime to link together GPU device code";
@@ -2,12 +2,16 @@
backendStdenv,
buildRedist,
cudaAtLeast,
cudaMajorMinorVersion,
cudaOlder,
e2fsprogs,
elfutils,
flags,
gst_all_1,
lib,
qt6,
libjpeg8,
qt5 ? null,
qt6 ? null,
rdma-core,
ucx,
}:
@@ -20,86 +24,116 @@ let
.${backendStdenv.hostPlatform.system}
or (throw "Unsupported system: ${backendStdenv.hostPlatform.system}");
in
buildRedist {
redistName = "cuda";
pname = "nsight_compute";
buildRedist (
finalAttrs:
let
qt = if lib.versionOlder finalAttrs.version "2022.2.0" then qt5 else qt6;
qtwayland =
if lib.versions.major qt.qtbase.version == "5" then
lib.getBin qt.qtwayland
else
lib.getLib qt.qtwayland;
inherit (qt) wrapQtAppsHook qtwebengine qtwebview;
in
{
redistName = "cuda";
pname = "nsight_compute";
# 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)
outputs = [ "out" ];
# 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)
outputs = [ "out" ];
allowFHSReferences = true;
allowFHSReferences = true;
nativeBuildInputs = [ qt6.wrapQtAppsHook ];
nativeBuildInputs = [ wrapQtAppsHook ];
buildInputs = [
(lib.getLib qt6.qtwayland)
qt6.qtwebview
qt6.qtwebengine
rdma-core
]
++ lib.optionals (cudaOlder "12.7") [
e2fsprogs
ucx
]
++ lib.optionals (cudaAtLeast "12.9") [ elfutils ];
buildInputs = [
(lib.getLib qtwayland)
qtwebengine
qtwebview
rdma-core
]
++ lib.optionals (cudaMajorMinorVersion == "12.0" && backendStdenv.hostPlatform.isAarch64) [
libjpeg8
]
++ lib.optionals (cudaAtLeast "12.1" && cudaOlder "12.4") [
gst_all_1.gstreamer
gst_all_1.gst-plugins-base
]
++ lib.optionals (cudaAtLeast "12.0" && cudaOlder "12.7") [
e2fsprogs
ucx
]
++ lib.optionals (cudaAtLeast "12.9") [ elfutils ];
dontWrapQtApps = true;
dontWrapQtApps = true;
preInstall = ''
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
preInstall = ''
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/
rm -rf host/${archDir}/Mesa/
patchShebangs .
'';
postInstall = ''
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 = ''
patchelf --replace-needed libtiff.so.5 libtiff.so "''${!outputBin}/bin/host/${archDir}/Plugins/imageformats/libqtiff.so"
'';
autoPatchelfIgnoreMissingDeps = [
"libcuda.so.1"
"libnvidia-ml.so.1"
];
meta = {
description = "Interactive profiler for CUDA and NVIDIA OptiX";
longDescription = ''
NVIDIA Nsight Compute is an interactive profiler for CUDA and NVIDIA OptiX that provides detailed performance
metrics and API debugging via a user interface and command-line tool. Users can run guided analysis and compare
results with a customizable and data-driven user interface, as well as post-process and analyze results in their
own workflows.
patchShebangs .
'';
homepage = "https://developer.nvidia.com/nsight-compute";
changelog = "https://docs.nvidia.com/nsight-compute/ReleaseNotes";
mainProgram = "ncu";
};
}
postInstall = ''
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 && cudaAtLeast "11.8" && 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 = ''
patchelf --replace-needed libtiff.so.5 libtiff.so "''${!outputBin}/bin/host/${archDir}/Plugins/imageformats/libqtiff.so"
'';
autoPatchelfIgnoreMissingDeps = [
"libcuda.so.1"
"libnvidia-ml.so.1"
];
brokenAssertions = [
{
message = "Qt 5 is required and available";
assertion = lib.versionOlder finalAttrs.version "2022.2.0" -> qt5 != null;
}
{
message = "Qt 6 is required and available";
assertion = lib.versionAtLeast finalAttrs.version "2022.2.0" -> qt6 != null;
}
];
meta = {
description = "Interactive profiler for CUDA and NVIDIA OptiX";
longDescription = ''
NVIDIA Nsight Compute is an interactive profiler for CUDA and NVIDIA OptiX that provides detailed performance
metrics and API debugging via a user interface and command-line tool. Users can run guided analysis and compare
results with a customizable and data-driven user interface, as well as post-process and analyze results in their
own workflows.
'';
homepage = "https://developer.nvidia.com/nsight-compute";
changelog = "https://docs.nvidia.com/nsight-compute/ReleaseNotes";
mainProgram = "ncu";
};
}
)
@@ -2,21 +2,21 @@
backendStdenv,
boost178,
buildRedist,
cudaAtLeast,
e2fsprogs,
gst_all_1,
lib,
nss,
numactl,
pulseaudio,
qt6,
qt5 ? null,
qt6 ? null,
rdma-core,
ucx,
wayland,
xorg,
}:
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 =
{
@@ -33,114 +33,144 @@ let
.${backendStdenv.hostPlatform.system}
or (throw "Unsupported system: ${backendStdenv.hostPlatform.system}");
in
buildRedist {
redistName = "cuda";
pname = "nsight_systems";
buildRedist (
finalAttrs:
let
qt = if lib.strings.versionOlder finalAttrs.version "2022.4.2.1" then qt5 else qt6;
qtwayland =
if lib.versions.major qt.qtbase.version == "5" then
lib.getBin qt.qtwayland
else
lib.getLib qt.qtwayland;
qtWaylandPlugins = "${qtwayland}/${qt.qtbase.qtPluginPrefix}";
inherit (qt) wrapQtAppsHook qtwebengine;
in
{
redistName = "cuda";
pname = "nsight_systems";
allowFHSReferences = true;
allowFHSReferences = true;
outputs = [ "out" ];
outputs = [ "out" ];
# An ad hoc replacement for
# https://github.com/ConnorBaker/cuda-redist-find-features/issues/11
env.rmPatterns = toString [
"${hostDir}/lib{arrow,jpeg}*"
"${hostDir}/lib{ssl,ssh,crypto}*"
"${hostDir}/libboost*"
"${hostDir}/libexec"
"${hostDir}/libstdc*"
"${hostDir}/python/bin/python"
"${hostDir}/Mesa"
];
# An ad hoc replacement for
# https://github.com/ConnorBaker/cuda-redist-find-features/issues/11
env.rmPatterns = 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 = ''
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
# NOTE(@connorbaker): nsight-exporter and nsight-sys are deprecated scripts wrapping nsys, it's fine to remove them.
prePatch = ''
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
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 = ''
for path in $rmPatterns; do
rm -r "$path"
done
patchShebangs nsight-systems
'';
nativeBuildInputs = [ qt6.wrapQtAppsHook ];
dontWrapQtApps = true;
buildInputs = [
qt6.qtdeclarative
qt6.qtsvg
qt6.qtimageformats
qt6.qtpositioning
qt6.qtscxml
qt6.qttools
qt6.qtwebengine
qt6.qtwayland
boost178
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 backendStdenv.hostPlatform.isAarch64 [
gst_all_1.gst-plugins-bad
];
postInstall = ''
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 = ''
patchelf --replace-needed libtiff.so.5 libtiff.so "''${!outputBin}/${hostDir}/Plugins/imageformats/libqtiff.so"
'';
autoPatchelfIgnoreMissingDeps = [
"libcuda.so.1"
"libnvidia-ml.so.1"
];
meta = {
description = "System-wide performance analysis and visualization tool";
longDescription = ''
NVIDIA Nsight Systems is a system-wide performance analysis tool designed to visualize an application's
algorithms, identify the largest opportunities to optimize, and tune to scale efficiently across any quantity or
size of CPUs and GPUs, from large servers to our smallest systems-on-a-chip (SoCs).
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
'';
homepage = "https://developer.nvidia.com/nsight-systems";
changelog = "https://docs.nvidia.com/nsight-systems/ReleaseNotes";
};
}
postPatch = ''
for path in $rmPatterns; do
rm -r "$path"
done
patchShebangs nsight-systems
'';
nativeBuildInputs = [ wrapQtAppsHook ];
dontWrapQtApps = true;
# TODO(@connorbaker): Fix dependencies for earlier (CUDA <12.6) versions of nsight_systems.
buildInputs = [
qt6.qtdeclarative
qt6.qtsvg
qt6.qtimageformats
qt6.qtpositioning
qt6.qtscxml
qt6.qttools
qtwebengine
qt6.qtwayland
boost178
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 (backendStdenv.hostPlatform.isAarch64 && cudaAtLeast "11.8") [
gst_all_1.gst-plugins-bad
];
postInstall = ''
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 = ''
patchelf --replace-needed libtiff.so.5 libtiff.so "''${!outputBin}/${hostDir}/Plugins/imageformats/libqtiff.so"
'';
autoPatchelfIgnoreMissingDeps = [
"libcuda.so.1"
"libnvidia-ml.so.1"
];
brokenAssertions = [
{
# Boost 1.70 has been deprecated in Nixpkgs; releases older than the one for CUDA 11.8 are not supported.
message = "Boost 1.70 is required and available";
assertion = lib.versionAtLeast finalAttrs.version "2022.4.2.1";
}
{
message = "Qt 5 is required and available";
assertion = lib.versionOlder finalAttrs.version "2022.4.2.1" -> qt5 != null;
}
{
message = "Qt 6 is required and available";
assertion = lib.versionAtLeast finalAttrs.version "2022.4.2.1" -> qt6 != null;
}
];
meta = {
description = "System-wide performance analysis and visualization tool";
longDescription = ''
NVIDIA Nsight Systems is a system-wide performance analysis tool designed to visualize an application's
algorithms, identify the largest opportunities to optimize, and tune to scale efficiently across any quantity or
size of CPUs and GPUs, from large servers to our smallest systems-on-a-chip (SoCs).
'';
homepage = "https://developer.nvidia.com/nsight-systems";
changelog = "https://docs.nvidia.com/nsight-systems/ReleaseNotes";
};
}
)
@@ -87,7 +87,7 @@ buildRedist (
fi
'';
autoPatchelfIgnoreMissingDeps = optionals libcudla.meta.available [
autoPatchelfIgnoreMissingDeps = optionals hasJetsonCudaCapability [
"libnvdla_compiler.so"
];