Lecture 12 · Reconfigurable Dataflow Architectures

Hardware Accelerators for Machine Learning · Lecture 12。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: Stanford CS 217 Hardware Accelerators for Machine Learning (Winter 2026), Lecture 12 · Thu 02/19/2026 · Reconfigurable Dataflow Architectures. HW3 (kernel fusion) is due 02/22. Reading (from the schedule): R. Prabhakar, Y. Zhang, D. Koeplinger, M. Feldman, T. Zhao, S. Hadjis, A. Pedram, C. Kozyrakis, K. Olukotun, Plasticine: a reconfigurable architecture for parallel patterns, ISCA 2017. Basis: The slides are not public. This lecture follows the session title and the Plasticine paper, whose architecture parameters, area breakdown and results are quoted from its Tables 3, 5, 6 and 7. Background comes from:

  • the Spatial language (Koeplinger et al., PLDI 2018);
  • the FPGA–ASIC gap measurements of Kuon and Rose (IEEE TCAD 2007).

The experiments use a model of a Plasticine-like fabric written for these notes (cgra.py):

  • functional parallel patterns;
  • a compiler from element-wise expressions to PCUs;
  • a token-level pipeline simulator;
  • simulated-annealing placement with XY routing;
  • analytical models of a spatial GEMM and of an MLP block.

Several quantities are assumed and labelled: transcendental-function expansions, hop latency, reconfiguration time. It is not the paper’s cycle-accurate simulator. Paper results are always marked as such. The experiments do not reflect what was said in class. Code: code/lecture12/ (4 scripts + 1 module; under 1 s each) Reading time: 3 hours including running the code


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Place ASICs, CGRAs, FPGAs and GPUs on the efficiency–flexibility spectrum, and explain why bit-level reconfigurability is expensive.
  2. Distinguish spatial from temporal execution.
  3. Name the parallel patterns (map, reduce, filter, hash-reduce, fold) and say what each tells a compiler. Recognize when a “sequential” loop is really a reduce.
  4. Describe Plasticine’s PCU, PMU and interconnect, and what each is sized for.
  5. Compute the throughput of a coarse-grained pipeline, balance it under a resource budget, and size its FIFOs and in-flight requests.
  6. Explain how a program is compiled onto a CGRA: partitioning under stage, register and port limits; memory sizing; placement and routing.
  7. Decide when spatial (fused) execution beats kernel-by-kernel execution, and what happens when a program does not fit.

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
Lecture 2: HLS, pipelining, ready/valid channelsspatial vs temporal execution; CGRAs vs FPGAsSambaNova’s RDU: Plasticine as a product (L13)
Lecture 6: vector units, exp and division as polynomial sequencesparallel patterns and their hardware templatesmemory-centric architectures (L14–15)
Lecture 7: banks, Little’s law, tiling and the √S lawPCUs, PMUs, coarse-grained pipelines, metapipelining
Lecture 9: mappings and cost modelscompiling to a CGRA: partitioning, placement, routing
Lecture 10: fusion; Lecture 11: GPUs as temporal machinesspatial fusion vs kernels; temporal partitioning

0.3 Map

§1  the efficiency-flexibility spectrum; spatial vs temporal; why not an FPGA
§2  parallel patterns                                                   ← code 01
§3  Plasticine: PCUs, PMUs, networks, coarse-grained pipelines          ← code 02
§4  compiling and mapping: Black-Scholes, GEMM, softmax, place & route  ← code 03
§5  spatial vs kernel-by-kernel execution                               ← code 04 (Parts 1-4)
§6  the cost of flexibility                                             ← code 04 (Part 5)
§7  summary   §8 pitfalls   §9 exercises   §10 further reading   §11 next lecture

0.4 Notation

SymbolMeaning
PCU / PMUpattern compute unit / pattern memory unit
AGaddress generator (a DRAM interface)
lanes, stagesSIMD width (16) and pipeline depth (6) of a PCU
parparallelization factor (lanes devoted to one pattern)
iiinitiation interval: cycles between consecutive tokens a stage accepts
tokenthe unit flowing through a coarse pipeline (a vector, a tile)
DFIFO depth between pipeline stages

1. The efficiency–flexibility spectrum

1.1 From fixed function to fully programmable

ASIC            CGRA                      FPGA                 GPU / CPU
fixed datapath  word-level units,         bit-level LUTs,      instructions fetched
                configured once           configured once      every cycle
<-- efficiency (energy/op, area/op)                     flexibility (what it can run) -->

