6.5.8Advanced & Emerging Architectures

Neural processing units (NPUs)

2,121 words10 min readdifficulty · medium

WHY do NPUs exist?

This is the 80/20: matrix-multiply (the 20% of operation types) is 80%+ of the runtime. Optimise that, ignore the rest.


WHAT is an NPU?

Key building blocks:

  • Processing Element (PE): one MAC unit — computes a×b+ca \times b + c.
  • Systolic array: a 2-D grid of PEs where data flows rhythmically (like a heartbeat — Greek systole) between neighbours, no global memory access per step.
  • On-chip SRAM / scratchpad: holds weights & activations near the compute.
  • Low precision datapaths: int8, fp16, bfloat16.

HOW does the core math map to hardware?

Step 1 — The operation we must accelerate

A fully-connected layer computes y=Wx\mathbf{y} = W\mathbf{x}, and a batch is a matrix multiply Y=XWY = XW. One output element is:

yij=k=1KXikWkjy_{ij} = \sum_{k=1}^{K} X_{ik}\, W_{kj}

Step 2 — Counting the work (derive the cost)

A matrix multiply of (M×K)(K×N)(M\times K)\cdot(K\times N) needs, per output element, KK multiplies and K1K-1 adds. There are MNMN outputs:

MACs=MNK\text{MACs} = M \cdot N \cdot K

Step 3 — The naïve cost is memory, not math

Do it the dumb way: for each MAC, load XikX_{ik} and WkjW_{kj} from memory. That's 2×MNK2 \times MNK memory reads. WHY bad? A DRAM read ≈ 640 pJ; a MAC ≈ 0.2 pJ. The memory tax dominates by 1000×.

Step 4 — The systolic array (derivation of the dataflow)

Arrange PEs in a K×NK\times N grid. Weights WkjW_{kj} are loaded and held stationary inside PEs (this is called weight-stationary). Activations XikX_{ik} flow left→right, one column of data entering per clock. Partial sums flow top→bottom, each PE doing:

psumout=psumin+Xin×Wstored\text{psum}_{\text{out}} = \text{psum}_{\text{in}} + X_{\text{in}} \times W_{\text{stored}}

Because each activation, once injected, marches across a whole row of PEs, one memory load feeds many multiplies. After the array fills (the "pipeline fill" latency), it produces a full result column every cycle.

Figure — Neural processing units (NPUs)

Step 5 — Throughput and efficiency (derive the win)

An array of R×CR\times C PEs performs up to RCR\cdot C MACs/cycle:

Peak throughput=RCfclock[MACs/s]\text{Peak throughput} = R \cdot C \cdot f_{\text{clock}} \quad [\text{MACs/s}]

TOPS=2RCfclock1012(the 2=one mult+one add)\text{TOPS} = \frac{2 \cdot R \cdot C \cdot f_{\text{clock}}}{10^{12}} \quad (\text{the } 2 = \text{one mult} + \text{one add})


Precision: WHY low bits win

Energymult(bit-width)2\text{Energy}_{\text{mult}} \propto (\text{bit-width})^2


Common mistakes (Steel-manned)


Forecast-then-Verify


Flashcards

What is an NPU in one line?
A domain-specific accelerator built around a spatial array of MAC units, optimised for neural-network matrix multiply using data reuse and low precision to maximise ops/joule.
What single operation dominates NN inference?
Matrix multiplication (dense multiply-accumulate / dot products).
Define a MAC operation.
Multiply-accumulate: compute a×b+ca\times b + c; one multiply plus an add into a running accumulator.
What is a systolic array?
A 2-D grid of processing elements where data flows rhythmically between neighbours, enabling massive data reuse without per-step global memory access.
Why is memory, not arithmetic, the real cost?
A DRAM read costs ~1000× more energy than a MAC, so naive loading dominates; reuse amortises fetches.
Formula for MACs in an M×K by K×N matmul?
MNKM\cdot N\cdot K.
Peak throughput of an R×C PE array at clock f?
RCfR\cdot C\cdot f MACs/s, i.e. 2RCf2RCf ops/s.
Why does low precision (int8) give more MACs per area?
Multiplier area/energy scales ~with (bit-width)², so int8 is ~16× smaller than fp32.
What is utilisation and why care?
actual MACs ÷ (R·C·cycles); peak TOPS is meaningless if the array sits idle due to small/mismatched layers or memory limits.
"Weight-stationary" means what?
Weights are loaded once and held in each PE while activations stream through, maximising weight reuse.
Why isn't peak TOPS the real performance?
It assumes 100% utilisation and unlimited bandwidth; real workloads are often memory-bound or under-fill the array.

