AI infrastructure and systemsPart 1: Foundations
Chapter 2GPUs and accelerators
An NVIDIA H100 can perform about 989 trillion BF16 operations per second, yet when it generates text for a single user it often sits mostly idle, waiting on memory. Knowing why, and reading a spec sheet well enough to predict it, is the skill that separates people who buy the right hardware from people who buy the expensive hardware.
After this chapter you can
- Explain why GPUs beat CPUs on matrix math, in terms of cores, threads and memory
- Identify whether a workload is limited by compute or by memory bandwidth
- Choose a precision format (FP32, FP16, BF16, FP8, INT8) and predict its memory and speed effect
- Read an accelerator spec sheet and compare NVIDIA, AMD, Google TPU and Apple silicon parts
- Estimate whether a given model fits on a given device, with headroom
CPUs and GPUs spend their transistors differently
A CPU core is built to finish one instruction stream as fast as possible: deep pipelines, branch prediction, out-of-order execution and large caches. A GPU spends the same silicon on thousands of simple arithmetic lanes and hides memory latency by keeping huge numbers of threads in flight, switching to another group whenever one stalls. You traded single-thread latency for throughput across thousands of threads.
NVIDIA calls each GPU building block a streaming multiprocessor (SM); AMD calls it a compute unit. An H100 SXM has 132 SMs. Threads are scheduled in groups of 32 called warps, which execute the same instruction on different data, the SIMT model (single instruction, multiple threads). If you know SIMD vector units from computer architecture, a warp is the same idea scaled up and managed by hardware.
| Property | Server CPU | Data center GPU |
|---|---|---|
| Cores or lanes | Tens to about 200 cores | Over 10,000 lanes, plus tensor cores |
| Optimized for | Low latency per thread, branchy code | Throughput on uniform, parallel work |
| Memory | DDR5, hundreds of GB to TB, about 0.1 to 0.5 TB/s | HBM, 80 to 288 GB, about 3 to 8 TB/s |
| Peak dense matrix math | Single-digit TFLOPS | Hundreds to thousands of TFLOPS |
Matrix multiplication fits this design perfectly. Each output element of C = A @ B is an independent dot product, so the work splits into tiles, each tile goes to an SM, and nothing needs to coordinate until the end.
Memory bandwidth is usually the real limit
Arithmetic is cheap; moving data is expensive. The useful question for any kernel is its arithmetic intensity: FLOPs performed per byte moved from memory. Divide a chip's peak FLOPS by its bandwidth and you get the intensity at which it stops waiting on memory, called the ridge point of the roofline model.
H100 SXM ridge point = 989e12 FLOP/s / 3.35e12 B/s = about 295 FLOPs per byte
Generating one token at batch size 1, BF16 weights:
each weight is read once (2 bytes) and used for 2 FLOPs -> 1 FLOP per byte
1 is far below 295: the GPU is memory-bound, compute units mostly idle
Upper bound on speed = bandwidth / bytes read per token
8B model in BF16: 3.35e12 / 16e9 = about 209 tokens per second, at bestThis is why batching matters so much for serving: 32 users decoding together read the weights once and do 32 times the math, moving the work toward the ridge. Large training matmuls, by contrast, have intensity in the thousands and are compute-bound.
Tensor cores and precision formats
Tensor cores are units inside each SM that compute a small matrix multiply-accumulate (D = A x B + C on a tile) per instruction, far faster than the general-purpose lanes. AMD calls the equivalent matrix cores. They run fastest at low precision, and each halving of bits roughly doubles peak throughput and halves memory traffic.
| Format | Bits (sign / exponent / mantissa) | Range and precision | Typical use |
|---|---|---|---|
| FP32 | 1 / 8 / 23 | Wide range, about 7 decimal digits | Master weights, optimizer state, reductions |
| FP16 | 1 / 5 / 10 | Max about 65,504; can overflow | Inference on older GPUs; training needs loss scaling |
| BF16 | 1 / 8 / 7 | FP32's range, about 3 decimal digits | Default for training and serving today |
| FP8 (E4M3, E5M2) | 1 / 4 / 3 or 1 / 5 / 2 | Narrow; needs per-tensor scale factors | Hopper and newer training and inference |
| INT8 | 8-bit integer | 256 levels plus a scale | Quantized inference |
| 4-bit (INT4, FP4, MXFP4) | 4 bits plus shared scales | 16 levels per group | Weight-only quantization, newest GPUs natively |
BF16 won because it keeps FP32's exponent: values that fit in FP32 fit in BF16, so training rarely overflows. Support is generational, which matters when you rent cheap hardware.
Reading a spec sheet
Vendors print the most flattering number first. Read these lines, in this order, and normalize before comparing.
Memory capacity and type
HBM (high-bandwidth memory, stacked next to the die) on data center parts; GDDR on consumer and inference cards; unified LPDDR on Apple silicon. Note GB versus GiB.
Memory bandwidth
In TB/s. This predicts decode speed for language models more than any other line.
Dense versus sparse FLOPS
Many headline figures assume 2:4 structured sparsity, which doubles the number but rarely applies to real models. Look for the footnote and halve the number if it says "with sparsity".
Precision of the headline number
An FP4 figure is four times an FP16 figure on the same chip. Compare like with like: BF16 dense against BF16 dense.
Interconnect, power and form factor
NVLink or Infinity Fabric bandwidth for multi-GPU work, board power in watts (it drives cooling and hosting cost), and SXM or OAM modules versus PCIe cards.
Here is how current parts compare on the lines that matter. Figures are vendor peaks as published, rounded; "dense" means without sparsity.
| Accelerator | Memory | Bandwidth | Peak dense matrix math | Scale-up link |
|---|---|---|---|---|
| NVIDIA T4 (2018, free tiers) | 16 GB GDDR6 | 320 GB/s | 65 TFLOPS FP16 | PCIe |
| NVIDIA RTX 5090 (consumer) | 32 GB GDDR7 | 1.79 TB/s | not comparable (consumer specs) | PCIe 5.0 |
| NVIDIA H100 SXM | 80 GB HBM3 | 3.35 TB/s | 989 TFLOPS BF16 | NVLink, 900 GB/s |
| NVIDIA B200 | 180 GB HBM3e | about 8 TB/s | about 4.5 PFLOPS FP8 | NVLink, 1.8 TB/s |
| AMD Instinct MI355X | 288 GB HBM3E | 8 TB/s | 2.5 PFLOPS BF16 | Infinity Fabric |
| Google TPU7x (Ironwood) | 192 GiB HBM | 7.37 TB/s | 4.6 PFLOPS FP8 | ICI, 1.2 TB/s per chip |
| Apple M4 Max | Up to 128 GB unified | Up to 546 GB/s | modest; not a training part | none |
| Apple M3 Ultra | Up to 512 GB unified | 819 GB/s | modest; not a training part | none |
Connecting several GPUs
When a model does not fit on one device, or one device is too slow, you split the work across several, and they must exchange data every layer or every step. The link between them then becomes part of your memory system.
- PCIe connects GPUs to the CPU and, on cheaper servers, to each other. PCIe 5.0 x16 moves about 64 GB/s in each direction.
- NVLink is NVIDIA's direct GPU-to-GPU link. An H100 SXM has 900 GB/s of total NVLink bandwidth, more than ten times PCIe; Blackwell doubles it to 1.8 TB/s. NVSwitch chips let all 8 GPUs in a server talk at full speed at once.
- AMD uses Infinity Fabric between Instinct GPUs; Google connects TPUs with ICI (inter-chip interconnect) links into pods of thousands of chips.
Run nvidia-smi topo -m on a multi-GPU machine to see whether pairs talk over NVLink (NV#) or traverse PCIe and the CPU (PIX, PHB, SYS). The Networking for AI clusters chapter covers links between servers.
The vendor landscape
NVIDIA
- Dominant share in training and serving
- CUDA ecosystem: most kernels and tools target it first
- Hopper (H100, H200) and Blackwell (B200, B300, GB200) are the current data center lines
- Consumer RTX cards are popular for local inference
AMD
- Instinct MI300X, MI325X and MI350 series
- Leads on memory capacity per GPU (288 GB on MI355X)
- ROCm software stack; PyTorch and vLLM support it, with a thinner long tail of tools
Custom silicon and Apple
- Google TPUs, AWS Trainium and Inferentia: available only in their clouds, programmed through JAX, PyTorch/XLA or vendor SDKs
- Apple silicon: CPU and GPU share up to 512 GB of unified memory, ideal for running big models locally, weak at training
Will it fit
Memory needed for inference is weights plus KV cache plus overhead. Weights are parameters times bytes per parameter. The KV cache depends on architecture, context length and concurrent sequences (formula in How AI systems work). Overhead covers the CUDA context, activations, temporary buffers and fragmentation; budget 10 to 20 percent and about 1 GB minimum.
needed = params x bytes_per_param
+ kv_bytes_per_token x context_tokens x concurrent_sequences
+ overhead (about 15%)
Example: Llama 3.1 8B in BF16, one 8K-token sequence
weights 8.03e9 x 2 = 16.1 GB
KV cache 131,072 B x 8,192 = 1.1 GB
overhead 15% = 2.6 GB
total = about 19.7 GB -> fits on 24 GB or moreFor three common open models, using about 4.5 bits per parameter for 4-bit quantization (the extra half bit is for scale factors) and one 8K-token sequence:
| Model | BF16 total | 4-bit total | T4 16 GB | RTX 5090 32 GB | H100 80 GB |
|---|---|---|---|---|---|
| Llama 3.1 8B | about 20 GB | about 6.4 GB | 4-bit only | Yes | Yes |
| Qwen3-32B | about 78 GB | about 24 GB | No | 4-bit only | BF16 is too tight; FP8 or 4-bit |
| Llama 3.3 70B | about 166 GB | about 49 GB | No | No | 4-bit only, or 2 GPUs at BF16 |
"Fits" means the model loads with room for one sequence. Serving many users at once needs far more KV cache, which is why production deployments usually run the 8B model on a card with 80 GB, not 24.
Key terms
- Streaming multiprocessor (SM)
- The repeated compute block of an NVIDIA GPU, holding arithmetic lanes, tensor cores and on-chip memory.
- Warp
- A group of 32 GPU threads that execute the same instruction together.
- HBM
- High-bandwidth memory stacked beside the GPU die, delivering terabytes per second.
- Memory bandwidth
- The rate at which a device can read and write its memory, in GB/s or TB/s.
- Arithmetic intensity
- FLOPs performed per byte moved from memory; it decides compute-bound versus memory-bound.
- Roofline model
- A plot of attainable performance as the lesser of peak compute and bandwidth times intensity.
- Tensor core
- A matrix multiply-accumulate unit that runs low-precision matmuls far faster than general lanes.
- BF16
- A 16-bit float with FP32's exponent range and fewer mantissa bits; the default for modern AI work.
- NVLink
- NVIDIA's high-bandwidth direct link between GPUs, many times faster than PCIe.
Profile your accelerator and build a fits-or-not table
Goal: measure the real matmul throughput and memory bandwidth of the hardware you have, compare them with the spec sheet, and produce a fits-or-not table for three models.
You need: Python 3.11 or newer and PyTorch (pip install torch). Any of: an NVIDIA GPU, an Apple silicon Mac, or just a CPU. No GPU? Open a free notebook at Google Colab, choose Runtime, then Change runtime type, then T4 GPU, and run the same commands in cells (prefix shell commands with !). Kaggle notebooks also offer free T4 GPUs under a weekly quota shown in your account settings.
- Inspect the device. On NVIDIA:
nvidia-smi
nvidia-smi --query-gpu=name,memory.total,memory.used,power.limit,clocks.max.sm --format=csvYou should see the GPU name, total memory (15360 MiB on a T4), the driver version and the highest CUDA version that driver supports. On an Apple silicon Mac, run system_profiler SPDisplaysDataType and sysctl hw.memsize. On a CPU, run lscpu (Linux) or sysctl -n machdep.cpu.brand_string (macOS).
- Save the benchmark. It times square matmuls in three precisions and a 1 GiB copy, synchronizing because GPU work is asynchronous.
import os, time, torch
force = os.environ.get("DEVICE")
if force == "cpu":
dev = "cpu"
print("device: CPU,", torch.get_num_threads(), "threads")
elif torch.cuda.is_available():
dev = "cuda"
print("device:", torch.cuda.get_device_name(0))
elif torch.backends.mps.is_available():
dev = "mps"
print("device: Apple GPU (MPS)")
else:
dev = "cpu"
print("device: CPU,", torch.get_num_threads(), "threads")
def sync():
if dev == "cuda":
torch.cuda.synchronize()
elif dev == "mps":
torch.mps.synchronize()
def timeit(fn, iters):
fn(); sync() # warm-up: kernel selection, allocation
t0 = time.perf_counter()
for _ in range(iters):
fn()
sync() # GPU work is asynchronous: wait for it
return (time.perf_counter() - t0) / iters
n = {"cuda": 8192, "mps": 2048, "cpu": 1024}[dev]
iters = 20 if dev != "cpu" else 2
print(f"\nmatmul {n}x{n} @ {n}x{n}")
for dtype in (torch.float32, torch.float16, torch.bfloat16):
try:
a = torch.randn(n, n, device=dev, dtype=dtype)
b = torch.randn(n, n, device=dev, dtype=dtype)
t = timeit(lambda: a @ b, iters)
print(f" {str(dtype):16s} {t * 1e3:9.2f} ms {2 * n**3 / t / 1e12:8.2f} TFLOPS")
except Exception as e:
print(f" {str(dtype):16s} unsupported here ({type(e).__name__})")
# Memory bandwidth: copy a 1 GiB buffer (read 1 GiB + write 1 GiB)
x = torch.empty(256 * 1024 * 1024, device=dev, dtype=torch.float32)
y = torch.empty_like(x)
t = timeit(lambda: y.copy_(x), iters)
print(f"\ncopy 1 GiB: {t * 1e3:.2f} ms -> {2 * x.numel() * 4 / t / 1e9:.0f} GB/s effective bandwidth")- Run it, and on NVIDIA watch the GPU in a second terminal while it runs.
python bench.py
# second terminal, NVIDIA only: one line per second
nvidia-smi --query-gpu=utilization.gpu,memory.used,power.draw,clocks.sm --format=csv -l 1On a T4 expect a few TFLOPS in FP32, a large jump in FP16 thanks to tensor cores (well below the 65 TFLOPS peak, because the 70 W card throttles), BF16 much slower than FP16 or unsupported, and roughly 200 to 260 GB/s for the copy.
A laptop CPU gives a fraction of a TFLOPS in FP32 and tens of GB/s; on CPUs without native half-precision instructions the FP16 and BF16 rows can take many seconds each, which is itself the lesson. Your numbers will differ; what matters is the ratios. Run DEVICE=cpu python bench.py to compare the same machine's CPU.
- Record measured against peak in a table, and compute efficiency. Below 50 percent of peak FLOPS is normal for a simple benchmark; bandwidth usually reaches 70 to 90 percent.
| Metric | Spec sheet | Measured | Efficiency |
|---|---|---|---|
| FP16 or BF16 TFLOPS | |||
| Memory bandwidth GB/s |
- Build the fits-or-not table. Save this and edit
DEVICE_GBto your device's memory.
DEVICE_GB = 16 # your accelerator memory in GB
CTX = 8192 # tokens of context for one sequence
models = { # name: (params, layers, kv_heads, head_dim)
"Llama-3.1-8B": (8.03e9, 32, 8, 128),
"Qwen3-32B": (32.8e9, 64, 8, 128),
"Llama-3.3-70B": (70.6e9, 80, 8, 128),
}
for name, (p, layers, kvh, hd) in models.items():
kv = 2 * layers * kvh * hd * 2 * CTX # BF16 cache, bytes
for label, bpp in (("bf16", 2), ("int8", 1), ("4-bit", 0.5625)):
need = (p * bpp + kv) * 1.15 / 1e9
verdict = "fits" if need <= DEVICE_GB else "no"
print(f"{name:15s} {label:6s} {need:7.1f} GB {verdict}")python fits.pyThe Llama 3.1 8B rows should read about 19.7 GB for BF16, 10.5 GB for INT8 and 6.4 GB for 4-bit.
- Test one prediction for real. If you have at least 8 GB free, load a small model and compare
torch.cuda.max_memory_allocated()(or Activity Monitor on a Mac) with what the formula predicts for its parameter count.
Check your work: you have a table of measured against peak numbers for your device with one sentence explaining the biggest gap, and a fits-or-not table whose 8B BF16 row is about 20 GB.
Stretch: for batch size 1, predict maximum tokens per second for an 8B BF16 model on your device as bandwidth divided by 16 GB. Then run a real model with llama.cpp or Ollama and compare the measured decode rate with your prediction.
Check yourself
An 8B model in BF16 decodes at 40 tokens per second for one user on a GPU with 1 TB/s of bandwidth and 300 TFLOPS. Which change most directly raises single-user decode speed?
A spec sheet lists 1,979 TFLOPS of BF16 with a footnote saying 'with sparsity'. What number should you use to compare it with another vendor's dense BF16 figure?
Why did BF16 replace FP16 as the default training format?
You split a model across 4 GPUs with tensor parallelism and it runs far slower than expected. nvidia-smi topo -m shows SYS between every GPU pair. What is the likely cause?
Recap
- GPUs win on matrix math because they trade single-thread speed for thousands of parallel lanes and terabytes per second of memory bandwidth.
- Compare a kernel's FLOPs per byte with the chip's ridge point: below it you are memory-bound, which describes single-user LLM decoding.
- Lower precision formats shrink memory and raise tensor core throughput; BF16 is the default, FP8 and 4-bit are growing, and old GPUs lack newer formats.
- Read spec sheets for memory, bandwidth, dense FLOPS at a named precision and interconnect, and halve any sparse figure.
- Memory needed is weights plus KV cache plus about 15 percent overhead; compute it before you pick hardware.
Go deeper
- NVIDIA H100 product page: a real spec sheet to practise reading, including its sparsity footnotes.
- Matrix multiplication background guide: NVIDIA's explanation of arithmetic intensity, tiling and tensor core efficiency.
- Making Deep Learning Go Brrrr From First Principles: Horace He on compute-bound, memory-bound and overhead-bound work.
- How to Scale Your Model: rooflines, TPUs and GPUs, and the math of splitting models across chips.
- Google TPU7x (Ironwood) documentation: official per-chip specs for Google's newest TPU.