Metrics tell you a service is slow; profiling tells you why. This lesson gives you the one model that explains most GPU performance questions, the roofline, and uses it to show exactly why decode is memory-bound and prefill is compute-bound, and when batching flips decode from one to the other. Then it covers the measuring tools in order of depth: nvidia-smi for a glance, DCGM metrics for fleets, Nsight Systems for timelines, and Nsight Compute for individual kernels.
- Compute arithmetic intensity and the ridge point of a GPU
- Use the roofline to classify a workload as compute-bound or memory-bound
- Predict how batch size changes decode from memory-bound toward compute-bound
- Choose between nvidia-smi, DCGM, Nsight Systems and Nsight Compute for a question
- Read GPU timeline gaps that point to CPU, synchronisation or communication stalls
Arithmetic intensity and the roofline
Every piece of GPU work does some floating-point operations (FLOPs) and moves some bytes to and from memory. Its arithmetic intensity is FLOPs per byte moved. A GPU has a peak compute rate (FLOP/s) and a peak memory bandwidth (bytes/s); their ratio is the ridge point. Work with intensity below the ridge cannot use all the compute because memory cannot feed it fast enough: it is memory-bound. Work above the ridge is compute-bound.
peak compute = 1,000 TFLOP/s (dense FP16 Tensor Core)
peak bandwidth = 3.3 TB/s
ridge point = 1,000e12 / 3.3e12 ~ 300 FLOPs per byte
attainable FLOP/s = min(peak compute, intensity x peak bandwidth)Plot attainable performance against intensity on log axes and you get a slanted line (bandwidth-limited) meeting a flat roof (compute-limited) at the ridge. Every optimisation either raises a kernel's intensity, moving it right toward the roof, or makes it run closer to the line it is already under.
Placing prefill and decode on the roofline
A forward pass costs about 2 FLOPs per parameter per token. In FP16 each parameter is 2 bytes. During decode at batch size B, the weights are read once and used for B tokens, so intensity is roughly 2B FLOPs over 2 bytes, about B FLOPs per byte. At batch 1 that is about 1, far below a ridge of around 300: the GPU uses well under 1% of its compute. At batch 64 it is about 64: much better, still memory-bound. Reading the KV cache adds bytes without many FLOPs, so long contexts push decode further toward the memory side.
Prefill of a 2,000-token prompt uses each weight for 2,000 tokens, an intensity in the thousands, well past the ridge: compute-bound. That is the roofline explanation of everything in the lifecycle lesson, and it predicts what helps: for decode, bigger batches, fewer bytes per weight (quantization) and faster memory; for prefill, more Tensor Core throughput and less redundant work (prefix caching).
Quantizing weights to FP8 halves the bytes per parameter, which both halves memory traffic and doubles intensity. That is why it speeds up memory-bound decode almost proportionally, even before faster FP8 Tensor Core maths is counted.
Measuring: from a glance to a kernel
| Tool | Answers | Cost |
|---|---|---|
| nvidia-smi | Is the GPU busy at all? Memory used? Throttling? | Free, instant |
| DCGM + dcgm-exporter | Per-GPU utilisation, Tensor Core and memory activity over time, across a fleet | Always on, Prometheus |
| Nsight Systems (nsys) | Timeline: where time goes across CPU threads, CUDA kernels, memory copies, NCCL | Minutes, per run |
| Nsight Compute (ncu) | Why one kernel is slow: achieved bandwidth and FLOPs versus peak | Slow, per kernel |
DCGM's profiling metrics are the useful upgrade over nvidia-smi's coarse utilisation: DCGM_FI_PROF_PIPE_TENSOR_ACTIVE shows how busy the Tensor Cores really are, and DCGM_FI_PROF_DRAM_ACTIVE shows how busy the memory interface is. A decode-heavy server typically shows DRAM activity high and Tensor activity low, the memory-bound signature in production. Some fields, such as SM activity, are commented out in the exporter's default counter list and must be enabled.
# timeline of CPU threads, CUDA kernels, memory copies and NCCL calls
nsys profile -o decode_run --trace=cuda,nvtx,osrt python bench.py
nsys stats decode_run.nsys-rep
# detailed counters for the first 5 matmul-like kernels
ncu --kernel-name regex:gemm --launch-count 5 --set full -o gemm python bench.pyReading a timeline
- Gaps between kernels on the GPU row with CPU activity at the same moment: the CPU is too slow to launch work (scheduling, tokenization, Python overhead). Engines use CUDA graphs to cut launch overhead for exactly this reason.
- Long memory copies between host and device in the steady state: something is being moved over PCIe each step that should stay on the GPU.
- NCCL kernels taking a large share of each step in a multi-GPU run: communication is the bottleneck, covered in the parallelism stage.
- One kernel dominating: profile it with Nsight Compute and compare achieved memory bandwidth with the GPU's peak. Near peak means it is already as fast as the hardware allows at that intensity.
Profile short, representative runs. A few seconds of steady-state decode at your real batch size tells you more than an hour of traces, and Nsight output for long runs gets unwieldy fast.