Lecture 1 traced most of a processor’s energy to instruction overhead: fetching, decoding and scheduling an instruction costs ~70 pJ around a ~1 pJ operation.

  • GPUs (Lecture 11) amortize that overhead over 32 lanes or a whole matrix instruction.
  • Reconfigurable architectures remove it: the “program” is a configuration loaded once. After that every unit does its piece of the computation each cycle with no instruction stream at all. This is spatial execution: each operation of the program has its own piece of hardware, and data flows between them.
  • Temporal execution (CPU, GPU) time-shares the same units among all operations, one instruction or one kernel after another.

1.2 Why not just use an FPGA?

An FPGA is the classic reconfigurable chip. Its fabric is bit-level: look-up tables (LUTs) implement any small Boolean function, and a programmable routing network wires them together. That generality is expensive. Kuon and Rose measured FPGAs against ASICs built from the same circuits (IEEE TCAD 2007 and Kuon’s thesis):

MetricFPGA / ASIC (paper)
area, logic and flip-flops35×
area with hard multipliers and memories18× (4.7× if heavily used)
critical-path delay3.4–4.6×
dynamic power~14×

The costs come from three places:

  • Configuring every bit separately means configuration memory and multiplexers for every bit of every wire. Most of an FPGA’s area is routing.
  • Clocks are slow: the Stratix V in the Plasticine paper ran its fabric at 150 MHz.
  • Compilation (synthesis, placement and routing of millions of LUTs) takes hours.

Hard blocks (DSP multipliers, block RAMs) narrow the gap for the operations they cover, which is a hint. ML and data analytics compute on words, not bits, so the fabric should be word-level: a coarse-grained reconfigurable array (CGRA). CGRAs are decades old (MorphoSys, ADRES and many others), but they traditionally required low-level programming and suffered from long compile times. Plasticine’s contribution is to design the units around a programming model, parallel patterns, so that a high-level compiler can target them.


2. Parallel patterns

2.1 The patterns

A parallel pattern is a higher-order function: a loop whose structure says what is parallel.

PatternComputesWhat the compiler learns
mapf(x) for every element (or zipped elements)every element independent
reducecombine all elements with an associative ⊕the order of combination is free
filter / flatMap0 or more outputs per elementvariable output count
hash-reduce (groupBy)accumulate into data-dependent bucketsdata-dependent addresses
foldsequential accumulation with an arbitrary fa loop-carried dependence

Patterns compose. The paper’s examples include GEMM, k-means, Black-Scholes, TPC-H Query 6, PageRank, BFS and a CNN, all built from these few patterns.

The paper’s Table 2 maps the programming model onto hardware. Parallel compute becomes pipelined SIMD lanes. Intermediate scalars become distributed pipeline registers. Tiled, linear accesses become banked scratchpads. Random reads become duplicated scratchpads. Streaming accesses become FIFOs.

2.2 Same answers, different order

Script 01, Part 1 computes several programs both as patterns and as plain loops:

ComputationPatternsDifference
sum of squaresmap + reduce5e-12
dot productmap(zip) + reduce2e-14
TPC-H Q6-like revenue (119 of 10,000 rows pass)filter + map + reduce6e-14
histogram of 64 keyshash-reduceexact
x ← a x + b, 1,000 stepsfold vs reduce of affine maps5e-15

Floating-point reductions differ in the last bits because the additions happen in a different order (Lecture 4). Integer results are identical.

The last row matters most. The recurrence x_{i+1} = a_i x_i + b_i looks inherently sequential. But each step is an affine map, and affine maps compose associatively: (a₂, b₂)∘(a₁, b₁) = (a₂a₁, a₂b₁ + b₂). So the recurrence is a reduce over pairs and can run as a parallel tree. Lecture 10’s online softmax used the same trick.

One subtlety appeared while writing the code. A SIMD unit naturally deals elements to lanes in a strided order (lane l gets l, l + 16, …). That reordering is only valid for operations that are associative and commutative. Composition is not commutative, so it needs a blocked layout: contiguous chunks, combined in order.

2.3 Hardware templates

Script 01, Part 2 (1 M elements, Plasticine’s 16 lanes × 6 stages per PCU):

PatternLanesPCUsCyclesTime
map y = a·x + b16 / 2561 / 1662,501 / 3,90762.5 / 3.9 µs
map, Black-Scholes body (83 FU ops)16 / 6414 / 5662,609 / 15,73462.6 / 15.7 µs
reduce (sum of squares)16 / 2561 / 3162,506 / 3,92462.5 / 3.9 µs
fold: the same sum, as a loop–14,000,0044,000 µs

