Skip to content

Bundle CUPTI 12 and 13 and pick one at runtime - #40

Draft
gnurizen wants to merge 2 commits into
mainfrom
bundle-cupti
Draft

gnurizen wants to merge 2 commits into
mainfrom
bundle-cupti

Conversation

@gnurizen

Copy link
Copy Markdown
Contributor

parcagpu now ships two CUPTI versions next to libparcagpucupti.so and picks one at runtime, so it works without LD_LIBRARY_PATH or other env vars on both CUDA 12 and CUDA 13 systems.

What ships

Docker builds (make build-<arch>, the runtime image's /usr/lib, and a new parcagpu-<arch>.tar.gz release asset) include:

  • libcupti.so.12 (CUDA 12.9.1) and libcupti.so.13 (CUDA 13.0.2)
  • libnvperf_host.so.12 and .13. CUPTI loads libnvperf_host.so by name for PC sampling and reports zero stall reasons without it.

A new Dockerfile stage downloads these from NVIDIA's cuda_cupti redist archives and checks their sha256. The arm64 tarball is 17 MB.

How parcagpu picks one

Proton's lookup still goes first: TRITON_CUPTI_LIB_PATH, an already loaded libcupti.so, then LD_LIBRARY_PATH and the system library paths. If none of these finds CUPTI, parcagpu loads:

  • libcupti.so.13 when cuDriverGetVersion is at least 13000 and every GPU has compute capability 7.5 or higher. CUPTI 13 dropped Volta and Pascal, which still run on driver 580. Compute capability comes from NVML, because cuDeviceGet does not work inside InitializeInjection.
  • libcupti.so.12 otherwise.

With PC sampling on, parcagpu also loads the matching libnvperf_host.so, which adds about 110 MB of RSS.

One build serves both

The fields parcagpu and ebpf/cupti_bpf.h read from CUpti_ActivityKernel5 sit at the same offsets in Kernel9 (emitted by CUPTI 12.9) and Kernel10 (emitted by 13.0). CUpti_PCSamplingPCData and CUpti_PCSamplingData are byte-identical in both versions. Every callback ID parcagpu or Proton uses keeps its number. So we still compile once against the 12.9 headers.

An app's own CUPTI is not reused

PyTorch cu13 loads libcupti.so.13 from its pip wheel. parcagpu still loads its bundled copy. CUPTI accepts only one subscriber per process either way. With a shared copy, kineto takes over parcagpu's activity buffers and PC sampling breaks. With separate copies, parcagpu keeps all kernel records, and a torch.profiler started later gets CUPTI_ERROR_MULTIPLE_SUBSCRIBERS_NOT_SUPPORTED, logs a warning and records nothing; nothing crashes.

Testing

Tested on an NVIDIA GB10 (Blackwell, sm_121, arm64) with driver 580.178.04, no env vars, and LD_LIBRARY_PATH unset:

  • parcagpu picked bundled CUPTI 13 for both CUDA 12.9 and CUDA 13.0 apps, and /proc/<pid>/maps showed only the bundled copy.
  • make test-pc-real passes with both a CUDA 13 toy (1627 PC samples) and a CUDA 12.9 toy (1613 PC samples).
  • make test-multi passes (890 kernel events through BPF; mock CUPTI).
  • The make build-arm64 output, run in an Ubuntu 24.04 container on the same GPU, recorded all 6 kernels and 36 stall reasons.
  • amd64 was not built locally. Its CUPTI download stage ran, the checksums matched, and all four files are x86-64 ELF.

Not tested: pre-Turing GPUs, and drivers older than 580 (the CUPTI 12 path on real hardware).

make test-nvtx (case9) and three BPF checks in make test-pc-mock fail the same way on the base branch, so this PR does not cause them.

ampagent and others added 2 commits November 19, 2026 01:12
Docker builds now ship libcupti.so (CUDA 12.9.1, from the cuda-headers
image) next to libparcagpucupti.so: in the export stage, the runtime
image's /usr/lib, make build-<arch>, and a parcagpu-<arch>.tar.gz release
asset. parcagpu tries Proton's usual lookup first and loads the bundled
copy from its own directory only when that fails.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1f095-6696-742c-b484-3c159d3570a0
Co-authored-by: Tommy Reilly <tommy.reilly@dash0.com>
Docker builds now ship libcupti.so.12 (CUDA 12.9.1) and libcupti.so.13
(CUDA 13.0.2) next to libparcagpucupti.so, each with the
libnvperf_host.so it loads for PC sampling, renamed libnvperf_host.so.12
and .13. A new Dockerfile stage downloads them from NVIDIA's cuda_cupti
redist archives and checks their sha256.

When Proton's usual lookup finds no libcupti.so, parcagpu loads the
bundled CUPTI 13 if the driver supports CUDA 13 and every GPU has compute
capability 7.5 or higher (read through NVML, since cuDeviceGet does not
work inside InitializeInjection), and CUPTI 12 otherwise. With PC sampling
on it also loads the matching libnvperf_host.so; without it CUPTI reports
zero stall reasons.

The activity and PC sampling layouts and callback IDs parcagpu uses are
the same in CUPTI 12.9 and 13.0, so one build against the 12.9 headers
serves both.

The mock libcupti.so.12 symlink in build-local/lib is gone: nothing used
it, and the bundled lookup would have loaded it on drivers below 580.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1f15d-3db3-720a-9385-b4ee902158c4
Co-authored-by: Tommy Reilly <tommy.reilly@dash0.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants