Unit 6 of 10 · about 4 hours · explain, measure
KernelBench, hardened evaluators and reward hacking
AI-generated kernels optimize the evaluator, not the hardware. The contract decides what counts; hardening decides what survives.
You'll be able to
- State the KernelBench task contract: levels, correctness trials, timing trials and the
fast_pmetric. - Explain the Verified hardening: TF32 baseline, four-distribution hidden suite, memory metric and degenerate exclusions.
- Classify reward hacks by mechanism and name the test that catches each.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Task contract, metrics and the ReLU shortcutKernelBench-Verified
Section 2.1 problem set and models (250 problems across Levels 1 to 3); Section 2.5 Metrics (Correctness, Correct Speedup, Fast@1, memory efficiency); Appendix H.1: the ReLU identity shortcut on Level 1 problem 19
- Running one problem and reading
EVAL.mdKernelBench - benchmark toolkit and task suiteREADME at commit 423217d: Task Description (Levels 1 to 4), Evaluation Methodology with
scripts/run_and_check.pyfor one sample, Overall Benchmark Metric (fast_p);EVAL.mdfor benchmarking guidance - Hardening and residual hacksKernelBench-Verified
Sections 2.2 to 2.4: TF32 baseline, the four-distribution hidden suite and memory profiling; Section 3 with Figure 1 and Tables 1 to 2: none above 1x after hardening; Appendix L.3 case studies: wrong-broadcast-axis hinge loss and early-termination cumprod
Read the two case studies for mechanism. Skim the remaining appendices; do not chase the full leaderboard.
Focus on
- Levels 1, 2 and 3 mean single ops, fused chains and full models. In the toolkit README,
fast_pcounts kernels both correct and faster than threshold , andfast_0is correctness alone; the paper reportsFast@1. - The ReLU shortcut passed because every test input was non-negative. The fix is negated inputs, not more trials of the same distribution.
- Wrong-axis and early-exit hacks survive value variation but break on distribution shift or sustained inputs. The judge audit flagged 6 of 453 survivors, with 4 genuine hacks.
- Degenerate constant-zero references were excluded, not fixed. Some problems cannot measure speedup, and the honest move is exclusion.
Common mistakes · 3
- More random tests equal stronger evaluation. The old suite ran many trials of one distribution; strength comes from distinct distributions, not count.
- A kernel faster on every tested shape generalizes. Shapes were fixed and shape specialization is declared legitimate; values are the held-out axis.
- Memory efficiency follows speed. In the Verified study, 28% of the best model's correctly generated kernels raised peak memory; measure both or the tradeoff hides.
Try it yourself
Closed-book, before checking anything
fast_p), the four hidden distributions with their scales, and the ReLU-hack mechanism plus its catching test.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.What does
fast_1count, exactly?AnswerThe fraction of tasks whose kernel is both correct and faster than the PyTorch baseline, a speedup above 1.
fast_0is correctness alone.2.How did the ReLU identity shortcut reach 374x, and which distribution catches it?Answer
Every test input came from
torch.rand, uniform and non-negative, so returning the input unchanged passed; a shape guard limited the trick to the benchmark shape. Negated inputs fail it with maximum error 1.0.3.Why did the hinge-loss wrong-axis kernel pass all four hidden distributions?Answer
Over 32768 by 32768 independent inputs the mean error stays under tolerance by the law of large numbers despite the wrong axis. Only a judge checking the axis, or a non-identical layout, catches it.
4.A fused GroupNorm kernel is fast but numerically unstable. Which hardening catches it, and why did the original suite miss it?Answer
The scaled distributions: times 3.0 stresses overflow and times 0.01 stresses underflow and near-zero paths. The original uniform small-positive inputs never touched those paths.
Practice
- KernelBench Level 1: one problem with
run_and_check.pyscripts/run_and_check.pyusage 2 (commit 423217d):ref_origin=kernelbench level=1 problem_id=<id> kernel_src_path=<your kernel file> eval_mode=localon one Level 1 problem, withgpu_archset to["Ampere"]The script takes an architecture family name (
Amperefor compute capability 8.6), notsm_86; pass your GPU's family, from its capability innvidia-smi --query-gpu=compute_cap --format=csv. Start from the example kernels insrc/kernelbench/prompts, run one problem only, then add one negated-input trial in the style of the hidden D4 distribution and report what changes. Do not chase the aggregate score.
You're done when
You can state the contract, the hardening and three hack mechanisms from memory, and your one-problem run reports correctness plus speedup with the extra negated trial.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 12 more in the section
- KernelBench-VerifiedKernelBench-Verified Authors · required
Study the evaluator hardening and baseline-parity failures found in the original benchmark. Run a very small task slice or port its adversarial testing ideas into the project evaluator; do not optimize for aggregate benchmark score.
- KernelBench - benchmark toolkit and task suiteScalingIntelligence · support
Clone the repository and check one Level 1 problem with
scripts/run_and_check.pyin local mode; readEVAL.mdfor the correctness and timing guidance. Do not chase the aggregate score.
Also in this section
- AI Systems Performance Engineering - Chapters 2, 19 and 20 and the Appendix checklistChris Fregly · primary
Read Chapter 2 for hardware generations, Chapters 19 and 20 on adaptive engine optimization and AI-assisted optimization, and use the Appendix checklist as an audit list for the final project. Treat every performance number as a hypothesis requiring your own evidence.
- AI Performance Engineering - Hardware, Frontier and Source PolicyWafer · reference
A dated map of current hardware and frontier work. Apply its Source Policy to every final claim, and use the hardware and frontier sections only to find primary documentation.
- GPU Microbenchmark and Kernel Suite - Final EvaluationRoadmap-Final · required
Complete Milestones C through F: CUDA and Triton kernel suite, failure injection, model-versus-profile reconciliation, strong baselines, real integration, full shape matrix, dispatch and fallback defense, clean reproduction and negative results.
- Performance Engineering and GPU Programming CheckpointRoadmap-Final · support
Use the checkpoint as the final adversarial assessment after the source-derived route. Pass the real kernel, compiler or communication modification and end-to-end evidence clauses; ignore its ordering where it conflicts with this track.
- SOL-ExecBenchNVIDIA · support
Inspect how correctness and performance are compared with a hardware speed-of-light model. Apply one attainable-efficiency analysis to a project kernel and explain missing hardware or model assumptions.
- MLPerf EndpointsMLCommons · support
Read the endpoint-level scenario and load-generation rules. Borrow the workload and result-boundary discipline for the integrated benchmark without claiming an official MLPerf result.
- CUDA Toolkit and Architecture Tuning GuidesNVIDIA · reference
Use the current toolkit root, release notes and the tuning guide matching the measured GPU. Pin the document and toolkit versions, verify capability checks and rerun any claim affected by compiler or architecture change.
- MIT 6.S894 Accelerated Computing (Fall 2025) - Lecture 10MIT · support
Use Lecture 10 (Accelerated Computing Beyond NVIDIA and CUDA) for AMD GPUs, TPUs, NPUs and higher-level kernel languages as portability vocabulary.
- Modern GPU Programming for MLSysMLC · depth
Use the Blackwell GEMM and Flash Attention path as a real architecture-specific reconstruction target if compatible hardware is available. Otherwise produce a static mechanism audit and leave all performance claims open.
- Etalon - holistic evaluation for LLM inferenceGeorgia Tech, Microsoft Research India and Intel AI Lab · support
Read Section 2.2 for TTFT and TPOT pitfalls, then the fluidity-index design (Section 4.1) for deadline-based, SLO-qualified capacity.
- ROCm Composable KernelAMD · support
Read the repository
READMEfor the tile-based programming model, Tensor Coordinate Transformation and the four CK layers; open one tiled operator and map each CUDA term to its CK counterpart. - DistServe: Disaggregating Prefill and Decoding for Goodput-optimized LLM ServingZhong et al. (OSDI 2024) · support
Read Section 1 with Figure 1 for per-GPU goodput: the highest request rate served while a target share of requests meets the TTFT and TPOT SLOs.