The templates follow from the patterns:

  • A map becomes a pipeline: the body’s FU operations occupy successive stages, ceil(ops/6) PCUs per 16 lanes.
  • A reduce adds a tree across lanes inside the PCU (log₂ 16 = 4 stages) and a tree of PCUs across lane groups.
  • A fold through a dependent 4-cycle adder processes one element every 4 cycles however many lanes exist: 1,019× slower than the 256-lane reduce of the same sum.

The pattern is a contract. It states what is parallel and what is associative, which a compiler often cannot prove from a loop. 256 lanes of Black-Scholes would need 224 PCUs, more than the chip’s 64.

Hash-reduce pays for data-dependent addresses (Part 3). 16 keys per cycle into 16 PMU banks take the largest number of keys that land in one bank, which is 3.07× the ideal cycles for uniform keys (Lecture 7’s balls into bins). 64 banks give 1.99×. A hot key (50% of keys) costs ≥ 8× whatever the banking, which is why hash-reduce hardware pre-combines duplicates.


3. Plasticine

3.1 The units

Plasticine is a 16 × 8 checkerboard of 64 PCUs and 64 PMUs connected by switches, with address generators along two edges that talk to DRAM (paper, Table 3 and Figure 5).

Pattern Compute Unit (PCU).

  • A pipeline of 6 stages × 16 SIMD lanes of floating-point/integer FUs; peak 96 FMAs per cycle.
  • 6 pipeline registers per stage carry live values down the pipeline.
  • Cross-lane reduction and shift networks support reduce and scan.
  • 3 vector inputs and 3 vector outputs (FIFOs), 6 scalar inputs and 5 scalar outputs.
  • Counters and control logic that sequence the pattern.

The stage count, lanes, registers and ports were chosen by sweeping benchmarks for minimum area (paper, §3.7).

Pattern Memory Unit (PMU).

  • A 256 KiB scratchpad in 16 banks of 16 KiB.
  • A small reconfigurable datapath for address calculation.
  • Banking modes for strided access, FIFOs, line buffers and duplication (for random reads).
  • N-buffering: several copies of a tile, so a producer can fill one while a consumer reads another.

Interconnect. Three static networks: word-level scalar, multi-word vector (16 lanes), and bit-level control, which carries tokens and credits between units’ controllers.

Off-chip. 4 DDR3-1600 channels (51.2 GB/s), with address generators and coalescing units for dense and sparse (gather/scatter) access.

The chip. 112.8 mm² in 28 nm, 1 GHz, 49 W maximum, 12.3 TFLOPS fp32 peak (64 × 16 × 6 × 2 × 1 GHz), 16 MiB of on-chip scratchpad. Area (paper, Table 5): PCUs 48%, PMUs 30%, interconnect 17%, memory controllers 5%. Inside a PCU, 73% of the area is FUs; inside a PMU, 90% is SRAM.

3.2 Coarse-grained pipelines

A spatial program is a pipeline at every level:

  • FU stages inside a PCU;
  • chains of PCUs;
  • the outer loops over tiles, where PMUs hand tiles from stage to stage.

Each unit has a controller, and the control network passes tokens (“a tile is ready”) and credits (“a buffer is free”): Lecture 2’s ready/valid protocol at the granularity of whole units. cgra.simulate_pipeline models it with this recurrence:

starti,s=max⁡(donei,s−1, starti−1,s+iis, donei−M,s, starti−D,s+1−lats)\text{start}_{i,s} = \max(\text{done}_{i,s-1},\ \text{start}_{i-1,s} + ii_s,\ \text{done}_{i-M,s},\ \text{start}_{i-D,s+1} - \text{lat}_s)

The four terms are: input ready; stage free; in-flight limit M; output FIFO of depth D has room.