Recall Feynman: explain to a 12-year-old

Imagine a huge factory of tiny workers arranged in a giant square grid. Each worker only knows ONE trick: "multiply two numbers and add the answer to my pile." Numbers walk along the rows like people on a conveyor belt, and each worker grabs a number as it passes, does its little trick, and passes the running total downward. Because thousands of workers all do their trick at the same time, a mountain of maths that would take your laptop ages gets done in a blink. That grid of tiny multiply-workers is an NPU — a calculator factory built just for the kind of maths that AI needs.

Connections

  • Systolic arrays — the dataflow engine inside most NPUs.
  • GPUs and SIMT — general parallel compute vs fixed-function NPUs.
  • Tensor cores — matmul units bolted onto GPUs (a hybrid step toward NPUs).
  • Quantization and int8 inference — why low precision works.
  • Roofline model — deciding compute-bound vs memory-bound.
  • Dataflow and data reuse — weight/output/row-stationary strategies.
  • Energy per operation — the physics motivating specialisation.
  • Domain-specific architectures — the broader design philosophy.

Concept Map

creates need for

motivates

leads to

is a

built from

computes

arranged in

enables

uses

kills

uses

implements

cost

maximises

boosts

NN inference ~90% matmul

Memory & control overhead on CPU

Specialise the hardware

Neural Processing Unit

Domain-specific accelerator

Processing Element

Multiply-accumulate a*b+c

Systolic array grid

Massive parallelism

On-chip SRAM reuse

Memory energy tax

Low precision int8/fp16

Matrix multiply Y=XW

MACs = M*N*K

Operations per joule

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, ek neural network chalane mein 90% kaam sirf matrix multiply ka hota hai — matlab bahut saare "multiply karo aur jodo" (MAC) operations baar-baar. CPU ek time pe thode hi operations karta hai aur apni zyada energy control cheezon (fetch, decode, branch) mein jala deta hai. NPU ka idea simple hai: agar ek hi kaam crore baar karna hai, to hardware ko usi shape mein bana do — ek bada grid of tiny multiply units. Isko systolic array kehte hain, jahan data dil ki dhadkan ki tarah rhythmically neighbour PEs mein flow karta hai.

Sabse bada catch yeh hai ki asli kharcha memory se data laana hai, multiply karna nahi. DRAM se ek number laana ek MAC se ~1000× zyada energy leta hai. Isiliye NPU "data reuse" pe focus karta hai — ek baar weight load karo aur usse baar-baar use karo (weight-stationary). Isse memory ka tax bahut kam ho jaata hai aur efficiency (ops per joule) jump kar jaati hai.

Do aur tricks: low precision (int8, fp16). Multiplier ka size bit-width ke square ke proportional hota hai, to int8 fp32 se ~16× chhota — same silicon mein 16× zyada MACs fit ho jaate hain, aur accuracy bhi bahut kam giri. Aur width — 256×256 array matlab 65536 MACs har cycle, isiliye modest clock pe bhi CPU se 100× fast.

Ek warning: peak TOPS ko blindly mat maano. Woh 100% utilisation aur unlimited bandwidth maan ke bola jaata hai. Agar layer chhoti hai ya memory-bound hai, to array aadha khaali baithta hai. Isliye hamesha effective throughput aur utilisation dekho, sirf marketing number nahi.

Go deeper — visual, from zero

Test yourself — Advanced & Emerging Architectures

Connections