Merge pull request #275922 from SomeoneSerge/fix/cuda-nvcc-profile
cudaPackages.cuda_nvcc: patch nvcc.profile
This commit is contained in:
commit
8fc12bc705
@ -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";
|
||||
|
@ -14,6 +14,7 @@ let
|
||||
cudaVersion
|
||||
flags
|
||||
libcublas
|
||||
setupCudaHook
|
||||
;
|
||||
in
|
||||
backendStdenv.mkDerivation {
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user