Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 271078 to staging 23.11 #273040

Merged
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
867c84d
opensubdiv: drop the cudatoolkit.run file, and respect cudaFlags
SomeoneSerge Nov 27, 2023
2d234b0
opensubdiv: use cuda_nvcc only if cudaSupport
veprbl Dec 8, 2023
c1ab852
suitesparse: migrate to redist cuda
SomeoneSerge Dec 9, 2023
0551e85
cudaPackagesGoogle: init, a package-set for jax and tf
SomeoneSerge Nov 24, 2023
b774fda
tensorrt: dont break eval for unrelated packages
SomeoneSerge Nov 24, 2023
32b15d3
blender: drop cudatoolkit.runfile
SomeoneSerge Nov 27, 2023
65f38d5
catboost: downgrade to cudaPackages_11 because of unsupported archite…
SomeoneSerge Nov 27, 2023
1c3e40c
ctranslate2: fix the cuda 12 build
SomeoneSerge Nov 27, 2023
7532a06
cudaPackages.cuda_nvcc: fix (getExe cuda_nvcc)
SomeoneSerge Nov 27, 2023
ea94f71
cudaPackages_12.cutensor: init and fix
SomeoneSerge Nov 27, 2023
10a73aa
python3Packages.cupy: fix (use older cutensor)
SomeoneSerge Nov 27, 2023
525df0e
ucx: fix the cudaPackages_12 variant; drop the cudatoolkit runfile de…
SomeoneSerge Nov 27, 2023
9bf80c5
gromacs: drop cudatoolkit.run
SomeoneSerge Nov 28, 2023
f89fab8
openvino: opencvConfig.cmake attempts to find_package(CUDA)
SomeoneSerge Nov 28, 2023
8e6c3ca
nvidia-thrust: rm as deprecated
SomeoneSerge Nov 28, 2023
e1ec747
ucc: drop the cudatoolkit runfile
SomeoneSerge Dec 3, 2023
6cc7ef3
ucc: respect cudaFlags
SomeoneSerge Dec 3, 2023
f49ae13
openmpi: drop the cudatoolkit runfile
SomeoneSerge Dec 3, 2023
923ead9
python311Packages.torchWithCuda: drop cuda_cudart.static at runtime
SomeoneSerge Dec 4, 2023
b93a4e2
cudaPackages.setupCudaHook: fix cudart flags
SomeoneSerge Dec 4, 2023
c5e5690
cudaPackages.setupCudaHook: rewrite cudartFlags, remove infinite recu…
SomeoneSerge Dec 4, 2023
94623d5
cudaPackages_11_3.saxpy: fallback to the cudatoolkit runfile
SomeoneSerge Dec 4, 2023
daafff2
cudaPackages.cuda_nvcc: fix hook's offsets (-1, -1) -> (-1, 0)
SomeoneSerge Dec 4, 2023
a557b50
cudaPackages.setupCudaHook: source only from nativeBuildInputs
SomeoneSerge Dec 4, 2023
a2bd1af
tiny-cuda-nn: cuda_cccl required with the newer cuda
SomeoneSerge Dec 5, 2023
ee31526
tiny-cuda-nn: prune runtime closure
SomeoneSerge Dec 5, 2023
545055a
cudaPackages.setupCudaHook: propagate buildInputs and self
SomeoneSerge Nov 30, 2023
5a66afc
opencv4: expose cxxdev, propagating optional cuda deps
SomeoneSerge Nov 30, 2023
7be294a
opencv4: propagate optical flow sdk same as cuda
SomeoneSerge Nov 30, 2023
1ab4e3a
opencv4: discard build-time cuda deps
SomeoneSerge Dec 3, 2023
ad2fd25
torch: add the cxxdev output for cmake consumers
SomeoneSerge Nov 30, 2023
50064e5
openvino: use opencv4.cxxdev in case cuda is enabled
SomeoneSerge Nov 30, 2023
484b846
cctag: unbreak the cuda variant
SomeoneSerge Nov 30, 2023
f68149e
python311Packages.torch: enable_language(CUDA) wants to -lcudart_static?
SomeoneSerge Dec 5, 2023
75cac5d
openvino: fix build by providing ocl-icd for libOpenCL.so.1
mweinelt Dec 8, 2023
270e8cb
cudaPackages.setupCudaHook: disable the guard for 23.11
SomeoneSerge Dec 10, 2023
d8ed2ba
cudaPackages.cudatoolkit: propagate the hook to nativeBuildInputs cor…
SomeoneSerge Dec 9, 2023
e5d569f
nvidia-optical-flow-sdk: refactor: propagation via setupCudaHook
SomeoneSerge Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkgs/applications/misc/blender/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ stdenv.mkDerivation (finalAttrs: rec {
nativeBuildInputs =
[ cmake makeWrapper python310Packages.wrapPython llvmPackages.llvm.dev
]
++ lib.optionals cudaSupport [ addOpenGLRunpath ]
++ lib.optionals cudaSupport [
addOpenGLRunpath
cudaPackages.cuda_nvcc
]
++ lib.optionals waylandSupport [ pkg-config ];
buildInputs =
[ boost ffmpeg gettext glew ilmbase
Expand Down Expand Up @@ -87,7 +90,7 @@ stdenv.mkDerivation (finalAttrs: rec {
llvmPackages.openmp SDL Cocoa CoreGraphics ForceFeedback OpenAL OpenGL
])
++ lib.optional jackaudioSupport libjack2
++ lib.optional cudaSupport cudaPackages.cudatoolkit
++ lib.optionals cudaSupport [ cudaPackages.cuda_cudart ]
++ lib.optional colladaSupport opencollada
++ lib.optional spaceNavSupport libspnav;
pythonPath = with python310Packages; [ numpy requests zstandard ];
Expand Down
34 changes: 29 additions & 5 deletions pkgs/applications/science/molecular-dynamics/gromacs/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{ lib, stdenv, fetchurl, cmake, hwloc, fftw, perl, blas, lapack, mpi, cudatoolkit
{ lib
, stdenv
, fetchurl
, cmake
, hwloc
, fftw
, perl
, blas
, lapack
, mpi
, cudaPackages
, singlePrec ? true
, config
, enableMpi ? false
Expand All @@ -7,6 +17,8 @@
}:

let
inherit (cudaPackages.cudaFlags) cudaCapabilities dropDot;

# Select reasonable defaults for all major platforms
# The possible values are defined in CMakeLists.txt:
# AUTO None SSE2 SSE4.1 AVX_128_FMA AVX_256 AVX2_256
Expand All @@ -31,7 +43,9 @@ in stdenv.mkDerivation rec {

outputs = [ "out" "dev" "man" ];

nativeBuildInputs = [ cmake ];
nativeBuildInputs =
[ cmake ]
++ lib.optionals enableCuda [ cudaPackages.cuda_nvcc ];

buildInputs = [
fftw
Expand All @@ -40,13 +54,17 @@ in stdenv.mkDerivation rec {
blas
lapack
] ++ lib.optional enableMpi mpi
++ lib.optional enableCuda cudatoolkit
;
++ lib.optionals enableCuda [
cudaPackages.cuda_cudart
cudaPackages.libcufft
cudaPackages.cuda_profiler_api
];

propagatedBuildInputs = lib.optional enableMpi mpi;
propagatedUserEnvPkgs = lib.optional enableMpi mpi;

cmakeFlags = [
(lib.cmakeBool "GMX_HWLOC" true)
"-DGMX_SIMD:STRING=${SIMD cpuAcceleration}"
"-DGMX_OPENMP:BOOL=TRUE"
"-DBUILD_SHARED_LIBS=ON"
Expand All @@ -66,7 +84,13 @@ in stdenv.mkDerivation rec {
else [
"-DGMX_MPI:BOOL=FALSE"
]
) ++ lib.optional enableCuda "-DGMX_GPU=CUDA";
) ++ lib.optionals enableCuda [
"-DGMX_GPU=CUDA"
(lib.cmakeFeature "CMAKE_CUDA_ARCHITECTURES" (builtins.concatStringsSep ";" (map dropDot cudaCapabilities)))

# Gromacs seems to ignore and override the normal variables, so we add this ad hoc:
(lib.cmakeFeature "GMX_CUDA_TARGET_COMPUTE" (builtins.concatStringsSep ";" (map dropDot cudaCapabilities)))
];

postInstall = ''
moveToOutput share/cmake $dev
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/cudatoolkit/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ backendStdenv.mkDerivation rec {
] ++ lib.optionals (lib.versionAtLeast version "11.8") [
qt6Packages.wrapQtAppsHook
];
depsTargetTargetPropagated = [
propagatedBuildInputs = [
setupCudaHook
];
buildInputs = lib.optionals (lib.versionOlder version "11") [
Expand Down
5 changes: 4 additions & 1 deletion pkgs/development/compilers/cudatoolkit/extension.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ final: prev: let
./hooks/mark-for-cudatoolkit-root-hook.sh)
{ });

# Normally propagated by cuda_nvcc or cudatoolkit through their depsHostHostPropagated
# Currently propagated by cuda_nvcc or cudatoolkit, rather than used directly
setupCudaHook = (final.callPackage
({ makeSetupHook, backendStdenv }:
makeSetupHook
{
name = "setup-cuda-hook";

substitutions.setupCudaHook = placeholder "out";

# Point NVCC at a compatible compiler
substitutions.ccRoot = "${backendStdenv.cc}";

# Required in addition to ccRoot as otherwise bin/gcc is looked up
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# shellcheck shell=bash

# Should we mimick cc-wrapper's "hygiene"?
[[ -z ${strictDeps-} ]] || (( "$hostOffset" < 0 )) || return 0
ConnorBaker marked this conversation as resolved.
Show resolved Hide resolved

echo "Sourcing mark-for-cudatoolkit-root-hook" >&2

markForCUDAToolkit_ROOT() {
mkdir -p "${prefix}/nix-support"
touch "${prefix}/nix-support/include-in-cudatoolkit-root"
[[ -f "${prefix}/nix-support/include-in-cudatoolkit-root" ]] && return
echo "$pname-$output" > "${prefix}/nix-support/include-in-cudatoolkit-root"
}

fixupOutputHooks+=(markForCUDAToolkit_ROOT)

This file was deleted.

101 changes: 86 additions & 15 deletions pkgs/development/compilers/cudatoolkit/hooks/setup-cuda-hook.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
# shellcheck shell=bash

echo Sourcing setup-cuda-hook >&2
# Starting with 24.05: only run the hook from nativeBuildInputs
# (( "$hostOffset" == -1 && "$targetOffset" == 0)) || return 0

extendCUDAToolkit_ROOT() {
if [[ -f "$1/nix-support/include-in-cudatoolkit-root" ]] ; then
addToSearchPathWithCustomDelimiter ";" CUDAToolkit_ROOT "$1"
guard=Sourcing
reason=

if [[ -d "$1/include" ]] ; then
addToSearchPathWithCustomDelimiter ";" CUDAToolkit_INCLUDE_DIR "$1/include"
fi
fi
[[ -n ${cudaSetupHookOnce-} ]] && guard=Skipping && reason=" because the hook has been propagated more than once"

if (( "${NIX_DEBUG:-0}" >= 1 )) ; then
echo "$guard hostOffset=$hostOffset targetOffset=$targetOffset setupCudaHook$reason" >&2
else
echo "$guard setup-cuda-hook$reason" >&2
fi

[[ "$guard" = Sourcing ]] || return 0

declare -g cudaSetupHookOnce=1
declare -Ag cudaHostPathsSeen=()
declare -Ag cudaOutputToPath=()

extendcudaHostPathsSeen() {
(( "${NIX_DEBUG:-0}" >= 1 )) && echo "extendcudaHostPathsSeen $1" >&2

local markerPath="$1/nix-support/include-in-cudatoolkit-root"
[[ ! -f "${markerPath}" ]] && return
[[ -v cudaHostPathsSeen[$1] ]] && return

cudaHostPathsSeen["$1"]=1

# E.g. cuda_cudart-lib
local cudaOutputName
read -r cudaOutputName < "$markerPath"

[[ -z "$cudaOutputName" ]] && return

local oldPath="${cudaOutputToPath[$cudaOutputName]-}"
[[ -n "$oldPath" ]] && echo "extendcudaHostPathsSeen: warning: overwriting $cudaOutputName from $oldPath to $1" >&2
cudaOutputToPath["$cudaOutputName"]="$1"
}
addEnvHooks "$targetOffset" extendcudaHostPathsSeen

setupCUDAToolkit_ROOT() {
(( "${NIX_DEBUG:-0}" >= 1 )) && echo "setupCUDAToolkit_ROOT: cudaHostPathsSeen=${!cudaHostPathsSeen[*]}" >&2

addEnvHooks "$targetOffset" extendCUDAToolkit_ROOT
for path in "${!cudaHostPathsSeen[@]}" ; do
addToSearchPathWithCustomDelimiter ";" CUDAToolkit_ROOT "$path"
if [[ -d "$path/include" ]] ; then
addToSearchPathWithCustomDelimiter ";" CUDAToolkit_INCLUDE_DIR "$path/include"
fi
done

export cmakeFlags+=" -DCUDAToolkit_INCLUDE_DIR=$CUDAToolkit_INCLUDE_DIR -DCUDAToolkit_ROOT=$CUDAToolkit_ROOT"
}
preConfigureHooks+=(setupCUDAToolkit_ROOT)

setupCUDAToolkitCompilers() {
echo Executing setupCUDAToolkitCompilers >&2
Expand Down Expand Up @@ -56,13 +97,43 @@ setupCUDAToolkitCompilers() {
# CMake's enable_language(CUDA) runs a compiler test and it doesn't account for
# CUDAToolkit_ROOT. We have to help it locate libcudart
if [[ -z "${nvccDontPrependCudartFlags-}" ]] ; then
export NVCC_APPEND_FLAGS+=" -L@cudartLib@/lib -L@cudartStatic@/lib -I@cudartInclude@/include"
if [[ ! -v cudaOutputToPath["cuda_cudart-out"] ]] ; then
echo "setupCUDAToolkitCompilers: missing cudaPackages.cuda_cudart. This may become an an error in the future" >&2
# exit 1
fi
for pkg in "${!cudaOutputToPath[@]}" ; do
[[ ! "$pkg" = cuda_cudart* ]] && continue

local path="${cudaOutputToPath[$pkg]}"
if [[ -d "$path/include" ]] ; then
export NVCC_PREPEND_FLAGS+=" -I$path/include"
fi
if [[ -d "$path/lib" ]] ; then
export NVCC_PREPEND_FLAGS+=" -L$path/lib"
fi
done
fi
}
preConfigureHooks+=(setupCUDAToolkitCompilers)

setupCMakeCUDAToolkit_ROOT() {
export cmakeFlags+=" -DCUDAToolkit_INCLUDE_DIR=$CUDAToolkit_INCLUDE_DIR -DCUDAToolkit_ROOT=$CUDAToolkit_ROOT"
}
propagateCudaLibraries() {
(( "${NIX_DEBUG:-0}" >= 1 )) && echo "propagateCudaLibraries: cudaPropagateToOutput=$cudaPropagateToOutput cudaHostPathsSeen=${!cudaHostPathsSeen[*]}" >&2

[[ -z "${cudaPropagateToOutput-}" ]] && return

mkdir -p "${!cudaPropagateToOutput}/nix-support"
# One'd expect this should be propagated-bulid-build-deps, but that doesn't seem to work
echo "@setupCudaHook@" >> "${!cudaPropagateToOutput}/nix-support/propagated-native-build-inputs"

postHooks+=(setupCUDAToolkitCompilers)
preConfigureHooks+=(setupCMakeCUDAToolkit_ROOT)
local propagatedBuildInputs=( "${!cudaHostPathsSeen[@]}" )
for output in $(getAllOutputNames) ; do
if [[ ! "$output" = "$cudaPropagateToOutput" ]] ; then
propagatedBuildInputs+=( "${!output}" )
fi
break
done

# One'd expect this should be propagated-host-host-deps, but that doesn't seem to work
printWords "${propagatedBuildInputs[@]}" >> "${!cudaPropagateToOutput}/nix-support/propagated-build-inputs"
}
postFixupHooks+=(propagateCudaLibraries)
35 changes: 6 additions & 29 deletions pkgs/development/compilers/cudatoolkit/redist/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,14 @@ in
]
);

cuda_nvcc = prev.cuda_nvcc.overrideAttrs (_: {
# Required by cmake's enable_language(CUDA) to build a test program
# When implementing cross-compilation support: this is
# final.pkgs.targetPackages.cudaPackages.cuda_cudart
env = {
# Given the multiple-outputs each CUDA redist has, we can specify the exact components we
# need from the package. CMake requires:
# - the cuda_runtime.h header, which is in the dev output
# - the dynamic library, which is in the lib output
# - the static library, which is in the static output
cudartInclude = "${final.cuda_cudart.dev}";
cudartLib = "${final.cuda_cudart.lib}";
cudartStatic = "${final.cuda_cudart.static}";
};

# Point NVCC at a compatible compiler

# Desiredata: whenever a package (e.g. magma) adds cuda_nvcc to
# nativeBuildInputs (offsets `(-1, 0)`), magma should also source the
# setupCudaHook, i.e. we want it the hook to be propagated into the
# same nativeBuildInputs.
#
# Logically, cuda_nvcc should include the hook in depsHostHostPropagated,
# so that the final offsets for the propagated hook would be `(-1, 0) +
# (0, 0) = (-1, 0)`.
#
# In practice, TargetTarget appears to work:
# https://gist.github.com/fd80ff142cd25e64603618a3700e7f82
depsTargetTargetPropagated = [
cuda_nvcc = prev.cuda_nvcc.overrideAttrs (oldAttrs: {
propagatedBuildInputs = [
final.setupCudaHook
];

meta = (oldAttrs.meta or { }) // {
mainProgram = "nvcc";
};
});

cuda_nvprof = prev.cuda_nvprof.overrideAttrs (oldAttrs: {
Expand Down
22 changes: 12 additions & 10 deletions pkgs/development/compilers/cudatoolkit/saxpy/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{ autoAddOpenGLRunpathHook
, backendStdenv
, cmake
, cuda_cccl
, cuda_cudart
, cuda_cccl ? null
, cuda_cudart ? null
, cudaFlags
, cuda_nvcc
, cuda_nvcc ? null
, cudatoolkit ? null
, lib
, libcublas
, libcublas ? null
, setupCudaHook
, stdenv
}:
Expand All @@ -17,23 +18,24 @@ backendStdenv.mkDerivation {

src = ./.;

buildInputs = [
buildInputs = lib.optionals (cuda_cudart != null) [
libcublas
cuda_cudart
cuda_cccl
] ++ lib.optionals (cuda_cudart == null) [
cudatoolkit
];
nativeBuildInputs = [
cmake

# NOTE: this needs to be pkgs.buildPackages.cudaPackages_XX_Y.cuda_nvcc for
# cross-compilation to work. This should work automatically once we move to
# spliced scopes. Delete this comment once that happens
cuda_nvcc

# Alternatively, we could remove the propagated hook from cuda_nvcc and add
# directly:
# setupCudaHook
autoAddOpenGLRunpathHook
] ++ lib.optionals (cuda_nvcc != null) [
cuda_nvcc
] ++ lib.optionals (cuda_nvcc == null) [
cudatoolkit
];

cmakeFlags = [
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/libraries/cctag/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ stdenv.mkDerivation rec {
buildInputs = [
boost179
eigen
opencv
opencv.cxxdev
];

# Tests are broken on Darwin (linking issue)
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/libraries/ctranslate2/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ stdenv.mkDerivation rec {
buildInputs = lib.optionals withMkl [
mkl
] ++ lib.optionals withCUDA [
cudaPackages.cuda_cccl # <nv/target> required by the fp16 headers in cudart
cudaPackages.cuda_cudart
cudaPackages.libcublas
cudaPackages.libcurand
Expand Down
5 changes: 3 additions & 2 deletions pkgs/development/libraries/hwloc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ stdenv.mkDerivation rec {
];

# XXX: libX11 is not directly needed, but needed as a propagated dep of Cairo.
nativeBuildInputs = [ pkg-config ];
nativeBuildInputs = [ pkg-config ]
++ lib.optionals enableCuda [ cudaPackages.cuda_nvcc ];

buildInputs = [ expat ncurses ]
++ lib.optionals x11Support [ cairo libX11 ]
++ lib.optionals stdenv.isLinux [ numactl ]
++ lib.optional enableCuda cudaPackages.cudatoolkit;
++ lib.optionals enableCuda [ cudaPackages.cuda_cudart ];

# Since `libpci' appears in `hwloc.pc', it must be propagated.
propagatedBuildInputs = lib.optional stdenv.isLinux pciutils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ stdenv.mkDerivation {
cp -R * $out/include
'';

postFixup = ''
mkdir -p $out/nix-support
echo $pname >> "$out/nix-support/include-in-cudatoolkit-root"
'';

ConnorBaker marked this conversation as resolved.
Show resolved Hide resolved
meta = with lib; {
description = "Nvidia optical flow headers for computing the relative motion of pixels between images";
homepage = "https://developer.nvidia.com/opticalflow-sdk";
Expand Down
Loading