cudatoolkit: expose compute-sanitizer, nsys utilities (#153542)

* cudatoolkit: expose compute-sanitizer, nsys commands

* Patch compute-sanitizer binary using addOpenGLRunpath

* Revert "Patch compute-sanitizer binary using addOpenGLRunpath"

This reverts commit 82aa57071a5106790fb08c0087189241693f456d.

* Patch compute-sanitizer libs using addOpenGLRunpath

* Patch nsys libs

* Call addOpenGLRunpath on nsys libs

* Clean weird quotation

* Use $ORIGIN in rpath

* Clean unnecessary string interpolation

* Replace while-read-find with for loop

* Move rpath def to preFixup, clean
This commit is contained in:
Matt Wittmann 2022-03-15 12:16:06 -07:00 committed by GitHub
parent 40a3103c0f
commit 8b8e0b4cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -61,8 +61,6 @@ stdenv.mkDerivation rec {
gtk2 glib fontconfig freetype unixODBC alsa-lib
];
rpath = "${lib.makeLibraryPath runtimeDependencies}:${stdenv.cc.cc.lib}/lib64";
unpackPhase = ''
sh $src --keep --noexec
@ -119,6 +117,12 @@ stdenv.mkDerivation rec {
fi
done
mv pkg/builds/cuda_nvcc/nvvm $out/nvvm
mv pkg/builds/cuda_sanitizer_api $out/cuda_sanitizer_api
ln -s $out/cuda_sanitizer_api/compute-sanitizer/compute-sanitizer $out/bin/compute-sanitizer
mv pkg/builds/nsight_systems/target-linux-x64 $out/target-linux-x64
mv pkg/builds/nsight_systems/host-linux-x64 $out/host-linux-x64
''}
rm -f $out/tools/CUDA_Occupancy_Calculator.xls # FIXME: why?
@ -184,22 +188,35 @@ stdenv.mkDerivation rec {
done
'';
preFixup = ''
while IFS= read -r -d ''$'\0' i; do
if ! isELF "$i"; then continue; fi
echo "patching $i..."
if [[ ! $i =~ \.so ]]; then
patchelf \
--set-interpreter "''$(cat $NIX_CC/nix-support/dynamic-linker)" $i
fi
if [[ $i =~ libcudart ]]; then
patchelf --remove-rpath $i
else
rpath2=$rpath:$lib/lib:$out/jre/lib/amd64/jli:$out/lib:$out/lib64:$out/nvvm/lib:$out/nvvm/lib64
patchelf --set-rpath "$rpath2" --force-rpath $i
fi
done < <(find $out $lib $doc -type f -print0)
'';
preFixup =
let rpath = lib.concatStringsSep ":" [
(lib.makeLibraryPath (runtimeDependencies ++ [ "$lib" "$out" "$out/nvvm" ]))
"${stdenv.cc.cc.lib}/lib64"
"$out/jre/lib/amd64/jli"
"$out/lib64"
"$out/nvvm/lib64"
];
in
''
while IFS= read -r -d $'\0' i; do
if ! isELF "$i"; then continue; fi
echo "patching $i..."
if [[ ! $i =~ \.so ]]; then
patchelf \
--set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $i
fi
if [[ $i =~ libcudart ]]; then
patchelf --remove-rpath $i
else
patchelf --set-rpath "${rpath}" --force-rpath $i
fi
done < <(find $out $lib $doc -type f -print0)
'' + lib.optionalString (lib.versionAtLeast version "11") ''
for file in $out/target-linux-x64/*.so; do
echo "patching $file..."
patchelf --set-rpath "${rpath}:\$ORIGIN" $file
done
'';
# Set RPATH so that libcuda and other libraries in
# /run/opengl-driver(-32)/lib can be found. See the explanation in
@ -208,6 +225,10 @@ stdenv.mkDerivation rec {
# --force-rpath prevents changing RPATH (set above) to RUNPATH.
postFixup = ''
addOpenGLRunpath --force-rpath {$out,$lib}/lib/lib*.so
'' + lib.optionalString (lib.versionAtLeast version "11") ''
addOpenGLRunpath $out/cuda_sanitizer_api/compute-sanitizer/*
addOpenGLRunpath $out/cuda_sanitizer_api/compute-sanitizer/x86/*
addOpenGLRunpath $out/target-linux-x64/*
'';
# cuda-gdb doesn't run correctly when not using sandboxing, so