Checking how many agents are working

How this works
Kontakt
← Blog
A dark graphics card seen from the side with olive threads of light queued up at one gate and a small teal timer, the AMARBARO mark centered.
✎Blogbeitrag

wavewait: seeing what a graphics card waits for

The short version

A per-instruction stall table from the hardware trace names the cause of each wait on a gfx1100 kernel and agrees with AMD's own decoder.

Part 4 of 20 in Tools we built and why. Previous: corewait: asking your CPU why a program is slow · Next: mokei: counting the lines and tokens in your code

What this is about

A graphics card, or GPU, does a huge amount of work at once. It runs small teams of threads, called waves, side by side. A kernel is the program those waves run. A kernel can look busy and still be slow, because each wave spends a lot of its time waiting. It waits for data from memory, for other waves to catch up, or for the result of an earlier step.

wavewait shows those waits. You give it a real trace from an AMD RDNA3 card, such as the RX 7900 XTX. It tells you, for every instruction of the kernel, how many cycles each wave waited before the instruction could start, and it names the cause.

Why it matters

Making a kernel faster is guesswork unless you know what it waits for. A listing might show one cheap-looking line, a wait for memory, that is actually the cost that matters. In our example the wait was 670 cycles. If you do not see that line, you may spend a week making the arithmetic faster while the real delay sits in a different place.

This is the same lesson we learned on a phone GPU. In The Counters Said ALU, and the Loads Were the Cost, the counters named one bucket, but the real lever was a different thing: the number of loads. A tool that points at the instruction saves that detour.

How it works

The input is a thread trace, a recording that the GPU itself writes of what its waves did. It is not a sampled guess.

There are two ways to capture one.

  1. rocprofv3 ATT, for any HIP program. AMD's thread trace is taken from compute unit 3 in shader engine 0. A wrapper script adds a size cap, a timeout, and a watcher that stops the run if ROCm reports a failed buffer.
  2. tinygrad's KFD runtime, for one workgroup of a kernel. It has more limits, so for real programs use the first path.

wavewait then decodes the trace packets itself, in Mojo, and charges cycles to the instruction that held the wave. With the --causes option the cost moves onto the wait instruction that held the wave, and each row gets a label: wave start, memory, LDS or scalar memory, barrier, dependency, and so on.

On the saxpy example, a small program that computes a times x plus y, the causes split like this: 27% wave start, 25% LDS or scalar memory, 21% memory, and 21% memory plus LDS.

How do we know the table is right? We check it against AMD's own decoder. A script compares every captured trace with AMD's code.json, and each wait instruction must agree within one cycle per wave.

How to do it, step by step

The project page gives this sequence for the saxpy example.

  1. Compile the program for your card: hipcc --offload-arch=gfx1100 -O3 examples/saxpy.hip -o .work/att/saxpy.
  2. Capture the trace with rocprofv3 --att --att-target-cu 3 --att-shader-engine-mask 0x1 --att-library-path <decoder dir> -d .work/att/run -- .work/att/saxpy.
  3. Convert it with tools/from-att.sh .work/att/run .work/att/saxpy_att.
  4. Read it with build/wavewait .work/att/saxpy_att --causes --top 10.

A capture needs hipcc, rocprofv3 and AMD's rocprof-trace-decoder library. A script called tools/doctor.sh reports what your machine is missing.

Other commands: wavewait rank RUNDIR lists every kernel of a whole process with its share of time, and wavewait diff A B compares two captures row by row so you can see whether a change helped.

What it does not prove

  • It works only on RDNA3 (gfx1100) and was tested on one RX 7900 XTX.
  • The ATT path traces only the workgroups that land on compute unit 3.
  • On this hardware generation the trace has no per-lane execution mask, so divergence is counted per wave, not per lane.
  • The energy split from --by-class is a cycle-share model, not a measured split of power.
  • On one torch matmul, a few wait rows differ from AMD's decoder by about 2.4 cycles per hit, while totals stay within 0.12%.
  • One command, sim, is not built yet. It exits with status 2.

A worked picture

Think of a kitchen with many cooks who all follow the same recipe. A cook who needs an ingredient from the far storeroom stands idle until it arrives. In a listing of the recipe, that step looks like one short line: fetch ingredient. In a trace it is the line where every cook stands still. wavewait finds that line and tells you how long the cooks stood there. If the cause is memory, you change how the ingredients are fetched. If the cause is a barrier, where cooks must all finish a step before moving on, you change how the work is split. The table does not fix the kernel for you. It points at the right line, which is most of the battle.

Words you may not know

  • GPU: a graphics processing unit, the chip on a graphics card.
  • Kernel: the program that runs on the GPU.
  • Wave: a small team of GPU threads that run in step.
  • Trace: a recording of what the hardware did, in order.
  • Cycle: one tick of the chip's clock.
  • Stall: waiting instead of working.
  • Oracle: a trusted decoder we compare ours with.
  • LDS: a small, fast memory that the waves of one workgroup share.
  • HIP and ROCm: AMD's language and software stack for running programs on its graphics cards.

Try it

  • Read the wavewait project page.
  • Get the code at github.com/amarbarosys/wavewait. The latest release, v1.2.0, is dated 2026-11-28.
  • If you have an RX 7000-series card and ROCm, run the saxpy example first and read the --causes summary.
  • If you do not have such a card, read the project page anyway. The wait table is the idea, and the page shows what one looks like.

Kommentare

Noch keine Kommentare.

Anmelden um zu kommentieren.