Lecture 13 · Domain-Specific Programming Systems and AI-Driven Performance Optimization

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

课程源码 ZIP ↓

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

本篇目录

Maps to: Stanford CS149 Fall 2025, Lecture 13 (Nov 6), slide deck 13_autooptimize (55 slides). Context for Programming Assignment 5 (make the fastest CUDA kernels you can). Sources: the public Fall 2025 slides; J. Ragan-Kelley, A. Adams et al., “Decoupling Algorithms from Schedules for Easy Optimization of Image Processing Pipelines” (SIGGRAPH 2012) and “Halide: A Language and Compiler for Optimizing Parallelism, Locality, and Recomputation in Image Processing Pipelines” (PLDI 2013); R. T. Mullapudi et al., “Automatically Scheduling Halide Image Processing Pipelines” (SIGGRAPH 2016); A. Adams et al., “Learning to Optimize Halide with Tree Search and Random Programs” (SIGGRAPH 2019); A. Ouyang et al., “KernelBench: Can LLMs Write Efficient GPU Kernels?” (2025). Every experiment and number below was written for these notes and run on the author’s machine (Apple M4 Pro; clang 21, macOS 27; numpy 2.5). No real Halide compiler and no LLM is used: the notes build a miniature Halide in Python and check hand-written candidate kernels. Code: code/lecture13/. Reading time: ~75 minutes for the prose; ~15 more for the demos.


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Explain the trade-off between performance (性能), productivity (生产力) and generality (通用性), and why a domain-specific language (DSL, 领域专用语言) gives up generality to get the other two.
  2. Optimize a 3 × 3 box blur (盒式模糊) by hand: the separable (可分离) two-pass form, chunking, fusion (融合), tiling, SIMD, threads. For each step, say whether it changes arithmetic, memory traffic or parallelism.
  3. Explain Halide’s central idea: separating the algorithm (算法), what each pixel’s value is, from the schedule (调度), the order in which values are computed and where they are stored.
  4. Read a Halide schedule (tile, vectorize, parallel, compute_root, compute_at, inlining) and write down the loop nest it stands for. Count its arithmetic, including recomputed halo (光晕区域) values, and its buffer sizes.
  5. Explain the three-way tension every schedule balances: parallelism, locality and redundant work (recomputation, 重计算).
  6. Explain autotuning (自动调优) by measurement and autoscheduling (自动调度) by search with a cost model (代价模型): why the space of schedules is huge, how greedy and beam search work, and why the cost model decides the outcome.
  7. Describe how LLM agents are used to write performance code (generate, run, profile, reflect, edit), what KernelBench measures (fast_p), and why checking a generated kernel is harder than it looks.

0.2 Prerequisites and scope

  • Prerequisites:
    • Lecture 2–3: SIMD, multi-core.
    • Lecture 5: assigning work to threads.
    • Lecture 6: locality, arithmetic intensity, the roofline model.
    • Lecture 9: tiling and fusion for DNN layers. Halide applies the same ideas to image pipelines.
  • Scope: the first half of the deck is Halide, a DSL whose design made automatic optimization possible. The second half is about LLM agents that write kernels. That field is young: these notes explain the ideas and show how to check results, but do not run an LLM.

0.3 Section → code map

SectionIdeaDemo in code/lecture13/
§2the blur optimized by hand, timed01_blur_ladder (uses blur_kernels.h, spin_pool.h)
§3algorithm vs. schedule; lowering; recomputation03_halide_schedules.py (uses minihalide.py)
§4.1autotuning by measurement02_blur_autotune
§4.2–§4.4autoscheduling: search spaces, search, cost models04_autoschedule.py
§5checking machine-written kernels; fast_p05_kernel_checker.py

Run them all with cd code/lecture13 && make run (~12–20 seconds).

0.4 Notation

  • Stencil (模板计算): each output value is computed from a small fixed neighbourhood of input values, like the 3 × 3 window of the blur.
  • MAC: one multiply-add. “MACs per pixel” counts arithmetic per output pixel.
  • W × H: the output image size. The input has a 1-pixel border, (W + 2) × (H + 2), so no version needs boundary code.
  • Func: a Halide function, an image defined at every integer (x, y). Producer / consumer: a Func that another reads / the Func that reads it.
  • Tile (分块): a TW × TH rectangle of the output computed as a unit.

1. Why domain-specific programming systems? (slides 2–10)

1.1 The problem: performance needs experts, and experts are scarce

Every assignment of this course so far has made the same point: getting near the hardware’s peak takes knowledge (SIMD widths, cache sizes, memory bandwidth, synchronization costs) and many careful rewrites. Slide 3 says it bluntly: CS149-educated programmers are hard to find, and optimizing in C++, ISPC or CUDA is low-productivity work, “proof by assignments 1, 2, 3, 4”. Worse, the work must be redone for each new machine and for each slightly different problem (slide 55).

The lecture offers three ways to make performance optimization more productive (slide 2):

  1. Raise the level of abstraction: let the programmer say what to compute and leave more of the how to a system.
  2. Intelligent search: let a machine try many implementations and pick the fastest.
  3. (Emerging) LLMs: use language models’ problem-solving and code-writing to do some of the optimization work.

1.2 The triangle: performance, productivity, generality (slides 4–6)

Pat Hanrahan’s triangle (slide 4) puts the three things we want from a language at three corners:

  • Performance: programs run close to the machine’s limits.
  • Productivity: programs are quick to write, read and change.
  • Generality: the language can express any program.

Popular languages sit on an edge, not in the middle (slide 5). C, C++ and CUDA give performance and generality, but low productivity: you manage threads, SIMD and memory by hand. Python, Java and JavaScript give productivity and generality, but not peak performance. The ideal language would sit in the middle, and nobody has built one.

Slide 6’s answer is to give up generality. A language that only has to express one domain (image processing, dense linear algebra, graph analytics, deep learning) can offer high-level primitives that are both easy to use and fast. The system knows the domain well enough to implement those primitives efficiently.

1.3 What a DSL is (slides 7–8)

A domain-specific language is a programming language whose expressiveness is deliberately restricted to one domain. It is usually high-level, declarative (声明式) (you state the result, not the steps) and deterministic (确定性) (same input, same output, regardless of how it is parallelized).

The goals (slide 8):

  • quickly write a high-performance program for one machine;
  • write one program and run it efficiently on different machines.