Script 02:

  • Throughput = 1 / slowest ii. A 4-stage pipeline with one 4× slower stage drops from 0.98 to 0.25 tokens/cycle. Giving that stage 4× the units restores it. Latency only adds a one-time fill (~170 cycles of 10,000+).
  • Balancing. An MLP block’s stages need 10,923 / 256 / 10,923 / 32 PCU-cycles per token (GEMM1, GELU, GEMM2, residual). Giving each stage PCUs in proportion to its work (31/1/31/1 of 64) needs 352 cycles per token; an even split (16 each) needs 683, 1.9× slower. The integer granularity costs utilization when units are few: the two small stages still occupy a whole PCU each, so utilization is 51% with 4 PCUs and 98% with 64.
  • Little’s law for DRAM. A loader at 100 cycles of latency streams one request per cycle only with 100 requests in flight: 16 give 0.16, 64 give 0.63 (Lectures 7 and 11 again).
  • FIFOs absorb burstiness. Three stages whose per-token time varies from 0.2 to 3.8 cycles lose 17% of their throughput with 1-deep FIFOs and 1% with 32-deep ones. That is what the units’ input FIFOs and the PMUs pay area for.
  • Metapipelining. Overlapping load, compute and store of a loop’s tiles with double-buffered PMUs gives 2.91× for balanced phases (ideal 3×) and 1.39× when compute dominates. The Spatial language calls such pipelined outer loops metapipelines.

4. Compiling and mapping

4.1 From patterns to units

The paper compiles programs written in DHDL, a precursor of the Spatial language: a hierarchy of pipelines with explicit on-chip memories and parallelization factors. The compiler:

  1. unrolls patterns by their parallelization factors;
  2. partitions each inner pattern’s dataflow graph into PCU-sized pieces;
  3. sizes and banks the memories into PMUs;
  4. places and routes the units on the grid.

All of this works on a few hundred coarse units, so the paper reports compilation in minutes, against the hours FPGA tools take.

4.2 Black-Scholes: partitioning under limits

cgra.compile_expr packs an element-wise DAG into PCUs, one FU operation per stage, closing a PCU when one of these runs out:

  • stages (6);
  • live values (6 pipeline registers);
  • vector inputs (3).

Transcendentals expand into polynomial and Newton–Raphson sequences, as in Lecture 6: exp and log 6 stages, division and square root 5, reciprocal 4 (assumed).

Script 03, Part 1. Black-Scholes with the Zelen–Severo normal CDF:

  • 45 operations expand to 83 FU operations, which pack into 17 PCUs per 16 lanes against an ideal 14 (81% of stages used);
  • the limit is the 3 vector inputs: operations needing S, K and an earlier result cannot share a PCU with others;
  • max live values are 3, well under 6;
  • the compiled DAG, evaluated in numpy, matches the closed-form price within 1.8e-5.

Parallelizing to 2 or 3 lane groups (34 or 51 PCUs) does not help. Even one lane group computes 16 G options/s, but 51.2 GB/s at 16 bytes per option delivers inputs for only 3.2 G/s. An element-wise kernel on Plasticine is DRAM-bound. The paper also found Black-Scholes memory-bound, but using 65% of the PCUs, and 5.1× faster than the FPGA. Our model reaches the bound at 27% because its PCUs are ideal and its options are smaller.

4.3 GEMM: on-chip capacity is the lever

cgra.gemm_spatial keeps the C tile (mt × nt) on chip in PMUs and streams double-buffered A and B panels from DRAM. The DRAM traffic is Lecture 7’s tiling formula, 4·(MNK/nt + MNK/mt) + 4MN bytes in fp32. That gives about mt·nt / (2(mt + nt)) FLOP per byte against Plasticine’s ridge of 240 FLOP/byte (12.3 TFLOPS / 51.2 GB/s).

Part 2 (4096³, 64 PCUs):

PMUs for tilesCapacityC tileFLOP/byteTFLOPSBound
20.5 MiB256 × 256623.2DRAM
82 MiB512 × 5121206.2DRAM
328 MiB1024 × 102422811.7DRAM
6416 MiB1024 × 204829312.3PCUs

This is the √S law: on-chip capacity buys arithmetic intensity, and only with all 16 MiB does the GEMM clear the ridge. Our compute bound assumes every FU does an FMA every cycle. The paper’s GEMM used 56% of its FUs and ran 33× faster than the FPGA (24.4× performance per watt).

4.4 Softmax: a pipeline that should not stand alone

Part 3. A row softmax as three patterns:

  • a max reduce;
  • an exp(x − max) map with a sum reduce;
  • a multiply by 1/sum.

Each 16 KiB row is buffered in a PMU between passes. With 16 lanes it takes 4 PCUs; with 64 lanes, 22. Either way it is DRAM-bound at 6.4 G elements/s (8 bytes per element at 51.2 GB/s). On a spatial machine, a standalone element-wise or reduction kernel wastes the fabric. Its value appears only when it is fused with its producer and consumer (§5).

