What this is about
A graphics card is a hall full of small workers. A kernel is the one set of instructions you hand to all of them at once, with each worker applying it to its own piece of the data. "Kernel" here has nothing to do with the operating system's kernel. It just means a small program that runs on the card.
When you run a model, the card runs a list of kernels, one after another, for every token. Model speed is the sum of how long each takes. This article explains what a kernel is, in pictures and without math, and what we have learned about making them fast.
Why it matters
When people say one engine is faster than another, they usually mean that its kernels are better. The model's design is the same. The numbers are the same. What differs is how the work is cut up, how data is moved, and how many times the card has to be told to start something.
If you know what a kernel is, you can read results like "one launch per token" or "tile size" without feeling lost.
How it works
Imagine you need to paint a thousand fence boards. You hand each of a thousand painters one board and the same instruction: "paint it olive." That instruction is the kernel. The painters are threads. The card runs them in small teams that move in lockstep. On our card a team has 32 workers, called a wave.
Three things decide how fast the painting goes.
1. How many launches. Every time you tell the card to start a new kernel, there is a small delay while it gets going. If a job needs thirty kernels, you pay for thirty starts. When the actual sums are small, those starts add up. For one token of text, our engine used to launch about thirty small kernels, one per weight table in each layer. We changed it to one launch that holds the card for the entire token, all 32 layers and the final choice. Same weights, no other change. Plain decode went from 67.13 to 81.98 tokens per second, a gain of about 22 percent, and the output was the same on all 20 prompts. On another model, we removed 100 launches that did nothing, checked by counting them in a trace, and got a gain of 1.055 times.
2. How the work is cut into pieces. A big multiplication is split into tiles. One tile size does not suit every job. Our first matrix kernel used one large tile and lost to the vendor library at small sizes, running at 0.78 to 0.98 times its speed. A big tile leaves many workers with nothing to do when the job is small. When we let the launcher pick a smaller tile for small jobs, it flipped to 1.01 to 1.18 times at the three small sizes, and ahead at all ten sizes we tested.
3. How long the workers wait for data. This is the one that surprises people. The sums are fast. Fetching the numbers from memory is slow. Writing one token needs every weight in the model to stream past the workers once, and that streaming is most of the job. For a single token, one multiplication has the shape of one row of numbers against a big table. A lot of the time the card is waiting for the table.
What waiting looks like
We built a tool, wavewait, to show it. For each instruction in a kernel, it shows how many cycles the workers waited before that instruction could run, and why. The reason might be memory, a shared on-chip memory called LDS, a barrier where all workers must meet, or a dependency on an earlier result.
Here is what it found for our small model's attention kernel. Between 55 and 68 percent of the cycles went to the on-chip shared memory, and only 20 to 23 percent to math. The card was mostly waiting on a small memory, not on arithmetic. The fix was to keep two tables in the workers' own registers instead of writing them to the shared memory. That cut the time of one kernel by 22 to 24 percent and another by 17 percent per launch.
Some ideas we tried lost. Moving two loads before a barrier made one kernel 16.9 percent slower. Using 16 waves per block gained nothing. We noted not to try them again without a new reason.
One shape that matters most
For writing text, the key job is a one-row multiplication against a table about 100 MB in size. We measured it carefully. The card has a 96 MB cache, but the model is many gigabytes, so by the time the next token needs a table again, it is long gone from the cache. Each launch really streams from memory.
Our kernel for this shape took 121.2 to 121.8 microseconds. The vendor library took 122.1 to 123.3. The ranges do not overlap, but the margin is about 1 percent. The win did not come from reading fewer bytes. It came from making the kernel smaller so that more workers could be active at once, which keeps more memory requests in flight. Two earlier rounds that tried to cut bytes both failed their predictions.
What this does not show
All of this is one card, an RX 7900 XTX. A different chip can have a different team size, a different shared memory and different best tile sizes. We do not claim any of these numbers transfer. And a faster kernel is not a faster engine until the rest of the token's work is measured too.
Words you may not know
- Kernel: a small program run by many workers on the card at once.
- Thread: one worker on the card.
- Wave: a team of 32 threads that move in lockstep on our card.
- Launch: telling the card to start a kernel.
- Tile: a block of a big job that one team handles.
- LDS: a small, fast memory shared by a team, on the chip.
- Register: the very fast storage inside one worker.
Try it
- Look at where a kernel waits with wavewait. The page has a small example kernel called saxpy and the three commands to trace it. It needs an RDNA3 card.
- See kernels in a full engine on the mojo-baro project page, including the results table with dates.
- A home exercise with no card at all: when you look at any speed claim, ask "how many launches" and "what was it waiting on".
Read next
- Measure the Kernel Before the Idea, the registers and shared-memory story in full.
- The Shape That Actually Matters, the single-token kernel and its four rounds.

Komentarze
Brak komentarzy.
Zaloguj się aby skomentować.