The means:

  • primitives that match the operations the domain uses all the time;
  • a system that uses domain knowledge to pick algorithms and parallelization strategies for each target machine.

Sometimes the hardware is even designed around the DSL’s abstractions (Lecture 10’s accelerators). The cost: you lose generality. Programs outside the domain cannot be written, or cannot be written efficiently.

You already use DSLs. SQL is one: you declare the result table and the database picks join orders and indexes. So are TensorFlow and PyTorch graphs, where you write layers and the framework picks kernels. In Lecture 11 ThunderKittens was a DSL for GPU AI kernels. This lecture’s main example is Halide, a DSL for image processing (slides 9–10). It ships in the camera pipelines of Google’s phones: HDR+ and parts of portrait mode, over 2,000 Halide functions in HDR+ alone (slide 26). Instagram and Adobe use it too.


2. A tutorial on high-performance image processing (slides 11–22)

Before looking at Halide, we optimize one tiny image-processing program by hand. That shows what a DSL must automate, and why the hand-optimized result is hard to live with.

2.1 The 3 × 3 box blur (slides 13–15)

A box blur replaces every pixel by the average of the 3 × 3 window around it:

for (int j = 0; j < HEIGHT; j++)
  for (int i = 0; i < WIDTH; i++) {
    float tmp = 0.f;
    for (int jj = 0; jj < 3; jj++)
      for (int ii = 0; ii < 3; ii++)
        tmp += input[(j+jj)*(WIDTH+2) + (i+ii)] * weights[jj*3 + ii];   // weights = 1/9
    output[j*WIDTH + i] = tmp;
  }

That is 9 MACs per pixel, and N² per pixel for an N × N filter.

2.2 Two passes: less arithmetic, more memory (slides 16–18)

A box filter is separable. Averaging a 3 × 3 window equals first averaging each row of 3 (a horizontal 1D blur), then averaging 3 of those results vertically. The two-pass blur:

  • writes the horizontal pass into a temporary image tmp_buf of W × (H + 2) values;
  • then runs the vertical pass from tmp_buf.

That is 6 MACs per pixel, and 2N instead of N² for an N × N filter.

Slide 18 analyzes its locality:

  • Input: each value is reused three times, in consecutive iterations of the inner loop. That is perfect cache behaviour.
  • tmp_buf: each value is also used three times, but three rows apart, so the cache must hold three image rows to catch the reuse.
  • The real cost: writing and re-reading tmp_buf is traffic that “is not intrinsic to the computation”. The blur only has to read the input once and write the output once. The two-pass version also writes and reads a whole extra image, so each output pixel costs more bytes of memory traffic than in the 2D version: its arithmetic intensity is lower. Fewer operations, but more memory traffic.

2.3 Chunking: producer-consumer locality (slides 19–20)

The fix is to stop producing tmp_buf for the whole image before consuming any of it. Interleave the two passes, so each tmp value is consumed while it is still in cache.

  • Chunked, version 1 (slide 19). For each output row, compute only the 3 rows of tmp_buf it needs, then that output row. The buffer is 3 rows and stays in cache. But each tmp row is now computed three times, once for each output row that uses it, so arithmetic rises to 3 × 3 + 3 = 12 MACs per pixel.
  • Chunked, version 2 (slide 20). Compute CHUNK + 2 rows of tmp_buf, then CHUNK output rows. Only the 2 overlap rows (the halo) are recomputed. The cost per pixel is 3 (CHUNK + 2)/CHUNK + 3: 6.375 at CHUNK = 16, which tends to 6 as CHUNK grows. Choose CHUNK so that the buffer still fits in cache.

This is the trade-off Halide’s authors put at the centre of their work. Pick a point between “compute everything once and store it” (two-pass: least arithmetic, most traffic) and “recompute everything where it is needed” (chunked v1, or the direct 2D blur: least storage, most arithmetic). Chunking with a well-chosen size gets nearly the best of both.

2.4 Still not done (slides 21–22)

The loops above still use one core and no SIMD. Slide 22 shows the end result, an optimized C++ blur with SSE intrinsics:

  • 256 × 32 tiles for cache hit rate;
  • the two passes fused, so tmp data is read from cache;
  • the image split vertically across cores.

It runs about 10× faster than the original two-pass code on a quad-core CPU. It is also specific to SSE (not AVX2), CPU-only, and nearly impossible to read. Any change to the algorithm means redoing the optimization.

2.5 The ladder measured on the author’s machine

Demo 01 implements each version and times it (best of 5) on two image sizes:

  • 1024 × 1024: the slides’ size, small enough that every buffer fits in the 16 MiB L2;
  • 4096 × 4096: 64 MiB per image, so buffers live in DRAM.

The scalar versions have auto-vectorization turned off, as “we have not used SIMD yet” assumes. Representative run, 4096 × 4096:

versionMACs/pxtemp buffertimevs. two-pass
2D direct, scalar (slide 15)9—14.8 ms0.85×
two-pass, scalar (slide 17)6.064 MiB12.5 ms1.00×
chunked v1, scalar (slide 19)1248 KiB21.4 ms0.59×
chunked v2, CHUNK = 16, scalar (slide 20)6.4288 KiB12.9 ms0.97×
two-pass, compiler-vectorized6.064 MiB3.4 ms3.7×
CHUNK = 16, compiler-vectorized6.4288 KiB3.0 ms4.2×
fused 256 × 32 tiles, NEON intrinsics, 1 core6.234 KiB7.9 ms1.6×
fused 256 × 32 tiles, same loops without intrinsics, 1 core6.234 KiB8.6 ms1.5×
fused 256 × 32 + NEON, 8 threads (slide 22)6.2272 KiB2.3 ms5.4×
two-pass, compiler-vectorized, 8 threads6.064 MiB1.15 ms10.9×
full-width chunks of 32 rows, compiler-vectorized, 8 threads6.24.2 MiB0.65 ms19.2×
copy input → output, 8 threads (the memory floor)0—0.77 ms—

