Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
GPUs: the bottleneck is never where you think.
Every AI engineer eventually has the conversation: "just get a bigger GPU." Sometimes right, often expensively wrong — because GPU performance isn't one number, it's a race between arithmetic and memory, and most workloads lose on the memory side. This is the mental model that tells you which wall you're hitting, why FlashAttention was inevitable, and when the bigger GPU genuinely helps.
Throughput machines, not fast machines
A CPU is a latency processor: a few heroic cores with deep caches and branch predictors, built to finish one thread as fast as possible. A GPU is a throughput processor: ~100+ streaming multiprocessors (SMs) hosting tens of thousands of lightweight threads, built to finish all the work per second — no single thread is fast, the swarm is.
The execution model is SIMT — single instruction, multiple threads: threads run in lockstep groups of 32 called warps, one instruction driving 32 data elements. This is why GPUs devour uniform work (every element gets the same treatment — exactly what a matmul is) and why branch divergence hurts: if half a warp takes the if and half takes the else, the hardware runs both paths serially. Deep learning happens to be the most uniform large-scale workload ever invented — the marriage wasn't luck, it was fit.
The memory hierarchy is the whole game
The compute units can chew through data far faster than HBM can deliver it. So the central discipline of GPU performance is arithmetic intensity: FLOPs per byte moved. Each GPU has a break-even ratio (peak FLOPs ÷ bandwidth ≈ ~300 FLOPs/byte on H100 BF16). Above it, you're compute-bound — the cores are the wall. Below it, memory-bound — the cores idle while bytes crawl. That one ratio — the roofline — explains most "why is this slow" mysteries in AI.
Where LLMs land on the roofline
| Workload | Bound by | So the fix is… |
|---|---|---|
| Training / prefill | compute — big matmuls, high intensity | tensor cores, lower precision (BF16→FP8), better MFU |
| Decode (one token) | bandwidth — every weight read for little math | quantize (fewer bytes), batch (share the read), speculative decoding |
| Attention (naive) | bandwidth — the N×N matrix commutes to HBM | fuse it: FlashAttention |
| Elementwise ops | bandwidth — one FLOP per byte | kernel fusion, so bytes are read once for many ops |
Tensor cores are why the compute side got so tall: dedicated units performing small matrix multiply-accumulates in hardware, with throughput that roughly doubles each precision step down (BF16 → FP8 → FP4 on the newest parts) — the hardware reason low-precision training and serving keep winning. And MFU (model FLOPs utilization) is the honesty metric: real training jobs hitting 35-45% of peak is good; the marketing number assumes a workload nobody runs.
Same math, tiled so the N×N scores live in on-chip SRAM and never touch HBM: the operation was bandwidth-bound, so moving fewer bytes made it directly faster. Memorize the shape of that win — the modern optimization is almost never "compute less," it's "move less."
The ridge point is one division
"Compute- or memory-bound?" isn't a vibe — it's arithmetic. The ridge point is where the two roofs cross: the arithmetic intensity (FLOP per byte moved) at which a kernel stops being starved for data and starts being limited by math. It's just peak compute divided by peak bandwidth:
Below 156 FLOP/byte you're wasting the A100's compute waiting on memory; above it, you're finally math-limited. Now place LLM decoding on that axis. Decoding one token reads every weight (2 bytes each) to do ~2 FLOPs per weight — so its intensity is a dismal 1 FLOP/byte. Batch B tokens and the same weight read serves all of them:
To cross the ridge on an A100 you need batch ≥ 156. That single number is why batched serving exists.
This is not a memorized fact — it's a calculation you can rerun for any chip and batch size. The roofline calculator below does exactly that: pick a device, sweep the batch size, and watch decode climb off the bandwidth roof toward the compute roof.
The kernel stack: who writes the fast code
A kernel is a function launched across a grid of thread-blocks — the unit of GPU work. Almost nobody hand-writes them anymore; the stack has layers:
The practical division of labor: use the framework; take the torch.compile win; profile before believing anything; and reach for Triton only when the profiler shows a genuinely unfused hot spot. Writing CUDA is a specialization — reading a profile is table stakes.
Many GPUs: the interconnect becomes the memory wall
Models outgrew single GPUs, so the memory-hierarchy story repeats one level up: NVLink (~900 GB/s GPU-to-GPU inside a node) and InfiniBand (~400 Gb/s between nodes) are to the cluster what HBM is to the chip — the slow layer everything must be tiled around. The primitive is the collective: all-reduce (sum gradients everywhere), all-gather, reduce-scatter, moved by NCCL and overlapped with compute so communication hides behind math.
The three parallelism strategies in one line each: data parallel (copy the model, split the batch, all-reduce gradients), tensor parallel (split individual matrices across GPUs — needs NVLink-class bandwidth), pipeline parallel (split layers into stages — cheap on bandwidth, pays a bubble). Real frontier runs compose all three; that composition is its own handbook, coming next.
The working checklist
| Question | How to answer it |
|---|---|
| Compute- or memory-bound? | arithmetic intensity vs the GPU's ratio; profiler confirms |
| Is the GPU even busy? | MFU / SM occupancy — data loading and CPU stalls fake "slow GPU" constantly |
| Decode too slow? | bandwidth ÷ model bytes first; quantize or batch before shopping |
| Training too slow? | step-time breakdown: compute vs communication vs dataloader |
| Custom kernel worth it? | only if the profiler shows unfused memory-bound ops on the hot path |
Compute the roofline yourself
"Memory-bound" stops being jargon the moment you divide two numbers. This is the roofline model in a dozen lines: two accelerators (A100, H100) with their real peak FLOP/s and HBM bandwidth, the ridge point that separates memory-bound from compute-bound, and LLM decode placed on that axis. Sweep the batch size and watch a single-token decode — stuck at 0.6% of the A100's compute — climb the bandwidth roof until, at batch ≥ 156, it finally saturates the machine. That's not a rule of thumb; it's the number you just computed.
Worked example: how fast can one GPU decode a 7B model?
A 7B-parameter model in BF16 is 7B × 2 bytes = 14 GB of weights. Every decode step reads all of them. Use the page’s A100 and H100 numbers and its intensity rule (batch B gives B FLOP/byte) to find the ceiling, ignoring the KV cache for now.
| Step | Question | Arithmetic | Answer |
|---|---|---|---|
| 1 | Time to read the weights once on an A100 | 14 GB ÷ 2.0 TB/s | 7 ms per step |
| 2 | Time for the math, batch 1 | 2 × 7B FLOPs ÷ 312 TFLOP/s | 0.045 ms: the cores idle 99% of the step |
| 3 | Ceiling at batch 1 | 1 token per 7 ms | ~143 tokens/s |
| 4 | Batch 32 | math 1.44 ms, still under the 7 ms read | 4,571 tokens/s, still memory-bound |
| 5 | Batch 156 (the ridge) | math 7.0 ms = read 7.0 ms | 22,286 tokens/s; compute-bound from here |
| 6 | Same model on an H100, batch 1 | 14 GB ÷ 3.35 TB/s = 4.18 ms | ~239 tokens/s |
| 7 | H100 vs A100 at batch 1 | 3.35 ÷ 2.0, not 990 ÷ 312 | 1.68× faster, not 3.17× |
| 8 | A100 with 4-bit weights, batch 1 | 3.5 GB ÷ 2.0 TB/s = 1.75 ms | ~571 tokens/s, 4× step 3 |
Steps 2 and 3 are the page’s 0.6% figure seen from the other side: at batch 1 the A100 spends 7 ms moving bytes and 0.045 ms doing math. Batching (step 4) multiplies throughput at no cost per step until the ridge. Quantizing (step 8) helps even a single user, because it shrinks the bytes every step must read. Step 7 is the answer to “just get a bigger GPU”: for single-stream decode you get the bandwidth ratio, not the FLOP ratio. Real serving lands below these ceilings, and the KV cache is one reason. Each sequence in the batch reads its own cached keys and values every step, so bytes grow with batch × context length, and the ridge moves further away.
Cost and trade-offs of the standard fixes
Reusing the columns: Time is what the fix speeds up. Space is what it costs in memory, quality or hardware.
| Case | Time | Space | Why |
|---|---|---|---|
| Batching decode | Throughput rises about linearly with B up to the ridge (B ≈ 156 on an A100) | KV cache memory per sequence; each user waits for the batch step | Shares one weight read across B tokens. Latency per token does not improve. |
| Quantization (BF16 → 8- or 4-bit) | Fewer bytes per step: 2× or 4× on the weight read | Some quality risk; must be measured on your task | Helps memory-bound decode directly, even at batch 1. |
| FlashAttention | Fewer HBM round trips for attention | Score memory linear in sequence length instead of N×N | At N = 8,192 one head’s BF16 score matrix is 134 MB; tiling keeps it on-chip. |
Kernel fusion / torch.compile | Elementwise chains read memory once instead of once per op | Compile time, and occasional graph breaks | The page’s ~1.3–2× for most models, for one line of code. |
| Tensor parallel | Splits each matmul, and each weight read, across GPUs | An all-reduce per layer; needs NVLink-class links | Cuts per-token latency when one GPU’s bandwidth is the wall. |
| Pipeline parallel | Fits models too big for one node | A pipeline bubble of idle stages | Light on bandwidth, so it can cross nodes. |
| A bigger GPU | Bandwidth ratio for decode; FLOP ratio for training | Price | Check which roof you are under before paying for the other one. |
Every row except the last moves fewer bytes or reuses each byte more. That is the page’s FlashAttention lesson as a menu: the cheap wins are almost always on the memory side.
Common mistakes
- Comparing GPUs on peak TFLOP/s for inference
Single-stream decode is bandwidth-bound, so the spec that matters is memory bandwidth. The H100 has 3.17× the A100’s BF16 compute but 1.68× its bandwidth, and batch-1 decode speeds up by the smaller number.
- Reading nvidia-smi “GPU-Util” as how busy the GPU is
That figure is the share of time at least one kernel was running. A memory-bound kernel using a few percent of the FLOPs, or a tiny kernel on one SM, still shows 100%. Use MFU, SM occupancy and achieved bandwidth from a profiler instead.
- Timing GPU code without synchronizing
Kernel launches are asynchronous: the Python call returns before the GPU finishes. Timing it with a wall clock measures the launch. Call
torch.cuda.synchronize()before reading the clock, or use CUDA events, and discard the first iterations, which include warm-up and compilation. - Leaving the KV cache out of the batch math
The B FLOP/byte rule counts only weights. Each sequence also reads its KV cache every step, and that grows with context length. With long contexts, the cache can be read in larger volume than the weights, so a big batch may stay memory-bound long past B = 156.
- Mixing up Gb/s and GB/s
InfiniBand’s ~400 Gb/s is gigabits: 50 GB/s. NVLink’s ~900 GB/s is gigabytes, 18× more. That gap is why tensor parallelism, with an all-reduce in every layer, stays inside a node, and only pipeline or data parallelism crosses nodes.
Where this shows up in production and interviews
- LLM serving engines
Engines such as vLLM exist to push B up: continuous batching adds and removes sequences between decode steps, and paged KV-cache memory packs more sequences into the same HBM. Both are the batching row of the trade-off table, engineered.
- Training at scale
Large training runs report MFU as their efficiency figure, and the page’s 35–45% is the range worth aiming for. Sharding schemes such as ZeRO and FSDP split optimizer state, gradients and weights across data-parallel GPUs, trading extra communication for memory.
- Profilers
Nsight Systems shows the timeline: kernels, copies, gaps where the GPU waits on the CPU or data loader. Nsight Compute analyses one kernel and plots it on a roofline chart. The PyTorch profiler maps both back to your model’s code.
- The interview version
“Estimate tokens per second for a 70B model on 8 H100s.” 70B × 2 bytes = 140 GB. Split by tensor parallelism, each GPU reads 17.5 GB per step, and 8 × 3.35 TB/s gives about 5.2 ms per token, or ~191 tokens/s per stream as an upper bound. Then say what lowers it: all-reduce time, KV cache reads and kernel efficiency.
Check yourself
A 13B model in BF16 runs at batch 1 on one H100. What is the best possible decode speed?
About 129 tokens/s. The weights are 13B × 2 = 26 GB; 26 GB ÷ 3.35 TB/s = 7.76 ms per token. The math takes a fraction of a millisecond, so bandwidth sets the ceiling.
A square 4096 × 4096 × 4096 BF16 matmul: compute-bound or memory-bound on an A100?
Compute-bound. It does 2 × 4096³ ≈ 137 GFLOPs and moves three 4096² matrices of 2 bytes, about 101 MB. That is ~1,365 FLOP/byte, far above the A100’s ridge of 156. Big matmuls are why training is compute-bound.
Three elementwise ops (scale, add bias, GELU) run as three kernels. Roughly what does fusing them into one buy?
About 3× for that chain. Each op does almost no math per byte, so its time is the read and write of the tensor. Three kernels make three round trips to HBM; one fused kernel makes one. The FLOPs are the same.
A model needs 16 GPUs: two nodes of 8, NVLink inside each node, InfiniBand between them. How do you split it?
Tensor parallel inside each node, pipeline parallel across the two. Tensor parallelism all-reduces in every layer and needs NVLink-class bandwidth; pipeline parallelism only passes activations between stages, so it tolerates InfiniBand’s 50 GB/s.
Quick answers
Why are GPUs good at deep learning?
SIMT throughput machines + tensor cores meet the most uniform workload ever: giant matmuls. No single thread is fast; the swarm is.
What is arithmetic intensity?
FLOPs per byte moved. Above the GPU's ratio (~300 on H100 BF16) you're compute-bound; below it, memory-bound — and most inference is below it.
Why is FlashAttention faster?
Same math, tiled into on-chip SRAM so the N×N scores never touch HBM. Bandwidth-bound op + fewer bytes = directly faster.
Must I learn CUDA?
Learn the model and the profiler; use torch.compile; reach for Triton on proven hot spots. Hand-written CUDA is a specialization.
Ray tracing: how GPUs fake reality by chasing light
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The Prompting HandbookA friendly, hands-on field guide for everyday humans — learn the CRISP framework, spot bad prompts, practice with real recipes, play a drag-and-drop game, and test yourself with a quiz. No code required.Read →
- The Senior AI Engineer Interview Handbook60 questions across architecture, production incidents, agentic systems, RAG, evals, cost, safety, and leadership — what staff-level AI interviewers actually probe for.Read →
- The LLM Serving HandbookHow to serve large language models fast and cheap — prefill vs decode, the KV cache, continuous batching and PagedAttention (vLLM), quantization, speculative decoding, and the latency-vs-throughput tradeoffs that decide your inference bill.Read →
- The Transformers HandbookThe architecture behind every LLM, built up from scratch — tokens and embeddings, positional encoding, self-attention (query/key/value), multi-head attention, the transformer block (FFN, residuals, layer norm), and how a decoder-only model generates text autoregressively.Read →
- The Fine-Tuning HandbookWhen to fine-tune vs RAG vs prompting, full fine-tuning vs parameter-efficient methods, how LoRA and QLoRA make it cheap enough for a single GPU, why the data matters more than the method, catastrophic forgetting, and how to evaluate and decide.Read →
- The On-Device AI HandbookSmall models, everywhere: why 1–14B models got frontier-adjacent (distillation + textbook data), the napkin law of local inference (tokens/sec ≈ bandwidth ÷ bytes), quantization and the llama.cpp / GGUF / Ollama / MLX stack, the honest local-vs-cloud decision table, four hybrid patterns that ship, and the evals craft of choosing a small model that actually fits the device.Read →