4.5 Placement and routing

Part 4 places three Black-Scholes lane groups (51 PCUs, 12 PMUs, 6 AGs, 117 connections) on the grid by simulated annealing, the VPR-style algorithm of FPGA tools, and routes every connection with dimension-order (XY) routing (figure 03_placement.png):

PlacementWire lengthMean hopsBusiest linkLatency added along a PCU chain
random1,4578.9914 streams204 cycles
annealed3712.29564

The static network is pipelined, so placement changes latency and link load, not throughput, as long as no link is oversubscribed. A bad placement can make the design unroutable, though. The 14 streams on one link of the random placement would exceed a realistic link’s capacity.


5. Spatial versus kernel-by-kernel execution

5.1 One MLP block, two ways

Consider y = x + W₂·GELU(W₁x + b₁), with d = 512, d_ff = 2048, in fp32 (8.4 MB of weights).

  • Kernel by kernel: four configurations (GEMM1, bias+GELU, GEMM2, residual). Each uses the whole fabric, reads its inputs from DRAM and writes its output back, which is how a GPU runs unfused kernels (Lecture 10).
  • Spatially: all four operators are resident at once, with PCUs split in proportion to their work (31/1/31/1). Tokens stream through in tiles; the hidden activations never leave the chip and the weights stay in PMUs.

Script 04, Part 1:

TokensKernelsSpatialSpeedupDRAM saved
16217 µs175 µs1.24×1.1×
512634 µs258 µs2.46×2.9×
4,0963.89 ms1.52 ms2.56×7.8×
32,76830.3 ms11.6 ms2.60×10.9×

Part 2 shows where the kernel-by-kernel time goes at 4,096 tokens. The GELU and residual kernels take 47% of the time for 0.6% of the FLOPs: every element they touch makes a round trip to a 51.2 GB/s DRAM. The spatial version is bound by its slowest stage, the GEMMs, not by memory. This is Lecture 10’s fusion argument, and on a spatial machine fusion is the default rather than a compiler optimization.

5.2 Reconfiguration and small problems

At 16 tokens both versions mostly load weights. The spatial one still wins because it reconfigures once instead of four times. The reconfiguration time is an assumption (Part 3): at 16 tokens the speedup is 1.09× with 1 µs reconfigurations and 2.18× with 100 µs. For small, latency-sensitive work such as LLM decode, a resident program avoids paying setup per operator. Lecture 13 calls this kernel looping on SambaNova’s chip.

5.3 When the program does not fit

Part 4. With d = 1024 and d_ff = 4096 the weights (33.6 MB) exceed the 16 MiB of PMUs. The compiler must partition temporally:

  • configuration 1 runs [GEMM1 + GELU];
  • configuration 2 runs [GEMM2 + residual];
  • the hidden activations go through DRAM once in between.

The gain falls to 1.70×.

On-chip capacity decides how much of a model can be one spatial program. A product built on these ideas needs far more SRAM and a deeper memory hierarchy: SambaNova’s SN40L has 520 MB of SRAM, 64 GB of HBM and up to 1.5 TB of DDR (Lecture 13).

5.4 When dataflow wins, and when it does not

Wins:

  • producer–consumer chains, where fusion avoids DRAM round trips;
  • pipelined parallelism across operators, so every unit is busy on a different operator;
  • small batches, which reconfigure once;
  • streaming data, where FIFOs and PMUs match the access pattern.

Loses or struggles:

  • programs larger than the chip (temporal partitioning);
  • unbalanced stages with coarse granularity (a whole PCU for a 32-cycle residual);
  • irregular, data-dependent control flow;
  • dynamic shapes that change the best mapping;
  • compiler complexity: the dataflow program, its partitioning, placement and routing must all be found automatically.

Hardware link. The GPU of Lecture 11 is temporal, yet its fastest kernels already look spatial. In warp specialization, producer warps issue TMA copies into shared-memory stages that consumer warpgroups drain, a coarse-grained pipeline inside one SM. Spatial architectures make that structure the whole chip’s organizing principle.


6. The cost of flexibility

How much does Plasticine’s reconfigurability cost compared with a fixed ASIC for each benchmark? The paper’s Table 6 adds design decisions one at a time (geometric mean over its benchmarks):

Design decisionThis stepCumulative
reconfigurable, heterogeneous PCUs and PMUs2.77×2.77×
one PMU design for the whole chip1.41×3.92×
one PCU design for the whole chip2.32×9.07×
PMUs generalized across applications1.21×11.00×
PCUs generalized across applications1.04×11.46×