Across runs the times varied by up to ~35%: scalar two-pass took 12.5–17 ms, and the best threaded version 0.65–0.84 ms. The ratios held. What the table teaches:

  1. Arithmetic does not predict time. On one scalar core, the 2D blur (9 MACs) is about as fast as two-pass (6), and chunked v1 (12) is slowest. A scalar core is limited by how many instructions it can issue (loads, multiply-adds, stores), not by memory. Two-pass’s extra 64 MiB of traffic is completely hidden at this speed.
  2. The compiler vectorizes simple loops by itself. Allowing auto-vectorization makes two-pass 3.7× faster with no code change. The hand-written NEON tile is no faster than the same tile written as plain loops. On this compiler the intrinsics only made the code harder to read.
  3. Once the code is fast, memory traffic dominates, and slide 18 comes true. With 8 vector threads, two-pass (which sends tmp_buf through DRAM) takes 1.15 ms. The fused full-width chunks take 0.65 ms, 1.8–2.6× less across runs. The fused version moves about 135 MB, the two-pass version about 270 MB.
  4. The fastest version runs at the speed of memory. At 0.65 ms it moves its 128 MiB at ~205 GB/s, the same as a plain copy (175–210 GB/s across runs). Nothing but moving fewer bytes could make it faster, for example fusing the blur with whatever stage comes next.
  5. The slides’ tile was not the right tile for this machine. With 8 threads, the 256 × 32 tiles are 3.6× slower than tiles that span a full row; on one core they lose even to unfused, vectorized two-pass. A 256-float tile row is only 1 KiB, so each image row is read as 16 short pieces, scattered in time. Our explanation, which we did not measure directly, is that the M4’s hardware prefetchers (预取器) follow long sequential streams well and many short ones poorly. The slides’ tile was chosen for an older quad-core CPU with much smaller caches, where a small tile buffer had to stay in L1. Here a 34-row buffer of a full 4096-float row (544 KiB per thread) fits in the 16 MiB L2.
  6. The CHUNK sweep shows both forces at once (compiler-vectorized, one core). Small chunks recompute too much (CHUNK = 1: 12 MACs, 5.5 ms), and a single chunk spanning the whole image is two-pass again (3.5 ms). The best chunk sizes, 32–256 rows (2.6–2.8 ms), lie in between.

The best threaded version is 18.5–20× faster than scalar two-pass, more than slide 22’s “~10×”, because this machine has 8 fast cores. But look at what it took: about 60 lines of C++ for the tile and the thread loop, plus a header-only thread pool, all for a 3 × 3 average. Point 5 also means the right tile shape depends on the machine. The code would need retuning on a different CPU. That is what Halide sets out to fix.

Pause and think. The two-pass and chunked versions compute the same values. What exactly differs between them? Only the order of the loops and the size of the buffer between them. Keep that in mind for §3.


3. Halide: separating the algorithm from the schedule (slides 23–37)

3.1 The language (slides 23–26)

Halide is embedded in C++. A program is a set of Funcs:

Var x, y;
Func blurx, blury, bright, out;
blurx(x, y)  = 1/3.f * (in(x-1, y) + in(x, y) + in(x+1, y));
blury(x, y)  = 1/3.f * (blurx(x, y-1) + blurx(x, y) + blurx(x, y+1));
bright(x, y) = min(blury(x, y) * 1.25f, 255);
out(x, y)    = lookup(bright(x, y));
Buffer<uint8_t> result = out.realize(1024, 1024);
  • A Func maps integer coordinates to values. Conceptually it is an infinite (but discrete) image, defined at every (x, y).
  • A Func is defined by a side-effect-free expression (无副作用表达式) that says how to compute its value at one point from values of other Funcs.
  • The program forms a DAG (directed acyclic graph, 有向无环图) of Funcs (slide 24): in → blurx → blury → bright → out, with a lookup table on the side.
  • Nothing in the program says in which order to visit pixels, which values to store, or how to parallelize. Iteration is implicit (slide 25). realize(1024, 1024) asks for the output on that domain, and the system works out what it needs.

Real pipelines are long (slide 26): 9 Funcs for an unsharp mask, 30 for camera RAW processing, 103 for a local Laplacian filter, over 2,000 in Google’s HDR+.

3.2 The default meaning, and the second language (slides 27–29)

The simplest implementation of a Halide program is the one slide 27 shows. It computes each Func, in order, over the whole region its consumers need, and stores it. For the blur this is exactly the two-pass C code of §2.2.

How does the system know that blurx is needed on W × (H + 2) values and the input on (W + 2) × (H + 2)? This is bounds inference (边界推断): from out(x, y) = ... blurx(x, y-1) ... blurx(x, y+1) it follows that computing out over rows 0..H−1 needs blurx over rows −1..H. That is possible because every access is a known offset from (x, y) (§3.6).

Slide 28 states a design principle: pick representations that are natural for the programmer and let the system provide services. The algorithm language is natural for image processing, but it says nothing about performance. So Halide adds a second language, the schedule, for the decisions that §2 made by hand (slide 29):

out.tile(x, y, xi, yi, 256, 32).vectorize(xi, 8).parallel(y);
blurx.compute_at(out, x).vectorize(x, 8);

In words:

  • iterate over out in 256 × 32 tiles;
  • vectorize the inner x loop 8-wide;
  • run the rows of tiles on parallel threads;
  • compute the part of blurx that each tile needs, inside the tile loop;
  • vectorize blurx’s inner loop.

These two lines are slide 22’s unreadable C++.

3.3 Scheduling primitives (slides 30–34)

There are two kinds of decisions:

1. How to iterate over a Func’s domain (slide 30): loop order, tiling, vectorization, unrolling and parallelization of the loops that compute it. tile(x, y, xi, yi, 256, 32) splits the 2D loop into an outer pair (which tile) and an inner pair (which pixel within the tile). vectorize maps an inner loop to SIMD lanes. parallel hands a loop’s iterations to threads.

2. Where to compute each producer, relative to its consumer’s loops. It can go at the root, at some loop level of the consumer, or inline:

schedule for blurxloop nest (slide)bufferblurx computed per output pixel
compute_root()before out’s loops, whole image (slide 31)W × (H+2)1.0 (once)
compute_at(out, x) (out tiled)once per tile, the tile plus its halo (slide 33)256 × 3434/32 = 1.06
compute_at(out, y)once per output row: 3 rows (= chunked v1)W × 33
compute_at(out, xi)once per output pixel: 3 values (slide 32)1 × 33
inline (the default)substituted into out’s expressionnone3

Demo 03 lowers schedules to loop nests the way slides 31–34 draw them. Here is its output for slide 34’s schedule on a 1024² image:

allocate in[1026 x 1026]   (input)
allocate out[1024 x 1024]
parallel for y in 32 tile rows:
  for x in 4 tile columns:
    allocate blurx[256 x 34]   (per tile)
    for blurx_y in 34 rows:
      for blurx_x in 256 columns, 8 at a time (SIMD):
        blurx(x, y) = (((in(x-1, y) + in(x, y)) + in(x+1, y)) / 3)
    for yi in 32 rows of the tile:
      for xi in 256 columns, 8 at a time (SIMD):
        out(x, y) = (((blurx(x, y-1) + blurx(x, y)) + blurx(x, y+1)) / 3)

3.4 One algorithm, many schedules: verified

The central promise is that a schedule changes when and where values are computed, never which values. Demo 03’s miniature Halide (minihalide.py) executes schedules for real:

  • it walks the loop nest;
  • it allocates each buffer for exactly the region bounds inference says that loop iteration needs;
  • it evaluates expressions over whole regions with numpy;
  • it counts every arithmetic operation.

Nine schedules of the blur on a 512 × 64 test image:

scheduleidentical to reference?ops/px countedlargest intermediate buffermodel, 4096²
blurx inline (Halide’s default)yes12.0none33.6 ms
blurx root = two-passyes6.0933,792 values16.8 ms
blurx at row = chunked v1yes12.01,53633.6 ms
tile full-width × 16, blurx at tile = CHUNK 16yes6.3759,21617.8 ms
tile 256 × 32, blurx at point (slide 32)yes12.0367.1 ms
tile 256 × 32, blurx at tile (slide 33)yes6.198,70417.3 ms
… + vectorize 8 + parallel (slide 34)yes6.198,7043.5 ms
two-pass, vectorize 8 + parallelyes6.0933,7922.4 ms
full-width × 32 tiles + vectorize 8 + parallelyes6.1917,4081.1 ms

Every output is bit-identical, not just close. The same expression is evaluated in the same order at every pixel, and floating-point additions are never reassociated, so even the rounding agrees. The counted operations match slides 15–20’s formulas: 6.09 = 3 × 66/64 + 3 on the 64-row test image, and 6.19 = 3 × 34/32 + 3.

One subtlety: inlining blurx gives 12 operations per pixel, not the 9 of slide 15’s direct 2D code. Halide does not rewrite your algorithm. You wrote “three horizontal sums of three, then a vertical sum of three”, and inlining recomputes each horizontal sum wherever it is used. Getting 9 would take a different algorithm, one sum of nine.

The last column comes from estimate(), a cost model described in §4.3. It ranks slide 34’s 256 × 32 schedule (3.5 ms) behind full-width tiles (1.1 ms), the same order demo 01 measured (2.3 vs. 0.65 ms).

3.5 Composing choices: longer pipelines

With more Funcs, each one gets its own choice. Here is slide 23’s pipeline (blur, brighten, lookup) under schedules that are all vectorized and parallel (demo 03, Part D; model predictions for 4096²):

scheduleops/pxmodel
every Func a separate pass (all compute_root)9.14.6 ms
blurx root, the rest inline9.12.4 ms
everything inline15.01.5 ms
full-width × 32 tiles, blurx at tile, the rest inline9.21.1 ms

Two lessons:

  • Pointwise Funcs should simply be inlined. bright and the lookup each use their input once, so inlining them costs no recomputation and saves a buffer. Only stencils, which read a neighbourhood, force a real decision.
  • One pass per Func is the worst option once code is fast. Every intermediate image makes a round trip through DRAM. This is exactly the “one kernel per operator” problem of Lectures 9 and 11, where the cure was the same fusion.

The unsharp mask is different. There the input is read by two Funcs (a DAG, not a chain), and the 5 × 5 blur is costly. Inlining everything recomputes the blur at every pixel: 53 ops/px. All-root moves three images through DRAM. Tiles with blur_x computed per tile get both low arithmetic (22 ops/px) and low traffic.

3.6 Why Halide can do this: the constraints (slides 35–36)

Halide’s philosophy (slide 35):

  • The programmer describes the algorithm, and also knows how to schedule it but finds that slow and tedious. So Halide gives them a second language for those decisions: loop structure, unrolling, vectorization, multi-core parallelization.
  • The compiler is not smart. It does not decide anything. It mechanically carries out the schedule using the target machine’s mechanisms (pthreads, AVX intrinsics, CUDA…), and gets every detail right: boundary loops, buffer sizes, index arithmetic.

To provide this service, the language is restricted (slide 36):

  • computation on regular N-D domains;
  • feed-forward pipelines only, plus special support for reductions and fixed-depth recursion;
  • all dependencies inferable by the compiler.

The last constraint is what makes everything work. Since every access is a known offset (or a bounded region), the compiler can:

  • infer bounds;
  • size buffers;
  • check that a schedule is legal.

Demo 03 rejects two illegal schedules with exactly this check. One computes blurx once per row while its consumer blury is computed once per tile: the tile needs rows that no longer exist. The other uses compute_at(out, tile) when out is not tiled.

3.7 Results (slide 37)

The original Halide papers reported two results:

  • Camera RAW pipeline: the hand-tuned version was 463 lines of ARM NEON assembly. The Halide version had 2.75× less code and ran 5% faster.
  • Bilateral filter: the original was 122 lines of C++. Halide needed 34 lines of algorithm plus 6 of schedule. On the CPU it ran 5.9× faster than the original; on the GPU, 2× faster than hand-written CUDA.

For the blur, our two lines of algorithm and two lines of schedule replace 61 lines of C++ (blur_tile and blur_fused in blur_kernels.h). And retargeting the Halide version means changing the schedule, not rewriting the code.


4. Letting the machine choose the schedule (slides 38–44)

4.1 Autotuning by measurement

Halide made scheduling easier to express. It did not make it easier to choose. Slide 38: more than 80 programmers at Google write Halide, and very few of them are trusted to write schedules. The obvious remedy is to let a program try schedules and keep the fastest: autotuning.

