S440 of 55
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

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 B+2(n−1) cycles to fill, run and drain, and utilization is BB+2(n−1).
  • 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?

Name it

Guidelines for accelerators

  1. Dedicated memories (scratchpads managed by software) instead of caches, placed where the data flows.
  2. Spend area on arithmetic: many simple units, little control.
  3. The simplest parallelism that fits the domain: SIMD, systolic arrays or VLIW, statically scheduled.
  4. Smaller data types: 8-bit integers or 16-bit floats cut energy, area and bandwidth by large factors where accuracy allows.
  5. 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 B+2(n−1) cycles;
  • tiling: a dimension d occupies ⌈d/n⌉ tiles, with efficiency dn⌈d/n⌉;
  • 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
  1. Batch 200. 200/(200+510)=28%
  2. Batch 1000. 1000/1510=66%
  3. A 300-wide layer. It needs 2 tiles of 256: 300/512=58.6%full
  4. 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
  1. Ridge. 91.75×101234×109=2700ops/byte
  2. Ops per weight byte. With batch 10, each weight byte does 10 MACs, 20 ops.
  3. Attainable rate. 34GB/s×20=0.68TOPS under 1% of peak.
  4. 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
  1. Peak. R=16384×2×0.94GHz=30.8TOPS
  2. One pass. Filling, streaming B = 64 vectors and draining takes 64+2×127=318cycles
  3. Utilization. The array does useful work 64 of those 318 cycles, 20% of the time.
  4. 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 B+2(n−1) 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°.

Explain why

Why can a systolic array do so much arithmetic with so little memory bandwidth?

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.