S4 · Lesson 40 · Domain-specific architectures
Accelerators for one kind of work, systolic arrays, reduced precision, utilization and the TPU
With Dennard scaling gone and general-purpose cores near their limits, the way to make one kind of computation much faster and more efficient is to build hardware for that computation alone. Neural-network inference is the famous example: almost all of its work is multiplying matrices, so Google's first Tensor Processing Unit (2015) spent most of its area on a 256 × 256 grid of 8-bit multiply-accumulate units fed in a rhythmic, systolic pattern, with no caches, no branch prediction and no out-of-order logic. It ran inference far faster per watt than CPUs and GPUs of its day. The same principles guide every accelerator: use dedicated memories, keep parallelism simple, cut precision to what the application needs, and keep the giant array busy.
- Utilization of an n × n weight-stationary systolic array that streams B input vectors through one loaded set of weights. Inputs enter skewed, so the pass takes cycles to fill, run and drain, and utilization is .
- A big array needs a big batch to be busy: a 256 × 256 array fed 200 vectors is only 28% utilized in such a pass.
- The readout shows the other common loss: a layer whose size d doesn't divide evenly into the array leaves the last tile partly empty.
Predict
A 256 × 256 array of 8-bit multiply-accumulate units runs at 700 MHz. What's its peak rate, counting a multiply-accumulate as two operations?
65,536 MACs × 2 × 700 MHz = 92 trillion operations a second, the first TPU's figure. Its weight memory delivered 34 GB/s, so its roofline ridge was about 2700 operations per byte: only layers that reuse each weight thousands of times (large batches, convolutions) could approach the peak, and many production models ran far below it because they were memory-bound.
Name it
Guidelines for accelerators
- Dedicated memories (scratchpads managed by software) instead of caches, placed where the data flows.
- Spend area on arithmetic: many simple units, little control.
- The simplest parallelism that fits the domain: SIMD, systolic arrays or VLIW, statically scheduled.
- Smaller data types: 8-bit integers or 16-bit floats cut energy, area and bandwidth by large factors where accuracy allows.
- A domain-specific language (TensorFlow, Halide) so software can target the hardware.
Systolic arrays
Data pulses through a grid of processing elements, each doing one multiply-accumulate and passing its operands to its neighbors, so each value fetched from memory is reused n times without extra memory traffic. In a weight-stationary design each PE holds one weight. Utilization suffers from:
- fill and drain: a pass over B vectors takes cycles;
- tiling: a dimension d occupies tiles, with efficiency ;
- memory bandwidth: weights must be reloaded for each new tile; with batch B each weight byte feeds B multiply-accumulates.
Peak rate = number of MACs × 2 × clock.
Worked example
For a 256 × 256 array, find the utilization of a pass with batches of 200 and 1000, and the tiling efficiency of a 300-wide layer.
Show the solution
- Batch 200.
- Batch 1000.
- A 300-wide layer. It needs 2 tiles of 256:
- In practice. Real systems overlap the drain of one pass with the fill of the next and pick layer sizes that fit, but small batches, which low-latency inference needs, remain the hard case.
Answer utilization is 28% at batch 200 and 66% at batch 1000, and the 300-wide layer tiles at 58.6% efficiency.
Worked example
The array peaks at 91.75 TOPS with 34 GB/s of weight bandwidth. Where's the ridge, and what does a fully connected layer with batch 10 attain if each 8-bit weight is used once per input vector?
Show the solution
- Ridge.
- Ops per weight byte. With batch 10, each weight byte does 10 MACs, 20 ops.
- Attainable rate. under 1% of peak.
- The fix. That's why the TPU's successors added high-bandwidth memory.
Answer the ridge is at 2700 ops/byte, and the batch-10 layer attains only 0.68 TOPS, under 1% of peak.
Worked example
A weight-stationary systolic array has 128 × 128 multiply-accumulators at 940 MHz. What is its peak, and how busy is a pass over a batch of 64?
Show the solution
- Peak.
- One pass. Filling, streaming B = 64 vectors and draining takes
- Utilization. The array does useful work 64 of those 318 cycles, 20% of the time.
- Bigger batches. Batches in the thousands push that above 80%, which is why inference servers batch requests.
Answer the peak is 30.8 TOPS, and a pass over a batch of 64 keeps the array busy 20% of the time.
Check
A 128 × 128 array of multiply-accumulate units runs at 0.7 GHz. What's its peak rate, counting a MAC as two operations?
Check
A 128 × 128 systolic array streams 64 input vectors through one set of weights, taking cycles. What's its utilization?
Check
A layer dimension of 520 is mapped onto an array of width 128. What fraction of the tiles' width is used?
Check
An accelerator peaks at 100 TOPS with 30 GB/s of memory bandwidth. Where's its ridge point, in operations per byte?
Check
An accelerator peaks at 400 TOPS with 30 GB/s of weight bandwidth. A layer uses each 8-bit weight for a batch of 4 vectors (2 operations each). What does it attain?
Check
Weights stored as 32-bit numbers are quantized to 8 bits. By what factor does the memory traffic for weights fall?
Check
A weight-stationary systolic array is 128 × 128 at 0.7 GHz; a pass streams a batch of 512 vectors, and a layer is 1000 wide.
(a)
What is its peak?
(b)
How busy is it during a pass?
(c)
What is the layer's tiling efficiency?
Check
An accelerator peaks at P operations a second and loads weights at W bytes a second; each 8-bit weight is reused across a batch of B.
Step 1
What is the arithmetic intensity, in operations per weight byte?
Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.
Step 2
What rate does it attain?
Explain why
Why can a systolic array do so much arithmetic with so little memory bandwidth?
In a systolic array, each value read from memory enters at the edge and is passed from one processing element to the next, and every element it passes uses it in a multiply-accumulate. A weight held in place is used once for every input vector that flows by, and an input value is used by every element along its row. So a value fetched once does n operations in an n-wide array, without being read from memory or even from a register file again. The array needs only enough bandwidth to feed its edges, which grows with n, while its arithmetic grows with n², so the ratio of operations to bytes, its arithmetic intensity, grows with the size of the array.
Practice
Keep practicing
10 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.