Diving into TPU architectures
Published
This post intends to dive into a TPUv6e chip from a first principles perspective.
I’ve been training models, and optimizing AlphaFold3 for TPU v6e chips, so these notes are things I document as I go so that I understand the lower level more. I hope it will be an accessible guide once it’s fully written. This article assumes you have a bit of a background in computer architecture.11 I’m glad that at CMU we had guest lectures about TPUs from Google which dived in very well on how to code for TPUs. However at the time of learning, I was pretty naive since I wasn’t actively using TPUs. But now, I have more motivation to revisit and learn this more carefully.
What is inside a v6e chip
Alright, if we think from first principles, first off, for any kind of processor, we need to have something that controls the flow, meaning that it orders everybody to stay in sync.
Alright, diving bit deeper, we have the high bandwidth memory (HBM) that we all deeply value22 similar to how we say H100s have 80GB of VRAM.. While this is “high bandwidth” memory, the actual parts that do the computation operate quite fast33 each MXU giving out 459 TFLOP/s in bfloat16. That’s why VMEM exists.
Next, the question is, why do we have separate kind of arithmetic units? The simple answer is that these specialize on specific kind of operations :
- MXU: Perform matrix multiplications.
- VPU: Apply gating, elementwise products, activations, and normalization.
- XLU: Handle certain lane permutations and cross-lane data rearrangements.
What does a Pallas kernel control?
Pallas is an extension to JAX that lets you write kernels. Some of Anthropic’s bioml optimizations use Pallas: the FlashPairformer kernels for their JAX models are written in it44 These target NVIDIA GPUs only. Their PyTorch models use CUDA and Triton versions of the same kernels..
If Pallas can be used for both GPUs and TPUs, how does Pallas know such low level detail about both of them? It doesn’t: it hands your kernel to a compiler for that chip. On TPUs that is Mosaic, which turns it into TPU instructions; on GPUs it is Triton (what Anthropic’s kernels use) or Mosaic GPU.
So in summary, your Pallas kernel controls these parts of the TPU, and the compiler takes care of the more fine-grained components.
Your Pallas kernel decides
| The compiler decides
|
This split isn’t strict. You can pick a specific MXU yourself with pltpu.matmul_acc_lhs, and not every transpose needs an XLU: some only relabel dimensions, and others happen inside a matmul.
To be continued…
MoveThanks!