6.5.7Advanced & Emerging Architectures

Google TPU architecture and systolic arrays

2,326 words11 min readdifficulty · medium

WHY does the TPU exist?

The WHY: Consider a fully-connected layer y=Wxy = Wx. To compute it, you must do many multiply-accumulates. On a CPU each MAC involves:

  • fetch weight from register/cache,
  • fetch activation,
  • multiply, add to accumulator,
  • write accumulator back.

The arithmetic is cheap; the data movement dominates energy and time. This is the memory wall. The fix: build hardware where a value, once loaded, is reused maximally before it leaves.


WHAT is a systolic array?

Key properties (WHAT to remember):

  • Local wiring only → short wires → fast clock, low energy.
  • Massive reuse → each operand read from memory once, used by a whole row/column.
  • No instruction fetch per op → the dataflow is the program.
Figure — Google TPU architecture and systolic arrays

HOW does it compute a matrix multiply? (Derivation from scratch)

We want C=A×BC = A \times B where AA is m×km\times k and BB is k×nk\times n. Element:

Cij=p=1kAipBpjC_{ij} = \sum_{p=1}^{k} A_{ip}\,B_{pj}

Step 1 — map the sum onto a grid. Put PE (i,j)(i,j) in charge of computing CijC_{ij}. It must accumulate kk products. So each PE needs an internal accumulator:

accijaccij+AipBpj\text{acc}_{ij} \leftarrow \text{acc}_{ij} + A_{ip}B_{pj}

Why this step? Each output needs its own running sum, so accumulation must be local to the cell.

Step 2 — deliver operands without global memory. In a weight-stationary array (what the TPU uses), preload weights BpjB_{pj} into the cells (weight stays put). Then stream activations AipA_{ip} horizontally left→right, and stream partial sums vertically top→bottom.

At each clock a cell does: partialout=partialin+ainwstored,aout=ain\text{partial}_{\text{out}} = \text{partial}_{\text{in}} + a_{\text{in}}\cdot w_{\text{stored}}, \qquad a_{\text{out}} = a_{\text{in}}

Why this step? aout=aina_{\text{out}}=a_{\text{in}} means the activation is passed along to the next cell — that's the one-read-many-uses trick.

Step 3 — skew the input (staggering). Because it takes cell (i,j)(i,j) some cycles for data to reach it, inputs are fed diagonally staggered (each row delayed by one clock). This keeps every cell busy on the right operands at the right time.

Step 4 — count the cost. A naïve implementation of an n×nn\times n multiply reads O(n3)O(n^3) operands from memory. The systolic array reads each of the 2n22n^2 input values once and does n3n^3 MACs inside — so the arithmetic intensity is:

Arithmetic intensity=n3 MACs2n2 reads=n2\text{Arithmetic intensity} = \frac{n^3 \text{ MACs}}{2n^2 \text{ reads}} = \frac{n}{2}

Why this matters? Higher arithmetic intensity = fewer memory accesses per compute = you break through the memory wall. For a 256×256256\times256 array that's ~128 MACs per byte fetched.


The full TPU block diagram (WHAT sits around the array)

  • Matrix Multiply Unit (MXU) — the 256×256 systolic array. The workhorse.
  • Weight FIFO — feeds weights from off-chip DRAM into the array.
  • Unified Buffer (UB) — large (24 MB) on-chip SRAM holding activations; feeds the array and stores results. Keeps activations on-chip → avoids DRAM round-trips.
  • Accumulators — collect the column partial sums coming out the bottom.
  • Activation unit — applies ReLU / pooling etc. after the multiply.
  • No cache, no branch predictor, no out-of-order — deliberately simple; all die area goes to arithmetic. This is the domain-specific bet.

Worked examples


Common mistakes (Steel-manned)


Flashcards

What does "systolic" refer to in systolic array?
The heartbeat-like rhythmic pumping of data cell-to-cell each clock (from systole).
What is the core computational unit in a systolic array?
A multiply-accumulate (MAC) cell wired only to its nearest neighbours.
Why does a systolic array beat a CPU for matmul?
It reads each operand once and reuses it across many cells, breaking the memory wall (high arithmetic intensity).
What is the peak throughput of an N×N MAC array at clock f?
2N2f2N^2 f FLOP/s (N² cells, 2 FLOPs each per clock).
What is TPUv1's array size and rough throughput?
256×256 MAC array, ~92 TOPS at ~700 MHz (8-bit).
Was TPUv1 used for training or inference?
Inference only (8-bit integer). Training on TPUs began with TPU v2+ (bfloat16 floating point).
In a weight-stationary array, what stays put and what streams?
Weights are preloaded and stay in cells; activations stream horizontally, partial sums stream vertically.
What is arithmetic intensity of an N×N systolic multiply?
~N/2 MACs per operand read.
Why do systolic arrays favor large batches?
A fixed ~2N−1 pipeline fill/drain cost is amortized only when M ≫ N.
What is the Unified Buffer in the TPU?
Large on-chip SRAM (24 MB) holding activations so they never round-trip to DRAM.
Name three CPU features the TPU deliberately omits.
Caches, branch prediction, out-of-order execution (die area goes to arithmetic instead).
The per-cell update equation in a weight-stationary PE?
partial_out = partial_in + a_in·w_stored ; a_out = a_in.

Recall Feynman: explain it to a 12-year-old

Imagine a bucket-brigade line of kids putting out a fire. Each kid holds a fixed job (a weight). A bucket (a number) passes down the line; every kid pours a splash and adds it up, then hands the bucket to the next kid. Nobody runs back to the well for every splash — the bucket just keeps moving forward, and lots of kids work on it at once. That's a systolic array: numbers flow through a grid of little adders so you get tons of math done while only fetching each number once. The TPU is a huge grid of these little helpers built just for the math that AI needs.


Connections

  • GPU architecture and SIMT execution — the alternative: temporal parallelism + caches vs. TPU's spatial dataflow.
  • Memory wall and arithmetic intensity — the roofline reason TPUs exist.
  • Matrix multiplication algorithms — the operation being accelerated.
  • ASIC vs FPGA vs general-purpose processors — TPU as a domain-specific ASIC.
  • Dataflow architectures — systolic arrays are a classic dataflow design (Kung & Leiserson, 1978).
  • Quantization and 8-bit inference — why TPUv1 uses INT8 MACs.
  • Roofline model — visualizing when you're compute- vs memory-bound.

Concept Map

causes

motivates

built from

made of

does

uses

streams activations into

wired via

enables

fixes

accumulates to

Matrix multiply dominates NN

Memory wall

TPU accelerator ASIC

Systolic array grid

Processing elements MACs

Weight-stationary dataflow

Maximal operand reuse

Local nearest-neighbour wiring

Local accumulator per cell

Cij output computed

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, neural network ka zyada time matrix multiply karne me jata hai — bas bahut saare "multiply karo aur jodo" (MAC) operations. Normal CPU/GPU har MAC ke liye memory se number laata hai, multiply karta hai, wapas likhta hai — ye baar-baar memory se data laana hi asli bottleneck hai, jise hum memory wall kehte hain. Compute sasta hai, data laana mehnga.

Systolic array is problem ka jugaadu solution hai. Socho ek grid banaya jisme har chhota cell sirf ek MAC karta hai, aur cells sirf apne paas wale (neighbour) se juda hai. Ab data grid me se beh kar guzarta hai — jaise dil se khoon pump hota hai (isliye naam "systolic"). Ek number ek baar memory se aata hai aur poori row/column me use ho jaata hai, baar-baar memory jaane ki zaroorat nahi. Isse har byte ka reuse factor lagbhag NN ho jaata hai (256×256 array me 256 guna!).

TPU basically ek bada systolic array (256×256) hai jiske around memory (Unified Buffer) aur thoda control logic laga hai. Ek important baat: original TPUv1 sirf inference ke liye tha (8-bit integer) — training baad ke generations, yaani TPU v2 aur aage se shuru hui, jo bfloat16 floating point use karte hain. Iski peak power 2N2f2N^2 f FLOP/s hoti hai — matlab parallelism spatial hai, cells ki square ke hisaab se scale karti hai. Ek cheez yaad rakho: array me pehle data ko poore grid me faelne me 2N\sim 2N clock lagte hain (pipeline fill), isliye TPU chhote kaam me efficient nahi — bade batches pe magic dikhata hai. TPU me na cache hai, na branch predictor — saari jagah arithmetic ko de di, kyunki ye ek domain-specific ASIC hai, sirf AI ki math ke liye banaya gaya.

Go deeper — visual, from zero

Test yourself — Advanced & Emerging Architectures

Connections