The course

Beyond GEMM · 1/3

8×8 panel · four 4×4 tiles

01 Chapter 2 · pack

Pack

An 8-wide row-major panel stores a 4-wide chunk contiguously in its row and four addresses away on the next row. Pack copies each 4×4 tile into one run.

Instruction
source  address = row·8 + col
pack    4×4 tile → 16 contiguous addresses

The number in each cell is the source address, row·8 + col. Four tiles cover the 8×8 panel. Each packed tile is 16 contiguous addresses. Inside a row the four values are adjacent; the next row of the same tile starts eight addresses later in the panel and only four later in the packed run.

row-major · address = row·8 + col

packed · four tiles, 16 addresses each

pack · strided source, contiguous run

Four tiles. Play, and watch a chunk of four move.

Arrow keys step, space plays or pauses.

Reading the picture

  1. The next row skips

    Inside a row the four values are adjacent. The next row of the same tile starts eight addresses later in the panel and only four later in the packed run, so the source skips four addresses and the packed side skips none.

  2. Unit stride is the point

    A microkernel wants a contiguous vector load. Pack pays the strided reads once, then every k step is a unit-stride load. The copy is the layout fix, not the arithmetic.

  3. The same habit in front of QKᵀ and PV

    The GEMM microkernel packs A and B before the K loop. Attention's two matrix multiplies want the same panels. Memory in flight is what happens to those bytes after they are packed. Open the microkernel Open memory in flight Open attention

Each cell shows its source address. Packed addresses run 0–63, tile by tile.