Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ A read-only check of target identity, probe resolution, CUDA filters, correlatio
- `already_loaded`
- `injection_required`: `measure` will inject the Agent; sets `target_mutation: true` and warns `TARGET_PROCESS_WILL_BE_MODIFIED`.
- `startup_required`: an NVTX selector needs the Agent loaded at startup; `valid: false`.
- A CUDA major other than 12 or 13, or conflicting majors, returns `UNSUPPORTED_CUDA_VERSION`.
- The CUDA major comes from the target's loaded `libcupti` (by file name, or by SONAME for calendar-versioned files), or from its `libcudart` when no CUPTI is loaded. A `libcudart` of another major beside a loaded `libcupti` gives the warning `EXTRA_CUDA_RUNTIME`. A major other than 12 or 13, or two majors of the deciding library, returns `UNSUPPORTED_CUDA_VERSION`.

## Correlation policies

Expand Down Expand Up @@ -269,7 +269,7 @@ Results follow `schemas/trigger-result.schema.json` (schema `3.0`).
### Live capture and the CUDA Agent

- Host endpoints attach every eBPF link before arming. A duration capture that reaches `--max-events` fails with `EVENT_RATE_TOO_HIGH`.
- CUDA endpoints find the Agent from `--agent`, then `XPROBE_CUPTI_AGENT_PATH`, then `../lib/xprobe/cuda12|cuda13`, then the matching build path.
- CUDA endpoints find the Agent from `--agent`, then `XPROBE_CUPTI_AGENT_PATH`, then `../lib/xprobe/cuda12|cuda13` and `../libexec/xprobe/cuda12|cuda13` next to the CLI, then the matching build path.
- One xprobe session owns the Agent at a time. While it runs, another `measure` on the same target fails with `CUPTI_AGENT_BUSY` and leaves the capture alone; combine edges into one measurement graph instead. If torch.profiler or an Nsight tool holds the target's CUPTI subscriber, `measure` fails with `CUPTI_NOT_AVAILABLE` and a hint naming them.
- Live injection needs Linux x86_64, the same mount namespace as the target, and ptrace permission. It prints a warning to stderr and emits `CUPTI_AGENT_INJECTED`. On stop it disables CUPTI and removes its private socket while leaving the `.so` mapped. A later `measure` reuses the mapped Agent, even if its file was deleted. `validate` warns `CUPTI_AGENT_ALREADY_LOADED` with `agent_path` and `file_deleted` when a target holds an Agent; see [CUPTI Agent](cupti-agent.md) for what it keeps.
- NVTX thread ranges are tracked by `(tid, push_level)` and process ranges by `range_id` across threads (`start_tid`). ASCII `PushA`/`StartA` and the `Ex` forms are supported; wide and registered strings and CUPTI Range Profiling are not.
Expand Down
4 changes: 2 additions & 2 deletions docs/cupti-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

`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`.
Release packages ship separate builds linked to `libcupti.so.12` and `libcupti.so.13`. `measure` takes the major from the target's loaded `libcupti` (its file name, or its SONAME for a toolkit's calendar-versioned `libcupti.so.2025.x`), else from its `libcudart`, else from the single installed CUPTI major. It fails before ptrace attach when that library is mapped in two majors, when the major is unsupported, or when the `.so` is missing.

## Measurement lifecycle

