Start with the latency you care about

Measure request time for a service, iteration time for a training loop, or items per second for a batch job. Use representative input sizes, warm up the workload, and record the GPU, software versions, input shapes, precision, and batch size. A fixed baseline makes it easier to tell whether a change improved performance or merely shifted work outside the timer.

CUDA work is often asynchronous. A host timer that stops as soon as a launch returns can miss the execution entirely. To measure device work, record CUDA events on the stream that runs the work and wait for the closing event. For end-to-end timing, measure wall-clock time through actual result completion. See the CUDA Best Practices Guide on timing.

Capture a short system timeline

Use Nsight Systems to see CPU activity, CUDA calls, transfers, and GPU kernels on a shared timeline. NVTX ranges can label the parts you already recognize, such as input preparation, forward pass, and postprocessing. For a small standalone benchmark, a starting capture is nsys profile --trace=cuda,nvtx -o timeline ./benchmark. See the Nsight Systems user guide.

Timeline clues and experiments
What you seeWhat to investigate
Long gaps before kernels launchCheck input preparation, CPU scheduling, synchronization, and host-side dispatch.
Copies on the critical pathCheck whether intermediate data can stay on device or whether independent copies and compute can overlap.
Many short kernels with launch gapsMeasure launch overhead and test whether compatible operations can be fused.
A kernel dominates the critical pathCollect kernel-level counters and check which hardware resource limits it.

Profile the kernel that can move the baseline

Use Nsight Compute on a representative invocation. Start with compute and memory throughput, then inspect memory traffic, cache behavior, or stall reasons as the evidence warrants. A roofline chart relates achieved performance to the work performed per byte moved. It can help distinguish compute and bandwidth limits. A point well below both ceilings calls for more investigation. See the Nsight Compute profiling guide.

Consider a synthetic workload with an 8 ms request and a 2 ms kernel on its critical path. A twofold kernel speedup saves 1 ms, yielding a 7 ms request if the other work stays fixed. That gives you a concrete way to weigh the kernel change against a potential saving elsewhere in the trace.

Validate without the profiler

Change one thing and rerun the baseline with the same inputs and timing boundaries. Check outputs against the reference and compare repeat runs. Profiling can add overhead or change execution behavior, so use the trace to diagnose the workload and the unprofiled baseline for the final performance comparison. The Nsight Compute guide describes where profiling overhead comes from.