CUPTI Agent and Online Injection
libxprobe-cupti.so runs inside a CUDA target process to collect Runtime/Driver API callbacks, kernel/memcpy/memset activity, and ASCII NVTX range boundaries. Users normally drive it through xprobe measure --pid; it is not a daemon or persistent profiling session.
Release packages ship separate builds linked to libcupti.so.12 and libcupti.so.13. measure picks the major from the target's mapped CUDA libraries (or from the single installed CUPTI major when the target doesn't expose one) and fails before ptrace attach on conflict, unsupported major, or missing .so.
Measurement lifecycle
- Validate & inject:
validateis read-only. When it reportsinjection_required,measurewarns on stderr and uses Linux x86_64 ptrace to call targetdlopen,dlsym, andxprobe_cupti_agent_start. Loading opens a mode-0600 Unix control socket without enabling CUPTI yet. - ARM:
measuresendsARMwith record capacity and up to eight endpoint filters. The Agent allocates fresh storage, installs filters, and enables only the required callbacks and activity families.- API names/domains, memcpy directions, and exact/prefix/suffix/contains kernel or NVTX patterns under 128 bytes filter in the Agent hot path before consuming capacity.
- Complex kernel regexes use a wider Agent filter and apply full regex matching in Rust.
- SNAPSHOT: flushes pending CUPTI activity and returns only contiguous records after the caller's checked offset.
- STOP / CLOSE: flushes the final delta and disables CUPTI callbacks/activity.
STOPkeeps the control socket open so a preloaded Agent can handle later captures.CLOSE(used after automatic injection) also removes the private socket.- Neither path calls
dlclose: unloading callback code in a live CUDA process is unsafe.
Prerequisites: target and xprobe must share a mount namespace, and ptrace permissions (Yama, CAP_SYS_PTRACE, seccomp, LSM) apply. Every remote ptrace call saves and restores registers and touched stack memory on both success and failure.
NVTX ranges
Online attach cannot retrofit an already initialized NVTX dispatch table. Set NVTX_INJECTION64_PATH to the matching Agent .so before the target's first NVTX call.
- Startup installs NVTX routing and a dormant CUPTI subscriber kept alive for the process lifetime (CUDA 13 continues referencing it across captures).
ARMenables only the six ASCII/Ex range callbacks (StartA/StartEx/End,PushA/PushEx/Pop) with name matching before timestamping or table insertion;STOPdisables those callbacks without unsubscribing.- Only ASCII range names, IDs, kind, and thread IDs are copied (no payload, color, category, registered strings, wide strings, or env vars).
- Because CUPTI tracks push levels only while callbacks are enabled, a pop of a range pushed before
ARMreports no level and is ignored.
Aggregate mode
An aggregate ARM allocates a fixed --max-groups hash table instead of per-event records:
- Kernels group by
(name, device_id); memcpy by(direction, src_memory, dst_memory, device_id); memset bydevice_id. - Activity callbacks update count, min/max/total duration, and bytes in place.
- The CLI reads the table once at
STOP; table saturation fails explicitly instead of silently sampling.
Capture window edges & start_unknown
- Activity that ended before
ARMis excluded; activity still running atARMkeeps its earlier start so overlapping work isn't hidden. - Activity still running at
STOPkeeps a start record so the stream and GPU stay busy through the capture end rather than looking idle. CUPTI may report no start for it, or one not yet converted to host time, so the Agent writes the record without a time and flags it (XPROBE_CUPTI_RECORD_START_UNKNOWN); the clock check skips it. The CLI sets its time to the stream's last activity end, or to the capture start if nothing else ran, and adds thestart_unknownattribute. It is never used as a duration, gap, or latency endpoint. - Records with unavailable timestamps after the first timed activity count as dropped.
Control and capture ABI
Defined in cupti/include/xprobe/cupti_agent.h:
Control protocol v6 (xprobe_cupti_control_request, 1192 bytes)
- Native-endian request carrying magic (
XPCTRL\0), version (6), command (ARM/SNAPSHOT/STOP/CLOSE),record_capacity,record_offset,capture_mode(EXACT=0,AGGREGATE=1,RING=2),filter_count, and up to 8 fixedxprobe_cupti_filterentries. - Exact
ARMrequires offset 0; subsequent snapshots return records at/afterrecord_offsetfollowed by EOF. Aggregate mode uses offset 0 on every command.
Ring mode (--trigger-*)
- Keeps the newest
record_capacityexact records in a ring without stopping at the limit. - Each slot carries its logical index; snapshots copy under a sequence lock so overwritten slots are discarded along with older records.
- The response header's
record_offsetis the first returned record; a value above the requested offset counts overwritten records. SetsXPROBE_CUPTI_FEATURE_RING_RECORDS.
Capture ABI v4 (xprobe_cupti_output_header, 88 bytes)
- Followed by an optional device table (
XPROBE_CUPTI_FEATURE_DEVICE_TABLE: count, entry size, and 48-bytexprobe_cupti_device_entryrecords mapping each CUDA ordinal to its GPU/MIG UUID, read outside CUDA init and Agent locks without recording the Agent's own driver calls). - Followed by 200-byte exact records (
xprobe_cupti_record) or aggregate records (xprobe_cupti_aggregate_record). - Header tracks capture state, stop reason, capacity, observed/retained counts, Agent and CUPTI drops, unknown records, record sizes, feature flags, and payload offset.
- Capacity comes directly from
--max-events/--max-groups(no2^16cap). Reaching the limit freezes capture and fails explicitly. - If
STOPfails to disable every callback/activity kind, it reports stop reason5(XPROBE_CUPTI_STOP_CLEANUP_ERROR) and keeps the socket open so the CLI returnsCLEANUP_FAILEDand retriesCLOSE.
Record semantics & clock normalization
- Peer-to-peer copies: collected via CUPTI
MEMCPY2records (XPROBE_CUPTI_FEATURE_PEER_MEMCPY); they carrystream_idand no runtime correlation ID. - NVTX records: carry 64-bit range ID, thread/process kind,
start_tid, andname_complete. - Clock alignment: activity timestamps normalize to
CLOCK_MONOTONICvia the CUPTI timestamp callback or CUDA 12 clock calibration. The Agent setsXPROBE_CUPTI_FEATURE_HOST_MONOTONIC_TIMESTAMPSonly after verifying an activity ended betweenARMand the check, or a kernel started no earlier than its launch call. If alignment cannot be proven, GPU-only durations remain usable in rawcuptitime and cross CPU/GPU subtraction returnsCLOCK_ALIGNMENT_FAILED. Because CUPTI provides no numeric error bound, normalized results emitCLOCK_ERROR_UNAVAILABLE.
Hot-path rules
ARMenables only the activity kinds and Runtime/Driver callback IDs needed by the validated endpoints.- Callbacks and activity decoders check filters before reading time or writing records, and stop immediately once capacity is reached.
- Hot paths never allocate, perform file/socket I/O, symbolize names, or take blocking locks. Flushing and socket I/O run on the control thread.
- CUPTI Range Profiling metrics and replay passes are out of scope for this timeline collector.