Skip to content

Commit

Permalink
Fix libcupti RPATH and add CUPTI samples
Browse files Browse the repository at this point in the history
CUPTI was not working because it was lacking an RPATH entry that would
ensure it can load libraries in the same directory (e.g.
libnvperf_host.so).

Tested by running CUPTI samples
  • Loading branch information
danielfullmer committed Aug 20, 2024
1 parent 6d30a91 commit c29413c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkgs/cuda-packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,19 @@ let
'';
};
cuda_cuobjdump = buildFromSourcePackage { name = "cuda-cuobjdump"; };
cuda_cupti = buildFromSourcePackage { name = "cuda-cupti"; };
cuda_cupti = buildFromSourcePackage {
name = "cuda-cupti";

# We append a postFixupHook since we need to have this happen after
# autoPatchelfHook, which itself also runs as a postFixupHook.
# TODO: Use runtimeDependencies instead
preFixup = ''
postFixupHooks+=('
# dlopen in libcupti.so needs to be able to access these libnvperf_host.so in this directory
patchelf --add-rpath $out/lib $(readlink -f $out/lib/libcupti.so)
')
'';
};
cuda_cuxxfilt = buildFromSourcePackage { name = "cuda-cuxxfilt"; };
cuda_documentation = buildFromSourcePackage { name = "cuda-documentation"; };
cuda_gdb = buildFromSourcePackage { name = "cuda-gdb"; buildInputs = [ expat ]; };
Expand Down
72 changes: 72 additions & 0 deletions pkgs/samples/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,71 @@ let
'';
};

cupti-samples = stdenv.mkDerivation {
pname = "cupti-samples";
version = debs.common."cuda-cupti-dev-${cudaVersionDashes}".version;
src = debs.common."cuda-cupti-dev-${cudaVersionDashes}".src;

unpackCmd = "dpkg -x $src source";
sourceRoot = "source/usr/local/cuda-${cudaVersion}/extras/CUPTI/samples";

nativeBuildInputs = [ dpkg pkg-config autoAddDriverRunpath ];
buildInputs = [ cudaPackages.cudatoolkit ];

preConfigure = ''
export CUDA_INSTALL_PATH=${cudaPackages.cudatoolkit}
'';

enableParallelBuilding = true;

buildPhase = ''
runHook preBuild
# Some samples depend on this being built first
make $buildFlags -C extensions/src/profilerhost_util
for sample in *; do
if [[ "$sample" != "extensions" ]]; then
make $buildFlags -C "$sample"
fi
done
runHook postBuild
'';

installPhase = ''
runHook preInstall
for sample in *; do
if [[ "$sample" != "extensions" && "$sample" != "autorange_profiling" && "$sample" != "userrange_profiling" ]]; then
install -Dm755 -t $out/bin $sample/$sample
fi
done
# These samples aren't named the same as their containing directory
install -Dm755 -t $out/bin autorange_profiling/auto_range_profiling
install -Dm755 -t $out/bin userrange_profiling/user_range_profiling
runHook postInstall
'';
};
cupti-test = writeShellApplication {
name = "cupti-test";
text = ''
# Not entirely sure which utilities are relevant here, I'll just pick a few
# See: https://docs.nvidia.com/cupti/main/main.html?highlight=samples#samples
#
# TODO: cupti_metric_properties needs libnvidia-ptxjitcompiler, which is either in l4t-3d-core or in cuda-compat...
#
for binary in cupti_query callback_timestamp pc_sampling; do
echo " * Running $binary"
${cupti-samples}/bin/$binary || echo " *** FAILED RUNNING $binary"
echo
echo
done
'';
};

graphics-demos = stdenv.mkDerivation {
pname = "graphics-demos";
version = debs.t234.nvidia-l4t-graphics-demos.version;
Expand Down Expand Up @@ -393,6 +458,11 @@ let
echo "====="
${cudnn-test}/bin/cudnn-test
echo "====="
echo "Running CUPTI test"
echo "====="
${cupti-test}/bin/cupti-test
echo "====="
echo "Running TensorRT test"
echo "====="
Expand All @@ -416,6 +486,8 @@ in
cuda-test
cudnn-samples
cudnn-test
cupti-samples
cupti-test
graphics-demos
libnvinfer-samples
libnvinfer-test
Expand Down

0 comments on commit c29413c

Please sign in to comment.