So a fully general Plasticine pays about 11× in area over benchmark-specific ASICs, compared with an FPGA’s ~35× for logic. Most of it comes from homogeneity: every PCU must be sized for the most demanding pattern.

Against a 28 nm Stratix V FPGA (paper, Table 7):

BenchmarkPerformancePerformance per wattCharacter
inner product1.4×1.6×DRAM-bound on both
Black-Scholes5.1×5.8×streaming floating point
GEMM33.0×24.4×compute-bound
CNN95.1×76.9×compute-bound
PageRank14.2×18.2×sparse gathers

DRAM-bound kernels gain little, because both chips have similar memory systems. Compute-bound kernels gain the most, because word-level units clocked at 1 GHz out-compute bit-level LUTs at 150 MHz.

The lesson carried into SambaNova’s products (Lecture 13): pick the right granularity of reconfigurability (words, vectors, patterns), give the compiler a programming model it can reason about, and feed the fabric with enough on-chip and off-chip memory.


7. Summary

  1. Reconfigurable architectures replace the instruction stream with a configuration: each operation gets its own hardware (spatial execution). FPGAs do this at bit level and pay ~35× area, ~14× power and 3.4–4.6× delay over ASICs. CGRAs do it at word level.
  2. Parallel patterns (map, reduce, filter, hash-reduce, fold) tell the compiler what is parallel and associative. A fold of the same sum is 1,019× slower than a 256-lane reduce, and a “sequential” affine recurrence is a reduce in disguise.
  3. Plasticine: 64 PCUs (6 stages × 16 lanes, 96 FMA/cycle each), 64 PMUs (256 KiB, 16 banks), static scalar/vector/control networks, 12.3 TFLOPS in 112.8 mm² at 28 nm.
  4. A spatial program is a pipeline at every level:
    • throughput = 1 / slowest stage, so units must be balanced (1.9× over an even split);
    • DRAM streaming needs latency × rate requests in flight;
    • FIFOs absorb burstiness;
    • double buffering overlaps tiles (2.91×).
  5. Compiling means partitioning under stage, register and port limits (Black-Scholes: 17 PCUs, port-limited), sizing memories (a GEMM needs all 16 MiB to beat its DRAM ridge), and placing and routing (annealing cuts wire length 3.9×).
  6. Spatial vs kernels: the MLP block runs 2.56× faster with 7.8× less DRAM traffic, because intermediates stay on chip and the fabric is configured once. Programs that do not fit fall back to temporal partitioning (1.70×).
  7. Flexibility costs ~11× area over per-benchmark ASICs for fully general Plasticine units, but buys 1.4–95× performance over an FPGA.

8. Common pitfalls

  • “An FPGA is the flexible accelerator.” Its bit-level fabric costs an order of magnitude; ML wants word-level reconfigurability (§1.2).
  • “A loop is a loop.” Only patterns tell the compiler what is parallel or associative; a fold stays sequential (§2.3).
  • “Any associative operation can be reduced in any lane order.” Strided lanes reorder elements and need commutativity too (§2.2).
  • “More PCUs, more speed.” Only for the bottleneck stage, and only until DRAM or on-chip capacity binds (§3.2, §4.2, §4.3).
  • “Placement affects throughput.” On a pipelined static network it affects latency and routability (§4.5).
  • “Spatial always wins.” Not when the program does not fit (§5.3) or the stages cannot be balanced.
  • “Element-wise kernels are cheap.” On a 51.2 GB/s machine they are DRAM round trips unless fused (§4.4, §5.1).

9. Exercises

Exercise 1 (recognize the pattern). Classify: (a) prefix maximum of an array; (b) an exponential moving average m_i = α m_{i−1} + (1 − α) x_i; (c) x_{i+1} = x_i² + c; (d) counting words by first letter; (e) the sum of all elements greater than 0.

Answer

(a) A scan with max, which is associative and commutative, so it is parallel (a reduce tree plus a down-sweep).

(b) An affine recurrence with a_i = α, b_i = (1 − α)x_i. It is a reduce/scan of affine maps, so it is parallel.

(c) Squaring is not affine, and the compositions grow in degree, so there is no compact associative form: a fold, sequential.

(d) Hash-reduce (groupBy first letter, sum 1).

(e) Filter + reduce (or a map to x·[x > 0] + reduce).