Demo 02 does this for real on the fused blur. It measures 8 tile widths × 9 tile heights = 72 schedules on 8 threads, at 4096², best of 5 each. One representative run:

  • Tile shape matters a lot. The fastest schedule (a full-width row × 32 rows, 0.61 ms) and the slowest (32 × 1, 40.6 ms) differ by 67×. The slides’ 256 × 32 took 2.33 ms: 3.8× the best, rank 41 of 72. Across runs the best tile always spanned a full row (TW = 4096) with 16–64 rows, and the slides’ tile was 3.3–5.4× slower.

  • Best schedules do not transfer. On one thread, the best tile is a full row × 64–256 rows. The 1-thread winner used on 8 threads was 1.35–1.84× slower than the 8-thread winner. One plausible cause: big per-thread buffers stop fitting in the shared L2 once 8 threads each have one. On the 1024² image the best tile was a full row (1024) × 8–128 rows, though at 30–50 µs per run the order there is noisy. Change the machine or the problem, and you must tune again.

  • Measurements are noisy. On a quiet machine, 15 single runs of the same schedule varied by 1.1–1.5×. With other programs running, they varied by up to 22× in one run: the OS paused one worker thread, and a few large tiles waited on it. The differences among the top five schedules (~30%) are often smaller than that noise. So an autotuner needs best-of-N or median timings, and must re-measure its finalists.

  • Search without measuring everything. Demo 02 computes, exactly, how good the best of k randomly chosen schedules is:

    k schedules measured1248163272
    expected best / true best6.1×2.9×2.1×1.6×1.3×1.1×1.0×

    Greedy hill climbing (贪心爬山) moves to a faster neighbour (tile width or height doubled or halved) until none is faster. It uses about 11 measurements, but across runs only 11–34 of the 72 starting points ended within 10% of the best. The landscape has local minima, made worse by noise.

4.2 The space of schedules is enormous (slides 39–40)

Seventy-two schedules can be measured exhaustively in seconds. Real pipelines cannot. Even in our toy space (demo 04, Part A):

  • the output has 84 choices (21 tilings × vectorize or not × parallel or not);
  • every other Func has 6 (inline, root serial or parallel, at tile, at row, at point).
pipelinecombinationslegal
blur (2 Funcs)504500
slide 23 (4 Funcs)18,1448,768
8 Funcs~10^7—
20 Funcs~10^17—
2,000 Funcs (HDR+)~10^1557—

Real Halide has far more choices per Func (loop orders, split factors, storage levels, unrolling…).

Slide 39 models scheduling as a sequence of choices. Start from the output, since every producer’s placement depends on its consumers’ loops. Choose its loop structure. Then, for each Func walking backwards through the DAG, choose where it goes in the existing loop nest (its compute_at) and its tile sizes. Slide 40 searches this tree of partial schedules with greedy search (take the best choice at each step) or beam search (束搜索) (keep the best B partial schedules at each step). Both need a way to score a partial schedule quickly.

Demo 04 implements both over our toy space, using estimate() as the score:

pipelineexhaustive optimumgreedybeam 4beam 16random, 100 samples
blur1.08 ms (500 evaluations)1.00× (90 evaluations)1.00×1.00× (178 evaluations)1.43×
slide 231.10 ms (8,768)1.15× (102)1.15×1.00× (334)1.42×
unsharp1.78 ms (8,768)1.22× (102)1.22×1.00× (314)1.02×

Beam search with B = 16 found the exhaustive optimum with ~4% of the evaluations. Greedy is cheaper but can lock in an early choice that is good on its own and bad in combination. On an 8-stage chain, too big for exhaustive search (~10^7), beam 16 reached its best schedule in 585 evaluations; random sampling needed ~1,000 draws to come within 2% of it.

The schedules found are instructive. For the 8-stage chain, beam search computes the first stage at root and every later stage per tile of full-width × 64. The two extremes are terrible:

  • every stage a separate parallel pass: 8.9 ms predicted, because 8 images make round trips through DRAM;
  • every stage inlined into the output: 1,100 ms, because each pixel recomputes the stages beneath it, 3^8-fold.

4.3 The cost model decides everything (slide 41)

Search needs to score hundreds of thousands of candidate schedules, and compiling and benchmarking each one would take far too long. So the search uses a cost model: a function that predicts a schedule’s run time from the program and the schedule.

Our model (minihalide.estimate) is a roofline (屋顶线模型), as in Lecture 6, with one roof per resource:

time = max(compute time, L2 time, DRAM time) + overheads

  • Compute: every computed value × its operations, at a scalar or vector rate, divided by the cores the parallel loop can keep busy (with load imbalance).
  • Memory: the input and output once, plus halo re-reads. Every buffer is written and read back: free if it fits in L1, at L2 bandwidth if it fits in its share of L2, otherwise at DRAM bandwidth. DRAM bandwidth is reduced for short contiguous runs, the effect demo 01 found.
  • Overheads: per parallel task and per buffer allocation.

Its constants were fitted to demos 01 and 02, so it is not an independent prediction:

  • 6 scalar and 25 vector operations per ns per core;
  • 180 GB/s of DRAM bandwidth for all cores, 72 GB/s for one core;
  • a “half bandwidth” run length of 2.5 KiB.

How good is it? Demo 04, Part D, predicts all 72 tile shapes that demo 02 measured, and compares:

  • Ranking: the Spearman rank correlation (斯皮尔曼秩相关) between predicted and measured times was 0.85–0.87 across runs, where 1 means the same order.
  • Top choices: the model’s favourite was 1.0–1.35× the measured best, and the best measured schedule among its top 5 was the true best.
  • Absolute error: predictions ran 0.8–8× the measurements, median ~1.4–1.7×. They were worst for very narrow tiles, where the model overestimates the prefetching penalty.

So a crude model ranks well enough to find good candidates, and then a few real measurements pick the winner.

Adams et al. 2019 replaced the hand-written formula with a learned one. A small neural network (an MLP, multi-layer perceptron) is trained on a large database of randomly generated Halide programs that were compiled and benchmarked. It runs in tens of microseconds per schedule: 1.4 million schedules scored in 166 seconds. It does not predict time directly. It outputs 27 coefficients that are plugged into a hand-crafted cost formula, so it combines learning with structure humans know is right.

4.4 Results and the takeaway (slides 42–44)

The autoscheduler’s schedules are comparable to the best known human-written ones for image pipelines on CPUs (slide 42): you would have to work hard to beat it by hand. An earlier autoscheduler (Mullapudi 2016) already matched experts’ throughput within minutes, where the experts needed up to two hours (slide 43).

The deeper takeaway (slide 44): Halide’s primitives were designed to make human experts productive. That high-level vocabulary of schedules turned out to also give a clear, enumerable space for a machine to search. Compare searching over “all C++ programs that compute the blur”, which is an impossible space. The abstraction made automation possible.


5. LLMs writing performance code (slides 45–54)

5.1 Trial and error with reflection (slide 46)

