Lecture 2 · A Modern Multi-Core Processor

Parallel Computing · Lecture 02。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

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

本篇目录

Maps to: Stanford CS149 Fall 2025, Lecture 2 (Sep 25), slide deck 02_basicarch (108 slides), “A Modern Multi-Core Processor (Part I)”. The hardware multi-threading part at the end of the deck was finished at the start of Lecture 3; it is taught here in full. Sources: the public Fall 2025 slides; the 2023 lecture video of the same title. Every experiment and number below was written for these notes and run on the author’s machine (Apple M4 Pro: 8 performance + 4 efficiency cores, 128-bit NEON SIMD, no hardware multi-threading; clang 21, macOS 27). Code: code/lecture02/. Reading time: ~90 minutes for the prose; ~30 more to run and read the demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Explain the three ways a modern chip executes instructions in parallel — multi-core (多核), SIMD (单指令多数据) and superscalar (超标量) execution — and say who finds the parallelism for each: the programmer, the compiler or the hardware.
  2. Turn a data-parallel loop into code for several cores (std::thread) and for SIMD lanes (intrinsics (内建函数)), and predict roughly how much each one should help.
  3. Explain how SIMD hardware runs an if with an execution mask (执行掩码). Define coherent (一致的) and divergent (发散的) execution, and compute lane utilization (通道利用率) for a given input.
  4. Explain why a processor stalls (停顿) on memory, and the three ways to fight it: caches, prefetching (预取) and hardware multi-threading (硬件多线程). Compute how many hardware threads a core needs to stay busy.
  5. Count how much independent work a chip needs before it can run at full speed — the product of cores, hardware threads and SIMD width — and relate it to Little’s law (利特尔法则).
  6. Read real chip diagrams (Intel Kaby Lake, NVIDIA V100, Apple M-series) in these terms.

0.2 Prerequisites and scope

  • Prerequisites: Lecture 1 — instructions, ILP, latency vs. throughput, caches and the memory hierarchy. You should be able to read a C loop and a std::thread call. Every intrinsic and C++ idiom used in the demos is explained in the code.
  • Scope: how a single chip is organized for throughput, seen “from a software engineer’s perspective” (the slides’ phrase). We do not cover how caches decide what to keep (set associativity), how branch predictors work, or how out-of-order logic is built. Memory bandwidth is Lecture 3; GPUs in depth are Lecture 7.

0.3 Section → code map

SectionIdeaDemo in code/lecture02/
§2–§3sinx; parallelism across cores with threads01_sinx_ladder (+ sinx.h)
§4.1–§4.3SIMD with intrinsics; who generates SIMD code01_sinx_ladder
§4.4–§4.5masks, coherence and divergence, lane utilization02_divergence.py (+ simd_emulator.py)
§4.6divergence on a real SIMD unit, branch prediction03_divergence_on_neon
§5superscalar + SIMD + multi-core together; peak throughput01_sinx_ladder, 06_peak_flops
§6.3–§6.6hardware multi-threading, context storage, SMT04_hardware_multithreading.py (+ mtcore.py)
§6.7hiding latency with independent loads in flight05_latency_hiding

Run them all with cd code/lecture02 && make run (~10 seconds).

0.4 Notation and the machine

  • W is the SIMD width (SIMD 宽度): how many data elements one vector instruction processes. For 32-bit floats: W = 4 for Arm NEON (128 bits), 8 for Intel AVX2 (256 bits), 16 for AVX-512, 32 for an NVIDIA warp.
  • A lane (通道) is one of the W slots of a vector instruction. An ALU (算术逻辑单元) is the hardware that computes one lane’s result.
  • FMA (fused multiply-add, 融合乘加) computes a·b + c with one rounding. We count it as 2 floating-point operations (FLOPs). GFLOP/s = 10⁹ FLOPs per second.
  • The author’s machine: Apple M4 Pro, 8 performance + 4 efficiency cores, one hardware thread per core (no SMT), NEON with W = 4. The CS149 class machines (myth) are 4-core Intel CPUs with 2 hardware threads per core and AVX2 with W = 8.
  • As in Lecture 1, another program used one core continuously during all runs. This mostly affects the 8- and 12-thread rows, and §3.5 explains how.

1. Review: programs, processors and memory

The lecture starts by recalling Lecture 1 in three questions, because the rest of the day is about making each part parallel.

1.1 What is a program? What does a processor do?

A compiled program is a list of processor instructions. Each instruction reads some values (from registers (寄存器) or memory), does one simple operation, and writes a result. The very simple processor of Lecture 1 has three parts:

  • fetch/decode (取指/译码): decides which instruction runs next and what it means;
  • an ALU / execution unit (执行单元): performs the operation;
  • an execution context (执行上下文): the registers holding the program’s state, plus the program counter.

It executes one instruction per clock. A superscalar processor adds a second fetch/decode unit, a second execution unit and out-of-order control logic. That logic finds independent instructions in the single instruction stream and runs up to two per clock.

The slides ask what it means for such a processor to “respect program order”. The answer: the results must be exactly as if the instructions ran one at a time, in order. The hardware may only overlap instructions that do not depend on each other. Parallel execution must not change the answer. Every version of every demo in this lecture checks that it computes the same bits as the serial version.

1.2 What is memory?

Memory is an array of bytes indexed by address (地址). A load copies a value from an address into a register; a store copies the other way. A load takes latency (延迟) — ~120 ns from DRAM on the author’s machine (Lecture 1, demo 08). Until it completes, every instruction that needs the value must wait: the processor stalls. Caches (缓存) keep copies of recently used data close to the processor, so a hit costs ~1 ns instead of ~120. They work when the program has locality (局部性).

1.3 Today’s plan

Lecture 2 is “computer architecture from a software engineer’s perspective”. It adds three ideas to the simple processor:

IdeaWhat it addsWhat it fixes
#1 multi-coremore complete processors on one chipone instruction stream can only go so fast
#2 SIMDmore ALUs that share one instruction streamthe cost of fetching and decoding each instruction
#3 hardware multi-threadingmore execution contexts per corethe core sitting idle while one thread waits for memory

The first two are about parallel execution; the third is about memory latency. Knowing these three is enough to understand why a modern laptop chip and a modern GPU look the way they do.


2. The running example: sinx

2.1 The program

The lecture follows one program all day: compute sin(x) for every element of an array, using the Taylor series

sin(x) = x − x³/3! + x⁵/5! − x⁷/7! + …