Exercise 2 (PCUs for a map). A map body has 25 FU operations, parallelized over 48 lanes. How many PCUs (ideal packing), what throughput, and how long for 10 M elements at 1 GHz?

Answer

ceil(25/6) = 5 PCUs per 16-lane group × 3 groups = 15 PCUs. Throughput 48 elements/cycle. Time 10⁷ / 48 ≈ 208,000 cycles = 208 µs, plus a pipeline latency of ~25 stages + 4 hops (negligible).

Exercise 3 (reduction latency). Sum 1 M elements with 256 lanes. Count the reduction stages after the last element enters, and compare the total with a fold.

Answer

Inside each PCU: a 4-level lane tree + 1 accumulator stage. Across the 16 lane groups: log₂ 16 = 4 more levels (plus hops). Total time is ≈ 10⁶/256 = 3,906 cycles of streaming + ~20 cycles of trees: ~3.9 µs (Script 01: 3,924 cycles).

A fold through a 4-cycle adder takes 4 × 10⁶ cycles = 4 ms.

Exercise 4 (balls into bins). Why do 16 uniform keys into 16 banks cost ~3 cycles, not 1? What would make a hash-reduce conflict-free?

Answer

16 random keys into 16 banks almost surely collide somewhere, and the busiest bank sets the cycle count. The expected maximum load of n balls in n bins grows like ln n / ln ln n; it is 3.07 by simulation here.

Ways to get closer to conflict-free:

  • more banks than keys per cycle (64 banks: 1.99×);
  • buffering conflicting keys and reordering them over several cycles;
  • pre-combining equal keys within a batch (essential for hot keys);
  • sorting by bank, or privatizing buckets per lane and merging later.

Exercise 5 (balancing by hand). Four stages need 12, 3, 6 and 1 unit-cycles per token. Allocate 8 units to maximize throughput.

Answer

Start at 1/1/1/1 (bottleneck 12) → 2/1/1/1 (6, from stages 1 and 3) → 3/1/1/1 (stage 3 is 6) → 3/1/2/1 (4) → 4/1/2/1: times 3, 3, 3, 1, so 3 cycles per token.

cgra.balance([12, 3, 6, 1], 8) returns the same. With 7 units the answer is 3/1/2/1 (4 cycles per token).

Exercise 6 (in-flight requests). Plasticine’s DRAM delivers 51.2 GB/s. With 64-byte requests and a 200 ns latency, how many requests must the address generators keep in flight?

Answer

51.2 GB/s / 64 B = 0.8 requests/ns. × 200 ns = 160 requests (10 KiB) in flight. The address generators’ and coalescing units’ request buffers must hold that many, which is Little’s law again.

Exercise 7 (double buffering). A loop has 100 tiles with load 800, compute 1,200 and store 400 cycles. Compare sequential and double-buffered times.

Answer

Sequential: 100 × 2,400 = 240,000 cycles.

Pipelined: ≈ 100 × 1,200 (the slowest phase) + 800 + 400 = 121,200 cycles, a 1.98× speedup. The ideal is 2,400/1,200 = 2×; the extra is the fill and drain.

Exercise 8 (port limits). In Script 03, the Black-Scholes operations kd = K · disc and c1 = S · N(d1) each sit alone in a PCU. Why? Try moving disc and kd to the front of the DAG with compile_expr. What happens?

Answer

kd needs K (a stream input) and disc (from another PCU), and c1 needs S and N(d1). Together with the values that must pass through toward C, these exceed 3 vector inputs, so the packer closes the PCU.

Moving disc and kd to the front gives 16 PCUs in the author’s run. But it creates a PCU with 4 vector outputs (limit 3), which is illegal. The packer checks outputs only after packing.

A legal improvement needs a packer that checks outputs while packing, or reordering that also respects outputs, or scalar/vector input trade-offs. The lower bound is ceil(83/6) = 14.

Exercise 9 (GEMM intensity). Derive the fp32 C-tile intensity mt·nt / (2(mt + nt)) FLOP per DRAM byte. Which square tile reaches Plasticine’s ridge of 240, and does it fit?

Answer

Per C tile, K steps load mt·K + K·nt elements (4 bytes each) and compute 2·mt·nt·K FLOPs. So the intensity is 2mt·nt·K / (4K(mt + nt)) = mt·nt / (2(mt + nt)).

