npx skills add ...
npx skills add nvidia/tensorrt-llm --skill perf-workload-profiling
Code instrumentation for timing workloads. Two scenarios: (1) Training loop — inject manual timing to report per-iteration latency, throughput (samples/sec), and data load time. (2) Standalone kernel/op — write CUDA event timing code with warmup, per-iteration statistics, and anti-pattern avoidance. Also covers NVTX annotation for labeling profiler timelines. NOT for: running or analyzing profiler tools (nsys, ncu, Nsight Systems, Nsight Compute), writing kernels (Triton, CuTe, CUDA), applying optimizations (CUDA Graphs, gradient checkpointing, fusion), or interpreting roofline/SOL% metrics. Triggers: "measure throughput", "benchmark this function", "time my training loop", "samples per second", "NVTX annotate", "instrument my dataloader", "data load time", "kernel timing", "how do I time".
npx skills add nvidia/tensorrt-llm --skill perf-workload-profiling
Pick ONE path based on the workload type:
| Workload | Approach | Section |
|---|---|---|
| Training loop | Manual torch.cuda.synchronize() + time.perf_counter() with warmup | Loop Workloads — Manual Timing |
| Single kernel or op | Write CUDA event benchmark (pre-allocate, warmup, event pairs) | Non-Loop Workloads — CUDA Event Benchmarking |
| Add timeline labels for nsys | Use @nvtx.annotate decorator or context manager | NVTX Reference |
time.perf_counter()) include host overhead and miss asynchronous execution.torch.cuda.synchronize() adds 10-50us overhead. Record CUDA events asynchronously, sync once at the end.cute.compile().For training loops and iterative workloads, use manual torch.cuda.synchronize() + time.perf_counter() timing with warmup to measure per-iteration latency, throughput, and data load time.
Read the user's training script, understand the dataloader and loop structure, then inject timing code.
data / iter > 0.2, data loading is a bottleneck.Manual timing reports aggregate iteration timing — not per-sub-phase breakdown (forward, backward, optimizer). When the user asks where time is spent within compute:
torch.cuda.synchronize() + time.perf_counter() around each sub-phase for a one-off diagnosis, ORnsys profile for timeline visualization.For single kernels, one-shot inference, or standalone operations, write CUDA event benchmarking code directly.
| Anti-Pattern | Problem |
|---|---|
torch.cuda.synchronize() before AND after each iteration | Adds ~10-50us overhead per iteration |
time.perf_counter() for GPU timing | Measures CPU time, misses async GPU execution |
| Missing warmup | First iterations include JIT, clock ramp-up, context init |
| Allocating tensors inside measurement loop | Allocation overhead pollutes timing |
| Reporting only mean | Hides variance, outliers, bimodal distributions |
For additional benchmarking templates (CUDA Graph, CuTe DSL, Triton, Raw CUDA), see references/benchmarking-patterns.md.
NVTX (NVIDIA Tools Extension) adds named annotations to profiler timelines. Use NVTX to label phases (forward, backward, optimizer) for readability in nsys — not for measurement.
For NVTX domains, categories, payloads, and legacy API details, see references/nvtx-api.md.
device_time vs deprecated cuda_time)