SimulatorApplied engineering
Multiplying in blocks
Two matrices are multiplied in two orders that do exactly the same work: straight through, and tile by tile. A small cache holds the lines read most recently. Count how often each order misses it.
- A times B gives C; the coloured squares are the tiles in use
- grey bar: cache misses in the plain order · coloured bar: in tiles
- Cache misses, plain order
- 3,744
- Cache misses, in tiles
- 1,872
- Plain order misses
- 2.0 times as often
- Elements read in all
- 41,472
Shrink the cache, then find the tile size that fits it. A tile as large as the matrix is the plain order.
What the simulator does
- Every order reads the same three elements for each of the n cubed steps; only the sequence differs.
- Straight through, the second matrix is read down its columns, and a small cache has forgotten each line before it is wanted again.
- Working through tiles that fit in the cache reuses what is already there. The counts are exact for the cache modelled here.
In Verace FastKernel
Schematic: the array library multiplies two strided arrays tile by tile, with each OpenMP thread owning an output tile and the inner loop vectorized with SIMD.
- Tile of 64
- One block of the inner dimension, sized for cache
- OpenMP threads
- Each thread owns its own output tiles
- Output tile
- Products accumulated into the result block
- Vectorized column loop
- Columns swept with SIMD in the innermost loop
What this is not
This simulator is an illustration of the principle, with made-up numbers. It does not run the lab's code or show the lab's data, and nothing in it is a measurement.
Read the write-up