Large language models can write CUDA. Slide 46 shows how an agent (智能体) loop uses one:

  1. Prompt: “You are a performance optimization engineer in CS149. Rewrite this PyTorch code as high-performance CUDA”, plus the optimization principles from class.
  2. Compile and run the result: is it correct? How long does it take? Profile it: SM utilization, DRAM utilization, L2 hit rate.
  3. Prompt again with the code and the profile: “reflect on what might be slowing the program down”, then “make an edit that addresses it”.
  4. Repeat.

This is the same generate–measure loop as autotuning. The difference is that the “search step” is a language model proposing an edit, guided by profiler output, instead of a fixed menu of schedule choices. The space is no longer enumerable: any program can come out.

5.2 KernelBench (slide 47)

KernelBench (Ouyang et al., 2025) is a benchmark of a few hundred PyTorch programs at three levels:

  • single operators, such as a matmul or a convolution;
  • short sequences of operators that invite fusion;
  • whole model architectures.

The agent must produce a CUDA kernel that is correct (it matches PyTorch’s output on random inputs, within a tolerance) and fast. The headline metric is fast_p: the fraction of tasks where the generated kernel is correct and faster than PyTorch by more than a factor p. fast_0 is simply correctness, and fast_1 means beating the baseline at all.

5.3 Why checking a generated kernel is hard

Each fast_p number rests on one judgement: is this kernel correct? Demo 05 builds a small KernelBench-style harness for three tasks: row softmax, linear + ReLU, and layernorm. It tests 12 candidate kernels written to imitate commonly reported failure modes. Three are correct; nine are subtly broken:

candidatewhat it does wrongnaive harnessthorough harness
softmax_unstableskips the max subtraction; exp overflows for logits > 88PASSFAIL (NaN on large logits)
softmax_block64processes rows in blocks of 64, forgets the last partial blockPASSFAIL (257 rows)
softmax_cachedremembers the result per input shapePASS, “6,300×”FAIL (stale answers)
softmax_inplacecorrect output, computed in the caller’s arrayPASSFAIL (input modified)
softmax_fp16computes in half precisionPASSFAIL (error 1.3e-3)
linrelu_nobiasforgets the biasPASS (the test’s bias is 0)FAIL
linrelu_tiled32drops a last partial 32-column tilePASSFAIL (1000 columns)
layernorm_onepassvar = E[x²] − E[x]²: catastrophic cancellation (灾难性抵消)PASS (zero-mean data)FAIL (mean 1000)
layernorm_noepsdrops εPASSFAIL (constant rows → NaN)

The naive harness is the kind of quick check many people write:

  • one shape, all dimensions multiples of 64;
  • standard-normal inputs and zero bias;
  • an elementwise tolerance of 1e-2;
  • correctness checked on the same input buffer that was timed.

The thorough harness varies everything the naive one holds fixed:

  • odd shapes (257 × 1000, 3 × 37);
  • large, offset and constant-row inputs;
  • random bias and fresh data for every trial;
  • a check that inputs are unmodified, and that every output is finite;
  • a tolerance relative to the output’s scale (1e-4);
  • timing over several different inputs, then one more check on a fresh input afterwards.

All nine broken kernels pass the naive harness. Each exploits something it never varies.

Now imagine an agent that submits its fastest kernel that passes. Under the naive harness it submits the stale cache for softmax (reported speedup ~6,300×) and the bias-less kernel for linear + ReLU. Judged by the thorough harness, fast_0 of those submissions is 0.33. Under the thorough harness it submits the correct kernels, with fast_0 = 1.00. Optimizing hard against a weak check reliably selects broken solutions. This is the same lesson as Goodhart’s law: a measure that becomes a target stops being a good measure. In February 2025, a widely shared report of LLM-written CUDA kernels with very large speedups was partly withdrawn when users found that some kernels exploited a loophole in the evaluation code; the authors acknowledged it and fixed their harness. Production harnesses also run candidates in a separate process, so a kernel cannot reach the reference’s outputs or the timer.

Two more points from demo 05:

  • Tolerance is a policy decision. Half precision is about 1e-3 accurate relative to the output’s scale. Correct float32 kernels that only reorder operations agree to ~1e-7, and dropping ε changes results by ~5e-6. Whether softmax_fp16 is “correct” depends on what the application needs, so decide that before measuring speed.
  • Honest speedups were modest. Fewer temporary arrays and in-place updates gave 1.0–1.2× in numpy. Huge reported speedups deserve the most suspicion.

5.4 DSLs help agents, too (slide 48)

An agent writing raw CUDA must get every index and every synchronization right, and LLMs make exactly those mistakes. Writing in a kernel DSL changes the job: the LLM assembles high-performance primitives instead of writing low-level code, so there are fewer places to go wrong. Examples are Triton, CUTLASS/CuTe, TileLang, and ThunderKittens from Lecture 11. The challenge: these languages are newer and less used, so there is less training data. Slide 48 expects that to resolve with time.

5.5 How agents could improve with experience (slides 49–54)

The open question on slide 49 is whether an LLM agent can be a great CS149 student, and at what token cost. Slides 50–54 sketch four ways an agent could improve with experience:

  1. Fine-tune a model on the agent’s own successful optimization trajectories for one kind of task (slide 50). This needs many tasks and the ability to fine-tune large models.
  2. A database of example solutions (slide 51): the agent stores good solutions to practice problems, including the sequence of optimization decisions, not just the final code. When given a new problem, it retrieves the most relevant ones. Slide 52 shows such an agent solving more problems over time when writing library functions for a domain-specific accelerator.
  3. Prompt optimization (slide 53): a second model inspects past optimization runs and summarizes them into facts and principles, which are added to the agent’s prompt.
  4. Combine search and agents (slide 54): use exhaustive, Halide-autotuner-style search together with agentic editing. The optimization cost is very high, but some of the best results come from this.

The lecture leaves an open debate (slide 55): is the lasting value in the DSL design, which makes the space searchable and the code checkable, or in the agent, which can explore spaces no DSL captures? The course’s bet is that the best performance engineers of the future will do both. They will think in abstractions, work alongside automatic tools, and know how to check what those tools produce.


6. Summary of the lecture (slide 55)

  • Performance optimization needs expertise, is tedious even for experts, and must be repeated for every new machine and every slightly different problem.
  • The stakes are large: companies spend tens to hundreds of millions of dollars a year on AI compute, so a strong case exists for automation.
  • Two routes: higher-level abstractions (DSLs such as Halide) make optimization more productive for humans and define spaces a machine can search. LLM agents bring problem-solving to spaces no DSL captures, but their output must be checked carefully.

