LAB / GPU PROGRAMMING

DAY 18 / 30 · WRITING CUDA · ~12 MIN READ

Reading an Nsight trace

What a real profiler trace tells you, and which numbers actually matter first.

01 · Two tools, two questions

"Where did the time go?" and "why is this kernel slow?"

NVIDIA ships two profilers and they answer different questions. Nsight Systems is the timeline: every kernel, copy, and sync across the whole program, as rows on a Gantt chart. It answers where the time went — gaps between kernels, serializations day 17 was supposed to remove, launch-bound stretches where the GPU sits idle between tiny kernels. Nsight Compute goes inside a single kernel and answers why — occupancy, memory throughput, bank conflicts, stall reasons.

The order matters: Systems first, Compute second. Profiling a kernel deeply before checking whether it's even running back-to-back with a gap is polishing an engine in a car that's stuck in traffic.

02 · The first screen: speed of light

Two bars, and the higher one is your ceiling

Nsight Compute opens each kernel with the SOL (speed of light) section — how close each subsystem runs to its theoretical maximum. Here's the panel for a hypothetical kernel, drawn the way the tool would show it:

NSIGHT COMPUTE · SOL PANEL · MATMUL_TILED, N=4096
DRAM THROUGHPUT87%
COMPUTE (SM) THROUGHPUT22%
L2 CACHE THROUGHPUT44%
ACHIEVED OCCUPANCY61%

DRAM at 87% is the limiter: this kernel is memory-bound — and day 11's chart predicted it (tiled matmul, intensity ~4, ceiling ~7% of compute peak). The fix is structural — more reuse — not micro-tuning. Compute and L2 both idling confirm nobody else is the bottleneck.

simplified: real SOL panels carry pipe utilization, issue-slot and SM-busy metrics too — the two bars shown are the ones to read first.

The rule is almost comically simple: the tallest bar is the wall; the others are suspects only if all bars are low. Both bars low means neither memory nor compute is saturated — the kernel is latency-bound, and day 06's occupancy or day 01's latency hiding is broken.

03 · The numbers to check first

Four metrics, each pointing at a chapter

Nsight Compute reports hundreds of counters; you need four before coffee. Each one maps to a day you've already read, which is the quiet payoff of the first two weeks:

ACHIEVED OCCUPANCY

how many warps were really resident to hide latency (day 06) — compare against the theoretical ceiling

MEMORY THROUGHPUT %

which level of the hierarchy is the limiter (day 10) — DRAM, L2, or shared

BRANCH EFFICIENCY

warp divergence cost (day 05) — day 16's stride-form fix shows up here

SHARED BANK CONFLICTS

serialized SRAM reads (day 08) — and day 09's spill counts sit in the same report

If you remember day 11's roofline, the SOL panel is that chart with the achieved position filled in: memory throughput % tells you which ceiling you're near, and how close you got tells you whether to fix the kernel or restructure the algorithm.

04 · The workflow

Measure, hypothesize, change one thing, measure again

The tool earns its keep through the loop, which is worth writing as a checklist because every experienced kernel engineer runs some version of it: (1) profile the baseline and write the number down — achieved GB/s or GFLOPS, and the SOL bars; (2) form one hypothesis — "uncoalesced column reads," "occupancy capped by registers," "divergent reduction"; (3) make exactly one change; (4) re-profile and compare against the written number; (5) keep the change or revert it, no sentiment. Two changes at once and the numbers can no longer attribute credit — the loop collapses into vibes.

That's the whole discipline. Day 28 runs it end-to-end on the day-16 reduction — five rungs from ~20% to ~88% of bandwidth, each one visible in a single metric — and it's the same loop you'll run on day 29's capstone. Everything left in this journey is material for it.

CHEATSHEET · DAY 18
  • 01Nsight Systems for 'where', Nsight Compute for 'why'. Timelines expose gaps and serializations; per-kernel metrics expose occupancy, throughput, and stalls. Always in that order.
  • 02The tallest SOL bar is the wall. Memory % up high: memory-bound, restructure data flow. Compute % up high: compute-bound, optimize math. Both low: latency-bound, check occupancy.
  • 03Four counters cover most diagnoses. Achieved occupancy (day 06), memory throughput (day 10), branch efficiency (day 05), bank conflicts and spills (days 08–09).
  • 04One change per measurement, always. Write the baseline down, change exactly one thing, re-profile. Attribution is the entire value of the loop.

Next: day 19 — a new phase. Why Triton exists: the tax of hand-indexed CUDA, and the bet that the compiler should own the lanes.

get in touch