Maps to: Stanford CS149 Fall 2025, Lecture 11 (Oct 28), slide deck
11_SpecializedHardwareProgramming(60 slides). Context for Programming Assignment 4 (an AI accelerator with explicitly managed on-chip memory). Sources: the public Fall 2025 slides; B. Spector et al., “ThunderKittens: Simple, Fast, and Adorable AI Kernels” (2024); R. Prabhakar et al., “Plasticine: A Reconfigurable Architecture for Parallel Patterns” (ISCA 2017) and “SambaNova SN40L: Scaling the AI Memory Wall with Dataflow and Composition of Experts” (MICRO 2024); D. Koeplinger et al., “Spatial” (PLDI 2018); J. Shah et al., “FlashAttention-3” (2024). Every experiment and number below was written for these notes and run on the author’s machine (Apple M4 Pro; clang 21, macOS 27; numpy 2.5). The author has no H100 and no dataflow chip, so those machines appear as simulators and cost models, labelled as such. Code:code/lecture11/. Reading time: ~80 minutes for the prose; ~10 more for the demos.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Explain the difference between synchronous (同步) and asynchronous (异步) execution. Predict, for a stream of tiles, the time each takes and the number of buffers (缓冲区) asynchrony needs.
- Explain why asynchrony matters more as compute units get faster, and why it is not enough once a kernel is memory-bound.
- Describe how a kernel reaches near-peak throughput on an H100: 16 × 16 tiles (分块), the TMA copy engine, warp specialization (warp 专用化) into producers and consumers, and mbarrier synchronization.
- Read a ThunderKittens kernel. Say what the tile abstraction and the load-compute-finish template hide from the programmer, and what can still go wrong.
- Explain why shared-memory swizzling (共享内存地址重排) removes bank conflicts without padding.
- Describe a reconfigurable dataflow architecture (可重构数据流架构), and how parallel patterns are compiled to it by tiling, parallelization and metapipelining (元流水线).
- Analyze a metapipeline: the slowest stage sets the pace, balancing stages by allocating hardware, and the role of on-chip memory.
- Explain why fusing a whole transformer decoder into one kernel speeds up small-batch LLM inference, and how much.
0.2 Prerequisites and scope
- Prerequisites:
- Lecture 2: latency hiding.
- Lecture 6: overlapping communication with computation, arithmetic intensity.
- Lecture 7: CUDA, shared memory and its banks.
- Lecture 9: GEMM blocking, fusion, FlashAttention.
- Lecture 10: tensor cores, TMA, the systolic array, dataflow processors.
- Scope: how to program specialized AI hardware. The first third of the deck recaps Lecture 10’s TPU material, which these notes only summarize (§2). Mapping AI to whole datacenters (collectives, parallelism strategies, memory systems) is Lecture 12.
0.3 Section → code map
| Section | Idea | Demo in code/lecture11/ |
|---|---|---|
| §1 | synchronous vs. asynchronous; buffers; faster compute | 01_async_execution.py (uses pipesim.py) |
| §3.3 | a producer/consumer pipeline on real cores | 02_producer_consumer |
| §3.4–§3.7 | ThunderKittens: tiles, template, matmul, swizzling | 03_thunderkittens.py |
| §4 | dataflow and metapipelining | 04_metapipeline.py |
| §5 | fusing a whole decoder | 05_kernel_fusion.py |
| §6 | programming explicit on-chip memory | 06_toy_accelerator.py (uses toy_accel.py) |
Run them all with cd code/lecture11 && make run (~5 seconds).
0.4 Notation
- A tile is a small 2D block of a matrix (16 × 16, 64 × 64, 128 × 512, …) that moves and is computed on as a unit.
- Load / compute / store: copy a tile from off-chip memory (HBM, 高带宽内存) to on-chip memory, operate on it, copy the result back.
- Stage (流水级): one step of a pipeline. Depth: buffer slots between two stages (2 = double buffering, 双缓冲).
- FLOPs per byte: arithmetic intensity (Lecture 6), the work done per byte moved from memory.
1. Synchronous and asynchronous execution
1.1 Three machines, three programming models (slides 2–3)
The deck opens with the question it answers: how do you program specialized hardware? It uses three machines:
- Google’s TPU: dense matrix multiply on a systolic array (Lecture 10). It is programmed through a compiler from high-level frameworks.
- NVIDIA’s H100 and B100: asynchronous compute and memory mechanisms, which make programming complex. A small domain-specific language (DSL, 领域专用语言), ThunderKittens, makes them manageable.
- SambaNova’s SN40L: a dataflow architecture, programmed by tiling and streaming with metapipelining.
Slide 3 recalls Lecture 10’s spectrum: the more specialized the hardware, the more efficient and the harder to program. Today is about that second half: what programming feels like at each point of the spectrum.
1.2 Synchronous execution (slide 4)
A kernel that processes a stream of tiles does three things per tile: load it (LD), compute on it (the slides’ “AO”, an arithmetic operation), and store the result (ST). Synchronous, or blocking, execution starts each operation only after the previous one has completed:
time →
LD0 AO0 ST0 LD1 AO1 ST1 LD2 AO2 ST2
While the loader works, the arithmetic units wait. While they work, the memory system waits. Total time = n × (load + compute + store).
1.3 Asynchronous execution (slide 5)
Asynchronous, or non-blocking, execution starts later operations before earlier ones complete. While tile 0 is computed, tile 1 is already being loaded:
load LD0 LD1 LD2
compute AO0 AO1 AO2
store ST0 ST1 ST2
Once the pipeline is full, a tile completes every max(load, compute, store), not every sum. The slide names the two ways to get there:
- Software + hardware: asynchronous instructions (start a copy now, check later) plus explicit synchronization (wait until the copy has landed). This is the GPU and accelerator way, and this lecture’s subject.
- Hardware alone: an out-of-order (乱序) CPU core finds independent instructions and overlaps them automatically (Lecture 2). §3.3 shows how well this works on the author’s machine.
01_async_execution.py simulates both with pipesim.py, a small simulator that computes exact schedules for stages on hardware units with bounded buffers between them. Part A, with load 2, compute 3 and store 1 time units for three tiles:
synchronous (blocking): every operation waits for the previous one
thread |LLLLLLCCCCCCCCCSSSllllllcccccccccsssLLLLLLCCCCCCCCCSSS| makespan 18
asynchronous: load of tile i+1 overlaps compute of tile i
load engine |LLLLLLllllll...LLLLLL.................................|
tensor cores |......CCCCCCCCCcccccccccCCCCCCCCC.....................| makespan 12
store engine |...............SSS......sss......SSS..................|
(Upper and lower case alternate between tiles.) After the first load, the tensor cores never wait: the pace is set by the slowest stage, compute.
1.4 How many buffers?
Overlap needs somewhere to put tile i+1 while tile i is still in use. Part B runs 64 tiles (load 2, compute 3, store 1):
| configuration | time | compute busy |
|---|---|---|
| synchronous (one unit) | 384 | 50% |
| 3 engines, 1 buffer per link | 321 | 60% |
| 3 engines, 2 buffers per link | 195 | 98% |
| 3 engines, 3 buffers per link | 195 | 98% |
| 1 DMA engine for loads and stores, 2 buffers | 384 | 50% |
| 1 DMA engine, 2 buffers, loads issued one tile early | 195 | 98% |
| 1 thread, 1 buffer, loads issued one tile early | deadlock | — |
Four lessons are in this table:
- One buffer is not enough. The load of tile i+1 needs the slot that compute(i) is still reading, so load and compute take turns. Double buffering (two slots, used alternately) is the minimum for overlap. A third slot adds nothing when the stage times are steady.
- Issue order matters when engines are shared. If one DMA engine does loads and stores in program order (LD0, ST0, LD1, …), the next load queues behind a store that waits for compute: no better than synchronous. Issuing loads one tile early (“prefetching”, 预取) restores the overlap. Real kernels are written in this skewed order, a transformation called software pipelining (软件流水).
- Asynchrony can deadlock. One thread that prefetches into a single buffer waits for a slot that only its own later compute can free. The simulator detects the cycle and reports no unit can proceed; real hardware just hangs.
- The fix is always the same: enough buffers, and an issue order consistent with them.
1.5 Why asynchrony matters more as compute gets faster
Part C takes a kernel whose tiles do I FLOPs per byte moved and runs it on three GPU generations (dense FP16 tensor-core peak and HBM bandwidth from NVIDIA’s data sheets):
| GPU | FLOPs/byte of the GPU | I = 128: sync / async | I = 256: sync / async | I = 512: sync / async |
|---|---|---|---|---|
| V100 (125 TF, 0.9 TB/s) | 139 | 48% / 92% | 65% / 100% | 79% / 100% |
| A100 (312 TF, 2.0 TB/s) | 153 | 46% / 83% | 63% / 100% | 77% / 100% |
| H100 (989 TF, 3.35 TB/s) | 295 | 30% / 43% | 46% / 86% | 63% / 100% |
(percent = time the tensor cores are busy)
Why it matters more. From V100 to H100, tensor-core throughput grew 8× and bandwidth 3.7×. The memory time per tile shrank less than the compute time, so the part a synchronous kernel cannot hide grew from 35% to 54% of its run time (at I = 256). The same kernel loses more on each new generation unless it overlaps.
Why it is not enough. Overlap gives at best max(compute, memory). When memory is the larger term (H100, I = 128), the asynchronous kernel still idles its tensor cores 57% of the time. The only cure is more FLOPs per byte, which means bigger tiles (§3.6). Faster compute needs both asynchrony and reuse.
Slide 31 gives the real-world version. FlashAttention-2 reached ~70% of peak on an A100 but only ~35% on an H100, whose tensor cores it could not keep fed. It took two years and FlashAttention-3, written for the H100’s asynchronous TMA and tensor-core instructions, to return to ~65%.
1.6 Variable load times need deeper pipelines
Real loads do not take a fixed time: some tiles hit in L2, others come from HBM. Part D draws 3 in 4 loads at 0.6 and 1 in 4 at 2.2 (mean 1.0, equal to compute):
| load buffers | 1 | 2 | 3 | 4 | 6 | 8 |
|---|---|---|---|---|---|---|
| tensor cores busy | 50% | 77% | 86% | 90% | 94% | 96% |
Extra slots let the loader run ahead during fast loads and absorb a slow one. That is why the ThunderKittens matmul of slide 39 uses four pipeline stages, not two. Each slot costs shared memory, so kernels choose the smallest depth that keeps the tensor cores fed.
2. Recap: specialized hardware for AI (slides 6–26)
Slides 6–26 repeat Lecture 10’s hardware story, which Lecture 10 §5–§7 covers with its own demos:
- everyone builds AI silicon;
- the TPU spends ~30% of its area on arithmetic and little on control;
- a weight-stationary systolic array computes y = W x as data flows between neighbours (slides 10–16);
- larger products are tiled onto it (slide 19);
- TPUs have high performance per watt (slide 23) and evolved over generations (slide 24);
- the hardware lottery (slide 25).
One table is new. Slide 17 names three dataflows for a systolic array, by what stays put in each processing element:
| dataflow | stays in each PE | streams through | main goal |
|---|---|---|---|
| weight-stationary (WS, 权重驻留) | a weight | inputs and partial sums | minimize reloading weights |
| output-stationary (OS, 输出驻留) | a partial sum (output) | inputs and weights | minimize moving accumulated results |
| input-stationary (IS, 输入驻留) | an input activation | weights and partial sums | minimize reloading inputs |
The choice is the same question as Lecture 9’s loop order and blocking: which operand do you keep close, and which do you stream?
Slide 26’s summary of specialized AI hardware is worth keeping, because the rest of the lecture is about programming each item:
- many arithmetic units;
- customized datapaths that move intermediates directly between units, so computation is scheduled by laying it out in space;
- large on-chip storage for intermediates.
3. Programming the H100 near its peak (slides 27–41)
3.1 The H100 and B100 have become asynchronous machines (slides 27–33)
Lecture 10 introduced the pieces. Here is what they mean for a programmer:
- Tensor cores (slide 29) execute a whole matrix multiply-accumulate per instruction. On the H100, an MMA is issued by a warpgroup, 4 consecutive warps = 128 threads, and runs asynchronously (
wgmma.mma_async). It reads its operands from shared memory and accumulates in registers. - The Tensor Memory Accelerator (TMA) (slide 28) copies a rectangular region of a tensor between global and shared memory. A single thread issues it with a copy descriptor; hardware generates the addresses, bypasses L1 and signals a barrier when the bytes have landed. It eliminates thousands of address-computation instructions and the detour of data through L1 and registers.
- On the B100 (slide 27) register bandwidth can no longer feed the tensor cores. Operands live in shared memory and a new tensor memory (TMEM), and a single thread issues an MMA: “no more warps” in the inner loop. Programming it means allocating TMEM and descriptors, streaming tiles with TMA coordinated by mbarriers, launching batches of asynchronous MMAs, and fencing their retirement. The slide’s verdict: “Not your father’s CUDA”.
Slide 30 checks the GPU against the ideal accelerator of Lecture 10:
| feature | why | NVIDIA GPU |
|---|---|---|
| tiled tensors (16 × 16, 32 × 32) | max TFLOPS on GEMM, low instruction overhead | ✅ tensor cores |
| asynchronous compute | overlap compute and memory access | ✅ mma_async |
| asynchronous memory access | overlap compute and memory access | ✅ TMA + TMEM |
| asynchronous chip-to-chip communication | overlap compute, memory and communication | (Lecture 12) |
| compute unit to compute unit communication | fusion and pipelining, streaming dataflow | ❓ thread-block clusters |
Why care? Slide 31: GPU kernels run on clusters worth hundreds of millions of dollars for months. A kernel at 35% of peak wastes most of that money. Slide 32: 89–98% of a GPU’s FLOPS are in the tensor cores, so a kernel that does not use them well uses almost none of the chip. Slide 33: each generation adds more specialized features: FP8 then FP4, a transformer engine, asynchronous copies, distributed shared memory, a decompression engine. The question is what all this means for programmers.
3.2 DSLs, and the recipe for peak (slides 34–35)
Writing these kernels in raw CUDA, with PTX inline assembly, descriptors and barrier phases, is expert work. A family of DSLs for GPU AI kernels has appeared (slide 34): Mosaic GPU, CuTe-DSL (CUTLASS in Python), Triton, ThunderKittens and others. Each raises the level of abstraction from threads to tiles.
The recipe for keeping the tensor cores >90% busy (slide 35):
- Use 16 × 16 tiles of FP16/BF16 data, the shape the tensor cores compute.
- Make sure compute is never idle.
- Overlap memory access and compute using asynchrony.
The picture is a tile-processing pipeline: TMA loads tiles from global memory (HBM/L2) into shared memory, tensor cores compute from shared memory into registers, results go back through shared memory to global memory. That is §1’s pipeline, with buffers in shared memory.
3.3 The producer/consumer protocol, measured on real cores
Before reading a GPU kernel, it helps to see the protocol work on hardware we can measure. 02_producer_consumer.cpp builds a pipeline on two CPU cores:
- a producer core does nothing but copy tiles from DRAM into a ring of S buffers (our stand-in for the TMA);
- a consumer core does nothing but compute on them (K multiply-adds per element, a stand-in for the tensor cores);
- per slot, a full flag (“data has arrived”) and an empty flag (“I am done with this slot”) are the analog of TK’s
inputs_arrivedandinputs_finishedbarriers.
The protocol, for tile i in slot k = i mod S, round r = i / S:
producer: wait until empty[k] has been signalled r times
copy tile i into slot k
signal full[k] (release: the tile is visible first)
consumer: wait until full[k] has been signalled r + 1 times (acquire)
compute on slot k
signal empty[k]
Measured (256 MiB of floats; ms, best of 5):
| K FMAs/element | copy alone | compute alone | synchronous | producer/consumer | direct (hardware overlap) |
|---|---|---|---|---|---|
| 0 | 3.5 | 3.5 | 7.5 | 3.7–4.1 | 3.6 |
| 2 | 3.5 | 5.4 | 9.4–9.9 | 5.5–5.8 | 5.5 |
| 8 | 3.6 | 18.5–19.1 | 22.5 | 18.7–18.9 | 18.5 |
(256 KiB tiles, 2 slots; ranges are across runs)
- The pipeline turns load + compute into max(load, compute). At K = 2 it is 1.7× faster than synchronous and within a few percent of the ideal. The gain is largest when the two stages are balanced, exactly as §1 predicted.
- One slot gains nothing (0.95–1.10× of synchronous across runs). The cores take turns, so nothing overlaps, and every turn adds a hand-off between them. Two slots give 1.5–1.6×.
- Every hand-off costs ~90–150 ns. Each flag is written on one core and read on another, so its cache line must travel between them, and so must the freshly written tile (Lecture 6’s inherent communication). With 4 KiB tiles there are 65,536 hand-offs, and the pipeline (12.8 ms) loses to the synchronous loop (9.1 ms). With 1 KiB tiles it is 2.7–4× slower than synchronous. Asynchrony pays only when each synchronization is amortized over enough work. That is one reason GPU kernels move tiles, never single values, between pipeline stages. Slide 60 calls it “minimizing synchronization overheads”.
- “Direct” is the CPU’s hardware asynchrony. Simply computing from DRAM is as fast as the two-core pipeline. The out-of-order engine and the hardware prefetchers already overlap memory traffic with arithmetic, on one core, with no flags. A GPU SM runs each warp in order and has no comparable prefetchers. It hides latency either with many warps (Lecture 7) or, on the H100, with the TMA and exactly this producer/consumer protocol. Specialized hardware moves the job of overlapping from hardware back to the program.
3.4 ThunderKittens (slide 36)
ThunderKittens (TK) is a small C++ template library embedded in CUDA, from Stanford’s Hazy Research group. It rests on three design principles:
- A 16 × 16 tile is the primitive data type. TK manages the layouts and provides the basic operations.
- Asynchrony everywhere. TK exposes the asynchronous primitives (TMA loads, asynchronous MMAs, barriers) for the programmer who needs top performance.
- High-level coordination patterns, chiefly producer/consumer processing, packaged as templates.
Its data types are templated by shape and layout:
- register tiles
rt<…>: 2D tensors spread over a warp’s registers; - register vectors: 1D tensors in registers, such as a row maximum;
- shared tiles
st<…>: 2D tensors in shared memory; - shared vectors;
- global layouts
gl<…>: descriptors of tensors in HBM, from which TMA descriptors are made.
Its operations work on whole tiles: initializers (zero), unary ops (exp), binary ops (mul), row/column reductions (row_max, row_sum), and MMAs (mma_AB, mma_ABt).
03_thunderkittens.py rebuilds a miniature TK in numpy with the same names, so that the slides’ kernel can be run and checked. Its “hardware” is numpy. Producer and consumers are Python generators run by a scheduler, so the demo checks the programming model, not performance.
3.5 The TK matmul (slides 37–40)
TK’s load-compute-finish (LCF) template (slide 37) runs three roles in each thread block:
- producer warps issue TMA loads into a ring of input stages;
- consumer warpgroups compute on full stages with tensor cores;
- finish stores the results.
The template allocates the stages and barriers, runs the loop and waits on the right barrier before each step. The kernel author fills in four pieces. Here they are in condensed form, following slides 38–40:
// layout: what one pipeline stage holds, what the result holds
struct input_block { st_bf<64,64> a[2]; st_bf<64,256> b; }; // A tile per consumer, one shared B tile
struct finish_block { st_bf<64,256> c[2]; };
struct consumer_state { rt_fl<16,256> accum; }; // per warp: 4 warps x 16 rows = 64 rows
// constants: 8 consumer warps (2 warpgroups), a 4-stage input pipeline;
// a stage is "arrived" after 1 producer arrival, "finished" after 2 consumer arrivals
NUM_CONSUMER_WARPS = 8; INPUT_PIPE_STAGES = 4;
producer::setup: decrease_registers<40>() // producers need few registers...
producer::load(it): if first warp: // one thread is enough to drive TMA
tma::expect(inputs_arrived, input) // bytes to wait for
for i in 0..1: tma::load_async(input.a[i], A, {2*blockIdx.x+i, it}, inputs_arrived)
tma::load_async(input.b, B, {it, blockIdx.y}, inputs_arrived)
consumer::setup: increase_registers<232>(); zero(accum) // ...so consumers get more
consumer::compute: mma_AB(accum, input.a[my_group], input.b) // async tensor-core MMA
mma_async_wait()
if lane 0: arrive(inputs_finished) // this stage may be reused
consumer::finish: store(finish.c[my_group], accum) // registers -> shared
store(C, finish.c[my_group], {2*blockIdx.x+my_group, blockIdx.y}) // -> global
Things to notice:
- Each block computes a 128 × 256 tile of C. Two consumer warpgroups each own a 64 × 256 slice and share one B tile per k-step. Per k-step (64 wide), the producer loads two 64 × 64 A tiles and one 64 × 256 B tile.
- Warp specialization. Producer warps only issue loads, consumer warps only compute. Since Hopper, warpgroups can move registers between each other (
setmaxnreg). The producers give up registers (40 each) so that the consumers can hold big accumulators (232 each). - mbarriers with transaction counts.
tma::expecttells theinputs_arrivedbarrier how many bytes to wait for. The barrier’s phase completes when the expected arrivals have happened and the TMA has delivered every byte.inputs_finishedcompletes after both consumer warpgroups have arrived. Hardware keeps a one-bit phase parity per barrier; the template tracks which phase each stage is in. - Storing through shared memory reorganizes the accumulator, which lives in a fragmented register layout, for coalesced writes to HBM (Lecture 7).
Demo 03 runs exactly this structure on a 512 × 512 × 512 problem. When every worker runs until it must wait, the first block’s events show the ring:
producer : TMA loads for iter 0 into stage 0
producer : TMA loads for iter 1 into stage 1
producer : TMA loads for iter 2 into stage 2
producer : TMA loads for iter 3 into stage 3 <- ring full: the producer must wait
consumer wg0 : MMA on stage 0 (iter 0)
...
consumer wg1 : MMA on stage 3 (iter 3)
producer : TMA loads for iter 4 into stage 0 <- only after BOTH warpgroups released it
The result matches a float64 product to 1.2 × 10⁻³ of the largest value, less than one bf16 rounding step (C is stored in bf16). Run with a different interleaving (round-robin), the result is bit-identical. That is the property that makes asynchronous code correct: the barriers, not the timing, decide the order wherever it matters.
What can still go wrong? Part B plants one bug: a consumer that forgets arrive(inputs_finished). The producer fills the 4 stages and then waits forever for stage 0. The consumers wait for data the producer never loads:
DEADLOCK -- producer waits for inputs_finished[0] phase 1; consumer 0 waits for inputs_arrived[0] phase 2; ...
On a GPU the kernel simply hangs, with no error message. The template removes most of the protocol from the author’s hands, but not all of it.
3.6 Why such big blocks?
Every k-step, a block loads (bm + bn) × 64 values and does 2 × bm × bn × 64 FLOPs. The intensity is bm·bn / (bm + bn) FLOPs per byte for bf16. Demo 03, Part C:
| output tile per block | FLOPs per byte loaded |
|---|---|
| 1 × 1 (a thread per output) | 0.5 |
| 16 × 16 (classic CUDA shared-memory tiling, Lecture 7) | 8 |
| 64 × 64 | 32 |
| 128 × 256 (slides 38–40) | 85 |
The H100 needs ~295 FLOPs per HBM byte to keep its tensor cores busy (§1.5). A 128 × 256 block gets 85 from its own loads. Most of the rest comes from L2: neighbouring blocks load the same rows of A and columns of B, which then hit in the 50 MB L2. Small tiles cannot feed fast tensor cores at any level of asynchrony, which is why TK’s primitive type is the tile and its kernels use large blocks.
3.7 Layouts: what “TK manages layouts” means
Shared memory has 32 banks of 4 bytes (Lecture 7, demo 04). Tensor-core fragment loads (ldmatrix) read 8 × 8 sub-matrices: 8 threads each read one 16-byte row of the sub-matrix, 128 bytes in all, one pass if the 8 rows fall in different banks.
In a row-major 64 × 64 bf16 tile, every row is 128 bytes = exactly one sweep through all 32 banks. Row r of any 8 × 8 sub-matrix therefore starts in the same bank as row 0: an 8-way bank conflict. Demo 03, Part D:
| layout | passes per 8 × 8 load | extra memory |
|---|---|---|
| row-major | 8 | 0 |
| padded (+16 bytes per row) | 1 | 1 KiB per tile |
| swizzled (16-byte chunk index XOR row mod 8) | 1 | 0 |
Padding (Lecture 7) fixes the conflict but wastes memory and breaks the dense rectangular boxes that the TMA copies. Swizzling permutes the 16-byte chunks within each row: chunk c of row r is stored at position c XOR (r mod 8). Consecutive rows then start in different banks, and the demo checks that this is a permutation of each row, so nothing is lost. The TMA and the tensor cores understand these swizzle patterns in hardware (32-, 64- and 128-byte modes). TK picks one from the tile’s width, so kernel authors never see it. That is one concrete thing a tile abstraction buys over thread-level CUDA.
3.8 Attention in tile operations, and TK’s performance (slide 41)
Part E writes FlashAttention’s forward pass (the algorithm is Lecture 9 §7) only in tile operations. For each K/V tile there are about ten operations: zero, mma_ABt, mul (scale), row_max, sub_row, exp, mul_row (rescale), row_sum, mma_AB, plus the running max. The result matches naive float64 attention to 2 × 10⁻⁷. The code reads like the math; each line is many tensor-core or vector instructions underneath.
Slide 41 plots TK’s matmul against NVIDIA’s cuBLAS. The TK paper reports matching cuBLAS on GEMM and FlashAttention-3 on attention inference, and beating the strongest baselines on several other kernels, in a few hundred lines of tile code. The point of the DSL is that near-peak performance becomes accessible without writing PTX.
4. Dataflow: asynchrony with a simpler programming model (slides 42–54)
4.1 A data-centric view (slides 42–43)
Slide 42 asks: can we have asynchrony with a simpler programming model? The hint is to take a data-centric view. An AI model already is a dataflow graph (数据流图) (slide 43): nodes are operators (GEMM, pool, softmax, sum), edges are tensors, and weights flow in from the side. A GPU executes that graph one kernel at a time, round-tripping every intermediate through HBM unless it is fused by hand. A dataflow processor executes the graph directly: each operator gets its own hardware, and data streams along the edges.
4.2 Reconfigurable dataflow architectures (slides 44, 46, 47)
Plasticine (Prabhakar, Zhang et al., ISCA 2017), which became SambaNova’s reconfigurable dataflow unit (RDU), is a grid of three kinds of tiles:
- PCU, pattern compute unit (模式计算单元): SIMD/systolic datapaths that execute the inner loops of parallel patterns.
- PMU, pattern memory unit (模式存储单元): scratchpad SRAM with flexible address generation, holding tiles and intermediate buffers.
- S, switches: a configurable on-chip network that wires units together.
- AGCU, address generator and coalescing unit: the portals to off-chip memory and I/O.
The SN40L (slide 47) has 1,040 PCUs and PMUs, 638 TFLOP/s of BF16, 520 MB of on-chip SRAM, 64 GB of HBM and 1.5 TB of DDR memory. “Reconfigurable” means the compiler configures the units and the switches for a program; the configuration is then fixed while the data streams through.
Against the ideal accelerator (slide 46), two properties stand out:
- No instructions, hence no instruction fetch or decode overhead (Lecture 10’s 2000% overhead does not exist).
- Extreme asynchrony. There is no sequential instruction stream at all; each unit fires when its input data arrives.
4.3 Streaming dataflow means kernel fusion (slide 45)
If every operator of attention (Q Kᵀ, mask, softmax, dropout, × V) is laid out on its own units and tiles stream from one to the next, the intermediates never leave the chip. That is FlashAttention’s fusion (Lecture 9), obtained by construction rather than by a hand-written kernel. Slide 45 calls this coarse-grained pipelining: whole tiles, not single values, move between stages.
4.4 Programming with parallel patterns (slide 48)
The programming model is a set of composable parallel patterns (并行模式): MM, Map, Zip, Reduce, Gather, Scatter (Lecture 8’s vocabulary). Slide 48’s simplified softmax, o = exp(x) / Σ exp(x), is:
m = Map(x, exp) # elementwise
r = Reduce(m, +) # sum
o = Zip(m, r, /) # combine elementwise
The compiler turns this into hardware in five steps. Each is a scheduling decision the GPU programmer makes by hand:
- tiling: cut the data into tiles that fit the PMUs;
- parallelization: decide how many PCUs execute each pattern;
- metapipelining: turn loops into pipelines of stages with buffers between them (next section);
- place and route: assign stages to physical units and wires;
- code generation: produce the configuration.
The patterns can be scheduled flexibly in space and time: this is spatial execution (空间执行).
4.5 Metapipelining (slides 49–50)
A metapipeline is a hierarchical, coarse-grained pipeline, a “pipeline of pipelines”. It is how dataflow hardware runs nested loops (slide 49):
- convert a parallel pattern (a loop) into a streaming pipeline by inserting stages into the loop body;
- the stages execute in parallel, so successive loop iterations overlap;
- intermediate data between stages sits in double buffers, which also absorb imbalance between stages;
- it works well with tiling, and buffers can change the access pattern (for example, transpose a tile);
- metapipelining works even when fusion does not, because a stage may need a whole tile of its input before it can start.
Slide 50’s example is Gaussian discriminant analysis (GDA). For every row of a matrix: subtract a mean vector, form the outer product of the difference with itself, accumulate. As a metapipeline, each step is a stage: Pipe1 (AGCU) loads row r, Pipe2 computes diff, Pipe3 the D × D outer product, Pipe4 accumulates. Different rows are in different stages at once.
04_metapipeline.py, Part A (D = 64, 1,024 rows; times in cycles, 16 operations per PCU per cycle):
| configuration | PCUs | cycles | speedup | busiest / idlest unit |
|---|---|---|---|---|
| loop body run step after step | 1 | 532,480 | 1.0× | — |
| metapipeline, 1 PCU per stage | 3 | 262,408 | 2.0× | 100% / 2% |
| metapipeline, 16 PCUs for each D × D stage | 33 | 16,408 | 32.5× | 100% / 25% |
- Pipelining alone gives only 2×. The D × D stages take 256 cycles per row while load and diff take 4. A pipeline runs at the pace of its slowest stage, and the fast stages sit idle 98% of the time.
- Balancing is the compiler’s job. Giving the slow stages 16 PCUs each (slide 48’s parallelization step) brings them to 16 cycles per row: 32.5× faster than the sequential loop.
- Balancing stops at the memory stage. With 64 or more PCUs per stage, the row load (4 cycles, limited by off-chip bandwidth) becomes the slowest stage, and more PCUs buy nothing.
4.6 The matmul metapipeline (slides 51–53)
Slide 51 writes C = A B (BF16) as two nested metapipelines. In condensed form:
METAPIPE over M/MM tiles of A: # outer pipeline
a_tile = LOAD_TILE(A, MM x K) # outer stage 1
METAPIPE over N/NN tiles of B: # outer stage 2 = an inner pipeline
b_tile = LOAD_TILE(B, K x NN)
c = MAT_MUL(a_tile, b_tile, row_par = 4)
c_tile = BUFFER(c)
STORE_TILE(C, c_tile)
with MM = 256 and NN = 64. An MM × K slab of A stays on chip while all of B streams past it. Slides 52–53 map it: AGCUs for the A, B and C streams, PMUs for the buffers, four PCUs for the row-parallel matmul. The outer pipeline overlaps loading the next A slab with the whole inner pipeline of the current one.
Part B models this on an SN40L-like machine with illustrative round numbers (1 TFLOP/s per PCU, 2 TB/s HBM shared by the streams), for M = N = K = 4096:
| MM | PCUs for MAT_MUL | time | TFLOP/s | PCU busy | FLOPs per HBM byte | on-chip buffers |
|---|---|---|---|---|---|---|
| 32 | 64 | 2,266 µs | 61 | 95% | 32 | 1.6 MB |
| 32 | 512 | 2,236 µs | 61 | 12% | 32 | 1.6 MB |
| 256 | 64 | 2,176 µs | 63 | 99% | 228 | 5.3 MB |
| 256 | 256 | 565 µs | 243 | 95% | 228 | 5.3 MB |
| 256 | 512 | 330 µs | 417 | 81% | 228 | 5.3 MB |
Each byte of B is used MM times, so the tile height sets the arithmetic intensity:
- With MM = 32, the memory roof is 32 FLOPs/byte × 2 TB/s = 64 TFLOP/s. Beyond 64 PCUs, more compute only idles.
- With MM = 256, 512 PCUs reach 417 TFLOP/s. Big tiles need on-chip memory for their double buffers: 5.3 MB here, and far more for bigger problems and deeper reuse. That is why the SN40L carries 520 MB of SRAM.
Pipelining the outer loop matters only when its stage is comparable to the inner pipeline:
| shape (M × N × K) | A-slab load alone | inner pipeline | outer pipelined | not pipelined |
|---|---|---|---|---|
| 4096 × 4096 × 4096 | 1.05 µs | 34 µs | 565 µs | 563 µs |
| 4096 × 256 × 4096 | 1.05 µs | 3.2 µs | 54 µs | 59 µs |
For the square product, the A load is negligible next to a long inner pipeline. For a skinny product (N = 256), the inner pipeline is short, and overlapping the A load saves 9%. Each level of the nest hides latency that the level inside it cannot.
4.7 FlashAttention as a metapipeline (slide 54)
Slide 54 lays FlashAttention out as a metapipeline: Q Kᵀ → mask → softmax → dropout → × V, each stage on its own PCUs and PMUs, with score tiles 0, 1, 2, … streaming through. In the slide’s picture, tile 4 is in Q Kᵀ while tile 3 is in mask, tile 2 in softmax, and so on. Stages are triggered by tokens: a stage starts when its input tile has arrived. There is no lock-based synchronization and no kernel launch.
Part C (16 score tiles of 128 × 128, head dimension d = 128; elementwise work counted per element):
| allocation | ns per tile | PCUs | PCU time useful |
|---|---|---|---|
| 1 PCU per stage | 4,194 | 5 | 41% |
| 16 PCUs per matmul | 262 | 35 | 93% |
| 64 per matmul, 2 for softmax | 65.5 | 132 | 98% |
With one PCU per stage, the two matmul stages (Q Kᵀ and × V, 2 × 128 × 128 × 128 FLOPs each per tile) dominate the elementwise ones by 50–250×. Allocating PCUs in proportion to the work balances the pipeline. In the balanced configuration, three tiles are in flight at once (one in × V, one in softmax, one in Q Kᵀ), the slide’s picture in numbers.
The intermediates never leave the chip. If every operator were its own kernel, these 16 tiles would send 4.2 MB through HBM, and a 4,096-token sequence would send 268 MB per head.
5. Fusing a whole model (slides 55–59)
5.1 The decoder graph and limited fusion on GPUs (slides 55–56)
Slide 55 draws one decoder layer of Llama 3.1 8B:
- RMSNorm;
- Q, K and V GEMMs;
- Q Kᵀ, scale, mask fill, softmax, P V;
- O GEMM, add;
- RMSNorm;
- gate and up GEMMs, SiLU, multiply, down GEMM, add;
- all-reduces when the model is split over several chips (Lecture 12).
There are 32 such layers, plus embedding, classifier and sampling.
On a GPU with TensorRT-LLM (slide 56), each layer runs as about 10 kernels, K1–K10, with FlashAttention as one of them. The slide lists three costs: low kernel fusion, low data locality between kernels, and high launch and synchronization overheads.
5.2 One kernel per decoder, or for all decoders (slides 57–58)
Slide 57 claims the RDU fuses an entire decoder into one kernel. Its 520 MB of SRAM, about 5× the ~100 MB of on-chip memory of an H100, keeps the intermediates on chip, which eliminates gigabytes of off-chip traffic. Slide 58 goes further with a kernel loop: one kernel call runs all the decoders, streaming each layer’s weights from HBM while the previous layer computes, so that HBM is busy all the time. That is 3 calls per generated token on the RDU vs. ~800 on a GPU, 100× fewer.
Why does this matter so much? 05_kernel_fusion.py models one generated token. Each kernel costs overhead + max(FLOPs / peak, bytes / bandwidth). The overhead is the launch, the synchronization and the drained pipeline at each kernel boundary. Lecture 7’s demo 05 measured 5.5 µs for an empty kernel on the author’s GPU, and the model uses 4 µs. The same H100-class numbers (989 TFLOP/s, 3.35 TB/s) are used for every execution model, so only the programming model differs.
Generating one token reads every weight once: 15.0 GB, which takes 4.5 ms at full bandwidth. At batch 1 there are only 2 FLOPs per weight, so decode is memory-bound, and HBM should be busy 100% of the time:
| execution model (batch 1, context 2,048) | kernels | time/token | tokens/s | HBM busy |
|---|---|---|---|---|
| one kernel per operator | 612 | 7.0 ms | 142 | 65% |
| ~10 kernels per decoder (slide 56) | 324 | 5.9 ms | 171 | 78% |
| one kernel per decoder (slide 57) | 36 | 4.7 ms | 213 | 97% |
| kernel loop (slide 58) | 3 | 4.6 ms | 219 | 100% |
The unfused count (612) is the same order as the slide’s ~800. Most operators are tiny: an RMSNorm moves kilobytes, so its kernel is all overhead. Every boundary is a few microseconds in which HBM sits idle.
How large the gain is depends on two things (Part C, kernel loop vs. ~10 kernels per decoder):
| overhead per kernel | batch 1 | batch 16 | batch 64 | batch 256 |
|---|---|---|---|---|
| 1 µs (launches replayed from a CUDA Graph) | 1.07× | 1.07× | 1.06× | 1.05× |
| 4 µs | 1.28× | 1.23× | 1.16× | 1.09× |
| 8 µs | 1.56× | 1.45× | 1.29× | 1.14× |
Fusion matters most for latency-critical, small-batch serving, the case slides 57–58 target. Cheaper launches and larger batches shrink the gap. GPU software attacks the same overhead from its side: CUDA Graphs record a sequence of launches once and replay it cheaply. Persistent “megakernels”, for example Hazy Research’s 2025 megakernel that runs a whole Llama-1B forward pass in one GPU kernel, apply the kernel-loop idea to GPUs. The vendor’s measured speedups on slides 57–59 compare different chips; our model isolates one cause.
5.3 Overlapping communication too (slide 59)
The last step is to overlap chip-to-chip communication as well. When a model is split across chips, every layer ends in an all-reduce. A dataflow pipeline can stream it while the next weights load and compute proceeds, and on the RDU the all-reduce does not consume HBM capacity or bandwidth. This is the fourth row of slide 30’s ideal-accelerator table, and the starting point of Lecture 12.
6. Programming an accelerator with explicit on-chip memory
Programming Assignment 4 runs on an accelerator of the Trainium/TPU kind. Its on-chip memory is a scratchpad (暂存存储器) that the program manages explicitly, not a cache. Separate engines (DMA, a systolic tensor engine, vector and scalar engines) run in parallel. toy_accel.py is a toy machine in that style, not Trainium and not its NKI API:
- HBM, off chip;
- SBUF, a 2 MiB scratchpad of 128 partitions;
- PSUM, a small float32 accumulation buffer;
- in-order instruction queues for two DMA engines, a 128 × 128 tensor engine and a vector engine.
The hardware tracks data hazards (数据冒险): an instruction waits until the tiles it reads have been written (read-after-write) and until the tiles it writes are no longer being read or written by earlier instructions (write-after-read, write-after-write). The program therefore has sequential meaning, yet engines overlap whenever their instructions touch different buffers.
06_toy_accelerator.py computes Y = relu(Wᵀ X + b) (W 512 × 512, X 512 × 4096, bf16) three ways. All three results match numpy:
| version | cycles | TFLOP/s | tensor engine busy | DMA busy | HBM traffic |
|---|---|---|---|---|---|
| v1: one buffer per tile kind, reload everything | 376,376 | 8.0 | 22% | 44% | 25.2 MB |
| v2: two buffers each (double buffering) | 190,776 | 15.8 | 43% | 86% | 25.2 MB |
| v3: W resident on chip, each X tile reused for all outputs | 91,808 | 32.7 | 89% | 40% | 8.9 MB |
v1 dma-in |##...##..##...##...##..##...##...##..##...##...##..##...##...##.|
tensor |....#...#....#....#...#....#....#...#....#....#...#....#....#...|
v2 dma-in |####.########.####.########.####.########.####.#############.###|
tensor |....#.#.#.#..#.#..#.#.#.#..#.#..#.#.#.#..#.#..#.#.#.#..#.#..#.#.|
v3 dma-in |####################.....#######.........#######..........######|
tensor |..........##.#.#################################################|
- v1 is correct and almost entirely serial. Every load waits for the matmul still reading the single buffer, and every matmul waits for its load to land.
- v2 changes only which buffer each tile goes to. Hazard tracking now lets loads run ahead, and the program is 2× faster. The DMA queue is then busy 86% of the time: overlap has turned a latency problem into a traffic problem.
- v3 attacks the traffic. The weights stay on chip and each X tile serves all four output blocks, so traffic drops from 25.2 to 8.9 MB and the tensor engine is busy 89% of the time. Overlap and reuse are separate steps, and both are the programmer’s job on this kind of machine.
- Capacity is the budget. A v4 that tries to hold all of X on chip fails:
SBUF overflow ... 16384 + 1024 > 16384 bytes per partition. Deciding what stays and what streams, and making both overlap, is what PA4 asks for, for a convolution fused with max pooling. These notes give no solution.
7. Summary of the lecture (slide 60)
Specialized hardware for AI executes the key computations efficiently with:
- large and numerous matrix-multiply units, often systolic arrays;
- customized or configurable datapaths that move intermediates directly between units, so computation is scheduled by laying it out in space;
- large on-chip storage for intermediates.
Programming it:
- H100: asynchronous compute and memory mechanisms make programming complex. DSLs such as ThunderKittens manage the complexity.
- SN40L: a dataflow model with metapipelining makes the programming model simpler, and a sophisticated compiler optimizes and maps it to the hardware.
- For both: minimizing synchronization overhead is required for high performance.
Summary
- Asynchronous execution overlaps load, compute and store, so time per tile drops from the sum of the stages to the slowest stage. It needs at least two buffers per link, and an issue order consistent with them. A wrong order is slow, and a wrong order with too few buffers deadlocks.
- As compute gets faster than bandwidth (V100 → H100: 8× vs. 3.7×), the share of time a synchronous kernel cannot hide grows. Asynchrony is necessary, but a memory-bound kernel also needs more FLOPs per byte, which means bigger tiles.
- Every synchronization has a cost (~100 ns per cross-core hand-off on the author’s CPU), so asynchronous pipelines move tiles, not values. A CPU core overlaps memory and compute in hardware; GPUs and accelerators make the program do it.
- ThunderKittens makes the tile the data type and packages the producer/consumer pipeline as a template. Producer warps drive the TMA, consumer warpgroups drive the tensor cores, mbarriers with transaction counts connect them, and registers are reallocated between them. The library picks swizzled layouts that avoid bank conflicts without padding. A missing
arrivestill hangs the GPU. - Dataflow architectures execute the model’s graph in space, with no instructions. Programs are parallel patterns, compiled by tiling, parallelization and metapipelining. A metapipeline runs at the pace of its slowest stage, so the compiler balances stages by allocating units. Big tiles need big on-chip memory.
- Fusing a whole decoder, or all of them, into one kernel keeps HBM busy and removes hundreds of kernel boundaries per token. That matters most for small-batch inference.
Common pitfalls
- Double buffering in name only. Two buffers do not help if the program waits for the load of tile i+1 right after issuing it, or if a shared engine executes the load after a store that depends on compute. Check the issue order.
- Too-small tiles. Each hand-off costs ~100 ns on a CPU and a barrier round trip on a GPU. A pipeline of tiny tiles can be slower than no pipeline at all (demo 02: 1 KiB tiles, 2.7–4× slower).
- Expecting overlap to fix a memory-bound kernel. Overlap gives max(compute, memory). When memory dominates, only more reuse helps.
- Forgetting a barrier arrival. The pipeline runs for exactly as many iterations as it has stages, then hangs. Count arrivals per phase: the template expects exactly
CONSUMER_BARRIER_ARRIVALS. - Padding shared-memory tiles to fix bank conflicts on the H100. It breaks TMA’s dense boxes. Use the swizzle modes, or a library that does.
- Balancing a dataflow pipeline by adding units to every stage. Only the slowest stage matters. Past the memory-bound stage, more compute units are wasted.
- Comparing chips with numbers from different programming models. A launch-bound GPU kernel and a fused dataflow kernel differ in software as much as in hardware. CUDA Graphs and megakernels close much of the gap.
Exercises
-
Pipeline arithmetic. A kernel processes 100 tiles. Load takes 3 µs, compute 5 µs, store 2 µs, each on its own engine. What is the total time synchronously, and asynchronously with double buffering?
Answer
Synchronous: 100 × (3 + 5 + 2) = 1,000 µs. Asynchronous: the first load (3) + 100 computes (500) + the last store (2) = 505 µs, since compute is the slowest stage and never waits after the first tile. That is 1.98×. -
Single buffer. In Exercise 1, with only one buffer between load and compute (and two between compute and store), what is the steady-state time per tile?
Answer
The load of tile i+1 cannot start until compute(i) has finished reading the buffer, so each tile costs load + compute = 8 µs: about 800 µs in total. Stores still overlap. -
Faster tensor cores. A kernel’s tiles need 4 µs of compute and 2 µs of memory on GPU A. GPU B computes 4× faster with 2× the bandwidth. What fraction of time are the tensor cores busy on each GPU, synchronously and asynchronously?
Answer
A: synchronous 4/6 = 67%, asynchronous 4/max(4, 2) = 100%. B: compute 1 µs, memory 1 µs; synchronous 1/2 = 50%, asynchronous 100%. On B asynchrony is worth 2×, on A only 1.5×. If B had only 1.5× the bandwidth (memory 1.33 µs), the asynchronous kernel would be memory-bound at 75%. -
Block intensity. A thread block computes a bm × bn tile of C in bf16, stepping through K in chunks of 64. Derive its FLOPs per byte loaded. Which square tile reaches 128 FLOPs/byte?
Answer
Per step: bytes = (bm + bn) × 64 × 2, FLOPs = 2 × bm × bn × 64, ratio = bm·bn / (bm + bn). For a square tile b × b this is b/2, so b = 256. -
Swizzle. Show that in a row-major bf16 tile 64 elements wide, the 16-byte chunk c of rows 0–7 all map to the same 4 banks. Then show that with chunk c stored at c XOR r, rows 0–7 cover all 32 banks.
Answer
The address of chunk c in row r is 128r + 16c bytes, so its bank is (32r + 4c) mod 32 = 4c, the same for every r: banks 4c to 4c + 3, an 8-way conflict. Swizzled, the address is 128r + 16(c ⊕ r) and the bank is 4(c ⊕ r). For fixed c, c ⊕ r takes all 8 values 0–7 as r goes over 0–7, so the 8 rows land on 8 disjoint groups of 4 banks. -
Balancing a metapipeline. A three-stage pipeline has stages of 100, 400 and 50 cycles per item on one unit each. You have 10 units in total. How should you allocate them (work divides perfectly), and what is the new time per item?
Answer
Allocate in proportion to the work (100 : 400 : 50 over 10 units ≈ 2 : 7 : 1): stage times 50, 57, 50 cycles, so about 57 cycles per item instead of 400, a 7× speedup. Any allocation is limited by its slowest stage; the ideal with 10 units is 550/10 = 55. -
Kernel launches. A model generates a token by reading 16 GB of weights at 3.2 TB/s, in 800 kernels with 5 µs of overhead each. What fraction of the time is overhead? What would a single persistent kernel achieve?
Answer
Memory time 5 ms; overhead 800 × 5 µs = 4 ms; total ~9 ms, so 44% is overhead. A persistent kernel would approach 5 ms, 1.8× faster, if it keeps HBM streaming. -
Explicit on-chip memory. In demo 06’s v3, the weights (512 × 512 bf16) stay in SBUF. If W were 2048 × 2048, would they still fit in a 2 MiB SBUF? What would you do?
Answer
2048 × 2048 × 2 B = 8 MiB > 2 MiB, so no. Keep only a block of W at a time (for example, the weight tiles of a few output blocks), stream X through for that block, and choose block sizes so that one W block plus double-buffered X and Y tiles fit. Each X tile is then reloaded once per W block: a trade between capacity and traffic, as in Lecture 9's cache blocking.
The related assignment
Programming Assignment 4 runs on AWS Trainium2, an accelerator with exactly this lecture’s structure:
- a systolic tensor engine, vector and scalar engines;
- explicitly managed on-chip SBUF and PSUM memories;
- DMA engines that move tiles asynchronously.
You write kernels in NKI and fuse a convolution with max pooling. The skills are §1 (overlap and buffers), §3.6 (tile sizes for reuse) and §6 (what stays on chip, what streams). These notes and demos give no solution; the toy machine’s API is deliberately not NKI.
Further reading
- The Fall 2025 slides for this lecture.
- B. Spector, S. Arora, A. Singhal, D. Fu, C. Ré, “ThunderKittens: Simple, Fast, and Adorable AI Kernels”, 2024 (ICLR 2025), and the ThunderKittens repository (the matmul of slides 38–40 is among its examples).
- J. Shah et al., “FlashAttention-3: Fast and Accurate Attention with Asynchrony and Low-precision”, 2024: warp specialization and TMA on the H100.
- NVIDIA, CUDA C++ Programming Guide, sections on asynchronous data copies, the Tensor Memory Accelerator and
mbarrier; the PTX ISA forwgmmaandsetmaxnreg. - R. Prabhakar et al., “Generating Configurable Hardware from Parallel Patterns”, ASPLOS 2016 (metapipelining).
- R. Prabhakar et al., “Plasticine: A Reconfigurable Architecture for Parallel Patterns”, ISCA 2017.
- D. Koeplinger et al., “Spatial: A Language and Compiler for Application Accelerators”, PLDI 2018.
- R. Prabhakar et al., “SambaNova SN40L: Scaling the AI Memory Wall with Dataflow and Composition of Experts”, MICRO 2024.
- Hazy Research blog, “Look Ma, No Bubbles! Designing a Low-Latency Megakernel for Llama-1B”, 2025.
Preview of Lecture 12 — Mapping AI applications to the datacenter
One chip is not enough for large models. Lecture 12 zooms out to clusters of thousands of accelerators:
- the memory system that feeds each chip (DRAM internals, and HBM stacked next to the processor);
- the collective operations (all-reduce, reduce-scatter, all-gather) that connect chips;
- where the parallelism in a transformer is: data, tensor and pipeline parallelism, and the communication each costs;
- how overlapping that communication with computation, as in §5.3, keeps a 32-socket system busy.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| synchronous / asynchronous execution | 同步 / 异步执行 |
| blocking / non-blocking | 阻塞 / 非阻塞 |
| tile | 分块(瓦片) |
| buffer / double buffering | 缓冲区 / 双缓冲 |
| pipeline / stage / pipeline depth | 流水线 / 流水级 / 流水线深度 |
| prefetching / software pipelining | 预取 / 软件流水 |
| deadlock | 死锁 |
| out-of-order execution | 乱序执行 |
| arithmetic intensity (FLOPs per byte) | 算术强度(每字节浮点运算数) |
| memory-bound / compute-bound | 访存受限 / 计算受限 |
| Tensor Memory Accelerator (TMA) / copy descriptor | 张量内存加速器 / 拷贝描述符 |
| tensor memory (TMEM) | 张量内存 |
| warpgroup | warp 组(4 个 warp) |
| warp specialization | warp 专用化 |
| producer / consumer | 生产者 / 消费者 |
| mbarrier / phase / transaction count | 内存屏障对象 / 相位 / 事务字节计数 |
| register reallocation (setmaxnreg) | 寄存器重分配 |
| domain-specific language (DSL) | 领域专用语言 |
| register tile / shared tile / global layout | 寄存器分块 / 共享内存分块 / 全局布局 |
| bank conflict | 存储体冲突 |
| swizzling | 地址重排(交错映射) |
| padding | 填充 |
| dataflow graph | 数据流图 |
| reconfigurable dataflow architecture (RDA/RDU) | 可重构数据流架构 |
| pattern compute unit (PCU) / pattern memory unit (PMU) | 模式计算单元 / 模式存储单元 |
| address generator and coalescing unit (AGCU) | 地址生成与合并单元 |
| parallel patterns (map, zip, reduce) | 并行模式 |
| spatial execution | 空间执行 |
| tiling / parallelization / place and route | 分块 / 并行化 / 布局布线 |
| metapipeline / metapipelining | 元流水线 |
| coarse-grained pipelining | 粗粒度流水 |
| kernel fusion / kernel launch overhead | 算子融合 / 内核启动开销 |
| persistent kernel / megakernel | 常驻内核 / 巨型内核 |
| scratchpad memory (SBUF) | 暂存存储器 |
| data hazard (RAW / WAR / WAW) | 数据冒险(写后读 / 读后写 / 写后写) |
| weight-, output-, input-stationary dataflow | 权重 / 输出 / 输入驻留数据流 |