Summary

  • A DSL trades generality for performance and productivity. It restricts the language to one domain, and the system uses domain knowledge to implement high-level primitives well on each machine.
  • Hand-optimizing a 3 × 3 blur means trading arithmetic against memory traffic:
    • separable two-pass: fewer operations, more traffic;
    • chunking and fusion: producer-consumer locality, at the cost of recomputing halos;
    • tiling, SIMD and threads: on top of those. On the author’s machine the best version runs at memory speed, 18–20× faster than scalar two-pass. The tile shape the slides chose is 3–5× slower than full-width tiles here.
  • Halide separates the algorithm (pure functions of (x, y)) from the schedule (tile, vectorize, parallel, compute_root, compute_at, inline). Every schedule computes bit-identical results. The schedule decides arithmetic (recomputation), buffer sizes (locality) and parallelism. Restricting the language to inferable dependencies is what lets the compiler size buffers and check legality.
  • Autotuning by measurement works on small spaces but needs best-of-N timing, and its results do not transfer across machines or sizes. Autoscheduling searches enormous spaces (greedy, beam) with a cost model. A crude roofline model ranked 72 real schedules with Spearman ≈ 0.86. Halide’s autoscheduler learns its model from benchmarked random programs.
  • LLM agents iterate generate → run → profile → reflect → edit. KernelBench scores them with fast_p. A weak correctness harness lets broken kernels through, and an optimizing agent will find them. Thorough checking (shapes, value ranges, fresh inputs, mutation and NaN checks, a deliberate tolerance policy) is part of the job.

Common pitfalls

  • Counting operations instead of bytes. Two-pass has fewer operations than the 2D blur, but once the code is fast, its extra memory traffic is what you pay for.
  • Copying a tile size from a paper or slide. Tile shapes depend on cache sizes, prefetchers, core counts and image sizes. Measure on your machine, or let a tuner do it.
  • Writing intrinsics before checking the compiler. clang vectorized the plain loops of the blur as well as hand-written NEON. Look at what the compiler already does before writing unreadable code.
  • Timing short parallel loops with thread creation inside. Creating 8 threads costs ~0.1 ms, as long as a whole 1024² blur. Keep a pool of workers alive.
  • Trusting one measurement. Single runs of the same schedule varied by up to 22× on a busy machine. Use best-of-N or medians, and re-measure finalists.
  • Expecting Halide to change your algorithm. Inlining a two-pass blur gives 12 operations per pixel, not 9. The schedule cannot turn three sums of three into one sum of nine.
  • Checking a generated kernel on one shape with one random input. Vary shapes (non-multiples of block sizes), value ranges (large, offset, constant), parameters (non-zero bias), and use fresh data after timing.
  • Choosing a tolerance after seeing the results. Decide the accuracy the application needs first: half precision gives ~1e-3, float32 reorderings ~1e-7.

Exercises

  1. Chunk size. For the 3 × 3 two-pass blur computed in chunks of C rows, the arithmetic is 3 (C + 2)/C + 3 MACs per pixel. What is the smallest C within 5% of the ideal 6? For a 4096-wide float image, how big is the buffer then?

    AnswerWithin 5% of 6 means at most 6.3, so 3(C+2)/C ≤ 3.3 and 6/C ≤ 0.3, giving C ≥ 20. The buffer holds C + 2 = 22 rows × 4096 floats × 4 B = 352 KiB. That is too big for a 128 KiB L1 but fits easily in L2, consistent with demo 01's CHUNK sweep, where chunks of 32–256 rows were fastest.
  2. Separable filters. A 7 × 7 box blur is applied to a 4096 × 4096 image. How many MACs does the direct 2D version need, and how many does a full two-pass version need? How much extra memory traffic does the two-pass version cause, in MB, for float data?

    AnswerDirect: 49 MACs per pixel, 49 × 4096² ≈ 822 M MACs. Two-pass: 7 + 7 = 14 MACs per pixel (slightly more for the 6 extra rows of the horizontal pass), ≈ 235 M MACs, 3.5× less arithmetic. The temporary image is 4096 × 4102 floats ≈ 67 MB, written once and read once: ≈ 134 MB of extra traffic, on top of the ~134 MB the blur must move anyway (read input, write output).
  3. Lowering. Write the loop nest for out.tile(x, y, xi, yi, 64, 64); blurx.compute_at(out, yi);. How big is blurx’s buffer, and how many blurx values are computed per output pixel? Which of the slides’ versions is this, inside each tile?

    Answerfor each tile row → for each tile column → for yi in 64 rows: allocate blurx[64 × 3]; compute the 3 rows × 64 values of blurx this output row needs; for xi in 64: out = …. The buffer holds 192 values, and 3 blurx values are computed per output pixel, so 3 × 3 + 3 = 12 ops per pixel. Inside each tile this is chunked version 1 (slide 19).
  4. Legality. In slide 23’s pipeline (in → blurx → blury → bright → out), out is tiled. Which of these schedules are legal? (a) blurx at tile, blury at row; (b) blurx at row, blury at tile; (c) blurx root, blury at point; (d) blurx at point, blury inline.

    AnswerA producer must be computed at the same loop level as its consumers or outside it. (a) Legal: blury's row needs three rows of blurx, and the whole tile's blurx is available. (b) Illegal: blury is computed once per tile, but blurx exists only for one row at a time. (c) Legal. (d) Legal. blury is inlined into bright, and bright is inlined into out, so blury is evaluated at every output pixel. blurx computed per point gives it exactly the values it needs. Demo 03's validator rejects only (b).
  5. Search budget. Our toy space gives the output 84 choices and every other Func 6. Adams et al.’s learned model scored 1.4 M schedules in 166 s. How long would that model need to score every schedule of a 10-Func pipeline? And of a 12-Func pipeline?

    AnswerThe rate is 1.4 M / 166 s ≈ 8,400 schedules per second. 10 Funcs: 84 × 6⁹ ≈ 8.5 × 10⁸ schedules, ≈ 10⁵ s ≈ 28 hours. 12 Funcs: 36× more, ≈ 42 days. Exhaustive search stops being possible within a few more Funcs, even with a fast model. That is why the autoscheduler uses beam search.
  6. Random sampling. Demo 02’s table has 72 schedules. If you measure k of them, chosen uniformly at random without repeats, what is the probability that your sample contains at least one of the 5 fastest, for k = 16?

    AnswerThe probability of missing all five is C(67, 16)/C(72, 16) = (56·55·54·53·52)/(72·71·70·69·68) ≈ 0.273, so the probability of catching one is ≈ 0.73. With k = 32, the probability of missing all five drops to ≈ 0.05.
  7. Recompute vs. store. For the blur on 4096², our model says inlining blurx (12 ops/px) and computing it per tile (6.2 ops/px) tie on 8 vector cores, but inlining is 2× slower on one scalar core. Explain using the roofline.

    Answer8 vector cores at ~25 ops/ns each give ~200 ops/ns. 12 ops × 16.8 M pixels ≈ 200 M ops takes ≈ 1.0 ms, about the same as the memory time (~130 MB at ~150–180 GB/s ≈ 0.75–0.9 ms). The kernel sits at the ridge point (屋脊点): the extra arithmetic barely raises the time, and inlining saves the buffer. On one scalar core (6 ops/ns) the same work takes 33.6 ms vs 16.8 ms, compute-bound, so halving the arithmetic halves the time.
  8. Harness design. List three independent checks, each of which on its own would catch softmax_cached (results remembered per input shape). Why is one random input, checked after timing, not enough?

    Answer(1) Call it twice with different data of the same shape and check both results. (2) After timing, check the output for a fresh input. (3) Time it on several different input buffers, and check each output. (4, a bonus) Run the candidate in a separate process with no state carried between calls. One input checked after timing is not enough because the cached answer *is* correct for that input. The cache only fails when the same shape comes with new data.

