Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 53 additions & 1 deletion pkgs/development/cuda-modules/cuda/overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,59 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) {

cuda_nvcc = prev.cuda_nvcc.overrideAttrs (
oldAttrs: {
propagatedBuildInputs = [final.setupCudaHook];

outputs = oldAttrs.outputs ++ [ "lib" ];

# Patch the nvcc.profile.
# Syntax:
# - `=` for assignment,
# - `?=` for conditional assignment,
# - `+=` to "prepend",
# - `=+` to "append".

# Cf. https://web.archive.org/web/20230308044351/https://arcb.csc.ncsu.edu/~mueller/cluster/nvidia/2.0/nvcc_2.0.pdf

# We set all variables with the lowest priority (=+), but we do force
# nvcc to use the fixed backend toolchain. Cf. comments in
# backend-stdenv.nix

postPatch =
(oldAttrs.postPatch or "")
+ ''
substituteInPlace bin/nvcc.profile \
--replace \
'$(TOP)/lib' \
"''${!outputLib}/lib" \
--replace \
'$(TOP)/$(_NVVM_BRANCH_)' \
"''${!outputBin}/nvvm" \
--replace \
'$(TOP)/$(_TARGET_DIR_)/include' \
"''${!outputDev}/include"

cat << EOF >> bin/nvcc.profile

# Fix a compatible backend compiler
PATH += ${lib.getBin final.backendStdenv.cc}/bin:
LIBRARIES += "-L${lib.getLib final.backendStdenv.nixpkgsCompatibleLibstdcxx}/lib"

# Expose the split-out nvvm
LIBRARIES =+ -L''${!outputBin}/nvvm/lib
INCLUDES =+ -I''${!outputBin}/nvvm/include

# Expose cudart and the libcuda stubs
LIBRARIES =+ -L$static/lib" "-L${final.cuda_cudart.lib}/lib -L${final.cuda_cudart.lib}/lib/stubs
INCLUDES =+ -I${final.cuda_cudart.dev}/include
EOF
'';

propagatedBuildInputs = [ final.setupCudaHook ];

postInstall =
(oldAttrs.postInstall or "")
+ ''
moveToOutput "nvvm" "''${!outputBin}"
'';

meta = (oldAttrs.meta or {}) // {
mainProgram = "nvcc";
Expand Down
1 change: 1 addition & 0 deletions pkgs/development/cuda-modules/saxpy/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let
cudaVersion
flags
libcublas
setupCudaHook
;
in
backendStdenv.mkDerivation {
Expand Down
20 changes: 0 additions & 20 deletions pkgs/development/cuda-modules/setup-hooks/setup-cuda-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,6 @@ setupCUDAToolkitCompilers() {
if [[ -z "${dontCompressFatbin-}" ]]; then
export NVCC_PREPEND_FLAGS+=" -Xfatbin=-compress-all"
fi

# 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
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)

Expand Down