15. Domain-Specific Architectures and AI Hardware
Description
With Moore's Law slowing and Dennard scaling over, general-purpose cores improve slowly. Domain-Specific Architectures (DSAs) tailor hardware to one class of problems and win large factors in performance and energy efficiency (for example Google's TPU for machine learning).
Five design guidelines (Hennessy & Patterson):
- Use dedicated memories to minimize data movement (software-managed scratchpads instead of big caches).
- Spend resources on more arithmetic units or bigger memories rather than on advanced microarchitecture (no big out-of-order machinery).
- Use the easiest form of parallelism that matches the domain (e.g. SIMD or systolic arrays).
- Use smaller data types (8-bit integers instead of 32-bit floats when accuracy allows).
- Use a domain-specific programming language (TensorFlow, Halide) so compilers can map software to the hardware.
AI background:
- Neural network: layers of neurons; each computes
y = f(Σ wᵢxᵢ + b)with an activation f (ReLU, sigmoid). Training adjusts weights (forward pass, backpropagation, gradient descent); inference just runs the forward pass with fixed weights. - Convolutional neural networks (CNNs): small filters slide over images, sharing weights; used for image classification (e.g. photo search and classification in Google Photos).
- Recurrent neural networks (RNNs, LSTMs): keep a hidden state across a sequence; used for text, speech and translation (e.g. next-word prediction). Transformers have largely replaced them in many language tasks.
- The core operation everywhere is matrix multiply / multiply-accumulate (MAC), which is why DSAs focus on it.
Hardware examples:
| System | What it is | Key ideas |
|---|---|---|
| TPU v1 (Google) | Inference accelerator in data centers | 256 × 256 systolic array of 8-bit MACs (65,536 MACs, 700 MHz, ≈92 TOPS), large software-managed on-chip buffer, runs TensorFlow models |
| TPU v2/v3 and later | Training and inference; pods of many chips | Floating-point (bfloat16) support, HBM, fast chip-to-chip network |
| Project Brainwave (Microsoft Azure) | FPGA-based real-time DNN serving | Very low latency at batch size 1; hardware microservices; serves requests in real time |
| Catapult (Microsoft) | FPGAs attached to data-center servers | Accelerates tasks such as Bing search ranking with reconfigurable hardware |
| Pixel Visual Core (Google Pixel phones) | Image-processing co-processor | Low-power image pipeline for HDR+ photos, programmed with Halide/TensorFlow |
| GPUs / tensor cores | General massively parallel accelerators | High memory bandwidth plus dedicated matrix units |
Systolic array idea: data flow rhythmically through a grid of simple MAC units; each operand is reused many times as it moves, so very little memory traffic per operation.
FPGA vs ASIC: FPGAs are reconfigurable (flexible, slower, less efficient); ASICs (like TPU) are fixed-function (fastest and most efficient, but costly and inflexible).
Key Formulas
Dense layer MACs = inputs × outputs (FLOPs = 2 × MACs)
Convolution layer MACs = H_out × W_out × C_out × (K × K × C_in)
Convolution parameters = K × K × C_in × C_out (+ C_out biases)
Peak ops/s of an N × N MAC array = N² × 2 × f (a MAC = 2 operations)
Arithmetic intensity of a fully connected layer with batch B, 1-byte weights:
AI ≈ (2 × in × out × B) / (in × out) = 2B ops per byte of weights
Memory footprint = parameters × bytes per parameter
Steps
Count the work of a CNN layer: (1) get output size H×W and channels, (2) multiply by kernel volume K×K×C_in, (3) double for FLOPs.
Quantize weights to 8 bits: (1) find max |w|, (2) scale = max/127, (3) q = round(w / scale), (4) store q as int8, keep the scale for dequantization.
Worked Example
A. Dense layer. 1000 inputs × 1000 outputs = 1,000,000 MACs = 2 MFLOP per input vector.
B. Convolution layer. Output 56 × 56 × 64, kernel 3 × 3 over 64 input channels: MACs = 56 × 56 × 64 × (3 × 3 × 64) = 3136 × 64 × 576 = 115,605,504 MACs (≈ 0.23 GFLOP); parameters = 3 × 3 × 64 × 64 = 36,864 (+64 biases). Few parameters but many operations, so convolutions reuse weights heavily and are compute-dense.
C. TPU v1 peak. 65,536 MACs × 2 ops × 0.7 × 10⁹ Hz = 91.75 × 10¹² ≈ 92 TOPS.
D. Memory footprint. 100 million parameters: 32-bit float = 400 MB; 8-bit = 100 MB (4× smaller, 4× less memory traffic). Horowitz's 45 nm estimates put an 8-bit integer multiply at about 0.2 pJ versus 3.7 pJ for a 32-bit float multiply, so small data types also save energy.
E. Batch size and the roofline. Fully connected layer with 8-bit weights: batch 1 → AI = 2 ops/byte (almost certainly memory-bound); batch 64 → AI = 128 ops/byte, which can approach the compute ceiling. Real-time services (Brainwave) need low latency at batch size 1, so they must solve the memory problem with on-chip weights.
F. Quantization. Weights [0.5, −1.27, 0.03, 0.9]: max |w| = 1.27, scale = 0.01 → int8 values [50, −127, 3, 90], recovered exactly here.
G. Why DSAs win. A CPU spends most of its energy on fetching, decoding, scheduling and cache access; a systolic MAC array spends it on arithmetic. Specialized, simple, parallel hardware with small data types is therefore far more efficient for fixed workloads like matrix multiply.
Python / Assembly
import numpy as np
def dense_macs(n_in, n_out):
return n_in * n_out
def conv_macs(h, w, c_out, k, c_in):
return h * w * c_out * k * k * c_in
print(dense_macs(1000, 1000)) # 1000000
print(conv_macs(56, 56, 64, 3, 64)) # 115605504
print(round(65536 * 2 * 0.7e9 / 1e12, 2)) # 91.75 (TOPS)
# One fully connected layer + ReLU
def forward(x, W, b):
return np.maximum(0, x @ W + b)
# Symmetric int8 quantization
w = np.array([0.5, -1.27, 0.03, 0.9])
scale = np.abs(w).max() / 127
q = np.round(w / scale).astype(np.int8)
print(scale, q, q * scale) # 0.01 [ 50 -127 3 90] [ 0.5 -1.27 0.03 0.9 ]
The multiply-accumulate loop that a DSA replicates tens of thousands of times in hardware:
# dot product of two double vectors: a0 = &x, a1 = &y, a2 = n, result in fa0
dot:
fmv.d.x fa0, zero
loop:
fld ft0, 0(a0)
fld ft1, 0(a1)
fmadd.d fa0, ft0, ft1, fa0 # fa0 += ft0 * ft1 (one MAC)
addi a0, a0, 8
addi a1, a1, 8
addi a2, a2, -1
bnez a2, loop
ret
Notes
- Common mistake: TPUs were not used "to train ChatGPT." Google's TPUs train and serve Google's own models; OpenAI's public descriptions of ChatGPT training mention large NVIDIA GPU clusters. A safe statement is: "TPUs are specialized processors for training and inference of neural networks."
- AI raises productivity by automating tasks and learning from data, which is why it shapes hardware design.
- FPGA accelerators (Catapult, Brainwave) trade peak efficiency for flexibility: the same chips can be reprogrammed as workloads change.
- DSAs complement CPUs; they do not replace them. The CPU runs the OS and general code and offloads the hot kernels.
- Quick facts: a DSA is hardware optimized for a specific task (e.g. Google TPU); CNNs process images; RNNs process sequences; TPUs speed up AI in data centers; Brainwave and Catapult use FPGAs; Pixel Visual Core accelerates image processing.
References: [HP6] Ch. 7 (7.1-7.9); Jouppi et al., "In-Datacenter Performance Analysis of a Tensor Processing Unit," ISCA 2017; Putnam et al., "A Reconfigurable Fabric for Accelerating Large-Scale Datacenter Services," ISCA 2014 (Catapult); Fowers et al., "A Configurable Cloud-Scale DNN Processor for Real-Time AI," ISCA 2018 (Brainwave); Horowitz, "Computing's Energy Problem (and what we can do about it)," ISSCC 2014; Hennessy & Patterson, "A New Golden Age for Computer Architecture," CACM, 2019;
All rights remain with the original author (Algo-holics). Publishing here does not grant a license to copy or reuse this text. Copyright & license. If you noticed a mistake or copyright issues, please contact: lebroskiofficial@proton.me