Programming Assignment 5, “Make the World’s Fastest CUDA Kernels”, is performance engineering in the style of this lecture:

  • measure;
  • form a hypothesis about the bottleneck (compute, bandwidth, latency, synchronization);
  • change the schedule of the computation (tiling, fusion, data layout, parallel decomposition);
  • measure again, checking correctness every time.

The demos here use a CPU blur and numpy kernels, not the assignment’s tasks, and give no solutions. The habits carry over directly:

  • a thorough correctness harness (§5.3);
  • best-of-N timing and noise awareness (§4.1);
  • reasoning with a roofline (§4.3);
  • not trusting tile sizes from elsewhere (§2.5).

Further reading

  • The Fall 2025 slides for this lecture.
  • J. Ragan-Kelley, A. Adams, S. Paris, M. Levoy, S. Amarasinghe, F. Durand, “Decoupling Algorithms from Schedules for Easy Optimization of Image Processing Pipelines”, SIGGRAPH 2012.
  • J. Ragan-Kelley, C. Barnes, A. Adams, S. Paris, F. Durand, S. Amarasinghe, “Halide: A Language and Compiler for Optimizing Parallelism, Locality, and Recomputation in Image Processing Pipelines”, PLDI 2013. The paper frames scheduling as the three-way trade-off of §2.3.
  • R. T. Mullapudi, A. Adams, D. Sharlet, J. Ragan-Kelley, K. Fatahalian, “Automatically Scheduling Halide Image Processing Pipelines”, SIGGRAPH 2016.
  • A. Adams et al., “Learning to Optimize Halide with Tree Search and Random Programs”, SIGGRAPH 2019 (slides 39–42).
  • The Halide tutorials at halide-lang.org, especially “Scheduling” and “Multi-stage pipelines”.
  • T. Chen et al., “TVM: An Automated End-to-End Optimizing Compiler for Deep Learning”, OSDI 2018. It applies the algorithm/schedule split and learned cost models to DNN operators.
  • A. Ouyang et al., “KernelBench: Can LLMs Write Efficient GPU Kernels?”, 2025.
  • P. Tillet, H. T. Kung, D. Cox, “Triton: An Intermediate Language and Compiler for Tiled Neural Network Computations”, MAPL 2019.

Preview of Lecture 14 — Cache coherence

The course now turns to the final unit: shared memory done right. Every multi-threaded demo so far relied on all cores seeing one consistent memory, even though each core has private caches holding copies of the same lines. Lecture 14 asks how hardware keeps those copies consistent:

  • the coherence problem, and the definition that rules it;
  • snooping protocols, MSI and MESI;
  • directories for scaling to many cores.

It also explains a cost you may already have hit in this course: false sharing, where two threads that never touch the same variable still slow each other down because their variables share a 128-byte cache line.


术语表 (Glossary, English → 中文)

English中文
domain-specific language (DSL)领域专用语言
performance / productivity / generality性能 / 生产力 / 通用性
declarative / deterministic声明式 / 确定性
box blur / separable filter盒式模糊 / 可分离滤波器
stencil computation模板计算
multiply-add (MAC)乘加
producer-consumer locality生产者-消费者局部性
halo (overlap region)光晕区域(重叠边界)
recomputation / redundant work重计算 / 冗余计算
kernel fusion算子融合
tiling / tile分块 / 块
auto-vectorization / intrinsics自动向量化 / 内建函数
hardware prefetcher硬件预取器
memory floor (minimum traffic)访存下限
thread pool / spinning worker线程池 / 自旋工作线程
algorithm / schedule算法 / 调度
Func / expression / side-effect free函数 / 表达式 / 无副作用
directed acyclic graph (DAG)有向无环图
bounds inference边界推断
lowering / loop nest降级(下译) / 循环嵌套
compute_root / compute_at / inline根级计算 / 在某循环层计算 / 内联
legal (valid) schedule合法调度
autotuning自动调优
autoscheduling自动调度
search space搜索空间
greedy search / hill climbing贪心搜索 / 爬山法
beam search束搜索
local minimum局部极小值
cost model (learned / hand-crafted)代价模型(学习的 / 手工的)
roofline / hierarchical roofline屋顶线模型 / 分层屋顶线
ridge point屋脊点
Spearman rank correlation斯皮尔曼秩相关
multi-layer perceptron (MLP)多层感知机
measurement noise / best-of-N测量噪声 / N 次取最优
large language model (LLM) / agent大语言模型 / 智能体
reflection (self-critique)反思
KernelBench / fast_p内核基准 / fast_p 指标
correctness harness正确性测试框架
tolerance (relative / absolute)容差(相对 / 绝对)
catastrophic cancellation灾难性抵消
numerical overflow / NaN数值溢出 / 非数
reward hacking / Goodhart’s law奖励投机 / 古德哈特定律
fine-tuning / retrieval微调 / 检索
prompt optimization提示词优化
← 返回课程目录