Maps to: Stanford CS149 Fall 2025, Lecture 1 (Sep 23), slide deck
01_efficiency(86 slides). Assignment: Programming Assignment 1 (performance analysis on a quad-core CPU) is introduced. Sources: the public Fall 2025 slides; the 2023 lecture video of the same title. The nine experiments and every number in this lecture were written for these notes and run on the author’s machine (Apple M4 Pro: 8 performance + 4 efficiency cores, clang 21, macOS 27). They re-enact the ideas of the in-class demos with threads; they do not reproduce what was shown in class. Code:code/lecture01/. Reading time: ~80 minutes for the prose; ~30 more if you run and read every demo.
0. How to read this lecture
0.1 Learning goals
After this lecture you should be able to:
- Define speedup (加速比) and efficiency (效率), compute them from measured times, and explain why “fast” and “efficient” are different questions.
- Name the three things that the in-class demos showed can limit speedup — communication (通信), load imbalance (负载不均衡), and a poor computation-to-communication ratio (计算/通信比) — and recognize each in a measured table.
- Explain what instruction-level parallelism (ILP, 指令级并行) is, how a superscalar (超标量) processor exploits it, and why its benefit flattens beyond about four instructions per clock.
- Explain the power wall (功耗墙): why dynamic power grows much faster than clock frequency, and why that pushed the industry to multi-core (多核) and specialized (专用) hardware around 2005.
- Explain why modern systems must be efficient, not just parallel — power, heat and battery — and what specialized processors buy.
- Explain memory latency (延迟), stalls (停顿), caches (缓存), cache lines, cold and capacity misses, and spatial / temporal locality (空间 / 时间局部性), and predict hits and misses for a short address trace.
- Explain why data movement (数据搬运) dominates both the time and the energy of modern computation.
0.2 Prerequisites and scope
- Prerequisites (from the course page): you can read and write C/C++, and you know that a compiled program is a sequence of machine instructions that update registers and memory. Some experience creating a thread (
std::threador pthreads) helps for the demos; every C++ idiom used is explained in the code comments. - Scope of this lecture: it is the map of the course. It motivates why parallel programming became unavoidable and why efficiency matters, and it introduces just enough processor and memory vocabulary to start. Multi-core, SIMD and multi-threading are Lecture 2; how to design a parallel program is Lectures 4–6; caches shared by several cores are Lecture 14.
- Not in scope today: how to write a good parallel program. The demos show what goes wrong; the cures are the rest of the course.
0.3 Section → code map
| Section | Idea | Demo in code/lecture01/ |
|---|---|---|
| §1.4 | many processing elements, measured | 00_know_your_machine |
| §2.1 | communication limits speedup | 01_demo1_communication |
| §2.2 | load imbalance limits speedup | 02_demo2_load_imbalance |
| §2.3 | communication can dominate computation | 03_demo3_communication_dominated |
| §3.3–3.4 | ILP, superscalar scheduling, diminishing returns | 04_ilp_scheduling.py (+ ilp_sched.py) |
| §3.5 | ILP measured inside one real core | 05_ilp_on_real_cpu |
| §3.6–3.7, §5.6 | the power wall; the energy of data movement | 06_power_wall.py |
| §5.3–5.5 | caches, misses, locality | 07_caches_and_locality.py (+ cachesim.py) |
| §5.4 | the real memory hierarchy’s latencies | 08_memory_latency |
Run them all with cd code/lecture01 && make run (~30 seconds).
0.4 Notation and the machine
- P is the number of processors (or threads); T(P) is the time with P of them; T(1) is the time of the serial (串行) program.
- “ns” = nanosecond = 10⁻⁹ s. At 4 GHz one clock is 0.25 ns. “pJ” = picojoule = 10⁻¹² J. 1 W = 1 J/s.
- The author’s machine: Apple M4 Pro — 12 cores in total: 8 performance cores (性能核) and 4 efficiency cores (能效核), i.e. a heterogeneous (异构) multi-core; 128 KiB L1 data cache per performance core; 16 MiB L2 shared by each group of 4 performance cores; 128-byte cache lines; 128-bit NEON SIMD; no hyper-threading. The CS149 class machines are 4-core Intel CPUs with 2-way hyper-threading and 8-wide AVX2 SIMD; Lecture 2 explains those terms.
- Honest measurement note. While these experiments ran, another long-running program used one core of the author’s machine continuously. Most results do not care; a few P = 8 results do, and §2.3 turns that into a lesson rather than hiding it.
1. What is a parallel computer, and what do we want from it?
1.1 The definition
A classic definition, used on the course’s third slide, says a parallel computer is “a collection of processing elements that cooperate to solve problems quickly” (Almasi and Gottlieb, 1989). Every phrase matters:
- a collection of processing elements (处理单元) — more than one thing that can execute instructions: cores, SIMD lanes, GPU threads, whole machines in a datacenter.
- cooperate — they work on one problem together, so they must divide the work and exchange results. Cooperation is where all the difficulty comes from: dividing well, exchanging little, and not waiting on each other.
- to solve problems quickly — the reason to have many processing elements is performance. Nobody builds a parallel computer for fun; if a single processor were fast enough, we would use it.
The slide adds a second goal right away: we care about performance, and we care about efficiency. Hold on to that; §1.3 and §4 explain why it is not the same thing.
1.2 Speedup
The basic measure of “quickly” is speedup (加速比):
execution time using 1 processor
speedup(P processors) = ----------------------------------
execution time using P processors
If 1 processor takes 100 s and 4 take 30 s, the speedup is 100/30 = 3.3×. The ideal is P: P processors, P times faster (“linear speedup”, 线性加速).
Two details that the formula hides, and that matter in every measurement of this course:
- What is “1 processor”? The honest baseline is the best serial program, not the parallel program run with one thread. A parallel program usually does extra bookkeeping (splitting work, locks, atomics); running it with P = 1 is typically a bit slower than the plain serial loop. In demo 01, the parallel code with one thread runs at 0.95× of the serial loop just because of a per-item counter it maintains. Measuring speedup against that slower version would flatter the parallel program.
- Same problem. Speedup compares two runs of the same problem. (Lecture 6 discusses “weak scaling”, where the problem grows with P; that is a different, also legitimate, question.)
1.3 Efficiency: fast is not the same as efficient
Efficiency (效率) asks how well the processors were used:
efficiency = speedup / P
A 2× speedup on 2 processors is 100% efficient. The slides ask: is a 2× speedup on a computer with 10 processors a good result? Efficiency says 20%: eight processors’ worth of hardware sat idle on average. Whether that is “good” depends on what the processors cost — in money, chip area, or power — compared with the time saved. Two perspectives appear throughout the course:
- The programmer’s perspective: make good use of the capabilities the machine provides. If you paid for 10 cores, a program that keeps 2 of them busy wastes the rest.
- The hardware designer’s perspective: choose which capabilities to put in the machine at all — performance per dollar, per square millimetre of silicon, per watt.
Course theme 3 is exactly this: FAST ≠ EFFICIENT. A program can run faster on a parallel computer and still be using the hardware badly.
1.4 A first measurement: processing elements working at the same time
Before any cooperation, let’s check that the machine really has many processing elements. 00_know_your_machine starts P threads, each running the same fixed, purely computational job (~0.14 s on one core) that needs no data from anyone:
threads P | wall time | throughput vs P=1 | fastest job | slowest job
1 | 0.135 s | 1.00x | 0.135 s | 0.135 s
2 | 0.137 s | 1.98x | 0.137 s | 0.137 s
4 | 0.138 s | 3.94x | 0.137 s | 0.138 s
8 | 0.146 s | 7.43x | 0.140 s | 0.146 s
12 | 0.186 s | 8.72x | 0.156 s | 0.186 s
24 | 0.365 s | 8.91x | 0.282 s | 0.365 s
Three things to notice:
- Up to 8 threads, the wall time barely changes: eight jobs take about as long as one. That is the definition of parallel execution — the jobs truly run at the same time on different cores — and throughput grows almost 8-fold.
- At 12 threads the four efficiency cores join in, and throughput rises to only 8.7×, not 12×: those cores are slower. Identical jobs now finish at different times (slowest/fastest = 1.20). A machine whose processing elements are not identical creates load imbalance even for perfectly balanced work — a preview of §2.2.
- Beyond 12 threads, nothing improves: 24 threads must share 12 cores, so the batch takes twice as long. More threads than processing elements is not more parallelism.
This was the easy case, an embarrassingly parallel (易并行) workload with zero cooperation. Real problems need the threads to cooperate. That is where the three classroom demos come in.
2. Three classroom demos, re-enacted with threads
The first lecture of CS149 opens with three live demos in which students play processors. The point is not the arithmetic; it is to feel what limits speedup. These notes cannot put you in a lecture hall, so each demo is re-enacted below with real threads on a real machine, where the same effects show up as numbers.
2.1 Demo 1 — communication limits speedup
In class. Students add up numbers written on cards. With two students, each adds half — but at the end they must tell each other their partial sums (部分和) to produce the total. The talking took time, so the speedup over one student was less than 2. Moving the students closer together (cheaper communication) improved it.
Our re-enactment (01_demo1_communication). 16.8 million “cards” are split into P equal blocks, one per thread. Each card’s value takes a little computation to “read” (a few rounds of a hash function). Each thread keeps a private running sum in a register — free — and every K cards it “shouts”: it adds its running sum into one shared total with an atomic add (原子加), and resets. K = 1 means shouting after every card; “once” means shouting only at the end. Every configuration does exactly the same additions and is checked to produce exactly the same total; only the amount of communication changes.
Speedup over the serial loop (31.1 ms):
shout every K cards | P=1 P=2 P=4 P=8 | efficiency at P=8 | shouts at P=8
1 | 0.89x 0.13x 0.11x 0.06x | 1% | 16777216
4 | 0.94x 0.38x 0.35x 0.14x | 2% | 4194304
16 | 0.96x 1.14x 0.75x 0.60x | 8% | 1048576
64 | 0.96x 1.55x 1.76x 1.81x | 23% | 262144
256 | 0.96x 1.77x 3.47x 4.46x | 56% | 65536
4096 | 0.96x 1.91x 3.75x 4.63x | 58% | 4096
once (at the end) | 0.95x 1.88x 3.72x 6.16x | 77% | 8
Reading the table.
- Shouting after every card, 8 threads are 16× slower than one thread (0.06×). Adding processors made the program worse. This is the most important surprise of the first lecture: parallelism is not automatically speedup.
- Even with one thread, an atomic add per card costs ~11% (0.89× in the first row). An atomic operation is far more expensive than adding two registers.
- With several threads it gets much worse, because all threads shout into the same memory location. A core can only update a memory location after it has obtained an exclusive copy of the cache line holding it; with eight cores taking turns, that line travels from core to core for every single shout. Lecture 14 (cache coherence) shows the protocol behind this; for now, think of eight students who must each walk to the same notebook to write down every number.
- Communicating less often recovers the speedup. At K = 256 the threads already do 256 cards of private work per shout, and P = 4 reaches 3.5×. Shouting once gives 3.7× at P = 4 and 6.2× at P = 8.
- Even “once” is not perfect (77% efficient at P = 8; 4.6× in another run). The P = 1 column shows ~5% bookkeeping overhead; thread start-up, the slower efficiency cores and other programs on the machine account for the rest (§1.4, §2.3).
The two cures from the classroom. Moving students closer made each communication cheaper; our K knob makes communication rarer. Both raise the ratio of computation to communication. In real programs you will do both: keep data local so communication is cheap (Lectures 6, 14), and structure the algorithm so communication is rare (Lectures 4–6, 8).
Why an atomic add and not just
total += local? If two threads executetotal += localat the same time, each reads the old total, adds its own value, and writes back — and one of the two updates is lost. That is a data race (数据竞争), and in C++ it is undefined behavior.std::atomic<uint64_t>::fetch_addperforms the read-add-write as one indivisible step. Lecture 15 explains what the hardware does to make this possible.
2.2 Demo 2 — load imbalance limits speedup
In class. Four students split a pile of work. Some finished early and sat idle while others were still working, so the group finished only when the slowest student did. Redistributing the work improved the speedup.
Our re-enactment (02_demo2_load_imbalance). 2,048 tasks of unequal cost, two workloads, three ways to assign (分配) tasks to threads:
- Blocked (分块): thread t gets the t-th contiguous quarter of the task list.
- Interleaved (交错 / 轮转): task i goes to thread i mod P, like dealing cards.
- Dynamic (动态): threads share a counter; whenever a thread is free it atomically takes the next unclaimed task.
Workload A: task i costs proportional to i + 1 (“the pile gets harder”). With P = 4, each bar shows one thread’s activity over the whole run (# busy, . idle):
P=4 blocked speedup 2.26x (efficiency 56%; counting work predicts 2.29x)
thread 0 |######..................................|
thread 1 |##################......................|
thread 2 |############################............|
thread 3 |########################################|
P=4 interleaved speedup 3.81x (efficiency 95%; counting work predicts 3.99x)
P=4 dynamic speedup 3.84x (efficiency 96%; counting work predicts 4.00x)
The program ends when its last thread ends. With blocked assignment, thread 3 holds the hardest quarter — 7/16 of all the work — so the best possible speedup is (total work)/(largest share) = 16/7 = 2.29×, and the measurement (2.26×) agrees. You can predict load imbalance just by adding up who got what. Threads 0–2 spend most of the run idle: hardware we paid for, unused.
Interleaving fixes this workload: each thread gets a mix of easy and hard tasks. But interleaving is still a static (静态) decision, made before anyone knows the costs. Workload B makes every 4th task 16× harder than the others:
P=4 interleaved speedup 1.20x (efficiency 30%; counting work predicts 1.19x)
thread 0 |########################################|
thread 1 |###.....................................|
thread 2 |###.....................................|
thread 3 |###.....................................|
P=4 dynamic speedup 3.87x (efficiency 97%)
All hard tasks have i mod 4 = 0, so dealing round-robin to 4 threads hands every hard task to thread 0. Same tasks, same threads, and the “clever” scheme is the worst one. Dynamic assignment adapts to whatever the costs turn out to be (3.87×) — at the price of one shared counter update per task, which is communication again (demo 1!). Choosing between static and dynamic assignment, and choosing the task size, is the subject of Lecture 5.
With 8 threads the same patterns hold (blocked 4.06× vs. predicted 4.27× on workload A; interleaved 2.31× vs. predicted 2.37× on workload B; dynamic 7.15× and 6.65×).
2.3 Demo 3 — when communication dominates
In class. The whole class worked on one problem at once (“massively parallel”), but the problem needed a lot of communication compared to computation, and the speedup was poor: communication costs can dominate a parallel computation.
Our re-enactment (03_demo3_communication_dominated). Many scientific computations proceed in steps: every cell of an array is updated from its neighbours, then the whole array is updated again, and so on. Thread t owns a contiguous block of cells, but to update the two cells at the edges of its block it needs one value from each neighbouring thread’s block from the previous step. So no thread may start step s + 1 until every thread has finished step s. The tool for “wait until everyone has arrived” is a barrier (屏障): each thread announces it is done (communication through a shared counter) and sleeps or spins until the last one arrives.
Every row below performs the same 67 million cell updates in total (array size M × number of steps is constant), so the serial time is the same in every row. What changes is how much each thread computes between two barriers.
cells M | steps | serial ms | P=1 P=2 P=4 P=6 P=8 | cells per thread per barrier (P=8)
64 | 1048576 | 142.6 | 1.00x 0.61x 0.27x 0.16x 0.10x | 7
512 | 131072 | 147.3 | 1.07x 1.52x 1.70x 1.38x 0.86x | 63
4096 | 16384 | 147.4 | 1.07x 2.00x 3.41x 4.07x 1.64x | 511
32768 | 2048 | 147.9 | 1.08x 2.07x 4.01x 5.71x 1.95x | 4095
262144 | 256 | 147.7 | 1.06x 1.99x 4.02x 5.70x 3.18x | 32767
Reading the table.
- Tiny arrays: more threads, slower program. With 64 cells, each of 8 threads updates 7 cells (~15 ns of work) and then waits at a barrier that costs about 1.3 µs. One barrier is worth ~590 serial cell updates. The program spends almost all its time synchronizing: 0.10×.
- Big arrays: real speedup. With 262,144 cells, each thread updates tens of thousands of cells per barrier, the barrier is a small tax, and the speedup grows with P (4.0× at P = 4, 5.7× at P = 6).
- Rule of thumb: each thread needs much more computation per synchronization than the synchronization costs. This ratio — computation per unit of communication — is what Lectures 4–6 teach you to raise.
The P = 8 column, and an unplanned lesson. In the big-array rows, 8 threads were slower than 6. A separate check on this machine gave 6.3–7.1× with 7 threads and 1.8–3.0× with 8. The reason was outside the program: another long-running program was using one of the 8 performance cores, so with 8 threads one of ours had to share a core (or move to a slow efficiency core). Independent jobs barely notice that (§1.4). A barrier-synchronized program notices it at every step: whenever the unlucky thread is paused, the other seven wait at the barrier. Synchronization turns one slow participant into a slow team. This is load imbalance (demo 2) and communication (demo 3) multiplying each other, and it is why parallel programs are sensitive to anything that perturbs a single thread. On an idle machine the P = 8 column should continue the trend instead; the demo detects the drop and prints this explanation when it happens.
2.4 What the demos teach: the three themes of CS149
The three demos are not tricks; they are the three recurring problems of parallel programming, and the course is organized around answering them.
| Theme | The question | What the demos showed | Where it is developed |
|---|---|---|---|
| 1. Designing and writing parallel programs that scale | How do I (a) decompose (分解) work into pieces that can safely run in parallel, (b) assign pieces to processors, and (c) manage communication and synchronization (同步) so they do not limit speedup? | demo 1: communication; demo 2: assignment; demo 3: synchronization frequency | Lectures 2–8 (threads, ISPC, CUDA, data-parallel thinking, work distribution, locality) |
| 2. How parallel hardware works | What mechanisms implement the abstractions, what do they cost, and what trade-offs (performance vs. convenience vs. cost) did the designers make? | the atomic’s cost comes from moving a cache line between cores; the P = 8 cliff comes from cores being a shared resource | Lectures 2–3, 7, 10–12, 14–18 |
| 3. Thinking about efficiency | Is my speedup a good use of the hardware? Fast ≠ efficient. | 8 threads at 1% efficiency (demo 1); idle threads (demo 2) | every lecture, especially 6, 9–13 |
Why must a programmer know about hardware (theme 2)? Because, as the demos just showed, the characteristics of the machine decide the speedup: the cost of communication (how far the “students” sit apart), how many identical processing elements there really are, and, as §5 will show, how fast data arrives.
3. Why parallelism? How single programs used to get faster for free
The demos showed that parallel programming is hard. So why does everybody have to do it now? For about thirty years they did not. This section explains what changed.
3.1 What is a program, from the processor’s point of view?
Here is a tiny C program that doubles x ten times:
int main(void) {
int x = 1;
for (int i = 0; i < 10; i++)
x = x + x;
printf("%d\n", x);
return 0;
}
A compiler (编译器) translates it into a list of machine instructions (机器指令). Compiled without optimization for the author’s arm64 machine (clang -O0 -S), the loop body is:
LBB0_2: ; the loop body
ldur w8, [x29, #-8] ; load x from memory into register w8
ldur w9, [x29, #-8] ; load x again into w9
add w8, w8, w9 ; w8 = x + x
stur w8, [x29, #-8] ; store the result back to x's memory slot
... ; then i = i + 1, compare with 10, branch back
From the processor’s point of view, a program is just a list of instructions, like the steps of a recipe. Each instruction describes one simple operation, and executing it changes the computer’s state (状态): the values stored in the processor’s registers (寄存器) and in memory (内存). (With -O2, by the way, the compiler computes the whole loop itself and the program just prints the constant 1024: mov w8, #1024. Compilers are very good at removing work whose result they can predict — a fact that bit the first version of demo 01; see the code README.)
3.2 A very simple processor
The slides introduce “Kayvon’s very simple processor”, a model with three parts:
- Fetch/decode (取指 / 译码): determines which instruction to run next and what it means.
- ALU / execution unit (算术逻辑单元 / 执行单元): performs the operation (add, multiply, compare…).
- Execution context (执行上下文): the registers R0, R1, R2, … that hold the program’s working values.
Executing add R0 ← R0, R1 takes four logical steps: fetch the instruction; read R0 and R1 (say 32 and 64) and feed them to the ALU; the ALU computes 96; write 96 back into R0. This simple processor executes one instruction per clock. A five-instruction program takes five clocks.
3.3 Instruction-level parallelism and superscalar execution
Consider a = x*x + y*y + z*z, with x, y, z already in registers R0, R1, R2:
1: mul R0, R0, R0 ; x*x
2: mul R1, R1, R1 ; y*y
3: mul R2, R2, R2 ; z*z
4: add R0, R0, R1 ; x*x + y*y
5: add R3, R0, R2 ; ... + z*z -> a
Five instructions, five clocks on the simple processor. Can we do better? Look at what depends on what. Instruction 4 needs the results of 1 and 2; instruction 5 needs 3 and 4. But 1, 2 and 3 need nothing from each other. They could run at the same time if the processor had more than one execution unit. This independence inside a single instruction stream is instruction-level parallelism (ILP).
04_ilp_scheduling.py builds the dependency graph (依赖图) and schedules the program greedily (each clock, start the oldest instructions whose inputs are ready):
1 execution unit(s): 5 clocks
2 execution unit(s): 3 clocks
clock | unit 1 | unit 2
1 | 1: mul R0, R0, R0 | 2: mul R1, R1, R1
2 | 3: mul R2, R2, R2 | 4: add R0, R0, R1
3 | 5: add R3, R0, R2 |
3 execution unit(s): 3 clocks
1 | 1: mul R0, R0, R0 | 2: mul R1, R1, R1 | 3: mul R2, R2, R2
2 | 4: add R0, R0, R1 | |
3 | 5: add R3, R0, R2 | |
Two units cut 5 clocks to 3. A third unit does not help at all: the chain 1 → 4 → 5 is three instructions long, and no amount of hardware can run an instruction before its inputs exist. The longest such chain is the critical path (关键路径); it bounds the running time on any machine.
What does it mean for a parallel schedule to “respect program order”? (A question from the slides.) It does not mean instructions must start in the order written. It means the result must be identical to running the instructions one at a time in program order: every instruction must see exactly the input values it would have seen in the sequential execution. Any schedule that respects the dependencies achieves that. This idea — parallel execution allowed only if the output is unchanged — returns in every lecture, up to memory consistency (Lecture 15) and transactions (Lectures 17–18).
A superscalar processor (超标量处理器) does this automatically, in hardware: it fetches and decodes several instructions per clock, finds the independent ones, and sends them to several execution units, often out of order (乱序) relative to the program text. The programmer writes ordinary sequential code and gets a speedup for free. (Alternatively, a compiler can find the independent instructions in advance and mark them in the binary; that is the “VLIW” approach.)
The slides’ “more complex example” has 11 instructions (tmp2 = a + b, tmp3 = tmp2 + a, …, if (tmp3 > 7) print tmp3 else print tmp7). Its dependency graph, as computed by the demo:
00 a = 2 waits for - earliest clock 1
01 b = 4 waits for - earliest clock 1
02 tmp2 = a + b waits for 00, 01 earliest clock 2
03 tmp3 = tmp2 + a waits for 00, 02 earliest clock 3
04 tmp4 = b + b waits for 01 earliest clock 2
05 tmp5 = b * b waits for 01 earliest clock 2
06 tmp6 = tmp2 + tmp4 waits for 02, 04 earliest clock 3
07 tmp7 = tmp5 + tmp6 waits for 05, 06 earliest clock 4
08 if (tmp3 > 7) waits for 03 earliest clock 4
09 print tmp3 waits for 03, 08 earliest clock 5
10 print tmp7 waits for 07, 08 earliest clock 5
critical path = 5 clocks, 11 instructions -> at most 2.2 instructions per clock
Even with infinitely many execution units, this program cannot average more than 2.2 instructions per clock; 3 units already reach the 5-clock minimum (1 unit: 11 clocks, 2 units: 6). (A real processor would also predict the branch at 08 and start 09 or 10 speculatively; that loosens the control dependency but not the data dependencies.)
3.4 Diminishing returns
How much ILP does real code have? A classic study (Johnson, 1991; the plot on slide 48 is from Culler and Singh’s textbook) simulated processors of increasing issue width on real programs: the speedup climbs steeply up to about four instructions issued per clock and then barely moves, staying well below 3×. Most available ILP is exploited by a processor that can issue about four instructions per clock; building a wider one buys little.
Our model reproduces the shape (not the data) of that curve on synthetic instruction streams in which each operand comes from an instruction a short, random distance back (as in real code, values are usually used soon after they are produced):
issue width W | speedup over W=1 (mean of 20)
1 | 1.00x ##########
2 | 1.73x #################
3 | 1.99x ####################
4 | 2.06x #####################
8 | 2.07x #####################
16 | 2.07x #####################
unlimited W, unlimited window: 2.07x (= instructions / critical path)
The curve flattens because it hits the ceiling the dependencies set (instructions ÷ critical path). Real processors face further limits that the model ignores — branches, cache misses, and how far ahead the hardware can look — so the real curve is lower still.
An aside: false dependencies and register renaming (寄存器重命名). Programs reuse register names. If the same temporary register R0 is used for a*a, then b*b, then c*c, three independent products look dependent: the second multiply must not overwrite R0 before the first result has been read (write-after-read), and must write after the first (write-after-write). These false dependencies (伪依赖) come from the names, not from the computation. The demo shows them costing 4 clocks instead of 2 on a 4-wide machine; real cores remove them by giving every write a fresh hidden physical register — register renaming — which is part of how “the processor automatically finds independent instructions”.
3.5 ILP inside a real core, measured
Is all this real? 05_ilp_on_real_cpu runs K independent chains of floating-point fused multiply-adds (FMA, 融合乘加: x = x·a + b in one instruction) on one thread. Inside a chain, every FMA needs the previous result; different chains are independent. The total number of FMAs is the same in every row.
independent chains K | FMAs per ns | speedup over K=1
1 | 1.15 | 1.00x
2 | 2.31 | 2.00x
4 | 4.93 | 4.28x
8 | 8.08 | 7.01x
16 | 15.83 | 13.73x
20 | 16.01 | 13.89x
24 | 14.14 | 12.27x
- One chain: 0.87 ns per FMA. Each FMA waits for the previous one; this is the instruction’s latency (about 3.5–4 clocks at this core’s ~4 GHz; macOS gives no cycle counter, so clock counts here are estimates).
- Independent chains overlap: almost 14× more FMAs per second, from one thread, with no parallel code. The core has several FMA units, each pipelined (流水线化) so it can start a new FMA every clock while earlier ones are still in flight. To keep them all busy you need about (latency × number of units) independent chains — here around 16.
- Beyond that, more chains do not help (and 24 is slightly worse): all units are busy. This is the hardware version of the diminishing-returns curve.
Two lessons. First, latency (how long one operation takes) and throughput (how many operations complete per unit time) are different numbers, and modern hardware improves throughput much more than latency — a distinction that returns in every lecture. Second, real code rarely contains 16 independent chains by accident; to get them, the programmer or the compiler must expose them (for example, summing with several accumulators — the classic “multiple accumulators” optimization).
3.6 The other engine: clock frequency, and the power wall
Until the mid-2000s, single-threaded performance doubled roughly every 18 months, from two sources: (1) exploiting ILP with ever more sophisticated superscalar cores, and (2) increasing the clock frequency (时钟频率). For a software developer this was paradise: do nothing, and your code runs faster next year. Working hard to parallelize code was often not worth it — just wait.
Around 2005 both engines stalled. ILP had been “tapped out” (§3.4). And the clock stopped rising because of power. The power a chip consumes has two parts:
- Dynamic power (动态功耗), spent every time transistors switch: approximately capacitive load × voltage² × frequency. Each clock, the circuit charges and discharges its capacitance, costing energy proportional to C·V².
- Static power (静态功耗): transistors leak current even when they are not switching.
The killer is that voltage is not independent of frequency. To switch faster, transistors need a higher supply voltage, and power grows with the square of the voltage, on top of the linear growth with frequency. Together, power grows much faster than frequency. 06_power_wall.py illustrates this with a simple, made-up-but-plausible voltage–frequency model:
f (GHz) | volts | dynamic W | static W | total W | perf (~f) | perf per watt
1.0 | 0.65 | 0.53 | 0.39 | 0.92 | 1.0 | 1.089
2.0 | 0.80 | 1.60 | 0.48 | 2.08 | 2.0 | 0.962
4.0 | 1.10 | 6.05 | 0.66 | 6.71 | 4.0 | 0.596
6.0 | 1.40 | 14.70 | 0.84 | 15.54 | 6.0 | 0.386
Doubling the clock from 2 to 4 GHz doubles performance but costs 3.2× the power. And power is heat. A chip can only get rid of so much heat (its TDP, thermal design power, 热设计功耗): the slides list ~95 W for a desktop Intel Core i9-10900K, 13 W for an Apple M1 laptop chip, 450 W for an NVIDIA RTX 4090 GPU, ½–2 W for a phone processor, and megawatts for the fastest supercomputers. Raising the clock further would have required cooling no product could afford. Herb Sutter summarized the consequence in a famous 2005 article, “The Free Lunch Is Over”: transistor counts kept growing (Moore’s law), but clock speed, ILP and power per chip all flattened.
3.7 The response: more processing elements, and specialized ones
If transistors keep coming but cannot be spent on a faster single core, spend them on more cores. 06_power_wall.py Part B divides one fixed 20 W budget among N identical cores, each running as fast as its share of power allows:
cores N | W per core | GHz per core | total throughput (N x GHz) | single-thread speed
1 | 20.00 | 6.72 | 6.72 | 6.72
2 | 10.00 | 4.88 | 9.76 | 4.88
4 | 5.00 | 3.42 | 13.69 | 3.42
8 | 2.50 | 2.26 | 18.12 | 2.26
16 | 1.25 | 1.35 | 21.54 | 1.35
Because power falls faster than frequency when you slow down, eight slower cores deliver 2.7× the throughput of one fast core in the same power budget. The catch is in the last column: each core is slower. Only software that is written to use all the cores benefits; a single-threaded program actually runs slower on the many-core design. (Past ~16 cores the model’s voltage floor and leakage stop the gains.)
That is the deal the whole industry took around 2005, and it is visible everywhere:
- Multi-core CPUs: a 10-core Intel “Comet Lake” desktop chip (2020); a 64-core AMD Threadripper 3990X built from 8-core “chiplets”; the 12-core M4 Pro these notes ran on.
- GPUs: NVIDIA’s AD102 (GeForce RTX 4090, 2022) has 76 billion transistors and 18,432 FP32 multipliers organized into 144 processing blocks called SMs (Lecture 7).
- Supercomputers: Frontier (Oak Ridge, #1 in 2022) combines 9,472 64-core CPUs (606,208 CPU cores) with 37,888 GPUs, drawing about 21 megawatts.
- Phones and small devices: Apple’s A15 (iPhone 13/14) has 15 billion transistors, 2 “big” + 4 “small” CPU cores, a multi-core GPU and a neural engine; even a Raspberry Pi 3 has a quad-core CPU.
Architects also spend transistors on specialized units (graphics, video encoding, neural networks), which do one job far more efficiently than a general core (§4.2, Lecture 10).
The consequence for programmers: no more free lunch. Software must be written to be parallel to see performance gains. And the gains are large. The slides’ preview of Programming Assignment 1: on a quad-core Intel CPU with SIMD vector instructions and hyper-threading, using all the parallel execution resources makes a program ~32–40× faster than a single-threaded C program compiled with -O3. Lectures 2–3 explain where that factor comes from (4 cores × 8-wide SIMD × a bit from hyper-threading).
4. Why efficiency?
4.1 In modern computing, parallel is not enough — it must be efficient
What is the biggest concern in mobile computing? Power. And the reason generalizes far beyond phones. There are two reasons to save power (slide 64):
- Power = heat. If a chip gets too hot, it must be clocked down to cool off; hotter systems also cost more to cool (think datacenters). So a more efficient design can run at higher performance for a fixed amount of time.
- Power = battery. Long battery life is a key feature of mobile devices. A more efficient design can run at sufficient performance for a longer time. An iPhone 13 battery holds 3,227 mAh ≈ 12.4 watt-hours — that is the entire energy budget for a day of use, shared by the CPU, GPU, display and radios.
Either way, the question is no longer only “how many operations per second” but “how many operations per joule”.
4.2 Specialized hardware for efficiency
The A15 chip in the slides is not just “6 CPU cores + a GPU”: it also contains a neural engine (NPU, 神经网络处理器) for deep-learning inference, an image/video encoding and decoding processor, and a motion (sensor) processor. Specialized processing is everywhere in mobile systems, because a unit built for one job wastes far less energy on overhead (fetching and decoding instructions, moving operands around) than a general-purpose core. The same logic drives datacenters: Google’s TPU (Tensor Processing Unit, 张量处理单元) pods, GPUs with tensor cores, and a zoo of AI accelerators (Huawei’s NPU, Apple’s Neural Engine, Graphcore IPU, Cerebras’s wafer-scale engine, SambaNova, AWS Trainium — the target of Programming Assignment 4). Lectures 9–12 are about using such hardware; Lecture 10 explains why specialization buys 10–100× in efficiency.
4.3 Efficient processing comes down to accessing data efficiently
The slides make one claim in large type, and it is perhaps the single most useful sentence of the course: achieving efficient processing almost always comes down to accessing data efficiently. The rest of this lecture explains what “accessing data” involves, and why it — not arithmetic — usually decides both time and energy.
5. Memory: latency, caches, and the cost of data movement
5.1 The memory abstraction
To a program, memory is a big array of bytes. Each byte has an address (地址), its index in the array: “the byte at address 0x10 holds the value 128”. A processor moves data between memory and registers with two kinds of instructions:
- a load (加载):
ld R0 ← mem[R2]— “read the four bytes starting at the address held in R2, and put that value in R0”; - a store (存储): write a register’s value to memory.
The abstraction is beautifully simple: any address, same behavior. The implementation, as we will see, is anything but.
5.2 Latency and stalls
Memory access latency (访存延迟) is the time between asking the memory system for data and getting it: on the order of 100 clocks, or ~100 ns, for main memory. A processor stalls (停顿) when it cannot run the next instruction because that instruction depends on one that has not finished. Loads are a major source of stalls:
ld r0, mem[r2]
ld r1, mem[r3]
add r0, r0, r1 ; cannot execute until both loads have returned
If each load takes hundreds of clocks, the add — and everything after it that depends on it — waits hundreds of clocks. For comparison, §3.5’s core could have completed ~4 FMAs per clock in that time.
5.3 Caches
A cache (缓存) is on-chip storage that keeps a copy of a subset of memory’s values. If an address is in the cache, the processor can load or store it much faster than if the data lives only in DRAM (the main memory chips). Two properties to keep in mind:
- A cache is a hardware implementation detail: it does not change what a program computes, only how fast. (Lecture 14 shows how hard it is to keep that promise when several cores each have their own cache.)
- Caches work in units of cache lines (缓存行): when you touch one byte, the whole line around it (64 bytes on most x86 CPUs, 128 on Apple’s M-series; 4 bytes in the slides’ toy example) is brought in.
Which data does a cache keep? Real designs (direct-mapped, set-associative — see CMU 15-213 Lecture 10) are beyond this course; the slides’ simplification is enough: a cache of N bytes keeps the most recently accessed data, and when it needs room it evicts the least recently used (LRU, 最近最少使用) line. 07_caches_and_locality.py traces the slides’ two examples with an 8-byte cache of two 4-byte lines:
Part A -- slide 79, cache example 1
addr | cache action | lines in cache after (LRU first)
0x0 | cold miss, load line 0x0 | 0x0
0x1 | hit | 0x0
0x2 | hit | 0x0
0x3 | hit | 0x0
0x2 | hit | 0x0
0x1 | hit | 0x0
0x4 | cold miss, load line 0x4 | 0x0, 0x4
0x1 | hit | 0x4, 0x0
-> 6 hits, 2 cold misses, 0 capacity misses (hit rate 75%)
This short trace contains both kinds of locality (局部性) that make caches work:
- Spatial locality: loading line 0x0 for address 0x0 also brought in 0x1–0x3, so the next three accesses hit “for free”.
- Temporal locality: addresses 0x2 and 0x1 are accessed again soon, and are still there.
Example 2 streams through 16 bytes and then returns to the start:
0x8 | cold miss, load line 0x8 (evict 0x0) | 0x4, 0x8
...
0xC | cold miss, load line 0xC (evict 0x4) | 0x8, 0xC
...
0x0 | capacity miss, load line 0x0 (evict 0x8) | 0xC, 0x0
-> 12 hits, 4 cold misses, 1 capacity misses (hit rate 71%)
Two kinds of miss appear: a cold miss (冷不命中) is the first-ever access to a line — unavoidable; a capacity miss (容量不命中) happens because the line was in the cache but was evicted for lack of room. (Real caches add a third kind, conflict misses, from their restricted placement.)
5.4 The memory hierarchy
A real computer implements “memory is one big array” with a hierarchy (层次结构) of caches: a small, very fast L1 next to each core; a larger, slower L2; often an even larger L3 shared by all cores; then DRAM. Smaller capacity close to the processor means lower latency; larger capacity further away means higher latency. One ld instruction may therefore involve a whole sequence of lookups. The slides’ example (an Intel Kaby Lake CPU at 4 GHz) gives approximate load latencies of 4 clocks (L1), 12 (L2), 38 (L3), and ~248 (DRAM, best case).
A few percent of DRAM accesses dominate the average. 07_caches_and_locality.py Part C:
good locality (1% DRAM) average 7.0 cycles (DRAM accesses cause 35% of it)
worse locality (5% DRAM) average 18.0 cycles (DRAM accesses cause 69% of it)
no locality (all DRAM) average 248.0 cycles
What does the hierarchy look like on a real machine? 08_memory_latency measures it by pointer chasing (指针追逐): it links nodes into one long cycle in random order and follows the links, so each load’s address depends on the previous load’s result — no overlap is possible, and the time per step is the true load latency. The working set grows from 16 KiB to 256 MiB:
working set | likely level | random order ns/load | in-order ns/load
16 KiB | L1 | 0.74 | 0.74
128 KiB | L1 | 0.75 | 0.75
256 KiB | L2 | 6.71 | 1.76
2 MiB | L2 | 6.89 | 1.70
8 MiB | L2 | 12.67 | 1.77
16 MiB | L2 | 37.28 | 2.72
32 MiB | beyond L2 | 104.27 | 8.12
256 MiB | DRAM (+TLB) | 121.90 | 9.11
- A staircase: ~0.75 ns while the data fits in the 128 KiB L1 (about 3 clocks), ~7 ns in L2, and ~100–120 ns once it spills to DRAM — 164× slower than L1. The steps sit where the cache sizes say they should. (At the largest sizes the random walk also misses in the TLB, the cache of virtual-to-physical address translations, which adds to the time.)
- In address order, the same 256 MiB costs only 9 ns per load. Hardware prefetchers (预取器) notice sequential patterns and fetch lines before they are requested. Predictable access patterns hide much of the latency; random ones cannot.
Caches therefore reduce the length of stalls — as long as the program accesses data it accessed recently or data near it. They also provide much higher bandwidth than DRAM, a point Lecture 3 develops.
5.5 Locality is a property of how you access data
The same data can have good or bad locality depending on the order of access. Part D of 07_caches_and_locality.py walks a 2-D array of 4-byte ints (stored row-major, as in C) through a 32 KiB cache with 64-byte lines:
array (rows x cols) | one column touches | row order miss | column order miss
256 x 256 | 256 lines = 16 KiB | 6.2% | 6.2%
1024 x 256 | 1024 lines = 64 KiB | 6.2% | 100.0%
Row order misses once per 16 ints (one new 64-byte line). Column order is the interesting case: it is just as good while the lines touched by one column (16 KiB) fit in the cache — the next column finds them all still there — and catastrophic (every access misses) once they do not (64 KiB). Part E shows the sharpest version of this, the LRU cliff: repeatedly scanning an array that fits in a 32 KiB cache misses only on the first pass, but an array just 1 KiB too big (33 KiB) misses on 100% of later accesses, because with LRU the line needed next is always the one that was just evicted. The size of the data a computation keeps reusing — its working set (工作集) — compared with the cache size is what matters.
5.6 Data movement has a high energy cost
Data movement is not only slow; it is expensive in energy. The slides give ballpark numbers (from Bill Dally of NVIDIA and Tom Olson of ARM) for the energy of the operation itself:
| Operation | Energy |
|---|---|
| integer operation | ~1 pJ |
| floating-point operation | ~20 pJ |
| read 64 bits from a small local SRAM (~1 mm away on chip) | ~26 pJ |
| read 64 bits from low-power mobile DRAM (LPDDR) | ~1,200 pJ |
06_power_wall.py Part C turns these into consequences:
Reading 10 GiB/s from DRAM: 1.34e+09 words/s x 1200 pJ = 1.61 W
The same reads from nearby SRAM: = 0.035 W
FP ops per DRAM word before compute energy >= read energy: 60 (= 7.5 ops per byte)
a = x*x+y*y+z*z with x,y,z read from DRAM : 3600 pJ loads + 100 pJ math -> 97% of energy is data movement
a = x*x+y*y+z*z with x,y,z read from nearby SRAM: 78 pJ loads + 100 pJ math -> 44% of energy is data movement
Just streaming 10 GiB/s from DRAM costs ~1.6 W — more than the ~1 W budget of an entire mobile GPU (and the phone must also run the CPU, display and radios). A computation must perform about 60 floating-point operations for every 8-byte value it loads from DRAM before the arithmetic, rather than the data movement, dominates its energy. This ratio of computation to data moved — arithmetic intensity (算术强度) — becomes a central quantity in Lectures 3, 6 and 9. The rule of thumb of modern system design: always seek to reduce the amount of data movement. Exploiting locality matters.
6. Course logistics (Fall 2025)
Briefly, because they shape what the course emphasizes:
- No textbook; slides, readings and the course website. Suggested reference: Hennessy and Patterson, Computer Architecture: A Quantitative Approach.
- Five programming assignments (56% of the grade), optionally with a partner: (1) analyzing parallel program performance on a quad-core CPU — threads, SIMD, ISPC; (2) scheduling a task graph on a multi-core CPU; (3) a circle renderer in CUDA on NVIDIA GPUs; (4) optimizing DNN computations on an AI accelerator (Trainium2); (5) writing the fastest possible CUDA kernels. Eight late days for assignments 1–4.
- Four written assignments (12%), in staff-assigned teams of three, built from modified past exam questions.
- Per-lecture participation (4%) via a short quiz; a midterm (12%) and a final (16%).
7. The road ahead
| Lectures | What they add | Which part of today they continue |
|---|---|---|
| 2–3 | multi-core + SIMD + hardware multi-threading; latency vs. bandwidth; ISPC | §3.7 (where PA1’s 32–40× comes from), §5.2 (hiding stalls) |
| 4–6 | decomposition, assignment, orchestration; work distribution; locality and communication | demos 1–3 |
| 7–8 | GPUs and CUDA; data-parallel thinking (map, reduce, scan) | §3.7 (throughput hardware) |
| 9–13 | DNNs on GPUs, accelerators, datacenter AI, DSLs | §4.2 (specialization), §5.6 (data movement) |
| 14–18 | cache coherence, synchronization, memory consistency, lock-free programming, transactions | demo 1’s atomic, demo 3’s barrier |
Summary
- A parallel computer is a collection of processing elements that cooperate to solve problems quickly — and, today, efficiently.
- Speedup = T(1 processor) / T(P processors), measured against the best serial program; efficiency = speedup / P. Fast ≠ efficient.
- The classroom demos, re-enacted: communication can make 8 threads 16× slower than one (demo 1); load imbalance lets the slowest thread set the pace (blocked 2.26× vs. predicted 2.29×; a static scheme defeated by a periodic workload, 1.20×); frequent synchronization makes small problems slower in parallel, and amplifies any single slow participant (demo 3).
- Single-thread performance used to improve for free through ILP (superscalar, out-of-order execution) and rising clock frequency. ILP is bounded by dependencies (critical paths) and gives diminishing returns beyond ~4-wide issue; one real core still overlaps ~14× more FMAs when they are independent.
- The power wall (dynamic power ∝ C·V²·f, with V rising with f) stopped clock scaling around 2005. Transistors went into more cores and specialized units. Software must be parallel to get faster: no more free lunch.
- Efficiency matters because power is heat and battery; specialization buys efficiency.
- Efficient processing comes down to accessing data efficiently. Memory latency causes stalls; caches (lines, LRU, cold/capacity misses) exploit spatial and temporal locality; the measured hierarchy runs from 0.75 ns (L1) to ~120 ns (DRAM); reading DRAM costs ~60× the energy of a floating-point operation.
Common pitfalls
- Measuring speedup against the parallel code run with one thread. Use the best serial program as the baseline (§1.2).
- Assuming more threads means more speed. Communication (demo 1) and synchronization (demo 3) can make a program slower as P grows; always measure a range of P.
- Splitting work into P equal-sized pieces instead of equal-cost pieces. The program ends when the last thread ends (demo 2).
- Trusting a static assignment because it worked on one input. A workload with structure can defeat it (workload B).
- Timing code the compiler has deleted or moved. If a “computation” takes 0 ms, the optimizer probably removed it; use the
keep/opaquerecipe incs149_timer.h. - Reasoning about performance by counting operations. Where the data lives (L1 vs. DRAM: 164×) and whether operations are independent (1 vs. 16 chains: 14×) matter more than the count.
- Expecting all cores to be equal. Heterogeneous chips (performance + efficiency cores) and other programs make “identical” threads finish at different times.
Exercises
-
Speedup and efficiency. A program takes 120 s on one core. With 8 cores it takes 24 s; with 16 cores it takes 20 s. Compute speedup and efficiency for both. Which configuration would you use if cores were free? If you paid per core-second?
Answer
8 cores: speedup 5×, efficiency 62.5%. 16 cores: speedup 6×, efficiency 37.5%. If cores are free, use 16 (it is faster). If you pay per core-second, 8 cores cost 8 × 24 = 192 core-seconds and 16 cores cost 320; 1 core costs 120. The fastest choice is not the cheapest — fast ≠ efficient. -
Predict the imbalance. 1,000 tasks, task i costs i + 1 units, blocked assignment to 2 threads. What speedup does counting work predict? What about 10 threads?
Answer
Total ≈ 1000²/2 = 500,000 units. With 2 threads the second thread gets tasks 500–999, ≈ 375,000 units, so speedup ≈ 500,000 / 375,000 = 1.33×. With 10 threads the last thread gets tasks 900–999, ≈ (1000² − 900²)/2 = 95,000 units, so ≈ 5.3×. In general, the last of P blocks holds a fraction (2P − 1)/P² of the work. -
Schedule by hand. For
a = x*x + y*y + z*z, suppose a multiply takes 3 clocks and an add 1 clock. How many clocks with 1, 2 and 3 execution units (assume units are pipelined: a new instruction can start every clock)? Check withilp_sched.parse_asm(..., latencies={"mul": 3}).Answer
1 unit: muls start in clocks 1, 2, 3; the first add needs both x*x (ready at clock 4) and y*y (ready at clock 5), so it starts at 5; the second add needs it (ready 6) and z*z (ready 6): starts at 6 → 6 clocks. 2 units: muls at 1, 1, 2; add at 4; add at 5 → 5 clocks. 3 units: muls at 1, 1, 1; add at 4; add at 5 → 5 clocks. The critical path (mul → add → add = 3 + 1 + 1 = 5) is the bound. -
Power arithmetic. Using dynamic power ∝ V²·f, a core runs at 3 GHz and 1.0 V. A new design runs two such cores at 2 GHz and 0.8 V each. Compare total dynamic power and peak throughput (assume throughput ∝ cores × frequency).
Answer
One core: 1.0² × 3 = 3 units of power, throughput 3. Two cores: 2 × 0.8² × 2 = 2.56 units, throughput 4. The dual-core design delivers 33% more throughput for 15% less power — but each core is 33% slower, so only parallel software sees the benefit. -
Trace a cache. Using the slides’ cache (8 bytes, 4-byte lines, LRU), classify each access in the sequence 0x0, 0x4, 0x8, 0x0, 0x4, 0x8.
Answer
0x0 cold, 0x4 cold, 0x8 cold (evicts 0x0), 0x0 capacity (evicts 0x4), 0x4 capacity (evicts 0x8), 0x8 capacity (evicts 0x0). Zero hits: three lines cycled through a two-line LRU cache always evict the line needed next — the LRU cliff of §5.5 in miniature. -
Energy of a loop. A loop reads two arrays of 10⁹ doubles each from DRAM and computes one FMA (count it as 2 FP ops) per element pair. Using the slide numbers, estimate the energy spent on DRAM reads and on arithmetic. What is the arithmetic intensity in FP ops per byte?
Answer
DRAM: 2 × 10⁹ reads × 1200 pJ = 2.4 J. Arithmetic: 10⁹ × 2 × 20 pJ = 0.04 J. Data movement is ~98% of the energy. Intensity: 2 FP ops per 16 bytes = 0.125 ops/byte, far below the ~7.5 ops/byte break-even of §5.6. Such a loop is limited by data movement, in energy and (Lecture 3) in time. -
Communication vs. computation. In demo 3, a barrier costs ~1.3 µs with 8 threads and a cell update ~2.2 ns. How many cells must each thread update per step for the barrier to cost at most 10% of a step?
Answer
We need 1.3 µs ≤ 0.1 × (cells × 2.2 ns), so cells ≥ 1300 / 0.22 ≈ 5,900 cells per thread per step, i.e. an array of ~47,000 cells for 8 threads. The table agrees: 4,095 cells per thread still lost a lot, 32,767 did well (on a quiet machine).
The related assignment: Programming Assignment 1
PA1, Analyzing Parallel Program Performance on a Quad-Core CPU, is mostly about measuring and explaining performance, exactly the skill this lecture practised. It asks you to parallelize a fractal image generator with C++ threads and explain why the speedup is not linear (load imbalance!), to vectorize a function with a simulated SIMD intrinsics library and analyze lane utilization, to run and tune ISPC programs with SIMD and tasks, to reason about inputs that maximize or minimize SIMD speedup, to explain why a memory-bound kernel (saxpy) barely speeds up, and to profile and speed up a K-means implementation. The class machines are 4-core Intel CPUs with hyper-threading and 8-wide AVX2. These notes do not provide solutions; the demos here and in Lectures 2–5 practise the same ideas on different workloads.
Further reading
- The Fall 2025 slides for this lecture and the 2023 lecture video “Why Parallelism? Why Efficiency?” (Stanford Online YouTube playlist linked from the course page).
- Herb Sutter, “The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software”, Dr. Dobb’s Journal, 2005 — the article behind the slides’ frequency/ILP/power chart.
- K. Olukotun and L. Hammond, “The Future of Microprocessors”, ACM Queue, 2005 — the source of the slides’ historical CPU-performance plot, by one of the course’s instructors.
- Hennessy and Patterson, Computer Architecture: A Quantitative Approach, 6th ed., chapter 1 (trends in technology, power and energy) and chapter 3 (ILP).
- M. Horowitz, “Computing’s Energy Problem (and what we can do about it)”, ISSCC 2014 — a widely cited table of the energy of operations and memory accesses.
- CMU 15-213 Lectures 9–10 in these notes (memory hierarchy and caches) for cache organization in depth.
Preview of Lecture 2 — A modern multi-core processor
Today’s processor executed one instruction stream, perhaps several instructions per clock. Next lecture builds a modern chip step by step from that simple core, adding three kinds of parallel hardware: multiple cores (several instruction streams), SIMD (单指令多数据: one instruction operating on a vector of data with many ALUs), and hardware multi-threading (several execution contexts per core, so that when one thread stalls on memory, another runs). We will see who is responsible for using each one — the hardware, the compiler, or you — what happens to SIMD at an if statement, and how many threads a core needs to hide a given memory latency. Together these explain where PA1’s 32–40× comes from.
术语表 (Glossary, English → 中文)
| English | 中文 |
|---|---|
| parallel computer / processing element | 并行计算机 / 处理单元 |
| speedup / linear speedup | 加速比 / 线性加速 |
| efficiency | 效率 |
| serial program / baseline | 串行程序 / 基线 |
| embarrassingly parallel | 易并行(无需协作的并行) |
| communication / synchronization | 通信 / 同步 |
| partial sum | 部分和 |
| atomic operation (atomic add) | 原子操作(原子加) |
| data race | 数据竞争 |
| load imbalance / load balancing | 负载不均衡 / 负载均衡 |
| decomposition / assignment / orchestration | 分解 / 分配 / 编排 |
| static / dynamic assignment | 静态 / 动态分配 |
| blocked / interleaved assignment | 分块 / 交错(轮转)分配 |
| barrier | 屏障(栅栏同步) |
| computation-to-communication ratio | 计算/通信比 |
| heterogeneous multi-core (performance / efficiency cores) | 异构多核(性能核 / 能效核) |
| instruction / machine code / compiler | 指令 / 机器码 / 编译器 |
| register / execution context | 寄存器 / 执行上下文 |
| fetch / decode | 取指 / 译码 |
| ALU (arithmetic logic unit) / execution unit | 算术逻辑单元 / 执行单元 |
| clock / clock frequency | 时钟周期 / 时钟频率 |
| instruction-level parallelism (ILP) | 指令级并行 |
| dependency graph / critical path | 依赖图 / 关键路径 |
| superscalar / out-of-order execution | 超标量 / 乱序执行 |
| true dependency (RAW) / false dependency (WAR, WAW) | 真依赖 / 伪依赖 |
| register renaming | 寄存器重命名 |
| fused multiply-add (FMA) | 融合乘加 |
| latency / throughput | 延迟 / 吞吐量 |
| pipelining | 流水线 |
| power wall | 功耗墙 |
| dynamic power / static (leakage) power | 动态功耗 / 静态(漏电)功耗 |
| thermal design power (TDP) | 热设计功耗 |
| multi-core / many-core | 多核 / 众核 |
| specialized hardware / accelerator | 专用硬件 / 加速器 |
| neural processing unit (NPU) / tensor processing unit (TPU) | 神经网络处理器 / 张量处理单元 |
| memory address space / address | 内存地址空间 / 地址 |
| load / store | 加载 / 存储 |
| memory access latency / stall | 访存延迟 / 停顿 |
| cache / cache line | 缓存 / 缓存行 |
| hit / miss; cold miss / capacity miss | 命中 / 未命中;冷不命中 / 容量不命中 |
| least recently used (LRU) | 最近最少使用 |
| spatial / temporal locality | 空间 / 时间局部性 |
| working set | 工作集 |
| memory hierarchy (L1 / L2 / L3 / DRAM) | 存储层次结构 |
| prefetching | 预取 |
| pointer chasing | 指针追逐 |
| TLB (translation lookaside buffer) | 快表(地址转换后备缓冲) |
| data movement | 数据搬运 |
| arithmetic intensity | 算术强度 |