Maps to: Stanford CS 217 Hardware Accelerators for Machine Learning (Winter 2026), Lecture 14 · Thu 02/26/2026 · Memory-Centric Computing (Part 1). Reading (from the schedule):
- W. Kautz, Cellular logic-in-memory arrays, IEEE Transactions on Computers C-18(8), 1969;
- O. Mutlu et al., Memory-centric computing: solving computing’s memory problem, 2025;
- X. Ma, D. Patterson, Challenges and research directions for large language model inference hardware, 2026 (arXiv:2601.05047).
Basis: The slides are not public. This lecture follows the session title and the readings. The device examples are published:
- Ambit (Seshadri et al., MICRO 2017) and SIMDRAM (Hajinazar et al., ASPLOS 2021);
- Samsung’s HBM-PIM (ISSCC and ISCA 2021);
- UPMEM (Gómez-Luna et al., IEEE Access 2022);
- AttAcc (Park et al., ASPLOS 2024).
The experiments use a model written for these notes (
pim.py):
- a bit-exact functional model of in-DRAM row operations, timed with Lecture 7’s HBM2-like DRAM;
- a roofline model of an H100 whose HBM stacks contain bank-level processing units.
The internal bandwidth factor, the PIM compute, the split of DRAM energy and the overheads are assumed and varied. Device numbers are labelled as published. The experiments do not reflect what was said in class. Code:
code/lecture14/(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:
- Quantify the memory wall for ML inference: compute vs bandwidth vs capacity growth, bandwidth inside vs outside a DRAM stack, and energy per byte by distance.
- Explain the taxonomy of memory-centric computing: logic-in-memory cells (Kautz), processing using memory (computing with the array itself), processing near memory (logic next to banks), logic under a 3D stack.
- Show how triple-row activation computes a bitwise majority, build AND, OR, NOT, XOR and bit-serial addition from it, and estimate when that beats a host.
- Estimate the time and energy of GEMV and reductions on bank-level units. Derive the break-even arithmetic intensity, and explain the role of data placement.
- Decide which parts of LLM decoding belong in memory, and explain why grouped-query attention changes the answer.
- Explain Ma and Patterson’s research directions (high-bandwidth flash, processing near memory, 3D memory-logic stacking, low-latency interconnect) as levers on capacity, bandwidth and communication.
- List the practical obstacles: logic in DRAM processes, data layout, host/PIM sharing of banks, coherence, programmability.
0.2 Prerequisites and scope
| Assumed | Introduced here | Developed later |
|---|---|---|
| Lecture 1: energy per operation, roofline, decode is memory-bound | memory-centric computing; Kautz’s arrays | analog computing in memory (L15) |
| Lecture 7: DRAM banks, rows, tRAS/tRP/tFAW, near-memory read-modify-write | triple-row activation, bit-serial in-DRAM arithmetic | AWS Trainium/Inferentia memory system (L16) |
| Lecture 10: decode intensity = GQA group size; KV caches | bank-level PIM; break-even intensity; data placement | NVIDIA’s roadmap (L17) |
| Lecture 13: tiers of memory, capacity vs bandwidth | PIM for decode (FC vs attention); Ma & Patterson’s directions |
0.3 Map
§1 the memory wall from the memory's side ← code 01 (Parts 1-3)
§2 a short history and a taxonomy ← code 01 (Part 4)
§3 processing USING memory: computing with DRAM rows ← code 02
§4 processing NEAR memory: units next to the banks ← code 03
§5 LLM decoding with PIM ← code 04 (Parts 1-4)
§6 research directions for LLM inference hardware ← code 04 (Part 5)
§7 summary §8 pitfalls §9 exercises §10 further reading §11 next lecture
0.4 Notation
| Symbol | Meaning |
|---|---|
| PIM / PuM / PnM | processing in memory (umbrella) / using memory / near memory |
| AAP | ACTIVATE–ACTIVATE–PRECHARGE: one row-copy step, tRAS + tRP = 47 ns here |
| TRA | triple-row activation (bitwise majority of three rows) |
| tFAW | the window allowing at most 4 activations per channel (power limit) |
| B_ext, B_int | bandwidth at a stack’s pins / inside it (all banks) |
| P_pim | peak FLOP/s of the PIM units |
| I* | break-even arithmetic intensity (FLOP per byte) |
| G | GQA group: query heads per KV head |
1. The memory wall, from the memory’s side
1.1 Compute outgrew bandwidth
Script 01, Part 1 (datasheets, dense 16-bit):
| GPU | Year | TFLOPS | HBM TB/s | Capacity | A 1 FLOP/byte kernel uses |
|---|---|---|---|---|---|
| V100 | 2017 | 125 | 0.90 | 32 GB | 0.72% |
| A100 | 2020 | 312 | 2.04 | 80 GB | 0.65% |
| H100 | 2022 | 989 | 3.35 | 80 GB | 0.34% |
| B200 | 2024 | 2,250 | 8.00 | 192 GB | 0.36% |
From V100 to B200, FLOPs grew 18×, bandwidth 8.9× and capacity 6×. A decode step is GEMVs and attention at 1–4 FLOPs per byte (Lectures 10–11), so it can use a fraction of a percent of the arithmetic. Ma and Patterson’s summary is that for LLM inference, and decode in particular, memory and interconnect, not compute, are the primary challenges.
1.2 The bandwidth exists, inside
A DRAM stack is narrow at its pins, not in its arrays. Part 2:
| Bandwidth | Value | vs external |
|---|---|---|
| external interface (Lecture 7’s HBM2-like stack) | 256 GB/s | 1× |
| row buffers: each of 128 banks opens a 1 KB row every 47 ns | 2.8 TB/s | 10.9× |
| Samsung HBM-PIM: what its PIM units consume (published rates) | 1,229 GB/s vs 307 GB/s | 4.0× |
| this lecture’s PIM-enabled H100 (assumed) | 13.4 TB/s vs 3.35 TB/s | 4× |
The interface is narrow because it is expensive: through-silicon vias, PHYs, interposer wires, and their energy. Every bank can read a whole row at once, so logic placed next to the banks can tap bandwidth the host never sees.
1.3 Where the energy of a byte goes
Part 3. A DRAM access costs ~3.9 pJ/bit for HBM2-class memory, the order of published estimates. Our assumed split:
| Component | pJ/bit |
|---|---|
| array (activate and sense, per bit read) | 0.6 |
| on-die movement (bank → TSVs) | 2.0 |
| I/O to the host | 1.3 |
A bank-level unit pays the array plus a 0.3 pJ/bit local hop. Bringing a byte to the host therefore costs 31 pJ, to a bank-level unit 7 pJ.
One batch-1 decode step of Llama 3 8B moves 16.6 GB, 0.52 J, for 18 mJ of arithmetic (45 nm MACs; modern MACs are cheaper still). At 100 tokens/s that is 50 W for data movement alone. Batching amortizes the weights, never the KV caches. The energy, like the time, is in the movement.
2. A short history and a taxonomy
1969. Kautz proposed cellular logic-in-memory arrays: two-dimensional arrays of identical cells, each combining storage with a little logic, so that operations such as searching and sorting happen across the whole array at once. The idea is the extreme of memory-centric computing: no separation between storage and processing. It did not become practical at the time. Logic per bit is expensive, and memory technology (dense, cheap storage) and logic technology (fast transistors, many wiring layers) diverged into different processes.
Why it is back. The memory wall (§1), the energy of data movement, and 3D stacking, which puts logic dies under DRAM dies, have made the idea attractive again. Mutlu et al.’s survey frames modern memory-centric computing at several distances from the data (Script 01, Part 4):
| Approach | Published examples | Good at |
|---|---|---|
| processing using memory: compute with the array’s analog behaviour | Ambit (MICRO 2017), SIMDRAM (ASPLOS 2021) | bulk bitwise operations, bit-serial arithmetic |
| processing near memory: logic next to banks | Samsung HBM-PIM (2021), UPMEM (2019+), SK hynix GDDR6-AiM (2022) | GEMV, element-wise, reductions |
| logic under a 3D stack | Hybrid Memory Cube’s logic layer; 3D memory-logic stacking | more bandwidth per mm² |
| analog computing in memory | resistive / SRAM crossbars | matrix-vector in the array (Lecture 15) |
3. Processing using memory: computing with DRAM rows
3.1 The primitives
A DRAM cell stores a bit as charge on a capacitor. Activating a row connects its cells to the bit lines, and the sense amplifiers resolve each bit line to 0 or 1 (Lecture 7). Ambit (Seshadri et al., MICRO 2017) adds three operations:
- RowClone. Activating a source row and then, without precharging, a destination row copies the whole row through the sense amplifiers: one AAP, 47 ns with our timings.
- Triple-row activation (TRA). Activating three rows at once shares their charge on each bit line. The sense amplifier resolves the bitwise majority, MAJ(a, b, c), and writes it back into all three rows. With a constant row: AND(a, b) = MAJ(a, b, 0) and OR(a, b) = MAJ(a, b, 1). TRA destroys its operands, so they are first copied into reserved rows.
- NOT. A row of dual-contact cells can be read out inverted: two AAPs.
SIMDRAM (Hajinazar et al., ASPLOS 2021) builds arbitrary operations from MAJ and NOT. Numbers are stored vertically: row i holds bit i of 8,192 numbers, one per column, so one row operation processes all of them. Addition is bit-serial:
3.2 It computes the right thing, at a price
Script 02, Part 1: pim.Subarray runs these sequences on numpy rows, and every result is bit-exact against numpy.
| Operation | AAPs per row-wide step | Time in one subarray |
|---|---|---|
| AND / OR (8,192 bits) | 4 | 188 ns |
| NOT | 2 | 94 ns |
| XOR (our sequence) | 16 | 752 ns |
| 8-bit addition (8,192 numbers) | 137 | 6.4 µs |
| 16-bit addition | 273 | 12.8 µs |
3.3 Throughput, power and row width
How many row operations can run at once? Every bank (or, with subarray-level parallelism, every subarray) can work on its own rows. But activations draw current, so DRAM allows at most 4 activations per tFAW window per channel. With tFAW = 16 ns and two activations per AAP, only ~5.9 of a channel’s 16 banks can be mid-AAP at once.
Part 2 compares against a host that reads the operands and writes the result over the 256 GB/s interface:
| Operation | Arrays (tFAW-limited) | No power limit | + 8 subarrays per bank | Host | PIM / host |
|---|---|---|---|---|---|
| AND (bits) | 2,048 G/s | 5,578 G/s | 44,620 G/s | 683 G/s | 3.0× |
| XOR (bits) | 512 G/s | 1,394 G/s | 11,155 G/s | 683 G/s | 0.75× |
| 8-bit add (elements) | 60 G/s | 163 G/s | 1,303 G/s | 85 G/s | 0.70× |
Simple bulk bitwise operations win. Bit-serial arithmetic loses under the power window: 137 AAPs per row are too many. It only pays with many subarrays working at once and no power limit, which is a circuit and power-delivery question, not a logic question.
Energy (Part 3) follows the same split. Assume an AAP activates two rows at 0.6 pJ per row bit. Then:
- an in-DRAM AND costs 38 pJ per result byte, against 94 pJ to move its operands to a host (2.4× less);
- an 8-bit addition costs 164 pJ per element, against 94 pJ on the host (1.75× more).
A database example (Part 4). Ambit’s motivating use is bitmap indexes: count users satisfying (A AND B AND NOT C) over three 16 MiB bitmaps. In DRAM, then read the 16 MiB result:
| Memory | Host reads 3 bitmaps | In-DRAM + host reads result | Speedup |
|---|---|---|---|
| HBM2-like stack (1 KB rows, 256 GB/s) | 197 µs | 229 µs | 0.86× |
| DDR4-like channel (8 KB rank rows, 25.6 GB/s) | 1.97 ms | 963 µs | 2.0× |
Processing using memory shines where rows are wide and the external interface is narrow, as in DDR. Ambit’s published gains were evaluated there. HBM’s narrow rows and wide interface favour the host.
Practical limits:
- operands must sit in the same subarray (RowClone works within one);
- data must be laid out vertically;
- only what the array’s physics offers (copy, majority, NOT) is available;
- the analog operations must work reliably across process variation and temperature.
4. Processing near memory: units next to the banks
4.1 Published devices
- Samsung HBM-PIM (ISSCC and ISCA 2021): an HBM2 stack in which some DRAM dies carry programmable FP16 units running at 300 MHz, one shared by each pair of banks, for 1.2 TFLOPS per stack (published).
- The units execute commands issued by the host’s memory controller, and banks switch between normal and PIM mode.
- Our reading of the arithmetic: 128 units × 16 lanes × 2 FLOP × 300 MHz = 1.23 TFLOPS. The units consume 128 × 32 B × 300 MHz = 1.23 TB/s, about 4× the 307 GB/s at the stack’s pins.
- UPMEM (Gómez-Luna et al., IEEE Access 2022):
- DDR4 DIMMs whose chips contain small 32-bit in-order cores (DPUs), each with exclusive access to its own 64 MB DRAM bank, a 64 KB scratchpad and a 24 KB instruction memory;
- up to 2,560 DPUs per 20-DIMM server;
- integer-oriented: 32-bit multiplication is emulated;
- DPUs cannot talk to each other directly. All communication goes through the host.
- SK hynix GDDR6-AiM (ISSCC 2022): MAC units per bank of a GDDR6 device, aimed at GEMV for inference.
The system we model (Script 03, Part 1): an H100 (989 TFLOPS, 3.35 TB/s over 5 stacks) whose stacks contain bank-level units with 4× the external bandwidth inside (13.4 TB/s) and 1 FLOP per internal byte (13.4 TFLOPS), plus 2 µs launches and 1 µs mode switches (assumed). The PIM units have 1/74 of the GPU’s FLOPs and 4× its bandwidth: they are built for kernels near 1 FLOP per byte.
4.2 GEMV and the break-even intensity
Part 2 (batch-1 GEMVs, bf16):
| Matrix | GPU | PIM | Speedup | Energy saved |
|---|---|---|---|---|
| 1024 × 1024 | 4.63 µs | 4.16 µs | 1.11× | 3.1× |
| Llama 3 8B: O (4096 × 4096) | 14 µs | 6.5 µs | 2.15× | 3.2× |
| Llama 3 8B: gate (14336 × 4096) | 39 µs | 12.8 µs | 3.06× | 3.2× |
| Llama 3 70B: gate (28672 × 8192) | 144 µs | 39 µs | 3.69× | 3.2× |
Large GEMVs approach the 4× bandwidth ratio; small ones are dominated by fixed overheads.
Part 3: batching. A batched GEMV reuses each weight across the batch, so its intensity is ~batch FLOP per weight byte. The GPU stays memory-bound up to its ridge (~295); the PIM becomes compute-bound early. With the GPU memory-bound and the PIM compute-bound, the two times meet at
| Batch | 1 | 2 | 4 | 8 | 64 | 256 |
|---|---|---|---|---|---|---|
| PIM speedup | 3.06× | 1.81× | 1.00× (tie) | 0.53× | 0.07× | 0.02× |
Below I*, PIM wins by bandwidth; above it, the GPU’s 74× larger compute wins.
Part 4: provisioning. I* runs from 1 FLOP/byte (2× internal bandwidth, 0.5 FLOP per byte) to 32 (8× bandwidth, 4 FLOP per byte). Bandwidth sets the best-case gain; compute sets how far up in intensity it survives. Compute costs DRAM-die area, which is why real PIM units are small.
4.3 Reductions and data placement
Part 5.
- Reductions: summing 2²⁸ fp32 values is 3.9× faster on PIM, since only 1,280 partial sums cross the pins.
- Data placement: a GPU interleaves consecutive addresses over all channels and banks for bandwidth (Lecture 7). Then no bank holds a whole matrix row, each unit returns partial sums, and the GPU must add them:
| Units sharing each row | 1 | 4 | 16 | 64 | 256 |
|---|---|---|---|---|---|
| GEMV 4096 × 4096 speedup | 2.15× | 1.33× | 1.31× | 1.26× | 1.08× |
Data must be laid out for the PIM, and the GPU’s own kernels must then live with that layout.
4.4 Why PIM is hard
- Logic in a DRAM process. DRAM processes optimize for dense, low-leakage capacitors: transistors are slower, there are few metal layers, and every mm² of logic displaces capacity. HBM-PIM’s units run at 300 MHz.
- Sharing banks with the host. In HBM-PIM the banks are either in host mode or in PIM mode. Mode switches and conflicts cost time, and the memory controller must orchestrate both.
- Data placement and layout: row partitioning, vertical layouts for bit-serial PuM (§3, §4.3).
- Coherence. PIM units write memory that the host may hold in caches, so software must flush or partition explicitly.
- Programming model. Which kernels go where, how data is distributed, how results are combined. UPMEM’s DPUs communicate only through the host, so all-to-all patterns are expensive.
- Capacity and thermal limits: logic dies in a stack must stay cool under DRAM.
5. LLM decoding with PIM
5.1 FC layers vs attention
A decode step has two kinds of memory-bound work (Lectures 10–11):
- FC layers: all weight matrices, a batched GEMV whose intensity grows with the batch;
- attention: each sequence’s KV cache, whose intensity is the GQA group size G at any batch.
Script 04, Part 1 (Llama 3 8B, G = 4, on the PIM-enabled H100; tokens/s):
| Context | Batch | GPU only | Attention on PIM | FC on PIM | Both |
|---|---|---|---|---|---|
| 4,096 | 1 | 202 | 197 | 673 | 619 |
| 4,096 | 16 | 2,174 | 2,137 | 732 | 727 |
| 4,096 | 64 | 4,252 | 4,216 | 735 | 734 |
| 32,768 | 1 | 165 | 161 | 383 | 365 |
FC layers on PIM pay at batch 1 (3.3×) and lose badly from batch ~4 on (5.8× slower at batch 64), Script 03’s break-even.
Attention on PIM gains nothing here. With G = 4, attention does 4 FLOPs per KV byte, and a PIM provisioned at 1 FLOP per byte is compute-bound, as slow as the GPU reading the KV over its pins.
5.2 Grouped-query attention raised the bar
Part 2 repeats the experiment with multi-head attention (32 KV heads, G = 1), the kind of model AttAcc (Park et al., ASPLOS 2024) targeted. Attention is then a pure bandwidth problem at any batch, and attention on PIM makes a batch-16 step 2.0× faster. Part of AttAcc’s design is to keep the batched FC layers on the GPU and put attention in PIM-enabled HBM.
Part 3. To exploit 4× the bandwidth on GQA attention, the PIM needs about G FLOPs per byte (batch 64, 8K context):
| PIM FLOPs per byte | 1 | 2 | 4 |
|---|---|---|---|
| step speedup with attention on PIM | 0.99× | 1.67× | 2.52× |
GQA was invented to cut KV traffic on GPUs, and it also cut the advantage of attention-in-memory unless the PIM carries ~4× more compute. Model architecture and memory architecture co-evolve.
5.3 Energy
Part 4 (energy per token, 4K context):
| Batch | GPU only | Attention on PIM | FC on PIM | Both |
|---|---|---|---|---|
| 1 | 536 mJ | 528 mJ | 183 mJ | 174 mJ |
| 64 | 43 mJ | 34 mJ | 69 mJ | 60 mJ |
Reading bytes inside the stacks costs ~4× less, so PIM saves energy even where it saves no time (attention at batch 64). The PIM’s assumed 3× costlier MACs eat into the saving as the batch grows.
6. Research directions for LLM inference hardware
Ma and Patterson (2026) highlight four architecture research opportunities for inference, from their abstract:
- High Bandwidth Flash, aiming at ~10× the memory capacity with HBM-like bandwidth;
- processing-near-memory and
- 3D memory-logic stacking, both for memory bandwidth;
- low-latency interconnect, to speed up communication between chips.
Script 04, Part 5 treats the first three as levers, with illustrative package parameters. Each package has either HBM3 (80 GB, 3.35 TB/s), flash with 10× capacity at the same bandwidth, 4× bandwidth from stacking (assumed), or PNM attention at 4×. The workload holds weights plus 64 sequences of 8K context:
| Model | Package | Packages needed | Tokens/s per user (batch 1) | Tokens/s per package (batch 64) |
|---|---|---|---|---|
| Llama 3 70B | HBM3 | 5 | 116 | 685 |
| high-bandwidth flash | 1 | 23 | 685 | |
| 3D stacking (4× BW) | 5 | 466 | 2,741 | |
| PNM attention | 5 | 118 | 1,165 | |
| Llama 3.1 405B | HBM3 | 16 | 66 | 198 |
| high-bandwidth flash | 2 | 8 | 198 | |
| 3D stacking | 16 | 263 | 792 |
The levers do different things.
- Capacity (flash) cuts the number of packages, which means cost, power and communication. But each token still reads every weight, so with fewer packages the total bandwidth, and with it per-user speed, falls. Throughput per package is unchanged.
- Bandwidth (3D stacking) speeds up everything.
- PNM speeds up the KV-cache part, which dominates at long contexts and large batches.
Communication, the fourth direction, is not modeled here, and its cost grows with the number of packages (Lecture 13: all-reduces were a third of a decode step).
7. Summary
- The memory wall: from V100 to B200, FLOPs grew 18× and bandwidth 8.9×; a decode-like kernel uses under 1% of the compute.
- The bandwidth exists inside the memory: row buffers deliver ~11× the pin bandwidth of our HBM2-like stack, and HBM-PIM’s units consume 4×. Moving a byte to the host costs ~31 pJ, to a bank-level unit ~7 pJ (assumed split).
- Memory-centric computing places compute at several distances from the data: in every cell (Kautz, 1969), using the array (Ambit, SIMDRAM), next to banks (HBM-PIM, UPMEM, AiM), under the stack (3D logic), or analog crossbars (Lecture 15).
- Processing using memory:
- Triple-row activation computes MAJ, and with NOT, any logic. Our in-DRAM AND, XOR and bit-serial additions are bit-exact.
- Bulk AND/OR beats the host (3.0×, 2.4× less energy). Bit-serial arithmetic does not under DRAM’s power window (0.70×) unless many subarrays work at once.
- Wide DDR rows and narrow interfaces favour it (2.0× for a bitmap query); HBM does not (0.86×).
- Processing near memory:
- GEMVs gain up to the bandwidth ratio (3.7×, 3.2× less energy).
- The gain ends at the break-even intensity I* = P_pim / B_ext (4 FLOP/byte here); provisioning moves it.
- Data placement can erase the gain (2.15× → 1.08×).
- LLM decoding:
- FC layers belong on PIM only at tiny batches.
- Attention belongs on PIM when its intensity is low: multi-head attention (2.0×).
- Under GQA the PIM needs ~G FLOPs per byte (2.5× with 4).
- Energy improves more reliably than time.
- Research directions: capacity (high-bandwidth flash) reduces packages but not bytes per token; bandwidth (3D stacking, PNM) raises speed; interconnect latency remains.
8. Common pitfalls
- “PIM is faster.” Only below the break-even intensity; at batch 64 the GPU is 14× faster on a GEMV (§4.2).
- “Attention is always the PIM kernel.” Under GQA it is compute-bound on a thin PIM (§5.1–5.2).
- “In-DRAM arithmetic is free parallelism.” The power window and 17 AAPs per bit make it slower than a host on HBM (§3.3).
- “Any layout works.” Interleaved layouts split rows across units and need host-side combining (§4.3).
- “More capacity means faster decoding.” Capacity reduces packages; per-token speed is bandwidth (§6).
- “Energy and time move together.” PIM can save energy where it saves no time (§5.3).
- “Published speedups transfer.” Ambit’s DDR results do not carry over to HBM’s narrow rows (§3.3).
9. Exercises
Exercise 1 (the wall). What fraction of peak can a kernel at 2 FLOP/byte use on an H100 and a B200 (16-bit)? What intensity would it need to reach peak on each?
Answer
H100: 2 × 3.35 TB/s / 989 TFLOPS = 0.68%. B200: 2 × 8 / 2,250 = 0.71%.
Reaching peak needs the ridge: 295 FLOP/byte (H100) and 281 (B200).
Exercise 2 (row-buffer bandwidth). A stack has 16 channels × 32 banks, 1 KB rows and tRC = 45 ns, and its pins deliver 670 GB/s. What is the ratio of row-buffer bandwidth to pin bandwidth?
Answer
512 banks × 1,024 B / 45 ns = 11.6 TB/s, so 11.6 / 0.67 ≈ 17×.
Real PIM designs use a fraction of it (HBM-PIM ~4×), because a unit per bank costs area and power and only some banks can be activated at once (tFAW).
Exercise 3 (majority logic). Show with a truth table that MAJ(a, b, 0) = AND and MAJ(a, b, 1) = OR. Verify the full-adder sum formula for (a, b, c) = (1, 0, 1).
Answer
MAJ outputs 1 when at least two inputs are 1. With c = 0 that requires a = b = 1 (AND); with c = 1 it requires a or b (OR).
For (1, 0, 1):
- c_out = MAJ(1, 0, 1) = 1;
- MAJ(a, b, ¬c) = MAJ(1, 0, 0) = 0;
- s = MAJ(¬1, 0, 1) = MAJ(0, 0, 1) = 0.
Correct: 1 + 0 + 1 = 10₂.
Exercise 4 (bulk AND). AND two 64 MiB bitmaps on the HBM2-like stack. How many row operations, how long with the tFAW limit, and how long on the host?
Answer
64 MiB × 8 / 8,192 bits = 65,536 rows, 4 AAPs each. At 2,048 Gbit/s of results (tFAW-limited) this takes 2³¹ bits / 2.048 × 10¹² = 262 µs.
The host reads 128 MiB and writes 64 MiB at 256 GB/s: 786 µs, so in-DRAM is 3.0× faster.
Exercise 5 (bit-serial arithmetic). How many AAPs does an n-bit addition take in our sequence? How many row operations must run concurrently in each of the 8 channels for 8-bit additions to match the host’s 85 G elements/s?
Answer
1 + 17n AAPs: 137 for n = 8.
Needed concurrency = 85 × 10⁹ × 137 × 47 ns / 8,192 elements ≈ 67 row operations at once, or ~8.4 per channel. tFAW allows ~5.9 per channel, so the stack cannot match the host without relaxing the power window or adding parallelism (subarrays).
Exercise 6 (energy split). With co-packaged memory, the I/O part of a host access might fall from 1.3 to 0.4 pJ/bit. What happens to the host-vs-PIM energy ratio per byte?
Answer
- Host: (0.6 + 2.0 + 0.4) × 8 = 24 pJ/B.
- PIM: (0.6 + 0.3) × 8 = 7.2 pJ/B.
The ratio falls from 4.3× to 3.3×. Most of the gap is on-die movement, not the I/O: putting logic near the banks pays even when the package is perfect.
Exercise 7 (break-even with published numbers). Using Samsung’s published HBM-PIM rates (1.23 TFLOPS of PIM compute, 307 GB/s at the pins), what is I*? What does that mean for a GEMV at batch 4?
Answer
I* = 1.23 × 10¹² / 307 × 10⁹ ≈ 4 FLOP/byte, the same ratio as our model, which was built to follow it. A bf16 GEMV at batch 4 has ~4 FLOP per weight byte: a tie. Larger batches belong to the host.
Exercise 8 (FC placement). Why does “FC on PIM” lose at batch 16 for Llama 3 8B (732 vs 2,174 tokens/s) even though the PIM has 4× the bandwidth?
Answer
At batch 16 the FC layers do ~16 FLOPs per weight byte, four times the break-even. On PIM they are compute-bound: 16 × 16 GB × 1 FLOP/byte / 13.4 TFLOPS ≈ 19 ms per step. The GPU reads the 16 GB once in 4.8 ms and computes 16 tokens’ worth at 989 TFLOPS in a fraction of that.
Batching turned a memory problem into a compute problem, which the GPU solves better.
Exercise 9 (GQA and PIM compute). Llama 3 70B has 64 query heads and 8 KV heads. What FLOPs per byte must a PIM provide for attention to run at internal bandwidth? What about an MQA model with 1 KV head?
Answer
G = 64/8 = 8 FLOP per KV byte, twice Llama 3 8B’s. MQA with 64 query heads: G = 64, where attention is effectively a small GEMM.
PIM compute that cheap DRAM logic can afford (~1 FLOP/byte) suits only low-G attention. For high-G models, bandwidth-rich designs with more compute (3D logic dies) fit better.
Exercise 10 (placement). For the 4096 × 4096 GEMV, when does gathering fp32 partial sums from s units per row take as long as the PIM GEMV itself (~2.5 µs of streaming at 13.4 TB/s)?
Answer
Gather time = 4,096 × s × 4 B / 3.35 TB/s = 4.9 ns × s. This equals ~2.5 µs at s ≈ 510.
Before that, the GPU’s extra combining kernel (a 4 µs launch) already dominates: Part 5 shows 2.15× falling to 1.33× as soon as s > 1. With placement done right (s = 1), the units return finished outputs and need no extra kernel.
Exercise 11 (flash for weights). Llama 3.1 405B’s bf16 weights are 812 GB. With high-bandwidth-flash packages of 800 GB at 3.35 TB/s, what is the batch-1 tokens/s per user with the minimum number of packages, against 11 HBM3 packages holding weights only?
Answer
- Flash: 2 packages (812 GB > 800 GB), 6.7 TB/s, so 812 GB / 6.7 TB/s = 121 ms, ~8 tokens/s.
- HBM3: 11 packages × 80 GB = 880 GB ≥ 812, at 36.9 TB/s: 22 ms, ~45 tokens/s.
Capacity saves 9 packages but costs 5.5× in latency. The Part 5 table, which also holds 64 sequences of KV, shows 2 vs 16 packages and 8 vs 66 tokens/s.
Exercise 12 (programming: a cheaper XOR). Our XOR takes 16 AAPs. Build XOR from OR, AND and NOT as (a OR b) AND NOT (a AND b) with pim.Subarray, check it, and count AAPs. How could an optimized sequence go lower?
Answer
In the author’s run: OR (4) + AND (4) + NOT (2) + AND (4) = 14 AAPs, bit-exact.
Lower counts come from reusing results: a TRA leaves its result in all three temporary rows, so a following operation can use one of them without a copy. Constant rows can also be prepared once. SIMDRAM synthesizes such MAJ/NOT sequences automatically.
Even at ~10 AAPs, XOR would beat the host only modestly (683 G/s host vs ~800 G/s tFAW-limited). Bitwise AND/OR remain the best fit.
10. Further reading
- W. Kautz, “Cellular logic-in-memory arrays”, IEEE Transactions on Computers C-18(8), 1969.
- O. Mutlu et al., “Memory-centric computing: solving computing’s memory problem”, 2025; O. Mutlu et al., “A modern primer on processing in memory”, 2020 (arXiv:2012.03112).
- X. Ma, D. Patterson, “Challenges and research directions for large language model inference hardware”, 2026 (arXiv:2601.05047).
- V. Seshadri et al., “Ambit: in-memory accelerator for bulk bitwise operations using commodity DRAM technology”, MICRO 2017; “RowClone”, MICRO 2013.
- N. Hajinazar et al., “SIMDRAM: a framework for bit-serial SIMD processing using DRAM”, ASPLOS 2021.
- Y.-C. Kwon et al., “A 20nm 6GB function-in-memory DRAM, based on HBM2 with a 1.2TFLOPS programmable computing unit using bank-level parallelism, for machine learning applications”, ISSCC 2021; S. Lee et al., “Hardware architecture and software stack for PIM based on commercial DRAM technology”, ISCA 2021.
- J. Gómez-Luna et al., “Benchmarking a new paradigm: experimental analysis and characterization of a real processing-in-memory system”, IEEE Access 2022 (UPMEM, PrIM benchmarks).
- J. Park et al., “AttAcc! Unleashing the power of PIM for batched transformer-based generative model inference”, ASPLOS 2024; G. Heo et al., “NeuPIMs: NPU-PIM heterogeneous acceleration for batched LLM inferencing”, ASPLOS 2024.
- M. He et al., “Newton: a DRAM-maker’s accelerator-in-memory (AiM) architecture for machine learning”, MICRO 2020.
11. Next lecture
Lecture 15, Memory-centric computing (Part 2), goes all the way into the array: analog computing in memory. Instead of moving bits to adders, a crossbar of memory cells stores a weight matrix as conductances. Applying the input as voltages produces the matrix-vector product as currents, by Ohm’s and Kirchhoff’s laws, in one step. We will model SRAM and resistive crossbars:
- the energy and density promise;
- the costs that decide everything: DACs and ADCs, noise and limited precision, and the weights that must stay put.