Warpspandocs

NVTX labels

Use the NVTX ranges an app (or TensorRT, PyTorch and other libraries) already emits as frames above each kernel, and see how long each stage takes, like Nsight's NVTX rows.

Many GPU programs already label their work with NVTX ranges for Nsight Systems: pipeline stages, model layers, training steps. Warpspan can record those ranges too. Every kernel then carries the ranges that were open on the thread that launched it, and the flame graph shows them as frames between the device and the kernel:

cuda:0
└─ infer batch n=4                          your app's range
   └─ ExecutionContext::enqueueV3           TensorRT's range
      └─ /model/model.2/m.0/cv1/conv/Conv   TensorRT's per-layer range
         └─ sm80_xmma_fprop_implicit_gemm_… the kernel

Warpspan also times every range, so you get the time per stage, including stages that never touch the GPU (see Time in each range).

This needs no code changes and no OpenTelemetry, and it works next to the span bridges: a kernel can have both a span and NVTX labels.

Turn it on

Point NVTX_INJECTION64_PATH at the same library as CUDA_INJECTION64_PATH:

export CUDA_INJECTION64_PATH=/opt/warpspan/lib/libwarpspan.so
export NVTX_INJECTION64_PATH=/opt/warpspan/lib/libwarpspan.so

The app logs warpspan: recording NVTX ranges as labels on its first NVTX call. Without the second variable, NVTX calls stay no-ops and kernels have no labels, as before.

In Kubernetes, add the variable next to CUDA_INJECTION64_PATH with the same value (/warpspan/libwarpspan.so).

What is recorded

  • nvtxRangePush* / nvtxRangePop and the domain versions (nvtxDomainRangePushEx / nvtxDomainRangePop), per thread, up to 32 levels deep.
  • ASCII, wide (converted to ASCII, other characters become ?) and registered-string messages, up to 256 bytes.
  • Ranges from every library in the process. Each library compiled with NVTX initialises it separately (TensorRT, cuDNN, PyTorch, your own code), and all of them are routed to Warpspan.

Not recorded: nvtxRangeStart/nvtxRangeEnd (they aren't tied to a thread), marks, categories, colours and payloads. Ranges of different domains share one stack per thread. A range must be popped on the thread that pushed it, as NVTX requires; one popped elsewhere stays open on the pushing thread.

Time in each range

Nsight Systems shows each NVTX range as a bar on its thread's timeline, so you see which stage is slow even when it runs on the CPU: decoding, pre-processing, drawing. Warpspan records the same thing as a profile: the time spent inside each range, summed over all threads, as profile type nvtx_time (and nvtx_ranges, how many ranges ended). In Grafana, pick nvtx → nvtx_time in Pyroscope:

total (all threads)
├─ infer batch n=8          35%
│  └─ enqueue > ExecutionContext::enqueueV3 > …
├─ decode s3 f#             27%   (one bar per stream)
├─ preprocess s3 f#         23%
├─ encode s3 f#              9%
└─ draw s3 f#                0.2%

That is Argus running 8 streams for 35 s. Each frame's width is the range's self time: its duration minus the ranges nested inside it, so a parent and its children add up and nothing is counted twice. It is wall time on the thread, whatever the thread did inside the range: computing, waiting on a lock or a queue, or waiting for the GPU (TensorRT's enqueue blocks while it runs the model). Several threads in the same stage add up, so the total can be longer than the run.

Unlike gpu_time, a stage doesn't need CUDA kernels to show up: one that runs only on the CPU, or on the hardware video decoder (NVDEC) and encoder (NVENC), still shows up with its duration. The process itself must use CUDA, though: the times are sent by the library's background thread, which starts when CUDA initialises with CUDA_INJECTION64_PATH set. Ranges in a process that never initialises CUDA are counted but not sent. The per-span view has each span's own stages: see Parent spans and CPU stages.

A range is counted when it ends, with its whole duration, in the second it ends. A range that stays open for minutes (a training epoch, a thread's whole lifetime) shows up as one spike when it is popped, or not at all if the process exits first.

Labels that change on every call

Labels like decode s3 f120 (stream 3, frame 120) would give every call its own label path and its own tiny bar. So once one parent range has 64 different labels under it (WARPSPAN_NVTX_MAX_CHILDREN), a new label whose last number is all that sets it apart from at least 8 of its siblings gets that number replaced by #: decode s3 f121 becomes decode s3 f#, and all later frames of stream 3 share it. Past 256 children (4 times the setting), the same goes for every number in the label (decode s# f#). Labels that merely contain a number, like conv2d next to conv3d, stay apart, and TensorRT layer names (/model/model.12/…) stay intact unless one range has more than 64 layers that differ only in one number.

Masking depends on order: labels seen before the parent reached 64 children keep their numbers, so a few early frames still have their own bars, and the same label can be masked in one process and not in another. A per-call label with ranges nested inside it (a frame label above TensorRT's per-layer ranges) uses a path per nested range for each of its first 64 values, about 64 × the number of layers.

There are hard limits too, so a long run can't use unbounded memory:

  • In the app: at most 16384 distinct label paths per process (WARPSPAN_NVTX_MAX_LABELS). Past it, a new label is recorded as (more NVTX labels) under its parent range, and the library logs it once and prints the count at exit. The table isn't emptied while the process runs, so once it is full, labels that first appear later (a new code path, a layer of a model loaded later) also land in (more NVTX labels). A per-frame label that masking can't merge (one that differs from its siblings in more than a number) above TensorRT's per-layer ranges uses about one path per layer per frame, so it can fill the table within a few hundred frames.
  • Registered strings and domains (nvtxDomainRegisterString, nvtxDomainCreate) are interned by text, at most 4096.
  • In the agent: the usual cap on distinct samples per process per interval. Past it, new samples lose their span and labels and are counted under the bare kernel name.

For a readable flame graph, keep the changing part out of the range message: put the frame number in the range's payload, which Warpspan ignores and Nsight Systems still shows.

Cost

Pushing a range takes a lock and a hash lookup in the library, on the app thread, and the first push of a new label allocates. Push and pop each read the clock, and a pop adds to two counters. Launching a kernel stores one more 32-bit word. Every second the library's background thread sends the times of the ranges that ended. NVTX ranges are usually coarse (a stage, a layer), so this stays small, but it has not been benchmarked yet.

Example: a TensorRT video pipeline

Argus decodes video streams, runs YOLO11s with TensorRT and encodes the result, and labels every stage with NVTX. Run with the two variables above on 4 streams, every one of its 50,845 kernels came with labels: Argus's own infer batch n=4, TensorRT's enqueueV3, and the TensorRT layer. In a 3-second run on a laptop RTX 3070, 13.6% of the GPU time went to a permutation kernel that TensorRT runs for its layout copies (the layers named … copy and Reformatting CopyNode), next to 68% in the convolutions. A trace or a kernel list alone doesn't show that.

On this page