L2 Intermediate · Module 4: CUDA programming fundamentals
4.8When not to use a GPU
A GPU is fast at big, regular, parallel work on data that already lives in its memory. Everything else, including small jobs, branchy logic, data that would have to cross the bus for one use, and most of the control logic of a serving engine, is often better on the CPU.
By the end you will be able to
- ✓Estimate the break-even size at which offloading work to a GPU pays off
- ✓List the workload properties that make a GPU a poor fit
- ✓Identify which parts of an inference server belong on the CPU
- ✓Recognize when CPU inference is the right answer
Every chapter so far has been about making GPUs go fast. This one is about recognizing work that shouldn’t go to a GPU at all.
The break-even test
Offloading pays off only if
Put numbers from this module into it. Add two vectors of 1 M floats (12 MB of traffic):
| Where the data is | CPU (one thread, ~24 GB/s) | GPU, including what it must move |
|---|---|---|
| In host memory, result needed on host | ~0.5 ms | copy 8 MB in + 4 MB out at ~13 GB/s ≈ 0.9 ms, plus ~0.08 ms of kernel |
| Already in GPU memory, result stays there | ~0.5 ms | ~0.08 ms of kernel + ~3 µs launch |
The same operation loses on the GPU in the first row and wins by about 6× in the second. Where the data lives decides it. A cheap operation on data that has to cross the bus once and come back is a loss; a cheap operation on data already in HBM, followed by more GPU work, is a win.
Signs that work belongs on the CPU
- It’s small. A few thousand elements can’t fill 270,000 thread slots (2.2), and a few microseconds of launch overhead may exceed the work itself (4.6).
- It’s sequential. A chain where each step needs the previous one gets nothing from parallel hardware, and a single GPU thread is much slower than a CPU core (2.1).
- It’s branchy and irregular. Parsing, string handling and pointer-chasing data structures diverge within warps and access memory randomly (2.4, 4.7).
- The data would cross the bus for one use. Moving data costs more than a light computation on it (4.3).
- It needs system services. Files, networks and most libraries are on the CPU side.
The CPU’s job in an inference server
A serving engine is a GPU program wrapped in a lot of CPU work:
| On the CPU | On the GPU |
|---|---|
| HTTP handling, request validation, chat templates | every layer of the model |
| Tokenization and detokenization | attention over the KV cache |
| Scheduling: which requests run this step, KV block allocation | sampling (to avoid shipping logits to the host) |
| Stop-string checks, streaming responses | KV cache reads and writes |
| Grammar and JSON-schema state machines (often) | applying the grammar’s token mask (often) |
The CPU part is serial, branchy, and small per step: exactly what CPUs are good at. The engineering problem is making sure it never makes the GPU wait. Engines overlap the CPU’s work for step with the GPU’s step , and move CPU work off the critical path (10.5).
When CPU inference is the right answer
Decode is memory-bound (3.4), so what matters for single-user generation is memory bandwidth and capacity, not FLOPs:
- A laptop running a 4-bit 7–8B model on its CPU with llama.cpp reads about 4.5 GB per token. At 50–100 GB/s of memory bandwidth that is roughly 10–20 tokens/s: perfectly usable for one person, with no GPU at all.
- A server CPU with 12 DDR5 channels (~460 GB/s) and a terabyte of RAM can hold models that don’t fit on any single GPU, and decode them at modest speeds.
- Apple silicon and similar chips share one large memory between CPU and GPU, removing the bus from the picture.
GPUs win decisively when there is concurrency (batching many users) or long prompts (compute-bound prefill). For one user, a small quantized model and a fast memory system, the CPU is often enough.
Sources
Check your understanding
0 / 4 answered1.An elementwise operation on 1 M floats starts and ends in host memory. What usually dominates the GPU version's time?
2.Which of these belongs on the CPU in an inference server?
3.Why can a CPU give usable single-user decode speed for a quantized 8B model?
4.What property of a workload most strongly favours the GPU?