Before you start#
| Word | Plain meaning |
|---|---|
| Core | One independent processor inside a chip. A server CPU has dozens to ~200; a GPU has thousands of much simpler ones. |
| Branch | An if in code. CPUs are built to guess branches well; GPUs are not. |
| Latency hiding | Keeping busy with other work while waiting for memory, instead of making the wait short. |
| PCIe | The bus that connects a GPU to the CPU and its memory (9.b). |
| Kernel launch | The CPU telling the GPU to run one GPU function (5.d). |
1. What is it?#
Two fundamentally different bets about what a processor is for.
CPU: a few very smart cores that finish one task as fast as possible
GPU: thousands of simple cores that finish enormous amounts of uniform work CPU (e.g. 32-core server) GPU (e.g. H100)
┌────┬────┬────┬────┐ ┌──────────────────────────┐
│ big│ big│ big│ big│ │▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪│
│core│core│core│core│ │▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪│
├────┴────┴────┴────┤ │▪▪▪▪▪▪▪ 16,896 ▪▪▪▪▪▪▪▪▪▪│
│ huge caches │ │▪▪▪▪ CUDA cores ▪▪▪▪▪▪▪▪▪│
│ branch predict │ │▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪│
│ out-of-order │ ├──────────────────────────┤
└───────────────────┘ │ small caches, huge BW │
~0.3 TB/s to DRAM └──────────────────────────┘
3.35 TB/s to HBMFor inference, the GPU wins — but understanding why tells you when it doesn’t.
2. Why does it exist?#
Historical accident turned into a deliberate divergence.
CPUs were designed for general programs: unpredictable branches, pointer chasing, system calls, one thing at a time as fast as possible. Enormous transistor budgets went into making a single instruction stream fast: branch predictors, out-of-order execution, speculative execution, deep caches. Perhaps 1% of a CPU’s die area is arithmetic units.
GPUs were designed to color millions of pixels with the same shader. Every pixel is independent and does the same operations. So: no branch prediction, no out-of-order, tiny caches per core, and spend the entire transistor budget on arithmetic and memory bandwidth. Perhaps 30-50% of a GPU’s die is arithmetic.
Neural networks turned out to be shaped exactly like graphics: enormous amounts of identical, independent arithmetic on large arrays. That coincidence is the reason NVIDIA is the most valuable company in the industry.
3. Simple analogy#
A brilliant professor versus a stadium full of students with calculators.
Ask “what’s the derivative of this unfamiliar function?” — the professor answers instantly, the stadium is useless (they’d have to coordinate, and only one person can think about it).
Ask “multiply these 10 million pairs of numbers” — the professor takes weeks, the stadium finishes in seconds.
Now the crucial extra detail that most versions of this analogy omit: the stadium’s real constraint is not thinking, it’s the aisles. Getting 10 million numbers to 50,000 students requires enormous throughput of paper. If the aisles can only carry 100 sheets/second, the students sit idle no matter how fast they compute. That’s memory bandwidth (2.e), and it is why so much of Modules 12 and 13 is about moving fewer bytes.
4. Tiny example#
// matmul.go — how far one CPU core gets on the GPU's favourite workload.
package main
import (
"fmt"
"time"
)
func main() {
const n = 1024
a, b, c := make([]float32, n*n), make([]float32, n*n), make([]float32, n*n)
for i := range a {
a[i], b[i] = float32(i%7), float32(i%5)
}
t0 := time.Now()
for i := 0; i < n; i++ {
for k := 0; k < n; k++ {
aik := a[i*n+k]
for j := 0; j < n; j++ {
c[i*n+j] += aik * b[k*n+j]
}
}
}
dt := time.Since(t0).Seconds()
fmt.Printf("go, 1 core, float32: %.0f ms %.4f TFLOP/s\n", dt*1e3, 2*n*n*n/dt/1e12)
}That prints roughly 0.007 TFLOP/s. Now the same multiplication (at 8192×8192) through an
optimised maths library on a 32-core server CPU, and on an A100 GPU (measured on 2020-era
hardware; a 2026 GPU is several times faster again):
go, 1 core, plain loops 0.007 TFLOP/s
cpu, 32 cores, AVX-512 BLAS 0.60 TFLOP/s 86x
gpu, float32 37.3 TFLOP/s 5300x
gpu, float16 (tensor cores) 250.0 TFLOP/s 35700xThree lessons in one table. Library-grade CPU code (SIMD + all cores, 3.d) is ~90x faster than a simple loop. The GPU is ~60x faster again at the same precision, and using the GPU’s specialized units (tensor cores, via FP16) gives another 7x on top. Buying a GPU and running FP32 leaves most of the value on the table — a mistake real teams make.
Now the reverse experiment:
// A branchy, sequential, data-dependent workload
func collatzSteps(n uint64) int {
c := 0
for n != 1 {
if n%2 == 0 {
n /= 2
} else {
n = 3*n + 1
}
c++
}
return c
}Try to make that fast on a GPU. You can’t, meaningfully: every element takes a different number of iterations (warp divergence, 6.c), and there’s no arithmetic density. The CPU wins easily. GPUs are not “faster computers.” They are faster at one specific shape of work.
5. Technical explanation#
The comparison table#
| Property | Server CPU (2026: AMD EPYC 9005, Intel Xeon 6) | H100 SXM | B200 |
|---|---|---|---|
| Cores | 64–192 heavyweight | 132 SMs × 128 lanes = 16,896 | 148 SMs |
| Threads in flight | 128–384 | ~250,000 | ~300,000 |
| Clock | 2–4 GHz | 1.4–1.8 GHz | ~1.9 GHz |
| Peak 16-bit matrix maths | ~5–15 TFLOP/s (AMX / AVX-512) | 989 TFLOP/s | ~2,250 TFLOP/s |
| Memory | 0.5–6 TB DDR5 | 80 GB HBM3 | 180–192 GB HBM3e |
| Memory bandwidth | ~0.5–0.85 TB/s (12 DDR5 channels) | 3.35 TB/s | ~8 TB/s |
| Cache | 300–500 MB L3 | 50 MB L2 | ~126 MB L2 |
| Latency to memory | ~100 ns | ~500 ns (hidden by threads) | similar |
| Branch prediction | excellent | none | none |
| Power | 300–500 W | 700 W | ~1,000 W |
The two numbers that matter for inference: memory bandwidth (5–15x more on a GPU) and matrix FLOPs (100x more). The CPU’s advantages — huge memory capacity and fast branchy code — matter for other jobs.
Latency hiding vs latency avoidance#
This is the deepest architectural difference and worth understanding precisely.
CPU strategy — AVOID latency:
big caches so most accesses never reach DRAM
prefetchers that predict what you'll need
out-of-order execution to keep going past a stall
→ optimizes for one thread that must not stall
GPU strategy — HIDE latency:
when a warp stalls on memory, instantly switch to another warp
keep 64 warps resident per SM so there is always one ready
→ optimizes for aggregate throughput; individual threads stall constantlyConsequence: a GPU needs enough parallel work to hide its latency. Give it a batch of 1 and you get a fraction of its capability — not because the hardware is broken, but because you gave it nothing to switch to. This is the architectural reason batching matters, complementing the bandwidth argument from lesson 2.d.
When the CPU is actually the right answer#
Genuine cases, not consolation prizes:
| Case | Why |
|---|---|
| Small models (< 1B params) at low QPS | GPU fixed overheads (launch, transfer) dominate |
| Sparse / irregular models (trees, GBDT) | branchy; GPUs hate it |
| Very strict cost floor, low traffic | a GPU idle at 2% utilization is pure waste |
| Embedding lookups on huge tables | random access to hundreds of GB; capacity beats bandwidth |
| Edge / on-device with no GPU | no choice |
| Preprocessing, tokenization, sampling logic | inherently serial and cheap |
| Very large models with offloading, batch-1 | when the model doesn’t fit, DRAM capacity wins over HBM speed |
Modern CPUs with matrix extensions (Intel AMX, Arm SME/SVE) and 8-bit or 4-bit weights do respectably on small transformers, and engines target them: llama.cpp everywhere, vLLM on x86 and Arm CPUs (15.e). Apple silicon’s unified memory gives ~400–800 GB/s, closer to a mid-range GPU than to a typical server CPU, which is why Macs are popular for local inference.
The transfer tax#
The GPU is behind a bus:
CPU DRAM ──── PCIe Gen5 x16 (~50 GB/s real) ────► GPU HBM (3,350 GB/s on H100)
↑
~65x slower than HBMMoving 1 GB to the GPU costs about 20 ms — longer than several decode steps. Rules that follow:
- Load weights once, keep them resident. Never stream weights per request.
- Transfer only tokens, not text. Tokenize on CPU; send small integer arrays.
- Overlap transfers with compute using pinned memory and separate CUDA streams.
- Never round-trip mid-model. A CPU-side operation in the middle of a forward pass costs two transfers plus a synchronization; it can easily dominate the entire step.
That last one is a real and common performance bug: a custom logits processor implemented in Python forces a device→host copy and a sync every single decode step.
6. Under the hood#
A GPU kernel’s life:
1. CPU: cudaLaunchKernel(...) ~5 µs of CPU work
2. Command written to a queue in pinned memory
3. GPU front-end fetches it, allocates blocks to SMs
4. Each SM launches warps; warp scheduler picks ready warps every cycle
5. Warps issue loads; stall; scheduler switches to other warps
6. Results written back to HBM
7. (optional) completion signal / eventStep 1 is why decode is launch-bound: a 70B model runs ~500-2,000 kernels per token, and at 5 µs each that is 2.5-10 ms of pure CPU launch overhead — potentially more than the GPU work itself at small batch. CUDA graphs (5.f) collapse those thousands of launches into one, and routinely give 20-40% end-to-end speedups on small-batch decode. That is one of the highest return-on-effort optimizations available, and it exists purely because of the CPU-GPU boundary.
7. Performance implications#
For an 8B model at 16 bits, one request at a time:
CPU (12-channel DDR5) GPU (H100)
Weights memory 16 GB DDR5 16 GB HBM
Bandwidth ~0.5 TB/s 3.35 TB/s
Decode floor 32 ms/token 4.8 ms/token
Realistic 45–70 ms/token 7–10 ms/token
Tokens/sec (1 user) 14–22 100–140
Max useful batch ~4–8 hundreds
Cost/hour (rental) ~$1.50 ~$2.50
Cost per 1M tokens ~$20–30 (1 user) ~$5–7 (1 user); far less batched (1.d)The GPU is about 6x faster per user and 4x cheaper per token even at one user, and it keeps getting cheaper as the batch grows while the CPU does not — because the GPU has the bandwidth and the arithmetic to serve many requests per weight read.
Where CPUs close the gap: small models and low traffic. At 0.5 requests/sec with a 300M model, the GPU sits idle 99% of the time and the CPU wins on cost outright.
8. Production implications#
- Right-size the accelerator to the model and traffic. An L4, L40S or RTX PRO-class card serving an 8B model at moderate traffic is often better economics than an H100 or B200. Not everything needs the flagship (Module 8).
- Keep the CPU busy with CPU work. Tokenization, detokenization, request parsing, JSON schema validation for structured output, image preprocessing. Under-provisioning CPU on a GPU node is a classic bottleneck — you will see GPU utilization dips that correlate with CPU saturation.
- Watch the CPU→GPU boundary in profiles. Nsight Systems showing gaps between kernels with busy CPU means you are launch-bound or Python-bound.
- Consider CPU inference for the long tail. A platform serving 200 models can put the 150 rarely-used small ones on CPU nodes and reserve GPUs for the hot ones (Module 21).
- Tightly coupled CPU–GPU systems change the calculus by widening the transfer bottleneck. NVIDIA’s Grace Hopper and Grace Blackwell superchips link CPU and GPU with NVLink-C2C at about 900 GB/s (Vera Rubin doubles it to 1.8 TB/s, 7.e), making CPU memory a practical overflow tier for the KV cache (14.k). Apple silicon goes further with one shared memory pool.
9. Common mistakes#
“GPU is always faster.” Not for small models, small batches, branchy code, or random access. Measure.
Running FP32 on a GPU with tensor cores. You are leaving 5-15x on the table. Use FP16/BF16 at minimum.
Under-provisioning CPU or host RAM on GPU nodes. Tokenization, the scheduler, and the HTTP stack all run on CPU. A saturated CPU starves an expensive GPU.
Transferring data every request. Weights resident, tokens transferred. If you see multi-MB H2D copies per request in a profile, something is wrong.
Ignoring launch overhead. At batch 1 it can exceed compute. Use CUDA graphs.
Comparing a tuned GPU path against an untuned CPU path (or vice versa). CPU inference with oneDNN/AMX/INT8 is 5-10x faster than naive PyTorch FP32 on CPU. Compare tuned to tuned or your conclusion is meaningless.
10. Hands-on exercise#
A. Benchmark both. Run the matmul benchmark on CPU FP32, GPU FP32, GPU FP16, GPU BF16.
Compute achieved TFLOP/s and the fraction of spec peak for each. Record in numbers.md.
B. Measure the transfer tax. Time tensor.cuda() for sizes from 1 KB to 1 GB, with and
without pinned memory (torch.empty(..., pin_memory=True)). Plot GB/s vs size. At what size do
you reach peak PCIe bandwidth? What is the fixed overhead per transfer?
C. Find the crossover. Run a small model (e.g. a 125M-parameter transformer) on CPU and GPU at batch sizes 1, 4, 16, 64. At which batch size does the GPU win? Why isn’t it batch 1?
D. Launch overhead. Time 1,000 tiny kernel launches (x + 1 on a 16-element tensor).
Divide by 1,000. That is your launch overhead. Multiply by the number of kernels in a decode
step for a 32-layer model (~200-400). Compare to your measured ITL.
11. Interview questions#
- Why are GPUs faster at inference than CPUs? Give two independent reasons.
- Explain latency hiding vs latency avoidance. Which does each architecture use and why?
- When would you choose CPU inference? Give three concrete scenarios.
- What is the cost of a CPU↔GPU transfer, and how do you avoid paying it per request?
- Why does a GPU need large batches to be efficient — give both the bandwidth and the occupancy explanation.
- An 8B model runs at 12 tokens/sec on an H100 at batch 1. Is that good? How would you tell?
- Your GPU utilization dips to 40% under load while CPU is pegged. Diagnose.
12. Further reading#
- [FUNDAMENTAL] Hwu, Kirk & El Hajj, Programming Massively Parallel Processors (4th ed.), chapters 1–4
- [REFERENCE] NVIDIA H100 architecture whitepaper and Blackwell architecture overview
- [FUNDAMENTAL] Hennessy & Patterson, Computer Architecture: A Quantitative Approach, chapter 4 (data-level parallelism)
- [ESTABLISHED] llama.cpp — read its CPU kernels to see how far CPU inference can be pushed
- [REFERENCE] AMD EPYC 9005 and Intel Xeon 6 product pages — CPU memory channels and bandwidth (checked on 11 November 2026)