Each term is the previous one times −x²/((2j+2)(2j+3)), so the loop keeps three running values. This is the version in sinx.h, the slides’ code with two small, documented changes:

void sinx_scalar(int N, int terms, const float* x, float* y) {
    for (int i = 0; i < N; i++) {             // independent iterations
        float value = x[i];
        float numer = x[i] * x[i] * x[i];
        float denom = 6.f;                    // 3!
        float sign  = -1.f;
        for (int j = 1; j <= terms; j++) {    // dependent iterations
            value += sign * numer / denom;
            numer *= x[i] * x[i];
            denom *= (2*j+2) * (2*j+3);
            sign  *= -1.f;
        }
        y[i] = value;
    }
}

The two changes:

  1. denom and sign are float, not int. With int, denom reaches 13! = 6,227,020,800 after the 5th term, which overflows a 32-bit integer. In C++ that is undefined behaviour. The slides use 5 terms, where the overflow happens on the very last update, after its last use, so the code “works” by luck. With 10 terms (our demos) it would not.
  2. The loop is marked so the compiler does not turn it into SIMD code by itself. This function is the honest scalar (标量) baseline for every speedup in this lecture (§4.3 explains why this matters).

With 10 terms on x ∈ [−π, π], the result matches std::sin to 5.4·10⁻⁷, which is float precision.

2.2 Where is the parallelism?

Look at the two loops:

  • Across i: computing y[5] needs nothing from y[4]. All N iterations are independent. That is data parallelism (数据并行): the same work on many independent data elements.
  • Across j: each step needs the previous step’s numer, denom and value. This is a dependency chain (依赖链), and no amount of hardware can run its steps at the same time.

That one property — independent across i, dependent across j — decides everything that follows. Multi-core and SIMD parallelism will come from the i-loop. The j-loop limits how fast each element can go.

2.3 How fast is one element?

Compiled for one core, the program is a scalar instruction stream that handles one element at a time. Measured on the author’s machine (demo 01): 17.5 ms for 2,097,152 elements, or 0.84 ns per Taylor term.

0.84 ns is the latency of one floating-point multiply on this core (Lecture 1 measured 0.87 ns for a dependent FMA). That is no coincidence. Each term multiplies denom by the previous denom, a chain of dependent multiplies. Each term must wait for the previous one, and the core cannot overlap enough consecutive elements to hide it. The slides make the same point with a picture (slide 30): a two-way superscalar core finds little ILP in this region of the program.


3. Idea #1: multi-core

3.1 Where the transistors went before 2005

Every two years, Moore’s law gave chip designers twice as many transistors. Before the multi-core era, they spent them on making one instruction stream run faster:

  • bigger caches (fewer stalls);
  • smarter out-of-order logic (more ILP found);
  • fancier branch predictors (分支预测器), which guess which way an if goes before it is known;
  • memory prefetchers (预取器), which guess which data will be needed next.

Each of these helps a single program without the programmer doing anything — the “free lunch” of Lecture 1. But Lecture 1 also showed why it ended: ILP has diminishing returns beyond ~4 instructions per clock, and the power wall stopped clock frequency from rising.

3.2 The idea

Idea #1: instead of using transistors to make one instruction stream faster, use them to build more cores.

Imagine replacing one fancy core with two simpler ones (smaller caches, a simpler predictor, less out-of-order logic). The slides assume each simpler core is 25% slower on a single instruction stream. Together they can still do 2 × 0.75 = 1.5× the work — if there are two instruction streams to run.

3.3 The catch: our program has only one instruction stream

sinx as written is one loop, compiled to one instruction stream, run by one thread. On the two-core chip it uses one simpler core and runs 25% slower than before. More cores help only a program that expresses parallel work. Hardware cannot discover that the i-loop could be split among cores; the program must say so.

This is the essential shift of the multi-core era. Speed now depends on the programmer, not just on the hardware.

3.4 Expressing parallelism with threads

The most direct way to use two cores is to create a second thread (线程) — a second instruction stream with its own registers and stack, sharing the same memory. Slide 35’s program, written with C++ std::thread (from 01_sinx_ladder.cpp):

void parallel_sinx_2threads(int n, int terms, const float* x, float* y) {
    int half = n / 2;
    std::thread my_thread([=] {                        // launch: first half
        cs149::prefer_performance_cores();             // macOS only, see below
        cs149::sinx_scalar(half, terms, x, y);
    });
    cs149::sinx_scalar(n - half, terms, x + half, y + half);   // main thread: second half
    my_thread.join();                                  // wait for the other worker
}

Notice three decisions, all made by the programmer:

  • Decomposition (分解): the work is split by loop iteration.
  • Assignment (分配): iterations are assigned in two contiguous blocks — a blocked (分块) assignment.
  • Synchronization (同步): join() waits for the other thread before returning, so the caller never sees half-finished results.

Lecture 4 names these steps formally. Measured result: 1.95× on 2 cores.

The line prefer_performance_cores() exists only because macOS cannot pin a thread to a core. It asks the scheduler for a performance core, which makes timing repeatable. A real program would not need it; a benchmark does (see Lecture 1, machine_info.h).

3.5 More cores

The same idea scales. With P threads, give each a contiguous chunk of the array (run_on_threads in demo 01). Measured on the author’s 12-core chip:

versiontimespeedup
scalar, 1 thread (baseline)17.54 ms1.00×
scalar, 2 threads9.00 ms1.95×
scalar, 8 threads3.03 ms5.78×
scalar, 12 threads2.16 ms8.11× (5.9× in other runs)

Why not 8× and 12×? The work is perfectly independent, so the losses are all overheads and imbalance:

  • Creating threads costs time. Starting and joining one thread costs ~19 µs on this machine (measured by demo 01). That is small next to 17 ms, but not next to the fastest versions of §5.
  • The slowest chunk sets the pace. The run ends when the last thread finishes. With 8 threads on 8 performance cores, one of them shares its core with the background program (§0.4), so one chunk takes longer. With 12 threads, 4 chunks run on efficiency cores, which are slower. How much this costs depends on where the OS puts the threads, which is why the 12-thread row varies between runs (5.9× to 8.1×). This is Lecture 1’s load imbalance (负载不均衡) again, caused here by unequal cores. Lecture 5 shows how dynamic assignment cures it.

Real chips: the slides show a 10-core Intel Comet Lake (2020); an NVIDIA RTX 4090 GPU with 144 cores (called SMs); and Apple’s A15 and M1 with “big” and “small” cores. The author’s M4 Pro has 8 performance + 4 efficiency cores, a heterogeneous (异构) chip like the M1.

