cudaPackages.cuda_nvcc: patch nvcc.profile

let nvcc know about cudart and the stub drivers; this way
we do not need to search for cudart in the setupCudaHook
This commit is contained in:
Someone Serge 2023-12-22 00:03:16 +00:00
parent bfbfb34459
commit 35b1e5803a
No known key found for this signature in database
GPG Key ID: 7B0E3B1390D61DA4
3 changed files with 25 additions and 21 deletions

View File

@ -61,7 +61,30 @@ attrsets.filterAttrs (attr: _: (builtins.hasAttr attr prev)) {
cuda_nvcc = prev.cuda_nvcc.overrideAttrs (
oldAttrs: {
propagatedBuildInputs = [final.setupCudaHook];
outputs = oldAttrs.outputs ++ [ "lib" ];
postPatch =
(oldAttrs.postPatch or "")
+ ''
substituteInPlace bin/nvcc.profile \
--replace \
'$(TOP)/lib' \
"''${!outputLib}/lib"
cat << EOF >> bin/nvcc.profile
LIBRARIES += "-L''${!outputBin}/nvvm/lib" "-L$static/lib" "-L${final.cuda_cudart.lib}/lib" "-L${final.cuda_cudart.lib}/lib/stubs"
INCLUDES += "-I''${!outputDev}/include" "-I''${!outputBin}/nvvm/include" "-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)