Merge pull request #275922 from SomeoneSerge/fix/cuda-nvcc-profile

cudaPackages.cuda_nvcc: patch nvcc.profile
This commit is contained in:
Someone 2023-12-23 13:17:22 +00:00 committed by GitHub
commit 8fc12bc705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 21 deletions

View File

@ -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";

View File

@ -14,6 +14,7 @@ let
cudaVersion
flags
libcublas
setupCudaHook
;
in
backendStdenv.mkDerivation {

View File

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