AI hardware and kernels: GPUs, TPUs, and FlashAttention
Memory bandwidth and kernel design, not raw chip speed, set the real cost of a token.
What are GPUs and TPUs, and why does the difference matter?
A GPU (graphics processing unit) is a general-purpose parallel processor adapted for the matrix math behind neural networks. A TPU (tensor processing unit) is a custom chip Google built specifically for that math. The TPU, described in Jouppi et al. (2017), centres on a 65,536-unit 8-bit matrix multiply array that reaches a peak of 92 TeraOps per second. It is backed by 28 MiB of on-chip memory managed by software rather than hardware.
Jouppi et al. tested the TPU against a contemporary Intel Haswell CPU and an Nvidia K80 GPU. All three ran production inference workloads at Google in the high-level framework TensorFlow. The TPU ran about 15 to 30 times faster than its contemporaries, and delivered 30 to 80 times more operations per watt. The gap came from a deliberate trade: the TPU skips the caches, out-of-order execution and prefetching that CPUs and GPUs use to boost average throughput, favouring predictable latency instead.
Why does memory bandwidth matter more than raw compute?
Every chip has two separate limits: how fast it can do arithmetic, and how fast it can move data between memory and the units doing that arithmetic. The FlashAttention paper (Dao et al., 2022) calls an operation compute-bound when arithmetic dominates its runtime, and memory-bound when moving data does. On an A100 GPU, the paper notes, high-bandwidth memory (HBM) runs at 1.5 to 2.0 terabytes per second. On-chip SRAM runs at roughly 19 terabytes per second — an order of magnitude faster, though far smaller.
Compute speed has outpaced memory speed on modern GPUs, Dao et al. write. So most transformer operations are now bottlenecked by memory access rather than arithmetic. Softmax, masking and dropout — the elementwise and reduction operations threaded through attention — fall into this memory-bound category. That means counting FLOPs (floating-point operations) no longer predicts wall-clock speed; counting memory reads and writes does.
Why does a kernel like FlashAttention matter?
A kernel is the unit of code a GPU executes: it loads data from HBM into registers or SRAM, computes, and writes results back. Standard attention implementations write the full sequence-length-squared attention matrix to HBM at each step. Dao et al. show this requires memory access that grows quadratically with sequence length.
FlashAttention instead tiles the computation. It splits the input into blocks small enough to fit in fast SRAM, computes attention incrementally without ever materialising the full matrix in HBM, and fuses every step into a single CUDA kernel. Dao et al. prove this cuts HBM accesses to a quantity proportional to sequence length squared divided by SRAM size — up to nine times fewer than standard attention for typical head dimensions. They also show no exact-attention algorithm can asymptotically beat this bound across all SRAM sizes.
The payoff was measured, not theoretical. On GPT-2 with sequence length 1024, Dao et al. report FlashAttention needed only 4.4 gigabytes of HBM reads and writes against 40.3 gigabytes for standard attention. That cut runtime from 41.7 to 7.3 milliseconds on an A100. The lesson generalises: a kernel that respects the memory hierarchy can beat one with fewer FLOPs but more traffic.
What does this mean for the cost of a token?
Training and serving large models bills by time on a chip. That time is set by whichever resource — compute or memory bandwidth — runs out first. Dao et al. report FlashAttention trained BERT-large 15% faster than the MLPerf 1.1 speed record. It trained GPT-2 up to three times faster than the HuggingFace baseline and 1.8 times faster than Megatron-LM, all on the same A100 hardware with no change to the model itself.
Faster, more memory-efficient attention also changes what is affordable to build. FlashAttention's memory use grows only linearly with sequence length rather than quadratically. Because of that, Dao et al. trained GPT-2 at a 4,000-token context length that still ran 30% faster than Megatron-LM's 1,000-token version, while scoring 0.7 points better on perplexity, a standard measure of language-model quality. Every token of longer context that used to cost quadratically more memory now costs proportionally less. That is the real-money consequence of IO-aware kernel design.
What are the trade-offs and limits?
The TPU's determinism and efficiency came at a cost Jouppi et al. (2017) are explicit about. It is specialised for inference on production neural networks such as multilayer perceptrons, convolutional networks and long short-term memory networks, trading away the general-purpose flexibility of a CPU or GPU to get there. The paper notes a further ceiling: using the GPU's faster GDDR5 memory in the TPU's design would have tripled achieved throughput. That implies the TPU of that generation was itself memory-constrained despite its specialised compute array.
FlashAttention's trade-off is recomputation. Rather than storing the large intermediate attention matrices for the backward pass, it recomputes them on-chip from stored output and normalisation statistics. Dao et al. report this increases total FLOPs but still speeds up training overall, because it eliminates far more expensive HBM traffic than it adds in arithmetic. Block-sparse FlashAttention, an approximate variant in the same paper, trades some accuracy for further speed by skipping blocks the sparsity pattern marks as zero.
Where is this used today?
The TPU described in Jouppi et al. (2017) was already deployed across Google's datacenters by 2015. It ran inference for workloads that represented 95% of the company's neural-network inference demand at the time. FlashAttention, released in 2022 and open-sourced by its authors, was built as a drop-in replacement for standard attention, requiring no change to the transformer architecture it accelerates.
Dao et al. report it enabled new capabilities outright: the first transformer to score better than chance on the Path-X task at a 16,000-token sequence length, and the first, using block-sparse FlashAttention, to do so on Path-256 at 64,000 tokens. Both results came from making longer context computationally affordable, not from a new model architecture.
Key terms
- TPU (tensor processing unit)
- A custom ASIC Google deployed in datacenters from 2015 to accelerate neural-network inference, built around a large matrix multiply unit and on-chip memory.
- HBM (high-bandwidth memory)
- The GPU's main memory, large in capacity but, per the FlashAttention paper, an order of magnitude slower than on-chip SRAM.
- SRAM
- The GPU's small, fast on-chip memory, estimated in the FlashAttention paper at around 19 terabytes per second of bandwidth on an A100, versus 1.5 to 2.0 terabytes per second for HBM.
- Arithmetic intensity
- The number of arithmetic operations performed per byte of memory accessed, used to classify an operation as compute-bound or memory-bound.
- Kernel
- A unit of GPU code that loads inputs from HBM, performs computation, and writes outputs back to HBM.
- Kernel fusion
- Combining multiple operations into one kernel so data is loaded from HBM once instead of repeatedly for each operation.
- Tiling
- Splitting large matrices into blocks small enough to fit in fast on-chip memory, computing on each block in turn rather than materialising the whole matrix at once.
- IO complexity
- A measure of an algorithm's cost in terms of memory reads and writes between HBM and SRAM, rather than in floating-point operations.
Written from
AI hardware and kernels in the news
AWS Shows Qwen3 Training on Trainium via torchtitan
A recipe for fine-tuning Qwen3 on Trainium2 without rewriting training code
Google Cloud to offer Nvidia Vera Rubin instances next month
A5X scales toward 960,000 GPUs, with Europe expansion planned
llama.cpp fixes a silent NEON fp32-to-fp16 bug on ARM CPUs
A hardware conversion instruction sat unused while software quietly took over
Hugging Face adds native TPU backend via TorchTPU
PyTorch users can now skip torch_xla and JAX to run models on Google's chips
Study finds mobile NPUs waste most of their edge on LLMs
Framework choice, not chip design, decides who wins the phone AI race
New CUDA kernels speed Llama inference on Hopper GPUs
FP8 prefill and INT4 decode cut latency, at a small cost in accuracy
llama.cpp patches Hexagon NPU attention bug in b11696
A single fix for Qualcomm's HMX flash-attention sinks ships in the latest build
Meta details how it made AMD GPUs production-ready for training
Porting recommendation models from Nvidia to AMD took more than a driver swap
AWS details MoE kernel fixes for SageMaker, upstreams them to vLLM
Three upstreamed vLLM fixes squeeze more throughput from Hopper GPUs
llama.cpp tunes CUDA kernel for Gated DeltaNet state updates
Release b11494 defaults GDN state updates to four columns per warp, a CUDA scheduling change in PR #30087.
llama.cpp adds BF16 support for XIELU on CUDA
Release b11457 closes a gap in the CUDA kernel, letting XIELU activations run in bfloat16 on Nvidia GPUs.
Benchmark finds LLM-generated GPU kernels fail in production
FastKernels shows kernel-level speedups mostly vanish once agents' code runs inside real models.
Study: TPU speed gains for AlphaFold2 vanish without proper batching
JAX's default path leaves seven of eight TPU chips idle. That erases the hardware's cost edge over a GPU.
Study maps when KV cache, not model weights, bottlenecks LLM inference
A paper derives exact context lengths where cache traffic overtakes weight traffic on H100, B200 and MI300X.
Written from the documents above by The Neural Net’s automated desk (claude-sonnet-5, theneuralnet/guides@1) without human review, and updated as news on this topic publishes. How this works.