For a square tile n × n that is n/4, so the ridge of 240 needs n ≈ 960, i.e. 1024 × 1024. Its C tile is 4 MiB plus double-buffered panels (2 × 2 × 1024 × 64 × 4 B = 1 MiB): ~5 MiB, so it fits in the 16 MiB of PMUs. Script 03: 228 FLOP/byte for 1024 × 1024 (the M·N output term lowers it slightly).

Exercise 10 (counting the round trips). For the MLP block at T = 4,096 tokens (d_ff = 2,048, fp32), how many bytes of hidden activations go through DRAM kernel by kernel, and how many spatially?

Answer

H = T × d_ff × 4 B = 33.5 MB.

Kernel by kernel: GEMM1 writes H, GELU reads H and writes H′, and GEMM2 reads H′. That is 4 × 33.5 = 134 MB.

Spatially: 0, since the tiles stream on chip. Together with the inputs, outputs and weights, that is why Part 1 shows 197 MB vs 25 MB.

Exercise 11 (fitting a layer). Would the d = 1024, d_ff = 4096 MLP fit in bf16? What else must fit?

Answer

In bf16 the weights are 2 × 1024 × 4096 × 2 B = 16 MiB, exactly the PMU capacity. They would fill the chip completely, leaving nothing for:

  • double-buffered activation tiles;
  • the C/accumulator tiles;
  • the PMUs used as FIFOs between stages.

It still does not fit as one configuration. Fitting needs a 2× larger chip, fp8/MX weights (Lecture 4) or partitioning.

Exercise 12 (programming: tile streaming instead of partitioning). Instead of splitting the large MLP into two configurations, keep all four operators resident and stream the weights from DRAM for every tile of tokens. Model the DRAM time per tile (W₁ + W₂ bytes) against the compute time per tile. At what tile size does streaming beat temporal partitioning?

Answer

Per tile of t tokens:

  • DRAM: 33.6 MB of weights (+ tiny activations) → 656 µs at 51.2 GB/s;
  • compute: t × 2 × 2 × 1024 × 4096 FLOPs / 12.3 TFLOPS → t × 1.37 µs.

Streaming is DRAM-bound until t ≈ 480 tokens per tile. But the on-chip activation tiles for t = 480 (x, h, h′, y, double-buffered) need ~4 × 480 × (1024 + 4096) × 4 B ≈ 39 MB, which does not fit.

On this chip, weight streaming loses to temporal partitioning for any feasible tile. That is exactly why a production dataflow chip needs hundreds of MB of SRAM and HBM bandwidth (SN40L: 520 MB SRAM, ~2 TB/s HBM).

Implementation: add a stream_weights option to mlp_spatial that charges (W₁ + W₂) bytes per tile and checks the activation bytes against the PMU capacity.


10. Further reading

  • R. Prabhakar et al., “Plasticine: a reconfigurable architecture for parallel patterns”, ISCA 2017; and “Plasticine: a reconfigurable accelerator for parallel patterns”, IEEE Micro Top Picks 2018.
  • D. Koeplinger et al., “Spatial: a language and compiler for application accelerators”, PLDI 2018.
  • R. Prabhakar et al., “Generating configurable hardware from parallel patterns”, ASPLOS 2016 (patterns to hardware).
  • I. Kuon, J. Rose, “Measuring the gap between FPGAs and ASICs”, IEEE TCAD 26(2), 2007.
  • V. Betz, J. Rose, “VPR: a new packing, placement and routing tool for FPGA research”, FPL 1997.
  • H. Singh et al., “MorphoSys: an integrated reconfigurable system for data-parallel and computation-intensive applications”, IEEE TC 2000; B. Mei et al., “ADRES: an architecture with tightly coupled VLIW processor and coarse-grained reconfigurable matrix”, FPL 2003 (earlier CGRAs).
  • Y. Zhang et al., “SARA: scaling a reconfigurable dataflow accelerator”, ISCA 2021 (compiling to large spatial machines).
  • T. Nowatzki et al., “Stream-dataflow acceleration”, ISCA 2017.

11. Next lecture

Lecture 13, SambaNova’s reconfigurable dataflow architecture (guest: Raghu Prabhakar), follows Plasticine into production: the SN10 and SN40L Reconfigurable Dataflow Units. We will model:

  • streaming dataflow that fuses a whole decoder layer into one spatial program, against kernel-by-kernel execution on the same chip;
  • the decode phase and kernel looping;
  • a three-tier memory system (520 MB SRAM, 64 GB HBM, 1.5 TB DDR) that lets one node switch between many expert models: composition of experts.
← 返回课程目录