Systolic Arrays Explained

/model

The cycle-accurate model

The model computes C = AB (A is M × K, B is K × N) on an R × C array. A frame is the state of every register after the clock edge that ends a cycle, computed only from the previous frame and the values entering at the edges, so data moves exactly one PE per cycle. A PE holds up to four registers: s, the stationary operand; h, the operand moving right; v, what moves down (a partial sum, or in output-stationary an operand); and acc, output-stationary's accumulator. Each register holds a tag naming the element of A, B or C it carries, so the captions can say which value is where. Source: reference/systolic.py and its exact TypeScript port src/lib/sa/model.ts.

Dataflows and closed forms

The array block each dataflow needs, what stays in it, where and when each product happens, the cycles of one pass (load, compute and drain) and the partial sums moved between PEs. The tests count all of these from the frames.

DataflowBlockStationaryProductCyclesPartial-sum hops
weight-stationaryK × NB (weights)aₘₖ in PE(k, n) at m + k + nK + (M + K + N − 2)M N (K − 1)
output-stationaryM × NC (outputs)aₘₖ, bₖₙ in PE(m, n) at k + m + n(K + M + N − 2) + MN M (M − 1) / 2
input-stationaryK × MA (inputs)bₖₙ in PE(k, m) at n + k + mK + (N + K + M − 2)M N (K − 1)

For a 128 × 128 × 128 problem on a 128 × 128 array:

DataflowCyclesBuffer readsBuffer writesPE-to-PE hopsPartial-sum hopsRegister writes
weight-stationary51032,76816,3845,201,9202,080,7685,251,072
output-stationary51032,76816,3845,201,9201,040,3847,331,840
input-stationary51032,76816,3845,201,9202,080,7685,251,072

The RTL cross-check

The design is a parameterised N × N output-stationary array with internal skew registers, from the author's Interview RTL challenge (modules pe and systolic_array, vendored unchanged at commit b37984f). rtl/tb_trace.sv drives one matrix multiply as the challenge's own testbench does and prints every accumulator after every rising edge; rtl/check_rtl.py builds it in Verilator 5.020, runs it and compares. Edge p is the model's compute cycle p − 1; after the last product (edge K + 2(N − 1)) the RTL holds its results and pulses valid_out, so there the check requires C = AB. Run with --shift 1, comparing each edge with the next cycle, it reports mismatches in every case: the comparison can fail. The same testbench in Vivado xsim 2025.2 gives byte-identical traces (run locally; CI has no Vivado).

CaseNKValues inEdgesAccumulators comparedMismatchesvalid_out at edge
n4_k4_small44-4 … 514224010
n4_k7_int847-128 … 12717272013
n3_k5_small35-4 … 51311709

The weight-stationary array has its own RTL (below). The input-stationary dataflow is not checked against RTL; it is checked against a direct matrix multiply, its textbook timing and its closed forms.

The processing element against its RTL

Chapter 6's PE is the author's three-stage mixed-precision MAC unit (modules fp16_mul_to_fp32, fp32_add and mac_unit_mixed_precision of the MAC unit challenge, vendored unchanged at commit b37984f as rtl/mac_unit.sv). rtl/tb_mac_trace.sv drives one operation per cycle and prints every pipeline register after every rising edge; the same script compares them with reference/pe.py, which models the unit register for register (FP16 mode: the stage-1 operands, the exact FP32 product, the FP32 accumulator, valid and clear; INT8 mode: the operand bytes, the INT16 product and the INT32 accumulator). With --shift 1 every case reports mismatches. The same five runs in Vivado xsim 2025.2 give byte-identical traces (run locally). The site's bfloat16 mode has no RTL counterpart and is checked against NumPy.

CaseModeOperationsValidDot productsEdgesRegisters comparedMismatches
mac_fp16_demoFP1688211990
mac_int8_demoINT888211990
mac_fp16_wideFP16400331254033,6270
mac_fp16_longFP1640031644033,6270
mac_int8_randINT8400319254033,6270

The weight-stationary array against its RTL

