§ 6.2. Systolic Array¶
A layer of a network computes y = x · W: each output y[j] is the sum
over i of x[i] × W[i][j]. Fetching every number from memory every time it
is used would make the memory the bottleneck. A systolic array keeps one
kind of number still inside a grid of multiply-add cells and passes the
others from neighbour to neighbour, so each number is fetched once and used
many times.
This array is weight-stationary, as in Google's first TPU: cell (i, j)
holds W[i][j]; inputs flow right along the rows, partial sums flow down the
columns, and each column's bottom delivers one output.
| Component | Description | Structural | Behavioral |
|---|---|---|---|
SystolicArray<N> |
N × N MacCells with input skew and output de-skew registers |
Yes | Yes (cycle-exact host model) |
Catalog accelerator.systolic-array.N for N = 2, 4, 8, 16.
IO pins¶
| Pin | Direction | Width | Meaning |
|---|---|---|---|
CLK, RST |
Input | 1 each | Clock; reset clears every register |
SHIFT |
Input | 1 | Shift weights down one row at this edge |
W_IN_j |
Input | 8 each | The weight entering column j's top cell, j = 0 … N−1 |
X_IN_i |
Input | 8 each | Input vector element i, entering row i, i = 0 … N−1 |
Y_OUT_j |
Output | 32 each | Output vector element j |
Behavior¶
Loading weights. Hold SHIFT at 1 for N edges; at the k-th edge put
row N−1−k of W on W_IN_0 … W_IN_{N−1}. Each edge moves every row's
weights one row down, so after N edges row i holds W[i][·]. The array is
not used for anything else meanwhile: with one weight register per cell,
loading costs N edges each time the weights change.
Multiplying. Put a vector x on X_IN_0 … X_IN_{N−1} before an edge e.
After edge e + 2N − 2, Y_OUT_j = Σ_i x[i] × W[i][j] (int32, wrapping).
A new vector may enter at every edge, so a stream of M vectors takes
M + 2N − 2 edges: the array is busy in every cell only while vectors keep
coming.
The timing, edge by edge. Row i's input waits i edges in a chain of skew registers, so it reaches row i just as the sum of rows 0 … i−1 comes down: cell (i, j) adds its product at edge e + i + j. Column j's sum leaves the bottom row at edge e + N − 1 + j, then waits N − 1 − j edges in a de-skew chain, so every column of one output vector appears at the same edge, e + 2N − 2.
C++ reference¶
#include <cstdint>
#include <vector>
// y[j] = sum over i of x[i] × W[i][j], int8 operands, int32 wrapping sums:
// what Y_OUT holds 2N − 2 edges after x entered.
std::vector<int32_t> systolic_ref(const std::vector<std::vector<int8_t>>& w, const std::vector<int8_t>& x) {
std::vector<int32_t> y(w.empty() ? 0 : w[0].size(), 0);
for (size_t i = 0; i < w.size(); ++i)
for (size_t j = 0; j < y.size(); ++j)
y[j] = int32_t(uint32_t(y[j]) + uint32_t(int32_t(x[i]) * w[i][j]));
return y;
}
Unknown inputs and timing¶
Every register captures at the rising edge; reset clears them all. The gates pass X and Z by the four-state rules. The compact array's domain is narrower (below): known values, plus one exact unknown case. Each edge's longest path is one cell's multiply-add, whatever N is, so the clock does not slow down as the array grows.
Implementation¶
Structural implementation¶
| Part | Responsibility |
|---|---|
SKEW_i_k |
Row i's input delay, i registers of 8 bits |
CELL_i_j |
MacCell (6.1.3): its weight, X_OUT to the right, SUM_OUT down |
DESKEW_j_k |
Column j's output delay, N − 1 − j registers of 32 bits |
The top row's SUM_IN is a constant zero; its W_IN comes from outside,
other rows take their weights from the cell above.
Behavioral implementation¶
A gate-level 16 × 16 array is 256 cells of about 700 gates each plus 240 registers; in the unit it would be the slowest part by far. The compact array is one part that keeps every register of the gates (weights, the cells' inputs and sums, the skew and de-skew chains) as host words and updates them at a clean rising clock edge from the values present at that edge, as the gates' registers do. Reset clears them all.
Its contract domain is known values, with one exception kept exact: a product with a known-zero operand is 0 even when the other operand is unknown. That case is real: when the unit gathers a layer whose input count is not a multiple of N, the unused bytes of the last buffer row are never written, and they meet weights that are zero (6.4). The gates give exactly 0 there, and so does the compact array; any other unknown makes the whole affected sum unknown.
Timing. Every array has the same kinds of paths whatever its size: row
0's input into a cell, other rows' inputs into a skew register, weights into
a cell, outputs from a cell or a de-skew register. The compact array of any
size runs on the delays the timing analyzer proves on the gate-level
SystolicArray<2>, assigned to the matching pins.
Examples¶
W = [[1, 2], [3, 4]] is shifted in (row 1 first), then x = (5, 6) and
x = (1, 0) enter on consecutive edges. y = (5·1 + 6·3, 5·2 + 6·4) = (23, 34)
appears 2N − 2 = 2 edges after x, and (1, 2) one edge later. The scenario
opens in the Gate profile (13,077 parts, a few seconds to load). The
simulator draws the array as its grid: CELL_i_j in row i and column j,
row i's SKEW_i_k registers to its left and column j's DESKEW_j_k
registers below it, so the staircase of delays is visible.
All 8 recorded rows of SystolicArrayWidth2ScenarioTest, in checkpoint order. Outputs are test expectations verified against the simulation. Time is the absolute settled checkpoint time in simulator units, not milliseconds or CPU cycles.
Default scenario profile: fidelity-gate-v1 / structural (ed03f70afe360dba). Changing fidelity or the circuit can change these times.
| Checkpointzero-based number · timeline label | Timesimulator units | CLKInput · 1 bit |
RSTInput · 1 bit |
SHIFTInput · 1 bit |
W_IN_0Input · 8 bit |
W_IN_1Input · 8 bit |
X_IN_0Input · 8 bit |
X_IN_1Input · 8 bit |
Y_OUT_0Expected output · 32 bit |
Y_OUT_1Expected output · 32 bit |
|---|---|---|---|---|---|---|---|---|---|---|
#0reset | 30 | 0 |
1 |
0 |
0x00 |
0x00 |
0x00 |
0x00 |
not checked | not checked |
#1ready | 43 | 0 |
0 |
0 |
0x00 |
0x00 |
0x00 |
0x00 |
0x00000000 |
0x00000000 |
#2shift-row-1 | 59 | 1 |
0 |
1 |
0x03 |
0x04 |
0x00 |
0x00 |
0x00000000 |
0x00000000 |
#3shift-row-0 | 85 | 1 |
0 |
1 |
0x01 |
0x02 |
0x00 |
0x00 |
0x00000000 |
0x00000000 |
#4x-5-6 | 125 | 1 |
0 |
0 |
0x00 |
0x00 |
0x05 |
0x06 |
0x00000000 |
0x00000000 |
#5x-1-0 | 170 | 1 |
0 |
0 |
0x00 |
0x00 |
0x01 |
0x00 |
0x00000000 |
0x00000000 |
#6y-23-34 | 211 | 1 |
0 |
0 |
0x00 |
0x00 |
0x00 |
0x00 |
0x00000017 |
0x00000022 |
#7y-1-2 | 231 | 1 |
0 |
0 |
0x00 |
0x00 |
0x00 |
0x00 |
0x00000001 |
0x00000002 |
Scroll within the table for all rows and pins. Buses use hexadecimal; values containing X/Z use MSB-first binary. Inputs show the declared values in effect at each checkpoint, including retained inputs. Sequential tests also replay preparation changes between checkpoints, such as lowering the clock. Use the matching checkpoint label in the simulation below.
Source and tests¶
Gate-level array, compact array and its timing, interface, tests.
| Test | Coverage |
|---|---|
SystolicArrayTest |
Random weights and vectors with ±127/−128 bursts: N = 2 and 4 on gates and compact, N = 8 and 16 compact; every output vector checked against the integer reference exactly 2N − 2 edges after its input; an unknown input meeting zero weights gives known sums on both forms |
SystolicArrayWidth2ScenarioTest |
The recorded example above, both available fidelities |
No test drives reset in the middle of a stream, and the gate-level arrays checked are N = 2 and 4; the larger ones are checked on the compact form only.