mirror of
https://github.com/bdbrown4/peltier.io.git
synced 2026-11-07 10:58:28 +00:00
phase5: kernel lane (SPEC §13) — FP-tolerance equivalence gate + reference-diff testing
The parser/service targets only ever needed byte-identical golden replay.
The kernel lane is the case that breaks it: a matmul optimization
(transpose-B for cache locality + eight-accumulator ILP) that REORDERS the
floating-point reduction, so its low bits differ by construction —
byte-identical is the wrong gate.
Adds:
- EquivalencePolicy::compare + Divergence (diff-test): byte-identical is
exact; fp-tolerance tokenizes and compares numeric tokens within
abs + rel*|baseline|, with explicit NaN handling. Non-numeric tokens and
token-count mismatches still fail exactly.
- fp-compare bin: applies a target's equivalence.toml to two output files.
- targets/matmul/kernel.c: matmul_ref (single-accumulator oracle) vs
matmul_opt (reordered, faster), with emit/check/run/bench modes.
- targets/matmul/equivalence.toml: fp-tolerance abs 1e-4 + rel 1e-3.
- scripts/kernel-lane-demo.sh + results/phase5/kernel-lane.txt: byte-identical
FAILs, fp-tolerance is EQUIVALENT, a +0.5 perturbation is still REJECTED,
speedup 3.23× measured with the same interleaved A/B + bootstrap CI.
Ledger row phase5-matmul-opt = needs-human-review: using the FP-tolerance
tier at all is a human-review signal (SPEC §8), same posture as mimalloc.
The trust machinery is unchanged; only the timer and the gate differ, which
is exactly the shape a future GPU kernel would slot into.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EcKPWQ3MQD4NdEHwar96u2
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
# Kernel-lane demonstration — matmul (n=512, f32)
|
||||
|
||||
## 1. Equivalence: byte-identical is the wrong gate
|
||||
byte-identical: FAIL — 244901 of 262144 result values differ (accumulation reordered)
|
||||
|
||||
diff-test FP-tolerance policy (targets/matmul/equivalence.toml):
|
||||
policy: FpTolerance { abs: 0.0001, rel: 0.001 }
|
||||
EQUIVALENT under policy
|
||||
|
||||
in-process reference differential test:
|
||||
kernel differential test (opt vs reference):
|
||||
max_abs_err = 3.815e-05
|
||||
max_rel_err = 2.173e-02 (dominated by near-zero elements; see abs floor)
|
||||
tolerance = abs 1.000e-04 + rel 1.000e-03 * |ref|
|
||||
byte_identical = NO (accumulation reordered by design)
|
||||
within_tolerance = YES
|
||||
verdict = EQUIVALENT
|
||||
|
||||
control — a genuine wrong result IS caught by the tolerance:
|
||||
tolerance correctly REJECTS a +0.5 perturbation of one element
|
||||
|
||||
## 2. Speedup: interleaved A/B, bootstrap 95% CI
|
||||
speedup (baseline/candidate): median 3.2301, 95% CI [3.1600, 3.2594]
|
||||
verdict: accepted
|
||||
|
||||
## What it demonstrates
|
||||
A real matmul speedup (transpose for cache locality + eight-accumulator
|
||||
ILP) that reorders the reduction. Byte-identical rejects it; the
|
||||
FP-tolerance gate accepts it (abs 1e-4 + rel 1e-3) while still catching
|
||||
a wrong result; the bench measures it with the same CI machinery as
|
||||
every other target. The GPU extension (Triton/CUDA vs a reference
|
||||
kernel) is the same shape — only the timer and the hardware change.
|
||||
Reference in New Issue
Block a user