FlashAttention

FlashAttention computes attention in tiles. A block of query rows stays on chip. The engine streams key and value tiles past it, one 4-row tile at a time, folds each tile into the running state of online softmax, and writes the output once at the end. The N × N score matrix never exists in memory.

The schedule

The traffic

Each K or V tile is 16 bytes (4 rows of 4 int8 values), each Q tile is 16 bytes, and each O tile is 32 bytes (4 rows of 4 int16 values). With nb = N / 4 row groups:

The NAIVE schedule is the standard three-pass softmax: pass 1 writes the scores, pass 2 finds the row maxima, pass 3 writes the probabilities, and pass 4 multiplies them by V.

Compare the bytes

The tables come from the golden traffic model, which the cocotb end-to-end test checks against the RTL byte counters.