Repository navigation
shim: load the libnvperf_host that matches CUPTI before PC sampling (#215) - #216
Merged
Merged
Conversation
…215) CUPTI loads libnvperf_host.so by name, and the CUPTI in the PyTorch wheels has no RUNPATH. On a host that also has a CUDA toolkit, the loader finds the toolkit's copy first, and CUPTI 13.0 calling a 13.3 libnvperf_host segfaulted in NVPW_CUDA_LoadDriver on every run with PC sampling enabled. With a PC tier selected, the adapter now loads the libnvperf_host next to the libcupti it resolved before CUPTI looks for one, so CUPTI's by-name dlopen returns that copy. If a different copy is already mapped, PC sampling is turned off for the process, and both paths are logged. The exit report carries the outcome as nvperf=. The decision is in core/nvperfpin.h, with its tests in nvperfpin_test.cc, which run without a GPU.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #215.
The bug
With PC sampling on, a PyTorch process using the CUDA 13 wheels segfaulted at context creation on any host that also had a CUDA toolkit installed: 20 of 20 runs, in both tiers.
cuptiPCSamplingEnableloadslibnvperf_host.soby name, and the wheel's CUPTI has no RUNPATH, so the loader found the toolkit's copy throughLD_LIBRARY_PATHor theldconfigcache. CUPTI 13.0.85 then called into a 13.3libnvperf_hostand crashed inNVPW_CUDA_LoadDriver. The process died, not just the profile.The change
When a PC tier is selected,
InitializeInjectionnow callspin_nvperf_host()before anything else reads the tier. It finds thelibcuptiin use withdladdr, checks whether alibnvperf_host.sois already mapped, and then does one of four things:dlopens thelibnvperf_host.sonext tolibcupti, and keeps it loaded. A by-namedlopenreturns an object already mapped under that soname, so CUPTI's own lookup gets this copy. The report showsnvperf=pinned.matched). Files are compared by device and inode, not path, so/usr/local/cuda/lib64and/usr/local/cuda-13.3/lib64are one copy.tier_refusedis incremented, and both paths are logged with theLD_PRELOADworkaround (mismatched). The process runs unsampled instead of crashing.libcupti: there is nothing to compare against, so it behaves as before and logs a warning (no-sibling).If the sibling exists but fails to load, PC sampling is turned off (
pin-failed). The sibling is looked up in the directorylibcuptiwas opened from, then in the directory its real path resolves to, so a symlink farm that links onlylibcuptistill finds it.The decision is in
shim/core/nvperfpin.h, with no dl calls, andnvperfpin_test.cccovers it inmake testwithout a GPU. The test includes a hard link standing in for the two-names-one-directory toolkit layout. Both exit report lines gain annvperf=field.bench/cmd/scenario/gpupc.goparses those lines as key=value pairs, so it is unaffected.docs/gpu-injection.mddescribes the requirement and the report values.The check runs only when a PC tier is selected. With PC sampling off, nothing changes and the report reads
nvperf=unchecked.Verification
make -C shim testandmake -C shim check-cupti-guardpass.LD_LIBRARY_PATH, shim only, the same setup that crashed 20 of 20:nvperf=pinnedto the wheel's copy,ctx_enabled=1and about 119k PCs per continuous run.LD_PRELOAD: the run completed withpc_sampling=off tier_refused=1 nvperf=mismatched, and the log names both paths.libcupti, serialized tier):nvperf=pinnedto the toolkit's own copy,ctx_enabled=1, about 9.8k PCs.Not in this PR
The continuous tier still deadlocks a process that unloads modules from more than one thread. That is #214.