rtl/systolic_array_ws.sv is chapter 5's machine in SystemVerilog, written for this site: an R × C grid of PEs, each with a stationary weight, a shadow weight, an activation and a partial-sum register (valid bit, 2-bit tile tag, value). Weights shift down each column's shadow chain; in load step l rows 0 … l shift and the rows below hold (a per-column step counter restarted by w_first). A PE latches an arriving activation only if its stationary or shadow weight carries the same tile tag, and swaps the shadow weight in on that edge. Row 0 starts each partial sum at zero; a tile of k rows completes its sums in row k − 1. rtl/tb_ws_trace.sv replays the model's edge inputs (the weights entering each column and the skewed activations entering each row, from simulate_ws_stream) and prints every register after every rising edge; edge t + 1 is the model's cycle t. The check compares all four registers of every PE (an empty register's stale bits are not compared), reads the results back from each tile's last row and requires them to equal AB, and records the negative control: every case mismatches against the model one cycle late. The testbench drives the schedule, so this checks the array, not a controller. Two mutations (shifting every shadow row on every load step; latching activations whatever their tile) were each caught by the check when it was written.

CaseM × K × NArrayWeightsTilesEdgesRegisters comparedMismatchesShifted one cycleC = AB
ws_demo6 × 6 × 63 × 3shadow4311,1160511yes
ws_ragged5 × 6 × 64 × 4shadow4261,6640500yes
ws_int88 × 8 × 84 × 4shadow4422,68801,275yes
ws_m11 × 6 × 63 × 3shadow4176120249yes
ws_single6 × 6 × 63 × 3single4521,8720578yes
ws_hbm6 × 6 × 63 × 3shadow, HBM 1 w/cycle, 1 buffer4642,3040542yes
ws_nine12 × 10 × 94 × 4shadow91137,23202,497yes

The panel draws the first case from the simulator's VCD (rtl/ws_wave.json, written by the same script; it checks that the VCD and the printed trace agree) beside the TypeScript model.

Loading the waveform…

Synthesis

rtl/synth_yosys.py synthesises the RTL with Yosys 0.69 (the YoWASP WebAssembly build, pinned in rtl/requirements-synth.txt, so it gives the same netlist on any machine; CI repeats it and fails if rtl/synth.json changes). The MAC unit goes through sv2v 0.0.13 first, because Yosys's front end does not accept its break. Two flows:

DesignGatesFlip-flopsDepthTransistors (est.)7-series LUTsFFsDSP48CARRY4
Weight-stationary PE (INT8, shadow weight)86965669,070133310
Output-stationary PE (INT8)85249628,01011710
MAC unit, INT8 mode only74169517,258663719
MAC unit, FP16 mode only2,49510017419,652705101151
MAC unit, both modes3,23814817626,056812133262
DesignGatesFlip-flopsDepthTransistors (est.)7-series LUTsFFsDSP48CARRY4
Weight-stationary array 4 × 49,13087266102,010228540164
Weight-stationary array 8 × 846,0003,83268493,3909122,144648
Weight-stationary array 16 × 16203,39216,000682,145,5523,6718,52825632
Output-stationary array 4 × 413,59481663128,8702176160
Output-stationary array 8 × 854,3703,45664520,71821,152640
Output-stationary array 16 × 16217,28714,208642,092,47425,5042560
DesignGatesFlip-flopsDepthTransistors (est.)7-series LUTsFFsDSP48CARRY4
Unsigned 4 × 4 multiplier6901448022002
Unsigned 8 × 8 multiplier3430302,4520010
Unsigned 11 × 11 multiplier6800424,8440010
Unsigned 16 × 16 multiplier1,51006310,7560010
Unsigned 24 × 24 multiplier3,45609124,5200020

The arrays scale with their PE count while the logic depth hardly moves: a systolic array's wires are all neighbour to neighbour. The 16 × 16 output-stationary array has 16 times the 4 × 4's PEs and 16.2 times its transistors. The weight-stationary array grows faster (21.0 times), because its top row's PEs need no adder (their partial sums start at zero): a quarter of a 4 × 4, a sixteenth of a 16 × 16. Both arrays expose every PE's registers as ports, as the trace check needs, so no register is optimised away.

Tiles back to back

Chapter 5 adds a shadow weight register to every PE and runs a GEMM's weight-stationary tiles back to back (simulateWsStream). The model checks, every cycle, that a PE swaps in the weight of the tile whose activation has just arrived and that every partial sum meets its next product in step; moving one tile's load or stream a cycle earlier makes it stop with an error. Its cycle counts equal the closed form Sj+1 = max(Sj + M, Lj+1 + kj+1), and with the shadow registers off they equal chapter 4's tiles in sequence.

The lowering against Torch_Sim_Frontend

Chapter 9 lowers a small ONNX model onto the array. scripts/check_simfront.py runs the author's Torch_Sim_Frontend (commit de3acd4) on the same file: its ONNX front end and GEMM rule give the same shapes, and its cycle-approximate array formula the same numbers, on a 8 × 8 array.

Nodesimfront categoryGEMM (batch, M, K, N)simfront cyclesAgree
Convmatmul1 × 36 × 27 × 8151yes
Reluelementwisenone–yes
Flattenviewnone–yes
Gemmmatmul1 × 1 × 288 × 10592yes

Row-stationary, as a reference

For a convolution, Eyeriss's row-stationary dataflow gives PE(i, j) filter row i and input row i + j; each PE slides its filter row along its input row, one MAC per cycle, and each column of PEs adds its rows into one output row. The model runs it too (simulateRs): a 6 × 7 input and a 3 × 3 filter take 17 cycles on 3 × 4 PEs, and the output equals a direct convolution. Chapter 8 animates it.