Unit 5 of 12 · about 4 hours · implement
Independent references and differential and property tests
A faster kernel that computes the wrong operation is not an optimization. Independent references and adversarial properties catch errors that two similar implementations share.
You'll be able to
- Build a reference that does not reuse the target's indexing or reduction logic.
- Test supported shapes, strides, dtypes and masks, including boundaries and invalid inputs.
- Gate every performance result on differential and property checks.
Covers
Read
In this order, only the parts listed
0 of 2 done
- Independent oracle and adversarial matrixGPU Microbenchmark and Kernel Suite - Harness and Instrumentation
Architecture constraints; Milestone A - Correct baseline; Correctness requirements; Failure-injection requirements
- PyTorch 2.14: test inputs and structural comparisonPyTorch 2.14 numerical accuracy and tensor testing
torch.testing.assert_close: shape, device, dtype, layout and stride checks;torch.testing.make_tensor: shape, range and noncontiguous parameters
Focus on
- Generate reference results from the specification using a CPU scalar or library path, not the target's address calculations. Use the same represented inputs.
- Include empty, singleton, odd, warp-edge and block-edge sizes; noncontiguous views; supported dtypes; and partial or all-masked rows. Unsupported combinations must reject or fall back explicitly.
- Properties complement an oracle: copies preserve each element, transposing twice restores the input, and finite nonempty softmax rows sum approximately to one. These properties alone do not identify every wrong output.
- Preserve seeds and failing inputs. Check output shape, dtype and required layout as well as values, with tolerances chosen before tuning.
Common mistakes · 3
- Sharing a stride calculation between the oracle and candidate, so both make the same indexing mistake.
- Comparing only sums or checksums. Permutations and compensating errors can preserve them.
- Silently making noncontiguous inputs contiguous before testing a path advertised as stride-aware.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Can the transpose-twice property prove a transpose implementation is correct?Answer
No. Even an identity operation passes it. Compare against an independent transpose reference as well.
2.Why test just above a block boundary?Answer
It forces a partial final block and exposes tail guards, skipped elements and out-of-bounds accesses.
3.Should a contiguous-only kernel pass a strided input by ignoring its strides?Answer
No. It must reject, use a correct fallback, or perform a declared layout conversion whose cost is included at the operator boundary.
You're done when
Your supported-input matrix passes independent full-output checks, and seeded tail and stride defects fail before the harness publishes timing results.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 10 more in the section
- GPU Microbenchmark and Kernel Suite - Harness and InstrumentationRoadmap-Final · support
Complete Milestones A and B: correct references, synchronized timing, raw samples, noise characterization, environment capture, operation and byte models, timeline traces and profiler evidence.
- PyTorch 2.14 numerical accuracy and tensor testingPyTorch · reference
Read the numerical-accuracy introduction, Extremal values, non-finite inputs and Ampere precision sections, plus the
assert_closecontract andmake_tensorparameters. These supply current comparison semantics missing from the pool's project checklist.
Also in this section
- AI Systems Performance Engineering - Chapters 6 to 8Chris Fregly · primary
Read Chapters 6 to 8: GPU architecture and occupancy, profiling and tuning memory access, and occupancy, warp efficiency and instruction-level parallelism, with their Nsight Systems, Nsight Compute and roofline workflows. Treat every quoted speedup as a hypothesis for your own hardware.
- AI Systems Performance Engineering companion code - Chapters 6 to 8Chris Fregly · required
Use selected baseline and optimized pairs from
code/ch06,code/ch07andcode/ch08plus the shared benchmark and verification machinery. Run only hardware-compatible paths, inspect the tests first, retain raw artifacts and document any guard or unavailable feature. - Nsight Systems User GuideNVIDIA · required
Learn capture, statistics, CUDA API and GPU timeline views, NVTX ranges and report export. Produce one trace that attributes a host gap, transfer or synchronization cost without using the kernel profiler first.
- Nsight Compute Profiling GuideNVIDIA · required
Study the profiling model, replay, metric collection, sections, roofline and source correlation. Collect the smallest counter set that can falsify your bottleneck hypothesis and record profiler overhead.
- Compute SanitizerNVIDIA · required
Run memcheck plus applicable racecheck, initcheck and synccheck cases against seeded defects. Preserve minimal reproducers and regression tests, and distinguish unsupported checks from a clean result.
- Roofline: An Insightful Visual Performance ModelUC Berkeley · required
Read the original model and construct one roofline plot with explicit peak assumptions, useful operations and bytes. Add measured points and explain gaps from launch, resource, cache or instruction effects.
- CUTLASS GEMM Performance Measurement MethodologyNVIDIA · support
Apply the environment, clock, warmup, timing, verification and reporting guidance to the benchmark harness. Generalize the method beyond GEMM and document every intentional deviation.
- CS336 Assignment 2 - Section 2.1 ProfilingStanford University · support
Do the
benchmarking_script,nsys_profile,mixed_precision_accumulationandmemory_profilingproblems on a model size that fits your GPU instead of the handout's B200 settings. Keep raw timings, traces and memory snapshots. - TensorTonic Language Modeling from Scratch - Measure Kernel Timeline UtilizationTensorTonic · support
Solve the timeline-utilization problem after the timeline unit, then repeat the calculation on a trace you captured yourself.
- CUDA 13.4 Floating Point and IEEE 754NVIDIA · reference
Read sections 2.2, 3.1 to 3.2 and 4.4 for reduction order and single-precision flush-to-zero flags. Do not use the historical CPU-has-no-FMA statements as current hardware facts.