3.6 A detour: the compiler changed the program (and our first measurement)

The first run of demo 01 gave 1.02× for 2 threads. The cause is worth telling because it can happen in any benchmark.

The first suspect was the OS: a new thread may land on an efficiency core. Adding prefer_performance_cores() was needed, but did not fix it. Timing the two halves separately showed the main thread’s half took 4.8 ms and the spawned thread’s half 8.9 ms, for the same amount of work.

The real cause was the compiler. The main thread called sinx_scalar(..., TERMS, ...) with TERMS = 10, a compile-time constant. The call was inlined (内联), so the compiler saw “terms = 10”, unrolled the j-loop completely and turned every denominator into a constant. That removed the chain of dependent multiplies, so its code ran 1.9× faster per element. The spawned thread’s lambda received terms as an ordinary variable and got the general loop. The two halves were running different machine code.

The fix: the kernels in sinx.h are marked noinline, so every caller runs the same instructions. Demo 01 also keeps one row, “scalar, constant terms” (1.86×), that shows what the compiler’s knowledge is worth. The lesson extends Lecture 1’s: a speedup is a ratio of two timings, and both must time the same computation compiled the same way.

3.7 Data-parallel expression: saying what, not how

Slide 36 rewrites sinx in a fictitious language with a forall loop:

forall (int i from 0 to N) { ... same body ... }

forall declares that the iterations are independent. It does not say how many threads to use or which iterations each gets. With that information, a compiler or runtime could create the threads and choose the assignment itself. This is the data-parallel (数据并行) style. It will come back as ISPC’s foreach (Lecture 3), CUDA kernels (Lecture 7) and map (Lecture 8). The programmer states what may run in parallel; the system decides how. Keep this distinction between abstraction (抽象) and implementation (实现) in mind all quarter.


4. Idea #2: SIMD

4.1 Amortizing the instruction stream

Look again at a core: fetch/decode, an execution context, and one ALU. Fetching and decoding an instruction, tracking its dependencies and scheduling it costs much more chip area and energy than the arithmetic itself (Lecture 10 measures this). Yet in a data-parallel loop, every iteration runs the same instructions on different data.

Idea #2: amortize the cost of managing one instruction stream over many ALUs. Give the core 8 ALUs that all receive the same instruction. Each operates on its own data. This is SIMD — single instruction, multiple data. One instruction now does 8 elements’ work, at little extra control cost.

4.2 Writing SIMD code with intrinsics

The compiler-visible form of SIMD is the vector instruction (向量指令), which operates on a vector register (向量寄存器) of W values. C/C++ reach vector instructions through intrinsics: functions that the compiler turns into one specific instruction each. Slide 46 shows sinx with Intel AVX intrinsics (W = 8). sinx.h has the same kernel for NEON (W = 4) and AVX2 side by side. The NEON version:

for (; i + 4 <= N; i += 4) {
    float32x4_t origx = vld1q_f32(x + i);          // load 4 inputs: 1 instruction
    float32x4_t x2    = vmulq_f32(origx, origx);   // 4 multiplies: 1 instruction
    float32x4_t value = origx;
    float32x4_t numer = vmulq_f32(x2, origx);
    float denom = 6.f, sign = -1.f;                // same for all lanes: plain scalars
    for (int j = 1; j <= terms; j++) {
        float32x4_t tmp = vdivq_f32(vmulq_f32(vdupq_n_f32(sign), numer),
                                    vdupq_n_f32(denom));
        value = vaddq_f32(value, tmp);
        numer = vmulq_f32(numer, x2);
        denom *= (2*j+2) * (2*j+3);
        sign  *= -1.f;
    }
    vst1q_f32(y + i, value);                       // store 4 outputs
}
// ... then the last N % 4 elements with the scalar code (the "tail")

How to read it:

scalarNEON (W = 4)AVX2 (W = 8)
x[i]vld1q_f32_mm256_loadu_ps
a * bvmulq_f32_mm256_mul_ps
a / bvdivq_f32_mm256_div_ps
a + bvaddq_f32_mm256_add_ps
one scalar in every lanevdupq_n_f32_mm256_set1_ps
y[i] = vvst1q_f32_mm256_storeu_ps

Three details matter:

  • Some values are the same in every lane. denom and sign depend only on j, not on the element. They stay in ordinary scalar registers and are broadcast (广播) into a vector only where needed. Lecture 3 calls such values uniform (统一的).
  • The tail (尾部). If N is not a multiple of W, the last N % W elements must be handled separately. Forgetting them is the most common SIMD bug. Demo 01 fills the output with NaN before each run, so a forgotten tail would show up as a wrong answer.
  • Same operations, same results. Per element, the vector code performs exactly the scalar code’s operations in the same order. The results are bit-identical, and demo 01 checks that.

Measured: SIMD on one thread runs 3.71× faster than the scalar baseline. One Taylor term now costs 0.90 ns per vector instead of 0.84 ns per element. One instruction simply does 4 elements’ work, at the same latency.

4.3 Who writes the vector instructions?

Slide 56 lists three routes to SIMD instructions in a CPU program:

  1. Intrinsics: the programmer requests specific vector instructions, as above. Precise, but tied to one instruction set (NEON code does not run on Intel).
  2. Parallel language semantics: the programmer writes forall / ISPC foreach, and the compiler maps iterations to lanes (Lecture 3).
  3. Auto-vectorization (自动向量化): the compiler analyzes an ordinary loop, proves the iterations independent, and emits vector code by itself.

Route 3 sounds ideal, so demo 01 tests it on sinx. With terms passed at run time, clang does not vectorize the loop at all. Its loop vectorizer works on innermost loops, and here the innermost loop is the j-loop: a dependency chain that cannot be vectorized. When terms is a compile-time constant, the compiler fully unrolls the j-loop, the i-loop becomes innermost, and clang vectorizes it:

versionspeedup
scalar, terms known at compile time (vectorization forbidden)1.86×
the same, auto-vectorization allowed7.45×
our NEON intrinsics, run-time terms3.71×

So auto-vectorization added 7.45 / 1.86 = 4.0× on top of the constant-terms code — just as good as hand-written intrinsics, when it works. One run-time parameter, and it silently stops working. That fragility is why languages like ISPC and CUDA exist: they make the parallelism part of the program’s meaning instead of something the compiler must prove.

In all three routes the binary contains vector instructions; the slides call this explicit SIMD (显式 SIMD). GPUs do it differently (§7.4): the binary has scalar instructions, and the hardware runs many instances side by side. That is implicit SIMD (隐式 SIMD).

