TPU hardware for PyTorch engineers¶
Every performance decision in this book comes back to a handful of hardware facts: how wide the matrix unit is, how much fast memory sits next to it, how quickly bytes arrive from HBM, and how chips talk to each other. You do not need to program the TPU directly to use them. You need them to read a spec sheet correctly, to predict whether a change to your model will help, and to recognize when a slow step is the hardware doing exactly what it was built to do. This chapter builds that model from the chip outwards, using the numbers TorchTPU and Google publish, and ends with what each fact means for the PyTorch code you will write in later chapters.
What you already know from GPUs
Most GPU concepts have a TPU counterpart, but two of them change shape on the way. The left column is what you know; the right column is where it lands on a TPU.
| On a GPU | On a TPU | What is different |
|---|---|---|
| Streaming multiprocessors with warp schedulers | TensorCores | A TensorCore is a single-threaded processor. There is no hardware warp scheduler swapping in other work when one stalls; the compiler schedules every unit ahead of time. |
| Tensor Cores | MXU (matrix multiply unit) | A large systolic array, 128x128 or 256x256 depending on generation. It wants big, aligned matrix tiles. |
| CUDA cores doing elementwise math | VPU (vector unit) | A 2D SIMD unit of shape (8, 128). The scaling book (How to Scale Your Model) compares each VPU ALU to a CUDA core. |
| Hardware-managed L1/L2 caches | VMEM | An on-chip scratchpad managed by the compiler (or by your kernel), not by cache hardware. Data must be in VMEM before the TensorCore can use it. |
| HBM | HBM | Same idea, same role. |
| NVLink and NVSwitch inside a node | ICI (inter-chip interconnect) | Direct links between neighbouring chips arranged as a torus, with no switch in between. |
| The network between GPU nodes | DCN (data-center network) | Host-to-host networking between slices, far slower than ICI. |
| One process per GPU | One process per device | Same model, but one chip can be more than one device. |
What this chapter covers¶
- The units inside a TensorCore (MXU, VPU, VMEM, scalar unit) and what each one does.
- How a weight-stationary systolic array computes a matrix multiply, and why it rewards dimensions that are multiples of 128 or 256.
- The memory hierarchy from VMEM to HBM to host memory, and the bandwidth drop at each step.
- Chips, devices, hosts, slices and pods, and why a v7x chip appears to PyTorch as two devices.
- ICI and DCN: their topology and speed, and when a slice has wraparound links.
- Pod totals, a decode-step lower bound and an ICI transfer time, worked from published per-chip numbers.
A chip in one picture¶
The TorchTPU documentation describes a TPU chip as one or more TensorCores, one or more SparseCores, a large HBM, and inter-chip links. Each TensorCore is a single-threaded processor that contains matrix multiply units (MXUs), a vector unit (VPU) and a scalar unit. The scaling book adds the piece that ties them together: VMEM, a scratchpad inside the TensorCore that every operand passes through.
Follow the arrows: nothing reaches the MXU or the VPU except through VMEM, and nothing reaches VMEM except by a DMA from HBM. The host and other chips only ever touch HBM.
| Part | What it does | The number to remember |
|---|---|---|
| MXU | Multiplies matrices. It is a systolic array of multiply-add cells. | On v7x, one bf16[8,256] @ bf16[256,256] -> f32[8,256] every 4 cycles per MXU. |
| VPU | Elementwise math (activations, adds, multiplies), and reductions. | Shape (8, 128): 8 sublanes by 128 lanes. |
| VMEM | Scratchpad next to the compute units. Operands are copied here from HBM, results go back from here. | 128 MiB per v7x chip, 64 MiB per TensorCore. |
| Scalar unit | Fetches and dispatches all instructions and issues the transfers from HBM into VMEM. | Single-threaded: one DMA request per cycle per core. |
| HBM | Main device memory where your tensors live. | 192 GiB at about 7.4 TB/s per v7x chip. |
| SparseCore | Specialized for sparse operations such as gathers and scatters; the TensorCore can offload work to it. | 2 per v7x TensorCore. |
| ICI | Direct links to neighbouring chips. | 4 or 6 links per chip, depending on generation. |
In one phrase, a TPU is a compiler-scheduled processor. The TensorCore is a VLIW (very long instruction word) machine, as Google's description of the TPU v2 and v3 design explains: the compiler packs scalar, vector, matrix and DMA operations into one wide instruction bundle per cycle. That is why the shapes and layouts XLA sees matter so much on a TPU: the schedule is fixed when the program is compiled, and nothing at run time fills idle units for you.
The MXU is a systolic array¶
The MXU is where almost all of a model's FLOPs happen, and its shape explains several rules you will meet later.
A systolic array is a square grid of cells, each able to multiply two numbers and add the result to a running sum. In the weight-stationary form the TPU uses, a block of the weight matrix \(W\) is loaded into the grid first, one value per cell, and stays there. Rows of the activation matrix \(X\) then flow in from the left, one cell per cycle, each row starting one cycle after the row above it. Partial sums flow down. When a sum leaves the bottom of a column, it is one finished element of \(Y = XW\).
Watch one output, Y[0,0]: it collects X[0,0] times w at the top cell, adds X[0,1] times w one row down a cycle later, and leaves the bottom after three cycles. The weights never move; only activations and sums do.
code/ch01_hardware/systolic.py is a cycle-by-cycle model of this mechanism that checks itself against X @ W. It is simplified, not the MXU's exact timing.
Three consequences follow from the mechanism.
Every cell works on every cycle once the pipeline is full. There is an initial bubble while weights and the first activations load. After that, new activation rows and new weight blocks can stream in without another bubble. That is why the MXU reaches its peak only on large matmuls.
Small dimensions waste cells. The array is 256x256 on v6e and v7x, and 128x128 on earlier generations. The scaling book states that weight matrices are padded to multiples of 256 (128 before v6e) in both dimensions, and smaller axes are padded up to the full size. A matmul with an output dimension of 100 on a 256-wide MXU uses 100 of 256 columns: 39% of the array does useful work. Because v6e and v7x have two MXUs per TensorCore (four on v4 and v5 chips), tiles larger than the array times the number of MXUs keep all of them busy.
The peak FLOP rate is arithmetic on the array's shape. On v7x one MXU completes a [8, 256] @ [256, 256] product every 4 cycles. A matmul of \([M, K] \times [K, N]\) costs \(2MKN\) FLOPs, so:
At the v7x clock of about 2.2 GHz that is about \(5.8 \times 10^{14}\) FLOP/s per MXU. With 2 MXUs per TensorCore and 2 TensorCores per chip:
That matches the 2,307 TFLOP/s per chip that TorchTPU's own hardware table records for v7x. hardware_math.py in the companion code does this calculation and the test suite checks it.
The MXU takes bf16 inputs and accumulates in fp32. Lower-precision inputs go faster: v7x does fp8 matmuls at twice its bf16 rate, and v6e does int8 at twice its bf16 rate. TorchTPU's documentation also notes that current TPUs do not accumulate matmuls in anything narrower than fp32. Chapter 6 is about what these precision rules do to your numbers.
The VPU and the scalar unit¶
Everything that is not a matmul runs on the VPU: activation functions, residual adds, layer norms, softmax, reductions. The VPU is a 2D SIMD unit of shape (8, 128), where 128 is the lane axis and 8 is the sublane axis. All lanes run the same instruction each cycle. Reductions along the 8 sublanes are cheap; reductions across the 128 lanes go through a separate, slower cross-lane unit.
The VPU is much slower than the MXU. The scaling book works it out for v7x: about \(9 \times 10^{12}\) fp32 FLOP/s per TensorCore on the VPU (about \(1.8 \times 10^{13}\) for packed bf16), against about \(1.2 \times 10^{15}\) on the MXU, a ratio of roughly 64 for bf16. An operation that cannot be expressed as a matmul runs at a small fraction of the chip's headline rate. That is one reason fusion (chapter 4) matters: it keeps elementwise work from adding extra trips to HBM on top of its already modest compute rate.
The (8, 128) shape also sets the natural tile for data in VMEM and registers: each vector register holds an (8, 128) array of 32-bit values, so tensor shapes aligned to (8, 128) are the ones that keep every lane and sublane busy.
The scalar unit is the control processor. It fetches and dispatches every instruction and issues the transfers from HBM into VMEM. Because it is single-threaded, each TensorCore can start at most one DMA per cycle. One scalar unit drives the whole VPU, two MXUs and several DMA engines; the scaling book points out that this skew is a source of efficiency, and also why data-dependent control flow is hard to make fast on a TPU.
Memory: VMEM, HBM and the host¶
There are three places a tensor's bytes can be, and each step away from the MXU is slower.
VMEM is the scratchpad inside each TensorCore: 64 MiB per TensorCore on v7x, 128 MiB per chip. The scaling book compares it to a CPU's L1/L2 cache, but much larger and controlled by the program rather than by cache hardware. Its bandwidth to the MXU is about 7 times the HBM bandwidth on v7x. All operands must be copied into VMEM before the TensorCore can compute on them.
HBM holds your model's weights, activations and optimizer state: 16 GiB on a v5e chip, up to 192 GiB on a v7x chip. To run a matmul, the TPU copies chunks of both operands from HBM into VMEM, feeds them to the MXU, and copies result chunks back. These copies are pipelined so that they overlap with the MXU's work. If the copies cannot keep up, the MXU waits and the operation is limited by HBM bandwidth rather than by compute. Chapter 2 turns that condition into the roofline test.
Host memory sits behind PCIe. The scaling book gives PCIe bandwidth as typically about 16 GB/s per TPU (32 GB/s on v6e), and gives v4 as an example at 16 GB/s each way, close to 100 times slower than HBM. You can offload tensors to host memory, but not cheaply.
Read the axis as powers of ten: the gap from HBM to PCIe is more than two orders of magnitude, and DCN sits at the bottom. The hatched bars are the figures the source gives only approximately; ICI is a bidirectional total and DCN an egress figure, so compare their orders of magnitude, not their exact ratio.
The scaling book's summary of the whole hierarchy is a rule you will apply for the rest of the book: keep the amount of data crossing each link proportional to that link's speed.
Peak bandwidth is not achieved bandwidth
Spec sheet bandwidths are theoretical peaks. For a v7x chiplet, the TPU Agent Suite's chip constants list 3,686 GB/s theoretical HBM bandwidth and 3,207 GB/s as the practical peak once protocol overheads are paid. When a later chapter asks you to judge a measured number, compare it against the practical figure, and say which one you used.
Chips, devices and hosts¶
PyTorch sees devices, not chips, and TorchTPU runs one process per device. How many devices a chip exposes depends on its generation.
- v5e and v6e chips have one TensorCore each, and each chip is one device.
- v4 and v5p chips have two TensorCores fused into one logical device, called a megacore. PyTorch sees one device per chip with twice the FLOPs.
- v7x drops megacore. Each chip is two chiplets, each with one TensorCore, two SparseCores and its own 96 GiB of HBM, joined by a die-to-die (D2D) link. TorchTPU exposes each chiplet as its own device, so one v7x chip is two PyTorch devices.
Compare the device tags. On v6e the chip and the device are the same thing; on v7x each half of the chip has its own HBM and its own device number, and the halves talk over the D2D link rather than sharing memory.
This changes the arithmetic you do on spec sheets. A v7x chip's 2,307 TFLOP/s and 192 GiB split into about 1,153 TFLOP/s and 96 GiB per device. A model that "fits on one chip" by the chip's HBM may not fit on one device. The v7x reference in the TPU Agent Suite also notes that the two chiplets share the chip's external ICI links, so when both drive the same link at once each gets about half its bandwidth.
Chips come in groups of four on a tray, connected to a CPU host over PCIe. A v7x host has 4 chips and therefore 8 devices; a v5e or v6e host has 4 or 8 chips (one or two trays), one device each; a v5p host has 4 chips and 4 devices. TorchTPU's documentation states that only one OS process can access a TPU device, which is why a training script launches one process per device, as on GPU, and why co-locating two independent processes on one device is not supported.
Networking: ICI, slices, pods and DCN¶
Chips connect to each other in two ways, and the difference between them shapes every distributed decision in Part IV.
ICI links each chip directly to its nearest neighbours, without going through a host or a switch. v5e and v6e chips have 4 neighbours, forming a 2D torus. v4, v5p and v7x chips have 6 neighbours, forming a 3D torus, which gives more bandwidth for training. In a torus the last chip on each axis links back to the first, which halves the longest path between two chips on that axis. A message to a distant chip still hops through every chip in between.
A slice is a set of chips connected by ICI. You choose a slice shape when you request capacity, and a slice is carved from a pod, the full preconfigured set of chips. Whether your slice gets the wraparound links depends on its shape:
- v5e and v6e pods are a single 16x16 2D torus. A slice gets wraparound on an axis only when that axis has the full 16 chips, so an 8x16 slice wraps on its long axis and a 4x4 slice does not wrap at all.
- v7x pods are built from 4x4x4 cubes joined by optical switches that can be reconfigured. Any multiple of a full cube, such as 4x4x4 or 4x4x8, has wraparounds. Smaller shapes such as 2x2x1 or 2x2x4 do not. A full v7x pod (the scaling book calls it a superpod) is 9,216 chips.
Without wraparound, most collectives take about twice as long, because traffic can only go one way around each axis.
DCN connects hosts, and through them, slices. It is much slower than ICI: on v7x the scaling book lists about 12.5 GB/s of DCN egress per chip against 1,200 GB/s of bidirectional ICI per chip. A transfer from a TPU in one slice to a TPU in another goes over PCIe to the source host, across the network, then over PCIe into the destination chip's HBM. Training that spans slices is called multi-slice; TorchTPU lists multi-slice training up to 8K chips as validated.
Notice that ICI links go chip to chip, while DCN goes host to host. Each dashed stub is a wraparound link to the chip at the other end of the same row or column; two are drawn in full. Slice A spans the full 16 chips on both axes, so it wraps; Slice B is a 4x4 slice and has no wraparound links.
This nearest-neighbour design is the largest difference from a GPU cluster. GPUs within a node are connected through switches that give close to all-to-all connectivity, and larger GPU clusters add switch tiers. TPUs give up that flexibility for a constant number of links per chip, which keeps per-chip bandwidth constant as the slice grows. The practical result for you: how you lay out a device mesh over the physical torus matters, and TorchTPU provides torch.tpu.distributed.topology_aware_mesh to align parallelism dimensions with the interconnect (chapter 13).
Generations at a glance¶
TorchTPU 0.2.0 lists v5e, v5p, v6e and v7 (the book writes v7x) as validated. v8i and v8t are listed as near-term work. v4 is included below for comparison only.
| Per chip | v4 | v5e | v5p | v6e (Trillium) | v7x (Ironwood) |
|---|---|---|---|---|---|
| PyTorch devices per chip | 1 (megacore) | 1 | 1 (megacore) | 1 | 2 |
| TensorCores per chip | 2 | 1 | 2 | 1 | 2 |
| MXUs per TensorCore | 4 of 128x128 | 4 of 128x128 | 4 of 128x128 | 2 of 256x256 | 2 of 256x256 |
| Peak bf16 TFLOP/s | 275 | 197 | 459 | 918 | 2,307 |
| HBM capacity | 32 GiB | 16 GiB | 95 GiB | 32 GiB | 192 GiB |
| HBM bandwidth | 1,200 GB/s | 819 GB/s | 2,765 GB/s | 1,638 GB/s | 7,380 GB/s |
| ICI | 3D torus, 6 links | 2D torus, 4 links | 3D torus, 6 links | 2D torus, 4 links | 3D torus, 6 links |
| ICI per link, one way | 45 GB/s | 45 GB/s | 90 GB/s | 90 GB/s | 90 GB/s |
| Chips per host | 4 | 4 or 8 | 4 | 4 or 8 | 4 (8 devices) |
| Largest pod | 4,096 chips | 256 (16x16) | 8,960 | 256 (16x16) | 9,216 |
| TorchTPU 0.2.0 | Not listed | Validated | Validated | Validated | Validated |
Notes on the table:
- Devices per chip, bf16 TFLOP/s and HBM capacity for v5e, v5p, v6e and v7x are TorchTPU's own hardware table (
csrc/common/tpu_hardware.cc). The scaling book rounds slightly differently: 96 GiB for v5p and 920 TFLOP/s for v6e. - HBM bandwidth, chips per host, MXU counts and the v4 column follow Google's published specifications and the scaling book, which gives the bandwidths in rounded form (for example 2.8e12 B/s for v5p).
- ICI per link is the scaling book's one-way figure. The TPU Agent Suite's v7x reference uses 80 GB/s for v7x; use 90 GB/s as the published peak and expect less.
The next generation appears in TorchTPU's source and documentation but is not yet validated:
| Per chip | v8i | v8t |
|---|---|---|
| PyTorch devices per chip | 2 | 1 |
| Peak bf16 TFLOP/s | 1,101 | 996.1 |
| HBM capacity | 309e9 bytes (288 GiB) | 231e9 bytes |
| Network | Boardfly topology | 3D torus |
| TorchTPU 0.2.0 | Near-term focus | Near-term focus |
The device counts, FLOP/s and capacities are from tpu_hardware.cc. The TorchTPU documentation describes TPU 8i HBM as "288 GB at 8.6 TB/s"; the source code records 309e9 bytes, which is 288 GiB, so read the documentation's figure as binary gigabytes. The same documentation gives ICI for TPU 8t and 8i as 19.2 "TBps" and TPU 8t DCN as 400 "GBps". Read as bits per second instead of bytes, the same figures are a factor of 8 smaller, so check Google's TPU 8 documentation for the unit before using them in a calculation.
What this means for your PyTorch code¶
Each hardware fact above turns into a habit, and each habit has a chapter.
| Hardware fact | What it means for your code | Where the book covers it |
|---|---|---|
| The MXU is 128 or 256 wide and pads smaller dimensions | Prefer hidden sizes, head dimensions and batch tiles that are multiples of 128 or 256; channels-last layout for CNNs | Chapter 2, chapter 11 |
| The MXU peak is far above the VPU and HBM rates | Judge every operation by its arithmetic intensity, not its FLOP count | Chapter 2 |
| The schedule is fixed at compile time | Shapes that change force a new compile | Chapter 7 |
| Data moves HBM to VMEM to MXU, and fusion avoids round trips | Let TorchTPU fuse ops (DeferAndFuse or torch.compile) |
Chapter 4 |
| The MXU multiplies bf16 and accumulates fp32 | Expect bf16-level differences from a GPU fp32 run | Chapter 6 |
| PCIe is about 100 times slower than HBM | Avoid host round trips such as .cpu() and .item() inside the step |
Chapter 4 |
| A v7x chip is two devices, one process each | World size is twice the chip count on v7x; budget memory per device | Chapter 8 |
| ICI is a nearest-neighbour torus and DCN is far slower | Map heavy-traffic parallelism onto ICI and light traffic onto DCN | Chapter 13 |
| Custom kernels manage VMEM directly | Pallas kernels must fit their tiles in the VMEM budget | Chapter 12 |
Three spec-sheet mistakes
- Mixing per-chip and per-device numbers on v7x. A per-device FLOP rate compared against a per-chip bandwidth is off by a factor of 2. Every number in this book says which it is; check that yours do too.
- Assuming a small slice has a torus. A v5e 4x4 slice or a v7x 2x2x2 slice has no wraparound links, so collectives take about twice as long as the bandwidth table suggests.
- Reading peak as achievable. Peak FLOP/s needs large, aligned matmuls with overlapped copies; peak bandwidth is a theoretical figure. Measured numbers belong next to the peak, not in place of it (chapter 24).
Verifying the result¶
A correct model of the hardware predicts what the machine reports. Check it in three steps.
- Reproduce the arithmetic. Run
python code/ch01_hardware/hardware_math.py --cpu-smoke. It derives the v7x peak from MXU geometry and prints it next to the value in TorchTPU's hardware table. You should be able to do the same calculation on paper and land within 1% of 2,307 TFLOP/s. - Check the machine against your table. On a TPU VM with TorchTPU installed, run the same script without
--cpu-smoke. It prints what the experimentaltorch.tpu.get_device_properties(0)API reports (name, devices per chip, HBM and bf16 FLOP/s per device) andtorch.accelerator.device_count(). Before you run it, write down what you expect for your generation; on a 4-chip v7x host you should predict 2 devices per chip, about 96 GiB per device and 8 visible devices. - Predict, then compare. If a reported number differs from your prediction by a factor of 2, you have mixed per-chip and per-device figures. If it differs by about 7%, you have mixed GB and GiB.
Worked problems¶
Problem 1. Name the four units inside a TensorCore and say which one runs torch.relu and which runs torch.matmul.
Answer
The MXU, the VPU, VMEM and the scalar unit. torch.matmul runs on the MXU; torch.relu is elementwise and runs on the VPU. Both read their inputs from VMEM, and the scalar unit dispatches the instructions and the DMA transfers that bring the data in from HBM.
Problem 2. Order these links from fastest to slowest for a v7x chip, and give an approximate bandwidth for each: DCN, HBM to VMEM, ICI, PCIe, VMEM to MXU.
Answer
VMEM to MXU (about 7 times HBM), HBM to VMEM (7,380 GB/s), ICI (1,200 GB/s bidirectional over all links), PCIe (typically about 16 GB/s), DCN (12.5 GB/s egress). PCIe and DCN are close; both are around two orders of magnitude below ICI.
Problem 3. A 4-chip v7x host runs a training script under torchrun. How many processes does it start, how much HBM does each process own, and why?
Answer
Eight processes. Each v7x chip is two chiplets, and TorchTPU exposes each chiplet as one device. TorchTPU runs one process per device, and only one process can open a device. Each chiplet has its own 96 GiB of HBM, so each process owns 96 GiB, not the chip's 192 GiB.
Problem 4. Derive the peak bf16 rate of a v7x chip from its MXU geometry. Use: one bf16[8,256] @ bf16[256,256] per MXU every 4 cycles, 2 MXUs per TensorCore, 2 TensorCores per chip, a clock of about 2.2 GHz.
Answer
FLOPs per MXU product: \(2 \times 8 \times 256 \times 256 = 1{,}048{,}576\). Per cycle: \(1{,}048{,}576 / 4 = 262{,}144\). Per second per MXU: \(262{,}144 \times 2.2 \times 10^9 \approx 5.77 \times 10^{14}\). Per chip: \(\times 4\) MXUs \(\approx 2.31 \times 10^{15}\) FLOP/s, which matches the 2,307 TFLOP/s in TorchTPU's hardware table.
Problem 5. On a v6e chip, a linear layer computes x @ w with x of shape [4096, 4096] and w of shape [4096, 100]. What fraction of the MXU's columns does useful work, and what would you change?
Answer
The v6e MXU is 256x256, and the output dimension of 100 is padded up to 256, so \(100 / 256 \approx 39\%\) of the columns do useful work. The other dimensions (4096) are multiples of 256 and cost nothing extra. If the model allows it, make the output dimension a multiple of 256, or fuse this layer with a neighbour that shares its input so the combined output dimension fills the array. On a pre-v6e chip the waste would be smaller, \(100/128 \approx 78\%\) useful, because the array is 128 wide.
Problem 6. A full v6e pod is 16x16 chips with 8 chips per host and 918 TFLOP/s and 32 GiB of HBM per chip. How many hosts, TensorCores and PyTorch devices does it have, and what is its total bf16 peak and HBM?
Answer
\(256 / 8 = 32\) hosts. One TensorCore per chip gives 256 TensorCores, and one device per chip gives 256 devices. Peak: \(256 \times 918 \ \text{TFLOP/s} \approx 235 \ \text{PFLOP/s}\). HBM: \(256 \times 32 \ \text{GiB} = 8 \ \text{TiB}\).
Problem 7. You serve a 70B-parameter model in bf16, sharded evenly over 8 v7x chips. Every decode step reads every weight from HBM once. What is a lower bound on the time per decode step, and why is it only a lower bound?
Answer
Bytes: \(70 \times 10^9 \times 2 = 1.4 \times 10^{11}\). Per chip: \(1.75 \times 10^{10}\). At 7,380 GB/s per chip: \(1.75 \times 10^{10} / 7.38 \times 10^{12} \approx 2.4\) ms. It is a lower bound because it assumes peak HBM bandwidth (the practical peak is lower), perfect overlap, and no other traffic such as the KV cache or collectives between chips. The scaling book uses the same reasoning for a 200B model on 32 v6e chips; chapter 17 builds on it.
Problem 8. On a v5e 4x4 slice, you send a bf16[8, 128, 8192] array from the chip at (0, 0) to the chip at (3, 3). Per-hop latency is about 1 µs and each ICI link carries 45 GB/s one way. How long does it take, and why can it not use wraparound links?
Answer
The array is \(2 \times 8 \times 128 \times 8192 = 16{,}777{,}216\) bytes. A 4x4 v5e slice has no wraparound (v5e wraps only on an axis of the full 16 chips), so the source can send on two links (right and down) at \(2 \times 45 = 90\) GB/s: \(16.8 \times 10^6 / 9 \times 10^{10} \approx 186\) µs. The path is 6 hops, adding about 6 µs, so about 192 µs in total. The bandwidth term dominates; latency is a small correction. This is the scaling book's Question 5, which rounds the array to \(1.7 \times 10^7\) bytes and gets 194 µs.
Quick questions¶
- Why must an operand be in VMEM before the MXU can use it, and what overlaps with the MXU's work to hide the copy?
- Explain in two sentences what moves and what stays still in a weight-stationary systolic array.
- What is the difference between megacore on v5p and the two-device layout on v7x, from PyTorch's point of view?
- A colleague requests a 2x2x2 v7x slice and expects the collective bandwidth of a full torus. What is wrong with that expectation?
- Why is the VPU's slower rate a reason to care about fusing elementwise operations?
- Which source would you check first for the HBM capacity of a v5p chip, and why might two sources disagree by 1 GiB?
Key takeaways¶
- A TPU chip is TensorCores (MXU, VPU, VMEM, scalar unit) plus HBM, SparseCores and ICI links. Every operand reaches the MXU through VMEM, and every VMEM fill is a DMA from HBM.
- The MXU is a weight-stationary systolic array, 256x256 from v6e on and 128x128 before. It reaches peak only on large matmuls, and pads smaller dimensions to its full width.
- Peak FLOP/s is arithmetic on the MXU's shape: on v7x, 262,144 FLOPs per cycle per MXU, times 4 MXUs, times about 2.2 GHz, gives about 2,307 TFLOP/s per chip.
- Bandwidth falls by roughly an order of magnitude or more at each step: VMEM, HBM, ICI, then PCIe and DCN. Keep traffic on each link proportional to its speed.
- PyTorch sees devices. v5e and v6e are one device per chip, v4 and v5p fuse two TensorCores into one device, and v7x exposes two devices per chip, each with its own 96 GiB of HBM.
- ICI is a nearest-neighbour torus (2D on v5e and v6e, 3D on v4, v5p and v7x). Wraparound links exist only on full-length axes or full cubes; DCN links slices through their hosts and is far slower.
- TorchTPU 0.2.0 validates v5e, v5p, v6e and v7x; v8i and v8t are near-term work. Always state whether a number is per chip or per device, peak or practical, GB or GiB.
References¶
- How to Think About TPUs: How to Scale Your Model, part 2; TensorCore units, memory hierarchy, networking and per-generation numbers
- How does a systolic array work?: the scaling book's appendix on the MXU
- TPU system architecture: Google Cloud's description of chips, hosts, slices and pods
- A domain-specific supercomputer for training deep neural networks: the TPU v2 and v3 design, including the VLIW core
- How TorchTPU works: TPU primer, slices and pods, TPU 8 figures
- TorchTPU supported feature set and future work: validated generations and multi-slice status
- Introduction to TorchTPU: one process per device, fp32 accumulation,
topology_aware_mesh csrc/common/tpu_hardware.cc: TorchTPU's per-generation hardware table_device_module.py:torch.tpu.get_device_properties- TPU v7x specification: TPU Agent Suite reference on v7x chiplets, the D2D link and shared ICI links
- Chip constants and compiler hard limits: TPU Agent Suite reference on v7x VMEM and theoretical and practical HBM bandwidth
- Companion code for this chapter