Expand All @@ -16,7 +16,7 @@ Release packages ship separate builds linked to `libcupti.so.12` and `libcupti.s
- `CLOSE` (used after automatic injection) also removes the private socket.
- Neither path calls `dlclose`: unloading callback code in a live CUDA process is unsafe.
- After a capture the Agent stays mapped with CUPTI callbacks and activity off, and keeps the last capture's record buffers: 200 bytes per `--max-events` record, plus as much again for a trigger's ring snapshot, until the next capture replaces them or the target exits.
- A later `measure` finds the mapped Agent by the name it was loaded under (`dlopen` with `RTLD_NOLOAD`), so deleting its file, as when a temporary venv is removed, does not stop later captures. `validate` warns `CUPTI_AGENT_ALREADY_LOADED` with `agent_path` and `file_deleted`.
- A later `measure` reads the start function from the mapped Agent's file. If that file was deleted, as when a temporary venv is removed, it asks the target's loader for the Agent by the name it was loaded under (`dlopen` with `RTLD_NOLOAD`), so later captures still work. `validate` warns `CUPTI_AGENT_ALREADY_LOADED` with `agent_path` and `file_deleted`.

**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.

Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ xprobe --version

For pre-releases (`X.Y.Z.devN`), pass `--pre` (`pip install --pre xprobe`).

`pip` installs `xprobe` into `<env>/bin/` and the CUPTI Agents into `<env>/lib/xprobe/cuda12` and `cuda13` (the layout the CLI searches automatically), plus `schemas/` and `skills/` under `<env>/share/xprobe`. This works in virtualenvs, conda/mamba, and `pip install --user`.
`pip` installs `xprobe` into `<env>/bin/` and the CUPTI Agents into `<env>/libexec/xprobe/cuda12` and `cuda13` (the CLI looks there automatically), plus `schemas/` and `skills/` under `<env>/share/xprobe`. This works in virtualenvs, conda/mamba, `pip install --user`, and `pip install --target DIR` (run `DIR/bin/xprobe`).

## Standalone release archive

Expand Down
9 changes: 5 additions & 4 deletions scripts/build-wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"""Build the PyPI wheel from a verified release staging directory.

The wheel installs the CLI into the environment's `bin/` and the CUPTI Agents
into `lib/xprobe/cudaNN/`, preserving the `bin/../lib/xprobe` layout the CLI
searches. It contains no Python code and supports glibc 2.34 or newer on
into `libexec/xprobe/cudaNN/`, which the CLI searches as `bin/../libexec/xprobe`.
`pip install --target` keeps `bin/`, `libexec/`, and `share/` but drops a
`lib/` data directory, so the Agents do not go there. It contains no Python code and supports glibc 2.34 or newer on
x86_64, matching the release archive.

scripts/build-wheel.py dist/xprobe-X.Y.Z-linux-x86_64 dist
Expand Down Expand Up @@ -43,8 +44,8 @@
# (path inside the staging directory, install scheme path, mode)
PAYLOAD = (
("bin/xprobe", "scripts/xprobe", 0o755),
("lib/xprobe/cuda12/libxprobe-cupti.so", "data/lib/xprobe/cuda12/libxprobe-cupti.so", 0o755),
("lib/xprobe/cuda13/libxprobe-cupti.so", "data/lib/xprobe/cuda13/libxprobe-cupti.so", 0o755),
("lib/xprobe/cuda12/libxprobe-cupti.so", "data/libexec/xprobe/cuda12/libxprobe-cupti.so", 0o755),
("lib/xprobe/cuda13/libxprobe-cupti.so", "data/libexec/xprobe/cuda13/libxprobe-cupti.so", 0o755),
)
SHARED_TREES = ("schemas", "skills")

Expand Down
33 changes: 22 additions & 11 deletions tests/install/test_wheel.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
# Install the PyPI wheel into a fresh virtual environment and check that the
# CLI runs and finds both CUPTI Agents through the bin/../lib/xprobe layout.
# Install the PyPI wheel into a fresh virtual environment, and with
# `pip install --target`, and check that the CLI runs and finds both CUPTI
# Agents through the bin/../libexec/xprobe layout.
set -euo pipefail

if [[ $# -ne 1 ]]; then
Expand All @@ -24,22 +25,32 @@ expected=$(basename "${wheel}" | sed -n 's/^xprobe-\([0-9]*\.[0-9]*\.[0-9]*\)\(\
echo "unexpected version: ${version} (expected ${expected})" >&2
exit 1
}
for major in 12 13; do
agent="$(dirname "${xprobe}")/../lib/xprobe/cuda${major}/libxprobe-cupti.so"
[[ -x "${agent}" ]] || { echo "CUDA ${major} Agent not installed beside the CLI: ${agent}" >&2; exit 1; }
LC_ALL=C readelf -d "${agent}" | grep -Fq "Shared library: [libcupti.so.${major}]" || {
echo "CUDA ${major} Agent is not linked to libcupti.so.${major}" >&2
exit 1
}
done
check_agents() {
local major agent
for major in 12 13; do
agent="$(dirname "$1")/../libexec/xprobe/cuda${major}/libxprobe-cupti.so"
[[ -x "${agent}" ]] || { echo "CUDA ${major} Agent not installed beside the CLI: ${agent}" >&2; exit 1; }
LC_ALL=C readelf -d "${agent}" | grep -Fq "Shared library: [libcupti.so.${major}]" || {
echo "CUDA ${major} Agent is not linked to libcupti.so.${major}" >&2
exit 1
}
done
}
check_agents "${xprobe}"
[[ -f "${work}/venv/share/xprobe/skills/xprobe-perf-profiling/SKILL.md" ]] || {
echo "Skill was not installed under share/xprobe" >&2
exit 1
}
"${xprobe}" doctor >/dev/null
"${work}/venv/bin/python" -m pip uninstall --quiet --yes xprobe
[[ ! -e "${xprobe}" && ! -e "${work}/venv/lib/xprobe/cuda12/libxprobe-cupti.so" ]] || {
[[ ! -e "${xprobe}" && ! -e "${work}/venv/libexec/xprobe/cuda12/libxprobe-cupti.so" ]] || {
echo "uninstall left xprobe files behind" >&2
exit 1
}

# A --target install keeps the same bin/ and libexec/ layout.
"${work}/venv/bin/python" -m pip install --quiet --no-index --target "${work}/target" "${wheel}"
[[ -x "${work}/target/bin/xprobe" ]] || { echo "--target install has no bin/xprobe" >&2; exit 1; }
check_agents "${work}/target/bin/xprobe"
"${work}/target/bin/xprobe" doctor >/dev/null
echo "wheel ok: ${version} with python $("${python}" -c 'import sys; print(sys.version.split()[0])')"
12 changes: 11 additions & 1 deletion xprobe/cli/src/live.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,12 @@ pub(crate) fn single_edge_plan(request: &LiveMeasureRequest) -> Result<LivePlan,
)
.map_err(|error| CommandFailure::new(error.code(), error.to_string(), error.recoverable()))?;
if let Some(issue) = validation.issues.first() {
return Err(CommandFailure::new(issue.code, issue.message.clone(), true)
let failure = CommandFailure::new(issue.code, issue.message.clone(), true);
// Only a policy problem is fixed by another --match.
if issue.code != ErrorCode::InvalidCorrelationPolicy {
return Err(failure);
}
return Err(failure
.with_detail(
"recommended_policy",
match_policy_name(validation.policy_recommendation.policy),
Expand Down Expand Up @@ -942,6 +947,11 @@ pub(crate) fn resolve_agent_path(
"../lib/xprobe/cuda{}/libxprobe-cupti.so",
cupti.major
)),
// Where the PyPI wheel installs it.
parent.join(format!(
"../libexec/xprobe/cuda{}/libxprobe-cupti.so",
cupti.major
)),
parent.join(format!("cuda{}/libxprobe-cupti.so", cupti.major)),
PathBuf::from(format!(
"build/cupti/cuda{}/libxprobe-cupti.so",
Expand Down
37 changes: 36 additions & 1 deletion xprobe/core/src/cpu_sampling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,17 @@ fn effective_perf_check(
)),
};
}
report.checks.perf_event_paranoid.clone()
let mut check = report.checks.perf_event_paranoid.clone();
// doctor allows perf_event_paranoid=2 for the caller's own processes;
// this target belongs to another user.
if check.status == CheckStatus::Available {
check.status = CheckStatus::Restricted;
check.detail = Some(format!(
"the target runs as another user; sampling it needs CAP_PERFMON or CAP_SYS_ADMIN; perf_event_paranoid={}",
check.detail.as_deref().unwrap_or("unknown")
));
}
check
}

fn python_symbolization_status(
Expand Down Expand Up @@ -333,3 +343,28 @@ fn warning(code: &str, message: &str) -> Warning {
details: BTreeMap::new(),
}
}

#[cfg(test)]
mod tests {
use xprobe_protocol::{CheckResult, CheckStatus};

use super::effective_perf_check;

#[test]
fn allows_paranoid_two_only_for_the_callers_own_processes() {
let mut report = crate::doctor::run().unwrap();
report.capabilities.uprobe = false;
report.environment.effective_uid = 1000;
report.checks.perf_event_paranoid = CheckResult {
status: CheckStatus::Available,
detail: Some("2".to_owned()),
};
assert_eq!(
effective_perf_check(&report, 1000).status,
CheckStatus::Available
);
let other_user = effective_perf_check(&report, 1001);
assert_eq!(other_user.status, CheckStatus::Restricted);
assert!(other_user.detail.unwrap().contains("another user"));
}
}
Loading