4.4 Conditional execution: masks

SIMD works because all lanes execute the same instruction. What happens at an if, when different lanes want different branches? Slide 50’s example:

forall (int i from 0 to N) {
    float t = x[i];
    if (t > 0.0) { t = t * t;  t = t * 50.0;  t = t + 100.0; }
    else         { t = t + 30.0;  t = t / 10.0; }
    y[i] = t;
}

The SIMD hardware cannot send different instructions to different lanes. Instead it:

  1. evaluates the condition in all lanes at once, producing a mask: one true/false bit per lane;
  2. runs the if side with the mask, so lanes where the mask is false compute but discard their results;
  3. inverts the mask and runs the else side the same way;
  4. continues at full width after the if.

02_divergence.py traces slide 51’s 8-wide vector, where 3 lanes take the if and 5 the else (# = lane does useful work, . = masked off):

   clock 1  load t = x[i]    # # # # # # # #
   clock 2  cmp  t > 0.0     # # # # # # # #
   clock 3    t = t * t      # # # . . . . .
   clock 4    t = t * 50.0   # # # . . . . .
   clock 5    t = t + 100.0  # # # . . . . .
   clock 6    t = t + 30.0   . . . # # # # #
   clock 7    t = t / 10.0   . . . # # # # #
   clock 8  store y[i] = t   # # # # # # # #
   -> 8 instructions x 8 lanes = 64 lane-slots, 43 useful: utilization 67%

Lane utilization = useful lane-slots / issued lane-slots. Both sides of the if took time, and during each side some lanes idled. The result is still correct: the emulator checks every output against scalar code.

4.5 Coherent and divergent execution

Two terms from slide 55:

  • Instruction stream coherence (“coherent execution”): the same instruction sequence applies to all the elements processed together. SIMD hardware needs coherence to be used efficiently.
  • Divergent execution: the lack of coherence. Lanes want different instructions, and some must wait masked off.

Multi-core execution does not need coherence. Each core has its own fetch/decode and can follow its own path through the code. Only SIMD lanes share an instruction stream.

Demo 02 measures utilization for slide 50’s kernel on different inputs and widths. As ISPC and GPUs do, a side whose mask is all-false is skipped.

input patternW=4W=8W=16W=32
all positive (coherent)100%100%100%100%
sorted (negatives, then positives)100%99.9%~100%~100%
random signs, 50% positive72%69%69%69%
random signs, 10% positive84%75%68%65%
alternating + − + −69%69%69%69%

Lessons:

  • Coherent input costs nothing. Sorted input is nearly as good: only the one vector that straddles the sign change diverges.
  • Wider SIMD is more fragile. With 10% positive inputs, a 4-wide vector has no positive lane 66% of the time and can skip the if side. A 32-wide vector almost always contains one (1 − 0.9³² = 97%), so it almost always pays for both sides.

Slide 54’s breakout question: what code runs at 1/8 of peak on an 8-wide SIMD machine? Answer: an if with a long body that exactly one lane in every 8 takes. The whole long body is issued for all 8 lanes and is useful in one. Demo 02 Part C measures it with a 40-instruction body: utilization 18.6% at W = 8 and 9.9% at W = 32. Inside the branch it is exactly 1/W; the coherent load, compare and store lift the total slightly.

Data-dependent loops are divergence too. A while loop whose trip count depends on the data runs until the slowest lane of the vector finishes; finished lanes idle masked off. Demo 02 counts Collatz steps (n → n/2 or 3n+1 until 1) for n = 1…4096, a loop of 0 to 237 iterations:

order of the inputsW=8W=32
natural order 1, 2, 3, …57%48%
random order53%45%
sorted by step count100%99%

This is load imbalance (Lecture 1, demo 2) inside one instruction. The cure is the same: put similar work together. Coherence is something a programmer can create by reordering work. Here we sorted by the true step count (an oracle); real programs sort by a cheap estimate, for example by ray direction in a ray tracer.

4.6 Divergence on a real SIMD unit

Demo 02 counted lane-slots in a model. Demo 03 asks the same question with real NEON instructions and a stopwatch. The kernel is y = (x > 0) ? costly(x) : cheap(x), where the costly side is 24 dependent FMAs and the cheap side 1. Three versions:

  • scalar: one element at a time, with a real branch;
  • both + select: SIMD; compute both sides for all 4 lanes, then pick each lane’s result with a bit-select instruction. This is what compilers produce (“if-conversion”). There is no branch at all.
  • skip empty sides: SIMD; test the mask first and run only the sides some lane needs. This is what ISPC and GPUs do.

Measured, ns per element:

input patternscalarboth + selectskip empty sides
all negative (cheap side only)0.280.480.19
all positive (costly side only)1.760.480.46
sorted: 1/3 negative, then positive1.260.490.38
random signs, 50% positive3.450.480.60
random signs, 10% positive0.920.450.75
exactly 1 lane per vector positive0.530.460.52

What the table shows:

  • Coherent input, costly side: 1.76 → 0.46 ns, 3.8× from 4 lanes.
  • Both + select is constant (~0.48): no penalty for divergence, no reward for coherence. Skipping wins whenever whole vectors agree: 0.19 vs. 0.48 on all-negative input.
  • Slide 54’s worst case on real hardware: with exactly one costly lane per vector, SIMD gets 1.01× instead of 4×. Every vector runs the costly side for one useful lane in four.
  • The scalar code has its own divergence problem. On random signs it takes 3.45 ns per element: worse than all-positive (1.76), although it does half the costly work. The CPU predicts each branch before x[i] is known and, on random data, guesses wrong half the time. Every wrong guess throws away the work done in the meantime. Branch-free SIMD is 7.1× faster here.
  • Skipping can backfire. With 10% positives, 66% of vectors need only the cheap side, so skipping should save work. Measured, it is slower than both + select (0.75 vs. 0.45). The all/any test is itself an unpredictable branch, and its mispredictions cost more than the work they save.

The general lesson: data-dependent control flow is never free. SIMD pays for it in idle lanes, and scalar CPU code pays in branch mispredictions. Coherent, predictable data is fast on both.

4.7 SIMD in real CPUs

The widths (slide 56):

instruction setregister32-bit floats per instruction
Arm NEON128 bits4
Intel AVX2256 bits8
Intel AVX-512512 bits16

A core usually has several SIMD units. The slides’ Intel Kaby Lake core can start up to three 8-wide vector instructions per clock. Demo 06 measures the M4 performance core. With enough independent work it completes ~15 scalar FMAs per ns, or ~13.4 vector FMAs per ns. Each vector FMA does 4 lanes, so peak arithmetic is 3.6× higher with SIMD (107 vs. 29.7 GFLOP/s; 3.4–3.6× across our runs), not 4×: the core completes slightly fewer vector than scalar instructions per ns.

The optional make avx2 builds demo 01 for x86-64 with AVX2 and runs it on the M4 through Apple’s Rosetta 2 translator. The results are correct, but SIMD gives only 2.06×. Rosetta has to express every 256-bit AVX2 instruction with 128-bit NEON instructions. An instruction set is itself an abstraction, and its implementation decides the speed.


5. Putting the three forms of parallel execution together

5.1 Three forms, three owners

Slide 58 summarizes the parallel hardware so far:

formwhat runs in parallelwho finds the parallelismneeds
superscalardifferent instructions from one instruction streamthe hardware, automatically, while runningindependent instructions close together in the stream (ILP)
SIMDthe same instruction on W data elementsthe compiler (explicit SIMD) or the hardware (implicit SIMD on GPUs); requested by the programmer via intrinsics or parallel language constructsdata parallelism, and coherent control flow
multi-coredifferent instruction streams, one per corethe programmer, who creates threads (or a runtime that creates them)independent tasks; no coherence needed

5.2 SIMD + ILP

In §4.2 one vector cost 0.90 ns per term: the latency of one multiply. The j-loop is a chain, so one vector’s work cannot go faster. The core has several SIMD pipelines, though, and a superscalar core can run independent instructions on them at the same time. sinx_simd_ilp<U> gives it U independent vectors per loop iteration — U·4 elements whose chains do not depend on each other:

version (1 thread)speedup over scalarover SIMD ×1
SIMD, 1 vector at a time3.71×1.00×
SIMD + ILP, 2 vectors5.41×1.46×
SIMD + ILP, 4 vectors6.03×1.63×
SIMD + ILP, 8 vectors6.82×1.84×

This is Lecture 1’s ILP result (independent FMA chains, demo 05) applied to vectors. The slides draw it as a “superscalar + SIMD” core (slides 99–104): one instruction stream feeding both scalar and vector units, with several instructions per clock.

5.3 All three at once

versiontimespeedup
scalar, 1 thread17.54 ms1.0×
SIMD + ILP ×4, 8 threads0.59 ms29.7×
SIMD + ILP ×4, 12 threads0.53 ms33.1×

The separate factors — cores 5.8×, SIMD 3.7×, ILP 1.63× — multiply to 35×. The measured 29.7× is close. The shortfall is the fixed cost of starting 7 threads one after another (~19 µs each, ~0.13 ms in total), which matters now that the whole run takes 0.59 ms. This is the same kind of 32–40× that PA1 asks you to explain on the class machines.

The lesson of the ladder: the three forms of parallelism multiply, provided the program supplies enough independent work for all of them. Here that means at least 8 threads × 4 vectors × 4 lanes = 128 independent elements in flight at any moment.

5.4 Peak throughput

Multiplying the hardware’s parallelism gives a chip’s peak throughput (峰值吞吐量): cores × SIMD lanes × SIMD units per core × clock. Slide 60 counts 4 cores × 8 lanes × 3 units × 4.2 GHz = 403 GFLOP/s for the class machines’ Intel i7-7700K. Slide 61 gives ~16 TFLOP/s for an NVIDIA V100 GPU at ~250 W.

Demo 06 measures the author’s machine with independent FMA chains and no memory traffic:

configurationGFLOP/s
1 core, scalar, 1 dependent chain2.3
1 core, scalar, 16 chains29.7
1 core, vector, 1 chain9.1
1 core, vector, 24 chains107
8 performance cores, vector, 24 chains each735 (sum of per-thread rates: 819)
all 12 cores825 (sum: 999)

From 2.3 to 825 GFLOP/s is a factor of ~360, and only a program that uses all the forms of parallelism at once gets there. Two caveats, both measured:

  • The wall-clock rate is below the sum of the threads’ own rates. Every thread does the same work, and the run ends with the slowest one (8.6 vs. 12.8 FMAs/ns with 12 threads).
  • Real programs must also move data, and §6 and Lecture 3 show that memory usually sets the limit long before arithmetic does.

6. Part 2: accessing memory

6.1 The problem

Caches cut the latency of data that was used recently, and prefetchers cut the latency of data whose address is predictable. Neither helps code like

int x = some_function();
int y = A[x];        // A is large; x is unpredictable

The data was not used recently and its address is unknown until some_function returns. The load goes to DRAM, ~120 ns on the author’s machine (Lecture 1, demo 08). At ~4 instructions per clock and ~4.5 GHz, that is ~2,000 instruction slots during which the instruction stream can do nothing that depends on y.

6.2 Prefetching

Prefetching hardware watches the program’s access pattern, predicts future addresses, and loads that data into the cache ahead of time. When the guess is right, the later load is a cache hit. Lecture 1 measured it: walking 256 MiB in address order cost 9.1 ns per load, against 122 ns in random order. The slides point out that prefetching can also hurt: a wrong guess wastes memory bandwidth and evicts useful data from the cache.

6.3 Idea #3: hardware multi-threading

Think of doing laundry: while the washer runs for 45 minutes you do not stand in front of it, you start cooking. Idea #3: interleave the processing of several threads on the same core. When one thread cannot make progress, run another.

A core with hardware multi-threading keeps the execution contexts (registers, program counter) of several threads on the chip at once. Switching from one thread to another is then instant: the core simply takes the next instruction from a different context. Compare an OS context switch, which saves and restores registers in software and takes microseconds. The core still has the same ALUs; multi-threading only helps keep them busy.

6.4 The utilization exercise

Slides 78–85 work through an example. Each thread runs a loop: 3 arithmetic instructions, then a load whose data arrives 12 clocks later, and the next arithmetic instruction needs that data. The core issues one instruction per clock. 04_hardware_multithreading.py simulates it clock by clock (# = the ALU runs this thread, . = stalled on memory, - = ready but another thread has the ALU):

  1 thread: utilization 20%
   Thread 0 | ###............###............###............

  2 threads: utilization 40%
   Thread 0 | ###............###............###............
   Thread 1 | ---###............###............###.........

  5 threads: utilization 100%
   Thread 0 | ###............###............###............
   Thread 1 | ---###............###............###.........
   Thread 2 | ------###............###............###......
   Thread 3 | ---------###............###............###...
   Thread 4 | ------------###............###............###

One thread uses the ALU 3 out of every 15 clocks (20%). Each additional thread fills 3 more of the 12 stall clocks, so 5 threads give 100%; a 6th or 7th adds nothing. In general, with C arithmetic instructions per load and a latency of L clocks:

threads needed for 100% utilization = ceil((C + L) / C) = 1 + ceil(L / C)

With 6 arithmetic instructions per load (slide 84), 1 + 12/6 = 3 threads suffice. Programs that do more arithmetic per memory access need fewer threads to hide memory stalls (slide 87). Against a realistic DRAM latency of ~250 clocks, demo 04 computes that a thread with 1 arithmetic instruction per load needs 251 threads, and one with 24 needs 12.

This is an instance of Little’s law (from queueing theory): the amount of work that must be in flight equals latency × throughput. To complete one arithmetic instruction per clock when each thread spends 15 clocks per 3 instructions, 5 threads must be in progress at once.

6.5 Two takeaways, and the price

Slides 86–87 state two takeaways:

  1. A multi-threaded processor avoids stalls by running instructions from other threads while one thread waits. The latency of the load does not change; it just stops costing utilization.
  2. It hides memory latency with arithmetic from other threads. The more arithmetic per memory access, the fewer threads are needed.

The price is the throughput computing (吞吐计算) trade-off (slide 74): any one thread may take longer to finish, because it is sometimes ready but waiting while another thread uses the core. The system as a whole finishes more work per second. The simulator in mtcore.py also shows a second-order effect (run it with policy="round_robin"). If the core rotates threads every clock instead of switching only when one stalls, each thread’s arithmetic is spread over more clocks, its next load starts later, and utilization drops slightly when threads are scarce (37.6% instead of 40% with 2 threads). Once there are enough threads, both reach 100%.

6.6 No free lunch: storing execution contexts

Each execution context occupies on-chip storage, mostly registers. That storage is finite (slide 75), so a core can hold:

  • many small contexts: many threads, each with few registers. Great latency hiding, but each thread must make do with a small working set; or
  • a few large contexts: few threads with many registers each. Less latency hiding, but each thread can keep more data in registers.

Demo 04 Part C gives a core 256 registers of context storage in total:

registers per threadcontextsmath-heavy (12 math per 40-clock load)memory-heavy (1 math per 40-clock load)
832100%78.1%
1616100%39.2%
328100%19.7%
64492.4%9.9%

Memory-heavy code needs many contexts; math-heavy code is fine with few. GPUs choose many small contexts (a V100 SM holds 64 warps); CPUs choose a few large ones (2 per core on Intel; 1 on the M4).

6.7 Interleaved vs. simultaneous multi-threading

Slide 88 distinguishes two kinds of hardware multi-threading:

  • Interleaved (temporal) multi-threading (交错多线程): each clock, the core picks one thread and runs its instruction. This is what §6.4 simulated.
  • Simultaneous multi-threading (SMT): each clock, the core picks instructions from several threads to fill its several execution units. Intel’s Hyper-Threading (超线程) is 2-way SMT.

SMT matters on a superscalar core. Demo 04 Part D simulates a core with 2 ALUs. A single thread whose instructions all depend on each other can use only one ALU per clock, so it reaches 50% even without any stalls. A second thread brings it to 100%. SMT fills issue slots that one thread leaves empty, whether because it stalls or because it has no ILP.

The author’s M4 has no hardware multi-threading. Apple’s cores instead rely on very deep out-of-order execution, which §6.8 measures.

6.8 Hiding latency without hardware threads

An out-of-order core can also overlap independent loads from one instruction stream, as long as the program provides independent loads. Demo 05 builds 256 MiB of nodes linked in one random cycle, so nearly every load misses all caches. One thread then follows K independent pointer chains at once:

for (each step) { p[0] = p[0]->next; p[1] = p[1]->next; ... p[K-1] = p[K-1]->next; }

Within a chain every load needs the previous one’s result. The K chains are independent of each other.

chains Kns per loadspeeduploads in flight (latency ÷ ns per load)
1121.71.0×1.0
260.62.0×2.0
430.04.1×4.1
814.98.2×8.2
167.616.0×16.0
324.030.5×30.5
643.633.7×33.7

No load became faster; up to ~34 were simply in flight at the same time. The speedup tracks K almost exactly up to 16 chains, then flattens at ~34. That is the number of outstanding cache misses one core can track: the CPU’s version of “number of execution contexts”. It is the same principle as §6.4, with a different implementation. The program exposes independent work, and the hardware (out-of-order execution instead of hardware threads) overlaps it.

With all 8 performance cores, each chasing 32 chains, the machine reaches 0.81 ns per load, 159 GB/s of useful data. At that point something new appears. If each core still keeps ~31 loads in flight, Little’s law implies each load now takes ~196 ns instead of 122: requests are queueing in the memory system. Its bandwidth (带宽), not its latency, is becoming the limit. That is the subject of Lecture 3.


7. How it all fits together

7.1 Kayvon’s fictitious multi-core chip

Slide 89 combines everything into one imaginary chip: 16 cores × 8 SIMD ALUs per core × 4 hardware threads per core. It runs 16 instruction streams simultaneously and keeps 64 in total. To use all its ALUs and its full latency-hiding ability, a program must supply 16 × 4 × 8 = 512 independent pieces of work. For the class machines’ i7-7700K (4 cores × 2 threads × 8 lanes) the same count is 64; for the author’s M4 Pro performance cores (8 × 1 × 4) it is 32. The M4’s out-of-order cores want more independent work than that count suggests, as demos 01 and 05 showed.

7.2 A real CPU core: Intel Skylake / Kaby Lake

Slide 90’s diagram of one Kaby Lake core: 2 hardware threads; up to 4 scalar instructions per clock and up to 3 eight-wide vector instructions per clock (at most 2 vector multiplies or 3 vector adds). The instruction-selection logic picks among the instructions of both threads, so it is a 2-way SMT, superscalar, SIMD core.

7.3 A real GPU: NVIDIA V100

Slides 91–93 show one V100 streaming multiprocessor (SM, 流式多处理器), which is a GPU “core”:

  • 4 sub-cores, each with a fetch/decode unit and 16-wide SIMD units (a 32-wide instruction runs over 2 clocks);
  • up to 64 warps (a warp (线程束) is a group of 32 threads sharing one instruction stream, the GPU’s execution context), backed by 256 KB of registers per SM;
  • so up to 64 × 32 = 2,048 data items processed concurrently per SM.

The V100 has 80 SMs: 163,840 pieces of data in flight to reach its full latency hiding. That is 5,000× the M4 Pro count of §7.1. Each SM has 64 FP32 FMA units, so 80 × 64 × 2 FLOPs × ~1.5 GHz ≈ 16 TFLOP/s, at about 250 W. Its memory delivers 900 GB/s from HBM stacked next to the chip (Lecture 12). A GPU is the throughput-computing idea taken to the extreme: very many small contexts, wide SIMD, and the expectation that the program supplies enormous amounts of parallel work.

7.4 GPU SIMT: implicit SIMD

How do the GPU’s SIMD units run threads whose code is scalar? Slide 107: the hardware runs many threads, each with its own scalar instruction stream. When the threads of a warp are at the same instruction, the hardware executes them together on the SIMD ALUs, one thread per lane. When a thread is at a different instruction (divergence), its lane is masked off. This is SIMT (single instruction, multiple threads, 单指令多线程): SIMD implemented by the hardware rather than the compiler. The costs of §4.4–§4.6 apply unchanged, at width 32. Lecture 7 covers SIMT in detail.

7.5 What an application must provide

Slide 94 sums up: to use a modern parallel processor efficiently, an application must have

  1. enough parallel work to use all the execution units, across many cores and many units per core;
  2. groups of work items that need the same instruction sequence, to use SIMD;
  3. more parallel work than there are ALUs, so that work can be interleaved to hide memory stalls.

7.6 Thought experiment: who decides where threads run?

Slide 108: a program spawns two threads on a chip with 2 cores, each with 2 execution contexts. Who maps the threads to the contexts? The operating system. If you wrote the OS, you would put the two threads on different cores: each then has a whole core’s ALUs and caches, instead of sharing one core while the other idles. With five threads and four contexts, one thread must wait for a context, and the OS time-slices it with the others (milliseconds per switch, very unlike §6.3’s instant hardware switch). On the author’s macOS, the scheduler also decides between performance and efficiency cores. That is why demo 01’s 12-thread row varies from run to run.


Summary

  • A modern chip has three forms of parallel execution. Superscalar execution runs independent instructions from one stream; the hardware finds them. SIMD runs one instruction on W data elements; the compiler, or the programmer through intrinsics or a parallel language, generates it. Multi-core runs a different instruction stream on each core; the programmer creates the threads. Their benefits multiply: sinx ran 29.7× faster on 8 cores with SIMD + ILP, and 33× on all 12.
  • Cores help only a program that expresses parallel work. Threads (std::thread) are the explicit way; forall / foreach / map state independence and leave the mapping to the system.
  • SIMD amortizes the cost of an instruction stream over W ALUs. It needs coherent control flow. At a divergent if both sides run under masks, utilization falls, and the worst case is 1/W of peak. Wider SIMD (GPUs: 32) is more fragile. Reordering work to group similar items restores coherence.
  • On a real CPU, data-dependent branches cost twice: idle lanes for SIMD, and mispredictions for scalar code (random signs made scalar code 2× slower than all-costly input).
  • Memory latency (~120 ns) is hidden in three ways: caches, prefetching, and having other work in flight. Hardware multi-threading keeps several execution contexts per core and needs 1 + L/C threads for full utilization (Little’s law). An out-of-order core without SMT hides latency with independent loads from one stream (~34 in flight on the M4).
  • Context storage is finite: many small contexts (GPUs) hide more latency; a few large contexts (CPUs) hold more data per thread.
  • A chip needs cores × threads × lanes independent work items to run at full speed: 512 for Kayvon’s chip, 163,840 for a V100.

Common pitfalls

  • Forgetting the SIMD tail when N is not a multiple of W. Initialize outputs to NaN in tests so missing elements show up.
  • Assuming the compiler vectorized your loop. One run-time parameter can silently prevent it. Check with -Rpass=loop-vectorize / -Rpass-missed=loop-vectorize (clang) or by timing.
  • Benchmarking two versions that the compiler compiled differently. Inlining with constants can change the machine code (§3.6). Keep the kernel out of line, or make sure every version sees the same information.
  • Expecting W× from W lanes. Dependency chains, divergence, instruction throughput (~3.6× at peak on the M4, not 4×) and memory all take their share. Measure.
  • Confusing hardware threads with software threads. Hardware threads are execution contexts in the core, switched every clock. Software threads (std::thread) are scheduled by the OS onto hardware contexts, and switching between them takes microseconds.
  • Thinking multi-threading makes memory faster. It keeps the ALUs busy while memory is slow; each load still takes its full latency.
  • Creating one thread per tiny task. ~19 µs per thread is a lot when the work takes 0.5 ms (§5.3). Use fewer, longer-lived threads (Lecture 5: thread pools).

Exercises

  1. Utilization by hand. An 8-wide SIMD core runs if (x > 0) { 6 instructions } else { 2 instructions }, plus a compare, a load and a store that always run at full width. Inputs in one vector: 5 positive, 3 negative. What is the lane utilization? What if all 8 are positive?

    AnswerIssued: 3 full-width + 6 + 2 = 11 instructions × 8 lanes = 88 lane-slots. Useful: 3 × 8 + 6 × 5 + 2 × 3 = 24 + 30 + 6 = 60. Utilization 60/88 = 68%. All positive: the else side is skipped (if the hardware skips all-false sides), giving 9 instructions, all useful: 100%. Without skipping: 11 instructions, 72 useful lane-slots out of 88, 82%.
  2. Worst case. On a 16-wide machine, write a one-if program that runs at about 1/16 of peak.

    Answerif (i % 16 == 0) { a long computation } over an array processed 16 elements at a time. Every vector has exactly one lane taking the branch, so the whole long body is issued for 16 lanes and is useful in one. Utilization of the branch body: 1/16 (demo 02 Part C measures 12.8% overall at W = 16 with a 40-instruction body, including the full-width load/compare/store).
  3. Threads needed. A thread does 4 arithmetic instructions per load; load latency is 30 clocks; the core issues 1 instruction per clock. How many hardware threads give 100% utilization? What utilization do 3 threads give?

    Answer1 + ceil(30/4) = 1 + 8 = 9 threads. With 3 threads: each is busy 4 out of every 34 clocks, so 3 × 4/34 = 35%. Check: mtcore.simulate(3, 4, 30, clocks=3400).utilization.
  4. Count the work. A GPU has 108 SMs, each holding up to 64 warps of 32 threads. How many independent work items does it need for maximal latency hiding? Why might a program with 10,000 items run well below peak on it?

    Answer108 × 64 × 32 = 221,184. With 10,000 items the GPU can fill ~4.5% of its contexts. Each SM then has only a few warps, so whenever they all wait for memory its ALUs idle. The GPU needs far more parallel work than its number of ALUs.
  5. Multiply the factors. A program gets 3.5× from SIMD and 1.6× from ILP on one core. On a 6-core chip with a 20 µs cost per thread created, the single-thread SIMD+ILP version takes 3 ms. Estimate the 6-thread time if work splits evenly and threads are created one after another.

    AnswerWork per thread: 3 ms / 6 = 0.5 ms. The last of the 5 extra threads starts after ~5 × 20 µs = 0.1 ms, so it finishes at ~0.6 ms. Speedup over the 3 ms version: 3/0.6 = 5× instead of 6×. Over scalar: 3.5 × 1.6 × 5 ≈ 28×.
  6. Coherence by design. Demo 02’s Collatz loop in random order uses 53% of an 8-wide machine. Sorting by the exact step count gives 100%, but computing the step count is the work. Suggest a cheap way to improve coherence, and say what it costs.

    AnswerSort, or bucket, the inputs by a cheap predictor of the step count. For example, process inputs in blocks and group similar sizes of n, since larger n tends to need more steps, or use a partial run (first 20 steps) to estimate. The costs: the sorting itself (time and memory traffic), the predictor's inaccuracy, and scattered output writes (results must go back to their original positions). Whether it pays depends on how expensive the loop is relative to the sort.
  7. Little’s law. A core keeps at most 34 cache misses in flight and DRAM latency is 120 ns. What is the maximum rate of 128-byte line fetches for this core, in GB/s? How many such cores are needed to reach 160 GB/s?

    Answer34 lines / 120 ns = 0.283 lines/ns × 128 B = 36 GB/s per core. 160 / 36 ≈ 4.4, so ≥ 5 cores at the unloaded latency. In practice latency rises as the memory system gets busy (demo 05: ~200 ns with 8 cores), so more cores are needed.

PA1 (Analyzing Parallel Program Performance on a Quad-Core CPU) exercises this lecture directly. You parallelize an image computation with std::thread and explain the speedup you get. You vectorize functions with a simulated SIMD intrinsics library that reports lane utilization, as simd_emulator.py does for a different kernel. You compile ISPC programs and reason about which inputs make SIMD efficient or inefficient. And you explain why a memory-bound kernel barely speeds up. These notes do not provide solutions; the demos here practise the same skills on sinx, Collatz and FMA chains. The class machines are 4-core Intel CPUs with 2-way Hyper-Threading and 8-wide AVX2, so their numbers differ from the M4’s: W = 8 instead of 4, and hardware threads that the M4 does not have.

Further reading

  • The Fall 2025 slides for this lecture and the 2023 lecture video “A Modern Multi-Core Processor” (Stanford Online YouTube playlist linked from the course page).
  • Kayvon Fatahalian, “From Shader Code to a Teraflop: How GPU Shader Cores Work” (SIGGRAPH 2008/2009 course talk). The origin of this lecture’s “fictitious chip” diagrams.
  • Matt Pharr, “The Story of ISPC” (blog series, 2018). How SIMD programming models came about; essential before Lecture 3.
  • Arm, NEON Intrinsics Reference, and Intel, Intrinsics Guide: look up any intrinsic used in sinx.h.
  • J. L. Hennessy and D. A. Patterson, Computer Architecture: A Quantitative Approach, 6th ed., chapter 3 (ILP and multi-threading) and chapter 4 (SIMD and GPUs).
  • J. D. C. Little, “A Proof for the Queuing Formula: L = λW”, Operations Research, 1961. Where the law used in §6 comes from.

Preview of Lecture 3 — Multi-core architecture (Part II) + ISPC

Demo 05 ended at 159 GB/s, where memory bandwidth begins to limit. Lecture 3 starts there: latency vs. bandwidth (highway and laundry analogies, pipelining), and why a loop that does one multiply per 12 bytes it loads cannot use a fast chip. The second half turns to programming abstractions: ISPC’s SPMD (single program, multiple data) model, where a “gang” of program instances is implemented with exactly the SIMD lanes and masks of today’s lecture. Keep the distinction between what a program means and how a machine runs it; it is the theme of the next lecture.


术语表 (Glossary, English → 中文)

English中文
multi-core processor / core多核处理器 / 核心
instruction stream指令流
execution context执行上下文
fetch / decode取指 / 译码
ALU / execution unit算术逻辑单元 / 执行单元
superscalar execution超标量执行
out-of-order execution乱序执行
branch prediction / misprediction分支预测 / 预测错误
thread / hardware thread线程 / 硬件线程
decomposition / assignment / synchronization分解 / 分配 / 同步
blocked assignment分块分配
data parallelism / data-parallel数据并行
dependency chain依赖链
heterogeneous cores (performance / efficiency)异构核心(性能核 / 能效核)
inlining内联
SIMD (single instruction, multiple data)单指令多数据
SIMD width / laneSIMD 宽度 / 通道
vector instruction / vector register向量指令 / 向量寄存器
intrinsic (function)内建函数(内在函数)
broadcast广播
uniform value统一值(各通道相同的值)
tail (of a vectorized loop)(向量化循环的)尾部
auto-vectorization自动向量化
explicit / implicit SIMD显式 / 隐式 SIMD
execution mask / masking执行掩码 / 掩码屏蔽
coherent / divergent execution一致执行 / 发散执行
lane utilization通道利用率
if-conversion / select条件转换 / 选择
fused multiply-add (FMA)融合乘加
FLOP / GFLOP/s / TFLOP/s浮点运算 / 每秒十亿次 / 每秒万亿次浮点运算
peak throughput峰值吞吐量
stall停顿
prefetching / prefetcher预取 / 预取器
hardware multi-threading硬件多线程
interleaved (temporal) multi-threading交错(时间)多线程
simultaneous multi-threading (SMT) / Hyper-Threading同时多线程 / 超线程
utilization利用率
throughput computing吞吐计算
latency hiding延迟隐藏
Little’s law利特尔法则
memory-level parallelism (loads in flight)访存级并行(同时在途的访存)
outstanding cache miss未完成的缓存缺失
memory bandwidth内存带宽
streaming multiprocessor (SM)流式多处理器
warp线程束
SIMT (single instruction, multiple threads)单指令多线程
HBM (high-bandwidth memory)高带宽内存
operating system scheduler操作系统调度器
← 返回课程目录