CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.
diff --git a/docs/abft/.crumb b/docs/abft/.crumb
new file mode 100644
index 00000000..eea70b70
--- /dev/null
+++ b/docs/abft/.crumb
@@ -0,0 +1,6 @@
+{
+ "schema_version": "1.0.0",
+ "name": "gemm-fault-detection-docs",
+ "layer": "docs",
+ "purpose": "Contract, declarations (fault model, precision, rounding, independence, known misses) and receipts for native/abft"
+}
diff --git a/docs/abft/CONTRACT.md b/docs/abft/CONTRACT.md
new file mode 100644
index 00000000..6a48ae17
--- /dev/null
+++ b/docs/abft/CONTRACT.md
@@ -0,0 +1,268 @@
+# GEMM fault detection and schedule perturbation: evaluator contract
+
+Linear DRA-420 (the numerical/GEMM slice only) and DRA-387 (the evaluator and concurrency slice).
+CUDApp#55 (schedule perturbation) and CUDApp#56 (reduced-concurrency witness) are covered on the
+host only. Weight integrity at load time belongs to the ownmodel loader and is not in this slice.
+
+Status labels: everything here is **SIMULATED/HOST_TESTED**. The candidate is a first-party `.om`
+tiled GEMM run by simulated workers on the host CPU. No GB10 (sm_121) kernel, device output buffer or
+device scheduler has been exercised. Every device edge in section 10 is **NOT_RUN**.
+
+## 1. Files and build
+
+| Path | Role |
+|---|---|
+| `tests/abft/frozen.om` | Frozen plan: 51 rows plus config. Its hash is in `tests/abft/FROZEN.sha256`, committed in `9a16df99` before any checker existed. |
+| `native/abft/lib.om` | Buffered output, splitmix64 streams, FNV-1a, bf16 and f32 decoding. |
+| `native/abft/check.om` | Independent checkers: full recompute, two-sided checksum, sampled recompute, input digest, structural check. |
+| `native/abft/cand.om` | Candidate tiled GEMM (W workers, two barriers per K tile) and the labelled fault injectors. |
+| `native/abft/sched.om` | CUDApp#55 admission. A refused row never forks. |
+| `native/abft/run.om` | Evaluator: fork, deadline, reap, collect, detect, admit, retry, tallies, witnesses, gates. |
+| `native/abft/cul1.om` | `kabft`: the same two-sided checksum on the merged learn53 CUL1 GEMM records. |
+| `tests/abft/cul1-unit.om` | CUL1 checksum unit cases. Uses `tests/learn53/fixtures.om`. |
+| `tests/abft/driver.om` | Seeded Omega driver: pin check, frozen-hash check, build, unit run and full evaluator run. |
+
+```sh
+mkdir -p build && "$OMEGA_OMC" < tests/abft/driver.om > build/abft-driver && chmod +x build/abft-driver
+OMEGA_OMC=/abs/omega-mv/seed/out/omc build/abft-driver build/abft # all 51 rows plus gates
+build/abft/abft FIRST LAST # a row range; gates are skipped
+```
+
+Run the driver from the repository root. It exits 0 when every step and gate passed, 2 when
+`OMEGA_OMC` is unset, 1 on a pin, frozen-hash, input or output failure, and otherwise with the
+failing step's status (omc, `cul1-unit`, then the evaluator).
+
+The compiler must be omega-mv `e5b32567a7aff3ce594e3254a622a846a6cd190b` `seed/out/omc`, sha256
+`2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`; the driver refuses any other.
+`build/abft/abft` exits with the number of failed gates (0 when all pass), or 64 for bad arguments.
+
+## 2. Roles and isolation
+
+- **Evaluator.** Owns the frozen plan, the seeds, the input matrices, the nonce, the tolerances, the
+ checkers, the deadline, the retry count, the trusted record and admission.
+- **Candidate.** Runs only in a forked child. Its one channel back is the bytes it writes into an
+ evaluator-created memfd, plus its exit status. Before any check runs, the evaluator reads those
+ bytes into `gobs`.
+- **Fault-free reference.** The evaluator also runs the candidate's own algorithm in-process, with
+ one worker, round-robin and no fault (`cref`, into `gref`). It is used only to label the ground
+ truth "corrupt" for the FP/FN table. No checker reads `gref`. The element order is k-ascending for
+ every element under every schedule, so a fault-free run is bitwise schedule-independent.
+- **Nonce.** The checksum multipliers and the sampled positions come from evaluator stream 1. That
+ stream is seeded with a nonce from `random` after the candidate has exited, so the candidate cannot
+ predict them.
+- **Freeze.** The plan hash was committed before any checker, tolerance or candidate code. Gates 1–9
+ (section 9) were written after the freeze but before the first run. After the first sandbox
+ development runs, gate 8 was revised and gate 10 was added (section 9 says why). The frozen rows,
+ seeds, S, deadline and retry count were never changed.
+
+## 3. Fault model, precision and tolerance
+
+**Fault model.** Errors that reach the output buffer:
+
+- Bit flips in output elements: single and multi-element.
+- Stale output: an uninitialised buffer, a skipped write, or a stale buffer that happens to be
+ identical.
+- Indexing errors: a dropped K tail, a transposed B, a row offset, or an out-of-bounds store.
+- Synchronisation errors: a missing load barrier, a missing compute barrier, a barrier that counts
+ only workers 0..1, or a hang.
+- Corruption of the evaluator's A input after generation (common mode).
+
+Not modelled: faults inside the checker itself, faults in the evaluator's generation code, and
+faults that alter both the candidate and the checker's view of the output identically.
+
+**Precision.**
+
+- **dt 0 (exact).** u32 inputs; products and sums mod 2^32; tolerance 0.
+- **dt 1, profile P1.** bf16 inputs (sign, exponent 120..127, 7-bit mantissa) and an f32 output. The
+ products of two bf16 values are exact in f32. Accumulation is sequential in f32, round-to-nearest-even,
+ with no FMA (OMEGESE float rules).
+
+Bounds with $u = 2^{-24}$, $u' = 2^{-53}$ and $\gamma_n(u) = nu/(1-nu)$:
+
+- **Per element.** Full and sampled modes compare against an f64 recomputation $s$:
+
+ $$|\hat c_{ij} - s| \le \bigl(\gamma_K(u) + \gamma_K(u')\bigr)(1+2^{-20})\,(|A||B|)_{ij}$$
+
+- **Checksum, one side.** $n$ is the summed extent: N for the right side, M for the left side. The
+ bound is $t(n,K)\,g$, with
+
+ $$t(n,K) = \bigl(\gamma_K(u) + \gamma_{n-1}(u')(2+\gamma_K(u)) + \gamma_K(u')(1+\gamma_{n-1}(u'))\bigr)(1+2^{-20})$$
+
+ For the right side, $g_i = \sum_k |a_{ik}| \sum_j |b_{kj}|$, which is $(|A||B|e)_i$ with $|r| = e$.
+ The left side is the mirror image. The multipliers are $\pm 1$ from the nonce stream.
+
+**Wolfram checks** (WolframLanguageEvaluator; definitions $u = 2^{-24}$, $u' = 2^{-53}$,
+$g[n] = nu/(1-nu)$, $g'[n] = nu'/(1-nu')$, $sl = 1 + 2^{-20}$):
+
+- `And @@ Table[(1+up) <= (1-up) sl (1-gp[k]), {k,1,256}]` → `True`.
+- `(1+up) <= (1-up) sl (1-gp[n+k])` for all $n, k \le 256$ → `True`.
+- Values: `GF[80] = 4.768394328e-6`, `GR[48,80] = 4.768394339e-6`, `GF[256] = 1.525902193e-5` and
+ `GR[256,256] = 1.525902198e-5`.
+- The slack actually needed is $5.7065\times10^{-14}$, far below $2^{-20}$.
+- Constants: `2^-24 == 59604644775390625/10^24` → `True`; `2^-20 == 95367431640625/10^20` →
+ `True`; the decimal literal `1.1102230246251565e-16` lies within $2^{-106}$ of $2^{-53}$ → `True`,
+ so it rounds to $2^{-53}$.
+
+Every comparison is written `not le d t`, so a NaN is detected. The structural check also counts
+outputs whose f32 exponent is all ones.
+
+**Rounding and quantisation declaration.** These bounds are for profile P1 only. A device kernel
+that uses FMA, a different accumulation order, split-K, tensor-core fragment accumulation, MUFU, or
+denormal flushing (GB10 flushes denormals) needs its own profile and bound before these checks
+apply. One example is gemm-any #283's bound $n/(2^{18}-n)\cdot\sum|ab|$ with $n = \lceil K/16\rceil$,
+recorded as profile **P2, NOT_RUN**. Inputs avoid denormals by construction (exponent ≥ 120).
+
+## 4. Exact mode (dt 0): checksum miss bound
+
+The two-sided Freivalds check works mod $2^{32}$ with odd multipliers. Let $v$ be the 2-adic
+valuation of the error pattern's combination. The miss probability is at most $2^{v-31}$ per side.
+
+Wolfram enumeration over the scaled model mod $2^6$:
+
+- Every single-element error is detected.
+- The $2^5$ rectangle is always missed.
+- The bound $2^{v-(w-1)}$ is attained.
+
+At 32 bits, an error of $2^{31}$ on the four corners of a 2×2 rectangle is a **deterministic miss**
+(row 40, gate 7). Full recompute catches it. On the merged learn53 CUL1 record, `kabft` misses the
+same rectangle while `keval` (exact) catches it (`tests/abft/cul1-unit.om`, `abrect`). Wolfram:
+`{2^31+21, 2^31+24, 2^31+47, 2^31+54}` → `{2147483669, 2147483672, 2147483695, 2147483702}`, and
+`{{1,2},{3,4}}.{{5,6,7},{8,9,10}}` → `{{21,24,27},{47,54,61}}`.
+
+## 5. Modes, admission and cost
+
+| Mode | Work | In admission |
+|---|---|---|
+| Structural | output length, exit status, nonfinite count | yes |
+| Input digest | FNV-1a over dims, A and B; detects common-mode input corruption | yes |
+| Full recompute (thorough) | $2MNK$ multiply-adds in f64 or mod $2^{32}$ | yes |
+| Checksum (ABFT, Huang–Abraham 1984, doi:10.1109/TC.1984.1676475; Freivalds) | $O(MK + KN + MN)$ per side | yes |
+| Sampled recompute | $S = 64$ elements with replacement; about $SK$ | **no**, reported only |
+
+- **Admission** is structural OR digest OR full OR checksum. Each detection is retried once, under a
+ new schedule. A pass on retry is RECOVERED; detection on both attempts is REJECTED.
+- **Sampled mode** is reported but does not affect admission. Its measured coverage and cost
+ (evidence, REALITY.md) do not justify admission on their own: for a single corrupt element the
+ detection probability is $1-(1-1/MN)^S$.
+- **Performance comparisons.** Check time is never included in `t_cand`. Any performance comparison
+ that uses these checks must charge equal check cost to both sides and disclose the mode.
+
+## 6. Frozen plan
+
+The row fields, fault codes and flags are documented in the header of `tests/abft/frozen.om`.
+
+| Rows | Content |
+|---|---|
+| 1–5 | Fault-free FP rows (bf16 and exact; odd shape 33×17×41). |
+| 6–14 | Single bit. |
+| 15–18 | Multi-element. |
+| 19–22 | Stale. |
+| 23–27 | Index. 26 is the out-of-bounds store and must exit 103. |
+| 28–37 | Sync. 34/35 is the W8/W2 pair; 36 is the hang; 37 is a wait removal without the control flag and must be refused. |
+| 38–39 | Unsupported sites. Must be refused with 69. |
+| 40–42 | Declared misses and common-mode corruption. |
+| 43–44 | Transient and persistent recovery. |
+| 45–49 | Host cost. |
+| 50–51 | Witness pair with a correct barrier. |
+
+Config: S = 64, deadline 20 s, 1 retry, plan version 1.
+
+## 7. CUDApp#55 schedule perturbation
+
+Policies:
+
+| Policy | Behaviour |
+|---|---|
+| 0 | Round-robin. |
+| 1 | Seeded random choice among ready workers. Stream 2, varied by seed, rep and attempt. |
+| 2 | Run-ahead: worker `tgt` goes first whenever it is ready. |
+| 3 | Delay: worker `tgt` is postponed while it sits at `site`, provided another worker is ready. |
+
+Sites: 1 load, 2 compute, 3 barrier arrival. Site 4 (intra-unit atomic) and site 5 (device
+instruction stream) are **refused with 69**, because there is no host atomic and no qualified delay
+opcode. Nothing is guessed (`docs/learn53/DEPENDENCIES.md` on the integration branch: "#55 NOT_RUN …
+no delay opcode guessed").
+
+Each row is validated before the first fork:
+
+| Code | Meaning | Status |
+|---|---|---|
+| 0 | ok | 0 |
+| 1 | unknown policy | 65 |
+| 2 | target out of range | 65 |
+| 3 | atomic site | 69 |
+| 4 | device instruction stream site | 69 |
+| 5 | wait removal without the known-bad control flag | 65 |
+| 6 | shape or worker bounds | 65 |
+| 7 | transposed index on a non-square shape | 65 |
+| 8 | delay policy without a site | 65 |
+| 9 | hang control with W < 2 | 65 |
+
+The SCHED record reports the number of distinct schedules, by an FNV hash of the worker-choice
+sequence, across reps.
+
+## 8. CUDApp#56 reduced-concurrency witness
+
+A row with flag bit 3 is the reduced-concurrency partner of the previous row: same seed and shape,
+fewer workers (W8 → W2). The evaluator compares the first-attempt output digests rep by rep and the
+admission detections:
+
+| Verdict | Meaning |
+|---|---|
+| 1 | Counterexample: the original detected a fault and the reduced run detected none. The fault depends on concurrency. |
+| 2 | The digests differ rep by rep, and there is no counterexample. |
+| 0 | Otherwise. |
+
+A reduced run that is clean is not proof that the original is correct. It is only a witness.
+
+## 9. Output records and gates
+
+Output is numeric, space separated, after the `COLUMNS` header lines printed by the driver. The
+records are PLAN, CASE, SCHED, TALLY, WITNESS, RESOURCES and GATE. In the CASE record, detector
+columns read 0 pass, 1 detect, 2 not evaluated (no usable output). Verdict codes: 0 ACCEPT,
+1 RECOVERED, 2 REJECTED, 4 retry follows. Times are in ns from `monons`.
+
+| Gate | Condition |
+|---|---|
+| 1 | No false positive in any detector, admission included. |
+| 2 | Admission FN = 0, except the declared rows 11 and 17 (low-mantissa flips below the P1 bound). |
+| 3 | Schedule status: row 37 → 65, rows 38/39 → 69, every other row 0. |
+| 4 | Row 43 all RECOVERED and row 44 all REJECTED. |
+| 5 | Resources: forks = reaped, fd first = fd last, no fd or wait errors. |
+| 6 | Row 36: timeouts = 2 × reps (both attempts killed at the deadline). |
+| 7 | Row 40: checksum FN = full TP = corrupt cases (deterministic rectangle miss). |
+| 8 | Row 42 (common mode): digest TP = corrupt cases, and full FN + structural TP = checksum FN + structural TP = corrupt cases. |
+| 9 | Row 51 witness: same = reps and verdict 0. |
+| 10 | Row 26: every attempt ends in Omega trap 3 (exit 103) before the store. |
+
+**Gate revisions after the first sandbox run.**
+
+- **Gate 8** first required full FN = checksum FN = corrupt cases. The frozen row flips bf16 bit 14,
+ which is the exponent MSB. In 2 of 10 sandbox attempts the corrupted A element overflowed the f32
+ product to inf or NaN. The structural check flags those outputs, and full recompute then also
+ fails them, because $|\hat c - s| = \infty$. The revised gate keeps the claim the row exists for:
+ the digest is the only checker that sees finite common-mode corruption.
+- **Gate 10** was added so the out-of-bounds exit status, previously only visible in CASE records, is
+ gated.
+
+## 10. Known misses and pending device evidence
+
+**Known misses (declared before the first run).**
+
+- f32 low-mantissa flips whose magnitude is under the P1 bound (rows 11 and 17). The bound allows
+ them; they are undetectable at this precision by design.
+- The checksum is looser than per-element recompute by roughly the row or column extent: the bound
+ sums $|A||B|$ over N or M elements.
+- The exact $2^{31}$ rectangle: a deterministic checksum miss.
+- The f32 ±e rectangle (row 41): a miss when the random signs cancel. Up to 1/4 per side pair is
+ expected; the measured rate is in the evidence.
+- Common-mode input corruption: only the digest catches it.
+
+**NOT_RUN (needs producer interfaces).**
+
+- Device output acquisition from a GB10 GEMM launch, i.e. a GEMM launch hook or an output dump from
+ gemm-any #283.
+- Device-side #55 instrumentation and a qualified delay opcode.
+- Atomic-site perturbation.
+- A GB10 profile P2 bound check.
+- Hardware fault injection.
diff --git a/native/abft/.crumb b/native/abft/.crumb
new file mode 100644
index 00000000..7e97c80c
--- /dev/null
+++ b/native/abft/.crumb
@@ -0,0 +1,6 @@
+{
+ "schema_version": "1.0.0",
+ "name": "gemm-fault-detection",
+ "layer": "native",
+ "purpose": "Seeded Omega GEMM fault detection (two-sided randomized checksum, thorough recompute, sampled elements) and DRA-387 schedule-perturbation/reduced-concurrency host bookkeeping; host SIMULATED only, GPU NOT_RUN"
+}
diff --git a/native/abft/cand.om b/native/abft/cand.om
new file mode 100644
index 00000000..7358e67b
--- /dev/null
+++ b/native/abft/cand.om
@@ -0,0 +1,470 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note native/abft candidate: a tiled GEMM run by W simulated workers that share tile buffers sa/sb and
+note meet at two barriers per K tile (after loads, after compute). It runs only in a forked child; its
+note one channel back to the evaluator is the memfd bytes plus its exit status. The scheduler applies
+note the evaluator's perturbation (sched.om validated it before fork). Fault injectors are labelled
+note controls selected by the frozen plan row, never by candidate logic. Label: SIMULATED.
+note Element order is k ascending for every element under every schedule, so a fault-free run is
+note bitwise schedule independent; any schedule dependence in the output is a fault.
+const TK ulong 8
+const PLOAD ulong 0
+const PB1 ulong 1
+const PCOMP ulong 2
+const PB2 ulong 3
+const PDONE ulong 4
+const KDT ulong 1
+const KM ulong 2
+const KN ulong 3
+const KK ulong 4
+const KW ulong 5
+const KPOL ulong 6
+const KTGT ulong 7
+const KSITE ulong 8
+const KFLT ulong 9
+const KSUB ulong 10
+const KP1 ulong 11
+const KP2 ulong 12
+const KSEED ulong 13
+const KFLG ulong 15
+global kp ulong 16
+global kat ulong 1
+global krep ulong 1
+global cc ulong 65536
+global sa ulong 2048
+global sb ulong 2048
+global wph ulong 64
+global wt ulong 64
+global wu ulong 64
+global warr ulong 64
+global clast ulong 1
+global csh ulong 1
+global gprev ulong 65536
+global gref ulong 65536
+fn kf f ulong to ulong
+ret get kp f
+end
+fn fact to bool
+if eq kf KFLT 0
+ret false
+end
+if eq and kf KFLG 1 1
+ret eq get kat 0 0
+end
+ret true
+end
+fn fis f ulong s ulong to bool
+if fact
+ret and eq kf KFLT f eq kf KSUB s
+end
+ret false
+end
+fn ntiles to ulong
+ret div add kf KK sub TK 1 TK
+end
+fn ctk t ulong to ulong
+k0 = mul t TK
+tk = sub kf KK k0
+if gt tk TK
+tk = TK
+end
+if fis 4 1
+if eq t sub ntiles 1
+tk = sub tk 1
+end
+end
+ret tk
+end
+fn rowskip i ulong to bool
+if fact
+if eq kf KFLT 3
+if ge kf KSUB 2
+p1 = kf KP1
+ret and ge i p1 lt i add p1 kf KP2
+end
+end
+end
+ret false
+end
+fn cloada w ulong k0 ulong tk ulong to void
+e = w
+while lt e mul kf KM tk
+i = div e tk
+q = rem e tk
+s = add mul i kf KK add k0 q
+v = get ga s
+put sa add mul i TK q v
+e = add e kf KW
+end
+end
+fn cloadb w ulong k0 ulong tk ulong to void
+n = kf KN
+e = w
+while lt e mul tk n
+q = div e n
+j = rem e n
+s = add mul add k0 q n j
+if fis 4 2
+s = add mul j n add k0 q
+end
+v = get gb s
+put sb add mul q n j v
+e = add e kf KW
+end
+end
+fn cload w ulong t ulong to void
+k0 = mul t TK
+tk = sub kf KK k0
+if gt tk TK
+tk = TK
+end
+cloada w k0 tk
+cloadb w k0 tk
+end
+fn bfu v ulong to f32
+ret bitcast f32 uint shl and v 65535 16
+end
+fn crowf i ulong tk ulong to void
+n = kf KN
+for j ulong n
+p = add mul i n j
+acc = bitcast f32 uint get cc p
+for q ulong tk
+a = bfu get sa add mul i TK q
+b = bfu get sb add mul q n j
+acc = add acc mul a b
+end
+put cc p fbits acc
+end
+end
+fn crowx i ulong tk ulong to void
+n = kf KN
+for j ulong n
+p = add mul i n j
+acc = get cc p
+for q ulong tk
+a = get sa add mul i TK q
+b = get sb add mul q n j
+acc = and add acc mul a b MASK
+end
+put cc p acc
+end
+end
+fn crow i ulong t ulong to void
+if rowskip i
+ret
+end
+if eq kf KDT 0
+crowx i ctk t
+else
+crowf i ctk t
+end
+end
+fn bset v ulong to bool
+if fis 5 3
+ret lt v 2
+end
+ret true
+end
+fn bpass c ulong to bool
+ok = true
+for v ulong kf KW
+if bset v
+if lt get warr v c
+ok = false
+end
+end
+end
+ret ok
+end
+fn cready w ulong to bool
+ph = get wph w
+if eq ph PDONE
+ret false
+end
+t = get wt w
+if eq ph PB1
+ret bpass add mul t 2 1
+end
+if eq ph PB2
+ret bpass add mul t 2 2
+end
+ret true
+end
+fn cnext w ulong to void
+t = add get wt w 1
+put wt w t
+if eq t ntiles
+put wph w PDONE
+ret
+end
+if fis 5 4
+if eq w 0
+put wph w PDONE
+ret
+end
+end
+put wph w PLOAD
+end
+fn carrive w ulong to void
+put warr w add get warr w 1
+end
+fn cstep w ulong to void
+ph = get wph w
+t = get wt w
+if eq ph PLOAD
+cload w t
+carrive w
+put wu w 0
+if fis 5 1
+put wph w PCOMP
+else
+put wph w PB1
+end
+ret
+end
+if eq ph PB1
+put wph w PCOMP
+put wu w 0
+ret
+end
+if eq ph PB2
+cnext w
+ret
+end
+i = add w mul get wu w kf KW
+if lt i kf KM
+crow i t
+put wu w add get wu w 1
+i = add w mul get wu w kf KW
+end
+if ge i kf KM
+carrive w
+if fis 5 2
+cnext w
+else
+put wph w PB2
+end
+end
+end
+fn csite w ulong to ulong
+ph = get wph w
+if eq ph PLOAD
+ret 1
+end
+if eq ph PCOMP
+ret 2
+end
+ret 3
+end
+fn crr ex ulong to ulong
+w = kf KW
+s = get clast 0
+for q ulong w
+v = rem add add s 1 q w
+if ne v ex
+if cready v
+ret v
+end
+end
+end
+ret w
+end
+fn ccount to ulong
+c = ulong 0
+for v ulong kf KW
+if cready v
+c = add c 1
+end
+end
+ret c
+end
+fn ckth k ulong to ulong
+c = ulong 0
+for v ulong kf KW
+if cready v
+if eq c k
+ret v
+end
+c = add c 1
+end
+end
+ret kf KW
+end
+fn cpick to ulong
+w = kf KW
+n = ccount
+if eq n 0
+ret w
+end
+pol = kf KPOL
+tg = kf KTGT
+if eq pol 1
+ret ckth rbelow 2 n
+end
+if eq pol 2
+if cready tg
+ret tg
+end
+end
+if eq pol 3
+if cready tg
+if eq csite tg kf KSITE
+if gt n 1
+ret crr tg
+end
+end
+end
+end
+ret crr w
+end
+fn chang to void
+note Simulated device hang: no worker can advance; the evaluator deadline kills this process.
+for q ulong 1000000
+z = sleepns 1000000
+if lt z 0
+trap 9
+end
+end
+trap 10
+end
+fn cinit to void
+m = kf KM
+n = kf KN
+for e ulong mul m n
+put cc e 0
+end
+if fact
+if eq kf KFLT 3
+for e ulong mul m n
+i = div e n
+if and ge i kf KP1 lt i add kf KP1 kf KP2
+if eq kf KSUB 3
+put cc e get gref e
+else
+put cc e get gprev e
+end
+end
+end
+end
+end
+for w ulong kf KW
+put wph w PLOAD
+put wt w 0
+put wu w 0
+put warr w 0
+end
+put clast 0 sub kf KW 1
+put csh 0 14695981039346656037
+end
+fn cflip e ulong b ulong to void
+put cc e xor get cc e shl ulong 1 b
+end
+fn cbit c ulong to ulong
+if eq c 1
+ret add 23 rbelow 3 9
+end
+if eq c 2
+ret rbelow 3 8
+end
+ret rbelow 3 32
+end
+fn cpos to ulong
+ret rbelow 3 mul kf KM kf KN
+end
+fn cfadd e ulong d f32 to void
+put cc e fbits add bitcast f32 uint get cc e d
+end
+fn crect b ulong to void
+m = kf KM
+n = kf KN
+i1 = rbelow 3 m
+i2 = rem add add i1 1 rbelow 3 sub m 1 m
+j1 = rbelow 3 n
+j2 = rem add add j1 1 rbelow 3 sub n 1 n
+if eq b 32
+e = f32 shl ulong 1 kf KP1
+cfadd add mul i1 n j1 e
+cfadd add mul i1 n j2 neg e
+cfadd add mul i2 n j1 neg e
+cfadd add mul i2 n j2 e
+ret
+end
+cflip add mul i1 n j1 b
+cflip add mul i1 n j2 b
+cflip add mul i2 n j1 b
+cflip add mul i2 n j2 b
+end
+fn cshift to void
+m = kf KM
+n = kf KN
+i = sub m 1
+while gt i 0
+for j ulong n
+put cc add mul i n j get cc add mul sub i 1 n j
+end
+i = sub i 1
+end
+for j ulong n
+put cc j 0
+end
+end
+fn cpost to void
+if not fact
+ret
+end
+f = kf KFLT
+if eq f 1
+cflip cpos kf KP2
+end
+if eq f 2
+for q ulong kf KP1
+cflip cpos cbit kf KP2
+end
+end
+if fis 4 3
+cshift
+end
+if fis 4 4
+note Out-of-bounds store: Omega traps 3 (exit 103) before writing.
+put cc add mul kf KM kf KN 65536 0
+end
+if fis 6 1
+crect 31
+end
+if fis 6 3
+crect 32
+end
+end
+note Child entry: runs the schedule to completion, applies post-run injectors, returns step count.
+fn crun to ulong
+cinit
+note Stream 2 varies with rep and attempt (a retry is a new schedule); stream 3 varies with rep only,
+note so a persistent fault lands on the same elements again on retry.
+base = add mul kf KSEED 2654435761 mul get krep 0 7919
+rseed 2 add base mul get kat 0 104729
+rseed 3 add base 1
+steps = ulong 0
+while true bound 999999
+w = cpick
+if eq w kf KW
+if eq ccount 0
+done = true
+for v ulong kf KW
+if ne get wph v PDONE
+done = false
+end
+end
+if done
+break
+end
+chang
+end
+end
+put clast 0 w
+put csh 0 fnvw get csh 0 w
+cstep w
+steps = add steps 1
+end
+cpost
+ret steps
+end
diff --git a/native/abft/check.om b/native/abft/check.om
new file mode 100644
index 00000000..b1c6f5aa
--- /dev/null
+++ b/native/abft/check.om
@@ -0,0 +1,308 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note native/abft evaluator checkers. Inputs: ga, gb (evaluator-generated), gobs (candidate bytes),
+note gd dims and the evaluator nonce stream 1. The fault-free reference gref is never read here.
+note dt 0: exact u32 products and sums mod 2^32. dt 1: bf16 inputs, f32 output, profile P1
+note (exact bf16 products, f32 sequential accumulation, |c^ - c| <= gamma_K(u) (|A||B|)_ij, u = 2^-24).
+note Checks use f64 (u' = 2^-53). Every comparison is written `not le d t` so NaN is detected.
+const UF f64 5.9604644775390625e-08
+const UD f64 1.1102230246251565e-16
+const SL f64 9.5367431640625e-07
+const MASK ulong 4294967295
+global ga ulong 65536
+global gb ulong 65536
+global gobs ulong 65536
+global gd ulong 8
+global xv f64 256
+global xh f64 256
+global xr f64 256
+global xu ulong 256
+global xq ulong 256
+global xm f64 1
+global xg f64 1
+fn dm to ulong
+ret get gd 1
+end
+fn dn to ulong
+ret get gd 2
+end
+fn dk to ulong
+ret get gd 3
+end
+fn ea i ulong k ulong to ulong
+ret get ga add mul i dk k
+end
+fn eb k ulong j ulong to ulong
+ret get gb add mul k dn j
+end
+fn ec i ulong j ulong to ulong
+ret get gobs add mul i dn j
+end
+fn gam n ulong u f64 to f64
+x = mul f64 n u
+ret div x sub 1.0 x
+end
+note Per-element bound (Wolfram-checked slack, docs/abft/CONTRACT.md section 3).
+fn gfull k ulong to f64
+ret mul add gam k UF gam k UD add 1.0 SL
+end
+note Two-sided checksum bound for one side: n is the summed output extent (N rows side, M cols side).
+fn gside n ulong k ulong to f64
+gp = gam k UF
+a = gam sub n 1 UD
+b = gam k UD
+t = add add gp mul a add 2.0 gp mul b add 1.0 a
+ret mul t add 1.0 SL
+end
+fn xmax d f64 t f64 to void
+if gt t 0.0
+put xm 0 fmax get xm 0 div d t
+end
+end
+fn fdotg i ulong j ulong to f64
+s = 0.0f64
+g = 0.0f64
+for k ulong dk
+p = mul bf ea i k bf eb k j
+s = add s p
+g = add g fabs p
+end
+put xg 0 g
+ret s
+end
+fn felem i ulong j ulong t0 f64 to bool
+s = fdotg i j
+d = fabs sub f3 ec i j s
+t = mul t0 get xg 0
+xmax d t
+ret not le d t
+end
+fn xdot i ulong j ulong to ulong
+s = ulong 0
+for k ulong dk
+s = add s mul ea i k eb k j
+end
+ret and s MASK
+end
+fn xelem i ulong j ulong to bool
+ret ne xdot i j and ec i j MASK
+end
+note Thorough mode: recompute every element.
+fn cfull to ulong
+put xm 0 0.0
+bad = ulong 0
+t0 = gfull dk
+for i ulong dm
+for j ulong dn
+if eq get gd 0 0
+if xelem i j
+bad = add bad 1
+end
+else
+if felem i j t0
+bad = add bad 1
+end
+end
+end
+end
+ret bad
+end
+note Sampled mode: S elements with replacement, positions from the evaluator nonce stream.
+fn csamp s ulong to ulong
+put xm 0 0.0
+bad = ulong 0
+t0 = gfull dk
+for q ulong s
+i = rbelow 1 dm
+j = rbelow 1 dn
+if eq get gd 0 0
+if xelem i j
+bad = add bad 1
+end
+else
+if felem i j t0
+bad = add bad 1
+end
+end
+end
+ret bad
+end
+fn fsign to f64
+if eq and rnext 1 1 0
+ret 1.0
+end
+ret -1.0
+end
+note FP right side: y = B r, rows test |A y - C r| against gside(N,K) (|A| (|B| e)).
+fn frow to ulong
+bad = ulong 0
+for j ulong dn
+put xr j fsign
+end
+for k ulong dk
+y = 0.0f64
+h = 0.0f64
+for j ulong dn
+b = bf eb k j
+y = add y mul b get xr j
+h = add h fabs b
+end
+put xv k y
+put xh k h
+end
+t0 = gside dn dk
+for i ulong dm
+if frowi i t0
+bad = add bad 1
+end
+end
+ret bad
+end
+fn frowi i ulong t0 f64 to bool
+z = 0.0f64
+g = 0.0f64
+for k ulong dk
+a = bf ea i k
+z = add z mul a get xv k
+g = add g mul fabs a get xh k
+end
+w = 0.0f64
+for j ulong dn
+w = add w mul f3 ec i j get xr j
+end
+d = fabs sub z w
+t = mul t0 g
+xmax d t
+ret not le d t
+end
+note FP left side: x = s^T A, columns test |x B - s^T C| against gside(M,K) ((e^T |A|) |B|).
+fn fcol to ulong
+bad = ulong 0
+for i ulong dm
+put xr i fsign
+end
+for k ulong dk
+x = 0.0f64
+h = 0.0f64
+for i ulong dm
+a = bf ea i k
+x = add x mul a get xr i
+h = add h fabs a
+end
+put xv k x
+put xh k h
+end
+t0 = gside dm dk
+for j ulong dn
+if fcolj j t0
+bad = add bad 1
+end
+end
+ret bad
+end
+fn fcolj j ulong t0 f64 to bool
+z = 0.0f64
+g = 0.0f64
+for k ulong dk
+b = bf eb k j
+z = add z mul get xv k b
+g = add g mul get xh k fabs b
+end
+w = 0.0f64
+for i ulong dm
+w = add w mul get xr i f3 ec i j
+end
+d = fabs sub z w
+t = mul t0 g
+xmax d t
+ret not le d t
+end
+note Exact right side: odd u32 multipliers r, y = B r mod 2^32, rows test A y = C r mod 2^32.
+fn xrow to ulong
+bad = ulong 0
+for j ulong dn
+put xu j or and rnext 1 MASK 1
+end
+for k ulong dk
+y = ulong 0
+for j ulong dn
+y = add y mul eb k j get xu j
+end
+put xq k y
+end
+for i ulong dm
+z = ulong 0
+for k ulong dk
+z = add z mul ea i k get xq k
+end
+w = ulong 0
+for j ulong dn
+w = add w mul ec i j get xu j
+end
+if ne and xor z w MASK 0
+bad = add bad 1
+end
+end
+ret bad
+end
+fn xcol to ulong
+bad = ulong 0
+for i ulong dm
+put xu i or and rnext 1 MASK 1
+end
+for k ulong dk
+x = ulong 0
+for i ulong dm
+x = add x mul get xu i ea i k
+end
+put xq k x
+end
+for j ulong dn
+z = ulong 0
+for k ulong dk
+z = add z mul get xq k eb k j
+end
+w = ulong 0
+for i ulong dm
+w = add w mul get xu i ec i j
+end
+if ne and xor z w MASK 0
+bad = add bad 1
+end
+end
+ret bad
+end
+note Checksum mode: one right and one left randomized check (failing rows plus failing columns).
+fn cabft to ulong
+put xm 0 0.0
+if eq get gd 0 0
+ret add xrow xcol
+end
+ret add frow fcol
+end
+note Common-mode guard: FNV-1a over dims and both inputs, compared with the generation-time digest.
+fn cdig to ulong
+h = ulong 14695981039346656037
+for q ulong 4
+h = fnvw h get gd q
+end
+for e ulong mul dm dk
+h = fnvw h get ga e
+end
+for e ulong mul dk dn
+h = fnvw h get gb e
+end
+ret h
+end
+note Structural: nonfinite f32 outputs (exponent all ones) counted; exact mode has none.
+fn cnonfin to ulong
+if eq get gd 0 0
+ret 0
+end
+bad = ulong 0
+for e ulong mul dm dn
+if eq and get gobs e 21390950402139095040
+bad = add bad 1
+end
+end
+ret bad
+end
diff --git a/native/abft/cul1.om b/native/abft/cul1.om
new file mode 100644
index 00000000..06a1efc1
--- /dev/null
+++ b/native/abft/cul1.om
@@ -0,0 +1,112 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note CUL1 two-sided randomized checksum (Freivalds) for the registered GEMM family (op 3).
+note Concatenate after native/learn53/task.om; task.om is unchanged and keval stays the exact oracle.
+note kabft n c seed: kvalid refusals pass through unchanged; 69 for a non-GEMM op; 65 bad length;
+note 1 canary/padding/residual mismatch; 0 pass. seed is the evaluator nonce; ko never chooses it.
+note Miss bound (Wolfram, docs/abft/CONTRACT.md section 4): a single wrong element is always detected;
+note an error pattern whose 2-adic valuation is v is missed with probability <= 2^(v-31) per side,
+note and a rectangle of 2^31 is always missed (keval still detects it).
+global kr ulong 64
+global kq2 ulong 64
+global ks ulong 1
+fn ksm to ulong
+s = add get ks 0 11400714819323198485
+put ks 0 s
+z = mul xor s shr s 30 13787848793156543929
+z = mul xor z shr z 27 10723151780598845931
+ret or and xor z shr z 31 4294967295 1
+end
+fn kca i ulong k ulong to ulong
+ret kw add 24 add mul i kw 8 k
+end
+fn kcb k ulong j ulong to ulong
+ret kw add add 24 kw 11 add mul k kw 9 j
+end
+fn kcx i ulong j ulong to ulong
+ret kc add 1 add mul i kw 10 j
+end
+fn kright to bool
+for j ulong kw 6
+put kr j ksm
+end
+for k ulong kw 7
+y = ulong 0
+for j ulong kw 6
+y = add y mul kcb k j get kr j
+end
+put kq2 k y
+end
+for i ulong kw 5
+z = ulong 0
+for k ulong kw 7
+z = add z mul kca i k get kq2 k
+end
+w = ulong 0
+for j ulong kw 6
+w = add w mul kcx i j get kr j
+end
+if ne and xor z w 4294967295 0
+ret false
+end
+end
+ret true
+end
+fn kleft to bool
+for i ulong kw 5
+put kr i ksm
+end
+for k ulong kw 7
+x = ulong 0
+for i ulong kw 5
+x = add x mul get kr i kca i k
+end
+put kq2 k x
+end
+for j ulong kw 6
+z = ulong 0
+for k ulong kw 7
+z = add z mul get kq2 k kcb k j
+end
+w = ulong 0
+for i ulong kw 5
+w = add w mul get kr i kcx i j
+end
+if ne and xor z w 4294967295 0
+ret false
+end
+end
+ret true
+end
+fn kabft n ulong c ulong seed ulong to int
+status = kvalid n
+if ne status 0
+ret status
+end
+if ne kw 2 3
+ret 69
+end
+if ne c mul 4 add kw 13 2
+ret 65
+end
+if ne kc 0 2779096485
+ret 1
+end
+if ne kc add kw 13 1 2779096485
+ret 1
+end
+for p ulong kw 13
+if ge rem p kw 10 kw 6
+if ne kc add p 1 2779096485
+ret 1
+end
+end
+end
+put ks 0 seed
+if not kright
+ret 1
+end
+if not kleft
+ret 1
+end
+ret 0
+end
diff --git a/native/abft/lib.om b/native/abft/lib.om
new file mode 100644
index 00000000..d17030e7
--- /dev/null
+++ b/native/abft/lib.om
@@ -0,0 +1,83 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note native/abft shared words: buffered stdout, decimal output, splitmix64 streams, FNV-1a digests,
+note bf16/f32 decoding. See docs/abft/CONTRACT.md.
+global ob uchar 65536
+global obn ulong 1
+global rs ulong 4
+fn now to ulong
+ret ulong monons
+end
+fn oflush to void
+n = get obn 0
+if gt n 0
+w = write 1 ob 0 n
+if lt w 0
+trap 8
+end
+put obn 0 0
+end
+end
+fn ochar c uchar to void
+n = get obn 0
+if ge n 65000
+oflush
+n = get obn 0
+end
+put ob n c
+put obn 0 add n 1
+end
+fn odig v ulong to void
+if ge v 10
+odig div v 10
+end
+ochar uchar add 48 rem v 10
+end
+fn onum v ulong to void
+ochar 32
+odig v
+end
+fn osig v long to void
+ochar 32
+if lt v 0
+ochar 45
+odig ulong neg v
+else
+odig ulong v
+end
+end
+fn onl to void
+ochar 10
+end
+note splitmix64 (Steele, Lea, Flood 2014). Stream 0 input generator, 1 evaluator nonce stream,
+note 2 candidate schedule, 3 candidate fault placement. Streams never share state.
+fn rseed k ulong v ulong to void
+put rs k v
+end
+fn rnext k ulong to ulong
+s = add get rs k 11400714819323198485
+put rs k s
+z = mul xor s shr s 30 13787848793156543929
+z = mul xor z shr z 27 10723151780598845931
+ret xor z shr z 31
+end
+fn rbelow k ulong n ulong to ulong
+ret rem rnext k n
+end
+note FNV-1a 64 over the low 32 bits of each word, little-endian byte order.
+fn fnvw h ulong v ulong to ulong
+x = h
+for i ulong 4
+x = xor x and shr v mul i 8 255
+x = mul x 1099511628211
+end
+ret x
+end
+fn bf v ulong to f64
+ret f64 bitcast f32 uint shl and v 65535 16
+end
+fn f3 v ulong to f64
+ret f64 bitcast f32 uint and v 4294967295
+end
+fn fbits x f32 to ulong
+ret ulong bitcast uint x
+end
diff --git a/native/abft/run.om b/native/abft/run.om
new file mode 100644
index 00000000..21b0cf0a
--- /dev/null
+++ b/native/abft/run.om
@@ -0,0 +1,731 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note native/abft evaluator driver. Owns inputs, the ground-truth record gref, the nonce stream, the
+note tolerances and admission. Each attempt forks a candidate child whose only channel back is a memfd
+note plus its exit status; the evaluator kills it at the frozen deadline and always reaps it.
+note Output columns are printed first (COLUMNS lines); docs/abft/CONTRACT.md section 8 decodes them.
+text MFN "abftout"
+text TCASE "CASE"
+text TSCH "SCHED"
+text TWIT "WITNESS"
+text TTAL "TALLY"
+text TRES "RESOURCES"
+text TPLAN "PLAN"
+text TGATE "GATE"
+text THDR "COLUMNS PLAN version rows S deadline_ns retries first last\nCOLUMNS CASE row rep att dt m n k w pol tgt site fault sub p1 p2 seed nonce exit sig bytes corrupt struct dig full abft samp adm verdict t_cand t_ref t_full t_abft t_samp t_dig sched steps\nCOLUMNS SCHED row status reason pol tgt site control distinct reps round_robin\nCOLUMNS TALLY row cases corrupt full_tp full_fn full_fp full_tn abft_tp abft_fn abft_fp abft_tn samp_tp samp_fn samp_fp samp_tn dig_tp dig_fn dig_fp dig_tn struct_tp struct_fn struct_fp struct_tn adm_tp adm_fn adm_fp adm_tn accept recovered rejected sched_status timeouts reps\nCOLUMNS WITNESS row partner reps same orig_det red_det verdict\nCOLUMNS RESOURCES forks reaped timeouts kills fd_errors wait_errors fd_first fd_last\nCOLUMNS GATE id pass observed expected\n"
+const CEXIT ulong 0
+const CSIG ulong 1
+const CBYT ulong 2
+const CCOR ulong 3
+const CSTR ulong 4
+const CDIG ulong 5
+const CFUL ulong 6
+const CABF ulong 7
+const CSAM ulong 8
+const CADM ulong 9
+const CTC ulong 10
+const CTR ulong 11
+const CTF ulong 12
+const CTA ulong 13
+const CTS ulong 14
+const CTD ulong 15
+const CSH ulong 16
+const CSTP ulong 17
+const CNON ulong 18
+const CVER ulong 19
+global gx uchar 262160
+global gst uchar 4
+global gnon uchar 8
+global gab uchar 32
+global gdig ulong 1
+global gcs ulong 32
+global gtl ulong 32
+global gtr ulong 2048
+global ghs ulong 256
+global gres ulong 8
+global kq ulong 16
+global gwp ulong 256
+global gwc ulong 256
+global gwn ulong 4
+global gexit ulong 64
+fn cs i ulong to ulong
+ret get gcs i
+end
+fn css i ulong v ulong to void
+put gcs i v
+end
+fn pget r ulong f ulong to ulong
+ret get pl add mul r 16 f
+end
+fn rinc i ulong to void
+put gres i add get gres i 1
+end
+fn tinc i ulong to void
+put gtl i add get gtl i 1
+end
+fn bv b bool to ulong
+if b
+ret 1
+end
+ret 0
+end
+fn ptxt0 to void
+for i ulong len TCASE
+ochar get TCASE i
+end
+end
+fn ptxt1 to void
+for i ulong len TSCH
+ochar get TSCH i
+end
+end
+fn ptxt2 to void
+for i ulong len TWIT
+ochar get TWIT i
+end
+end
+fn ptxt3 to void
+for i ulong len TTAL
+ochar get TTAL i
+end
+end
+fn ptxt4 to void
+for i ulong len TRES
+ochar get TRES i
+end
+end
+fn ptxt5 to void
+for i ulong len TPLAN
+ochar get TPLAN i
+end
+end
+fn ptxt6 to void
+for i ulong len TGATE
+ochar get TGATE i
+end
+end
+fn ptxth to void
+for i ulong len THDR
+ochar get THDR i
+end
+end
+fn bfgen to ulong
+s = and rnext 0 1
+e = add 120 rbelow 0 8
+m = rbelow 0 128
+ret or or shl s 15 shl e 7 m
+end
+fn gval to ulong
+if eq get gd 0 0
+ret and rnext 0 MASK
+end
+ret bfgen
+end
+note Inputs from stream 0 seeded by (row seed, rep); evaluator-owned, never candidate-chosen.
+fn gen rep ulong to void
+rseed 0 add mul kf KSEED 1000003 rep
+put gd 0 kf KDT
+put gd 1 kf KM
+put gd 2 kf KN
+put gd 3 kf KK
+for e ulong mul dm dk
+put ga e gval
+end
+for e ulong mul dk dn
+put gb e gval
+end
+end
+note Ground-truth record: the same tiled algorithm, fault free, one worker, round robin, in the
+note evaluator process. Used only to label corrupt/clean; no checker or admission reads it.
+fn cref to void
+for f ulong 16
+put kq f get kp f
+end
+put kp KFLT 0
+put kp KW 1
+put kp KPOL 0
+put kat 0 0
+s = crun
+if eq s 0
+trap 11
+end
+for e ulong mul dm dn
+put gref e get cc e
+end
+for f ulong 16
+put kp f get kq f
+end
+end
+fn cpack e ulong v ulong to void
+for b ulong 4
+put gx add mul e 4 b uchar and shr v mul b 8 255
+end
+end
+fn cpack8 o ulong v ulong to void
+for b ulong 8
+put gx add o b uchar and shr v mul b 8 255
+end
+end
+note Child: the candidate. Writes M*N little-endian u32 words, its schedule hash and step count.
+fn cchild fd int to void
+s = crun
+mn = mul kf KM kf KN
+for e ulong mn
+cpack e get cc e
+end
+nb = mul mn 4
+cpack8 nb get csh 0
+cpack8 add nb 8 s
+w = pwrite fd gx 0 add nb 16 0
+if ne w long add nb 16
+exit 70
+end
+exit 0
+end
+fn reap pid long to void
+dl = add now get pcfg 1
+r = long 0
+while true bound 999999
+r = waitpid int pid gst 0 4 1
+if ne r 0
+break
+end
+if gt now dl
+k = killpid int pid 9
+if ne k 0
+rinc 5
+end
+rinc 2
+rinc 3
+tinc 30
+r = waitpid int pid gst 0 4 0
+break
+end
+z = sleepns 100000
+if lt z 0
+rinc 5
+end
+end
+if lt r 0
+rinc 5
+else
+rinc 1
+end
+css CSIG and ulong get gst 0 127
+css CEXIT ulong get gst 1
+end
+fn word e ulong to ulong
+v = ulong 0
+for b ulong 4
+v = or v shl ulong get gx add mul e 4 b mul b 8
+end
+ret v
+end
+fn word8 o ulong to ulong
+v = ulong 0
+for b ulong 8
+v = or v shl ulong get gx add o b mul b 8
+end
+ret v
+end
+fn collect fd int to void
+mn = mul dm dn
+nb = mul mn 4
+for e ulong mn
+put gobs e 0
+end
+r = pread fd gx 0 add nb 16 0
+c = fclose fd
+if ne c 0
+rinc 4
+end
+if lt r 0
+css CBYT 0
+ret
+end
+css CBYT ulong r
+if ne ulong r add nb 16
+ret
+end
+for e ulong mn
+put gobs e word e
+end
+css CSH word8 nb
+css CSTP word8 add nb 8
+end
+fn okout to bool
+if ne cs CEXIT 0
+ret false
+end
+if ne cs CSIG 0
+ret false
+end
+ret eq cs CBYT add mul mul dm dn 4 16
+end
+fn truth to ulong
+if not okout
+ret 1
+end
+for e ulong mul dm dn
+if ne get gobs e get gref e
+ret 1
+end
+end
+ret 0
+end
+fn nonce to ulong
+r = random gnon 0 8 0
+if ne r 8
+trap 12
+end
+v = ulong 0
+for b ulong 8
+v = or v shl ulong get gnon b mul b 8
+end
+ret v
+end
+note Detectors. Timed with now (monons); check time is reported separately, never inside t_cand.
+fn detect to void
+t = now
+css CDIG bv ne cdig get gdig 0
+css CTD sub now t
+css CSTR bv not okout
+if not okout
+css CFUL 2
+css CABF 2
+css CSAM 2
+ret
+end
+if gt cnonfin 0
+css CSTR 1
+end
+n = nonce
+css CNON n
+rseed 1 n
+t = now
+css CFUL bv gt cfull 0
+css CTF sub now t
+t = now
+css CABF bv gt cabft 0
+css CTA sub now t
+t = now
+css CSAM bv gt csamp get pcfg 0 0
+css CTS sub now t
+end
+fn admit to ulong
+if eq cs CSTR 1
+ret 1
+end
+if eq cs CDIG 1
+ret 1
+end
+if eq cs CFUL 1
+ret 1
+end
+ret bv eq cs CABF 1
+end
+fn attempt att ulong to void
+for i ulong 32
+if ne i CTR
+css i 0
+end
+end
+put kat 0 att
+fd = memfd MFN 0 len MFN 0
+if lt fd 0
+trap 13
+end
+t = now
+pid = fork
+if eq pid 0
+cchild int fd
+end
+if lt pid 0
+trap 14
+end
+rinc 0
+reap pid
+css CTC sub now t
+collect int fd
+css CCOR truth
+detect
+css CADM admit
+end
+fn tadd b ulong d ulong c ulong to void
+if eq d 2
+ret
+end
+if eq c 1
+if eq d 1
+tinc b
+else
+tinc add b 1
+end
+else
+if eq d 1
+tinc add b 2
+else
+tinc add b 3
+end
+end
+end
+fn tcase to void
+tinc 0
+c = cs CCOR
+if eq c 1
+tinc 1
+end
+if eq cs CEXIT 103
+put gexit kf 0 add get gexit kf 0 1
+end
+tadd 2 cs CFUL c
+tadd 6 cs CABF c
+tadd 10 cs CSAM c
+tadd 14 cs CDIG c
+tadd 18 cs CSTR c
+tadd 22 cs CADM c
+end
+fn pcase r ulong rep ulong att ulong to void
+ptxt0
+onum add r 1
+onum rep
+onum att
+for f ulong 13
+onum kf add f 1
+end
+onum cs CNON
+for q ulong 10
+onum cs q
+end
+onum cs CVER
+for q ulong 6
+onum cs add CTC q
+end
+onum cs CSH
+onum cs CSTP
+onl
+end
+fn hseen h ulong to void
+n = get gwn 2
+for q ulong n
+if eq get ghs q h
+ret
+end
+end
+if lt n 256
+put ghs n h
+put gwn 2 add n 1
+end
+end
+fn odig2 to ulong
+h = ulong 14695981039346656037
+for e ulong mul dm dn
+h = fnvw h get gobs e
+end
+ret h
+end
+note One rep: fresh inputs, digest, ground truth, optional common-mode corruption, then up to
+note 1 + retries attempts. Verdict 0 ACCEPT, 1 RECOVERED, 2 REJECTED, 4 retry follows.
+fn runrep r ulong rep ulong to void
+gen rep
+put krep 0 rep
+put gdig 0 cdig
+t = now
+cref
+css CTR sub now t
+if eq kf KFLT 7
+p = kf KP1
+put ga p xor get ga p shl ulong 1 kf KP2
+end
+last = get pcfg 2
+for att ulong add last 1
+attempt att
+if eq att 0
+hseen cs CSH
+put gwc rep odig2
+if eq cs CADM 1
+put gwn 1 add get gwn 1 1
+end
+end
+if eq cs CADM 0
+css CVER bv gt att 0
+else
+if eq att last
+css CVER 2
+else
+css CVER 4
+end
+end
+tcase
+pcase r rep att
+if ne cs CVER 4
+tinc add 26 cs CVER
+break
+end
+end
+for e ulong mul dm dn
+put gprev e get gref e
+end
+end
+fn psched r ulong st ulong rsn ulong to void
+ptxt1
+onum add r 1
+onum st
+onum rsn
+onum kf KPOL
+onum kf KTGT
+onum kf KSITE
+onum shr and kf KFLG 2 1
+onum get gwn 2
+onum get kp 14
+onum bv eq kf KPOL 0
+onl
+end
+fn ptally r ulong to void
+ptxt3
+onum add r 1
+for q ulong 32
+onum get gtl q
+end
+onl
+for q ulong 32
+put gtr add mul r 32 q get gtl q
+end
+end
+note CUDApp#56: a row flagged bit3 is the reduced-concurrency partner of the row before it (same
+note seed). OR-RR: fault-free output digests equal rep by rep. OC-RC: verdict 1 means the original
+note concurrency detected a fault the reduced run never showed, a counterexample to using it as proof.
+fn pwit r ulong to void
+reps = get kp 14
+same = ulong 0
+for q ulong reps
+if eq get gwp q get gwc q
+same = add same 1
+end
+end
+od = get gwn 0
+rd = get gwn 1
+v = ulong 0
+if ne same reps
+v = 2
+end
+if and gt od 0 eq rd 0
+v = 1
+end
+ptxt2
+onum add r 1
+onum r
+onum reps
+onum same
+onum od
+onum rd
+onum v
+onl
+put gwn 3 add mul v 1000 same
+end
+fn runrow r ulong to void
+for f ulong 16
+put kp f pget r f
+end
+put kat 0 0
+for q ulong 32
+put gtl q 0
+end
+put gwn 2 0
+put gwn 1 0
+put gtl 31 get kp 14
+rsn = sreason
+st = sstatus rsn
+put gtl 29 st
+if ne st 0
+psched r st rsn
+ptally r
+ret
+end
+gen 1000000
+cref
+for e ulong mul dm dn
+put gprev e get gref e
+end
+for rep ulong get kp 14
+runrep r rep
+end
+psched r st rsn
+ptally r
+if eq and kf KFLG 8 8
+pwit r
+end
+for q ulong 256
+put gwp q get gwc q
+end
+put gwn 0 get gwn 1
+oflush
+end
+fn tl id ulong i ulong to ulong
+ret get gtr add mul sub id 1 32 i
+end
+fn pgate id ulong ok bool obs ulong exp ulong to bool
+ptxt6
+onum id
+onum bv ok
+onum obs
+onum exp
+onl
+ret ok
+end
+note Gates (docs/abft/CONTRACT.md section 9). Declared admission misses: rows 11 and 17
+note (f32 mantissa flips below the P1 rounding bound). Only meaningful over the full plan.
+fn gfp to ulong
+s = ulong 0
+for r ulong get pn 0
+for d ulong 6
+s = add s tl add r 1 add 4 mul d 4
+end
+end
+ret s
+end
+fn gfn to ulong
+s = ulong 0
+for r ulong get pn 0
+id = add r 1
+if and ne id 11 ne id 17
+s = add s tl id 23
+end
+end
+ret s
+end
+fn gsched to ulong
+bad = ulong 0
+for r ulong get pn 0
+id = add r 1
+e = ulong 0
+if eq id 37
+e = 65
+end
+if or eq id 38 eq id 39
+e = 69
+end
+if ne tl id 29 e
+bad = add bad 1
+end
+end
+ret bad
+end
+fn gates to ulong
+fail = ulong 0
+v = gfp
+if not pgate 1 eq v 0 v 0
+fail = add fail 1
+end
+v = gfn
+if not pgate 2 eq v 0 v 0
+fail = add fail 1
+end
+v = gsched
+if not pgate 3 eq v 0 v 0
+fail = add fail 1
+end
+v = add tl 43 27 tl 44 28
+if not pgate 4 eq v add tl 43 31 tl 44 31 v add tl 43 31 tl 44 31
+fail = add fail 1
+end
+ret add fail gates2
+end
+fn gates2 to ulong
+fail = ulong 0
+ok = and eq get gres 0 get gres 1 eq get gres 6 get gres 7
+ok = and ok eq add get gres 4 get gres 5 0
+if not pgate 5 ok sub get gres 0 get gres 1 0
+fail = add fail 1
+end
+v = tl 36 30
+if not pgate 6 eq v mul 2 tl 36 31 v mul 2 tl 36 31
+fail = add fail 1
+end
+v = add tl 40 7 tl 40 2
+if not pgate 7 eq v mul 2 tl 40 1 v mul 2 tl 40 1
+fail = add fail 1
+end
+note Gate 8 (revised after the first sandbox run, see CONTRACT.md section 9): the digest catches every
+note corrupt case, and full/checksum detect only the cases the structural check flags as nonfinite.
+s = tl 42 18
+c = tl 42 1
+ok = and eq tl 42 14 c and eq add tl 42 3 s c eq add tl 42 7 s c
+v = add add tl 42 14 tl 42 3 tl 42 7
+if not pgate 8 ok v sub mul 3 c mul 2 s
+fail = add fail 1
+end
+v = get gwn 3
+if not pgate 9 eq v tl 51 31 v tl 51 31
+fail = add fail 1
+end
+note Gate 10 (added after the first sandbox run): every row 26 attempt ends in Omega trap 3 (exit 103).
+v = get gexit 26
+if not pgate 10 eq v tl 26 0 v tl 26 0
+fail = add fail 1
+end
+ret fail
+end
+fn argnum i ulong d ulong to ulong
+if le ulong argcnt i
+ret d
+end
+n = argread i gab 0 32
+if le n 0
+ret d
+end
+v = ulong 0
+for q ulong ulong n
+c = ulong get gab q
+if or lt c 48 gt c 57
+exit 64
+end
+v = add mul v 10 sub c 48
+end
+ret v
+end
+fn fdprobe to ulong
+fd = memfd MFN 0 len MFN 0
+if lt fd 0
+trap 13
+end
+c = fclose int fd
+if ne c 0
+rinc 4
+end
+ret ulong fd
+end
+fn main to int
+pfill
+put gres 6 fdprobe
+first = argnum 1 1
+last = argnum 2 get pn 0
+if or or eq first 0 gt first last gt last get pn 0
+exit 64
+end
+ptxth
+ptxt5
+onum get pcfg 3
+onum get pn 0
+onum get pcfg 0
+onum get pcfg 1
+onum get pcfg 2
+onum first
+onum last
+onl
+oflush
+for r ulong sub add last 1 first
+runrow add sub first 1 r
+end
+put gres 7 fdprobe
+ptxt4
+for q ulong 8
+onum get gres q
+end
+onl
+fail = ulong 0
+if and eq first 1 eq last get pn 0
+fail = gates
+end
+oflush
+ret int fail
+end
diff --git a/native/abft/sched.om b/native/abft/sched.om
new file mode 100644
index 00000000..1edb5a38
--- /dev/null
+++ b/native/abft/sched.om
@@ -0,0 +1,68 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note CUDApp#55 schedule perturbation admission. The evaluator validates every frozen row before any
+note fork; a refused row never runs. Reason codes (docs/abft/CONTRACT.md section 7):
+note 0 accepted, 1 unknown policy, 2 target worker out of range, 3 atomic site unsupported (69),
+note 4 device instruction-stream site unsupported: no qualified delay opcode (69),
+note 5 wait removal without the known-bad control label, 6 shape or worker bounds, 7 transposed index
+note fault on a non-square shape, 8 delay policy without a site, 9 hang control with one worker.
+fn sreason to ulong
+m = kf KM
+n = kf KN
+k = kf KK
+w = kf KW
+if gt kf KPOL 3
+ret 1
+end
+if ge kf KPOL 2
+if ge kf KTGT w
+ret 2
+end
+end
+if eq kf KSITE 4
+ret 3
+end
+if gt kf KSITE 4
+ret 4
+end
+if eq kf KFLT 5
+if eq and kf KFLG 2 0
+ret 5
+end
+end
+if or eq w 0 gt w 64
+ret 6
+end
+if or or eq m 0 gt m 256 or eq n 0 gt n 256
+ret 6
+end
+if or eq k 0 gt k 256
+ret 6
+end
+if fis 4 2
+if ne n k
+ret 7
+end
+end
+if eq kf KPOL 3
+if eq kf KSITE 0
+ret 8
+end
+end
+if eq kf KFLT 5
+if eq kf KSUB 4
+if lt w 2
+ret 9
+end
+end
+end
+ret 0
+end
+fn sstatus r ulong to ulong
+if eq r 0
+ret 0
+end
+if or eq r 3 eq r 4
+ret 69
+end
+ret 65
+end
diff --git a/tests/abft/.crumb b/tests/abft/.crumb
new file mode 100644
index 00000000..cf3b59ed
--- /dev/null
+++ b/tests/abft/.crumb
@@ -0,0 +1,6 @@
+{
+ "schema_version": "1.0.0",
+ "name": "gemm-fault-detection-tests",
+ "layer": "tests",
+ "purpose": "Frozen DRA-420/DRA-387 evaluation plan, its committed SHA256, the learn53 CUL1 integration unit and the seeded Omega driver (driver.om); public fixtures, never sealed evaluation"
+}
diff --git a/tests/abft/FROZEN.sha256 b/tests/abft/FROZEN.sha256
new file mode 100644
index 00000000..23600b70
--- /dev/null
+++ b/tests/abft/FROZEN.sha256
@@ -0,0 +1 @@
+1725f1ee3662e0b49bdf33dcefc6effdf254c70806f43049e4e062ec68501e5c tests/abft/frozen.om
diff --git a/tests/abft/cul1-unit.om b/tests/abft/cul1-unit.om
new file mode 100644
index 00000000..552643e7
--- /dev/null
+++ b/tests/abft/cul1-unit.om
@@ -0,0 +1,86 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note Unit cases for native/abft/cul1.om; concatenated after native/learn53/task.om, tests/learn53/fixtures.om
+note and native/abft/cul1.om (tests/abft/driver.om). keval stays the exact oracle; kabft is the checksum.
+global ksave uchar 4096
+fn kseeds want int to void
+for s ulong 8
+check eq kabft 144 36 add mul s 2654435761 1 want
+end
+end
+fn abclean to void
+mat
+check eq keval 144 36 0
+kseeds 0
+end
+fn abone to void
+mat
+cw 7 60
+check eq keval 144 36 1
+kseeds 1
+mat
+cw 1 1073741845
+check eq keval 144 36 1
+kseeds 1
+mat
+cw 1 22
+cw 2 23
+kseeds 1
+end
+fn abcanary to void
+mat
+cw 0 0
+check eq kabft 144 36 1 1
+mat
+cw 4 0
+check eq keval 144 36 1
+check eq kabft 144 36 1 1
+mat
+cw 8 0
+check eq kabft 144 36 1 1
+end
+fn abrect to void
+note Declared miss: 2^31 added to C[0][0], C[0][1], C[1][0], C[1][1]; Wolfram 2^31+21 = 2147483669 etc.
+mat
+cw 1 2147483669
+cw 2 2147483672
+cw 5 2147483695
+cw 6 2147483702
+check eq keval 144 36 1
+kseeds 0
+end
+fn abrefuse to void
+vec
+check eq keval 136 28 0
+check eq kabft 136 28 1 69
+mat
+check eq kabft 144 32 1 65
+mat
+tw 21 1
+check eq kabft 144 36 1 65
+end
+fn abpure to void
+mat
+for i ulong 4096
+put ksave i get kt i
+end
+check eq kabft 144 36 7 0
+same = true
+for i ulong 4096
+if ne get ksave i get kt i
+same = false
+end
+end
+check same
+end
+fn main to int
+abclean
+abone
+abcanary
+abrect
+abrefuse
+abpure
+if ne get tally 1 0
+ret 1
+end
+ret 0
+end
diff --git a/tests/abft/driver.om b/tests/abft/driver.om
new file mode 100644
index 00000000..51e77d20
--- /dev/null
+++ b/tests/abft/driver.om
@@ -0,0 +1,856 @@
+om2
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note tests/abft/driver.om: DRA-420/DRA-387 GEMM fault-detection evaluator driver, seeded Omega. It
+note checks the compiler pin and the frozen plan hash, builds build/abft/abft and cul1-unit with the
+note pinned omc, runs the CUL1 unit and the evaluator, and prints the evaluator's GATE lines.
+note From the repository root:
+note mkdir -p build && "$OMEGA_OMC" < tests/abft/driver.om > build/abft-driver
+note chmod +x build/abft-driver && OMEGA_OMC=/abs/omega-mv/seed/out/omc build/abft-driver [OUT_DIR] [FIRST LAST]
+note OMEGA_OMC must be omega-mv e5b32567 seed/out/omc (sha256 PIN); any other compiler is refused.
+note Exit: 0 every step and gate passed; 2 OMEGA_OMC unset; 1 pin, frozen-hash, input or output
+note failure; otherwise the failing step's status (omc, cul1-unit, then the evaluator: its failed
+note gate count, 64 for bad arguments). A signalled child is 128 + signal. Children get an empty
+note environment and inherit stdin and stderr.
+
+text pinhex "2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f"
+text envkey "OMEGA_OMC="
+text frozen "tests/abft/FROZEN.sha256"
+text defout "build/abft"
+text slash "/"
+text two " "
+text nl "\n"
+text p1 "tests/abft/frozen.om"
+text p2 "native/abft/lib.om"
+text p3 "native/abft/check.om"
+text p4 "native/abft/cand.om"
+text p5 "native/abft/sched.om"
+text p6 "native/abft/run.om"
+text q1 "native/learn53/task.om"
+text q2 "tests/learn53/fixtures.om"
+text q3 "native/abft/cul1.om"
+text q4 "tests/abft/cul1-unit.om"
+text nabft "abft"
+text nabsrc "abft.om"
+text nabtmp "abft.tmp"
+text nculu "cul1-unit"
+text ncusrc "cul1-unit.om"
+text ncutmp "cul1-unit.tmp"
+text nlog "abft.log"
+text gatep "GATE"
+text enoomc "OMEGA_OMC: set OMEGA_OMC to the pinned omega-mv e5b32567 seed/out/omc\n"
+text epin "abft: OMEGA_OMC is not the pinned omc "
+text efrz "abft: FAILED "
+text enofrz "abft: no properly formatted lines in tests/abft/FROZEN.sha256\n"
+text eread "abft: cannot read "
+text ewrite "abft: cannot write "
+text emkdir "abft: cannot create "
+text ebig "abft: input or argument too large\n"
+text eproc "abft: fork or wait failed\n"
+
+global pb uchar 4096
+global pbn ulong 1
+global ob uchar 4096
+global obn ulong 1
+global cp uchar 4096
+global cpn ulong 1
+global ab uchar 8192
+global av uchar 16384
+global avp ulong 1
+global avc ulong 1
+global avl ulong 1
+global fa uchar 4194304
+global fan ulong 1
+global fb uchar 4194304
+global fbn ulong 1
+global hexd uchar 64
+global stb uchar 4
+global kk uint 64
+global ivs uint 8
+global hv uint 8
+global ws uint 64
+global st uint 8
+global blk uchar 64
+global bk ulong 2
+
+note ---- output ------------------------------------------------------------------------------
+fn say t view uchar * to void
+r = write 1 t 0 len t
+end
+
+fn esay t view uchar * to void
+r = write 2 t 0 len t
+end
+
+fn die t view uchar * to void
+esay t
+exit 1
+end
+
+note stderr: T, then the path pb, then a newline; exit 1
+fn diep t view uchar * to void
+esay t
+r = write 2 pb 0 get pbn 0
+esay nl
+exit 1
+end
+
+note ---- paths: pb is the working path, ob the output directory --------------------------------
+fn pclear to void
+put pbn 0 0
+end
+
+fn pcat t view uchar * to void
+p = get pbn 0
+n = len t
+if gt add p n 4095
+die ebig
+end
+for i ulong n
+put pb add p i get t i
+end
+put pbn 0 add p n
+end
+
+note pb = OUT/NAME
+fn opath t view uchar * to void
+n = get obn 0
+for i ulong n
+put pb i get ob i
+end
+put pbn 0 n
+pcat slash
+pcat t
+end
+
+fn opr to long
+ret fopen pb 0 get pbn 0 0 0
+end
+
+fn opw to long
+ret fopen pb 0 get pbn 0 577 438
+end
+
+fn fclo fd long to void
+if ge fd 0
+r = fclose int fd
+end
+end
+
+note ---- packed argument list ---------------------------------------------------------------
+fn areset to void
+put avc 0 0
+put avp 0 2
+put av 0 0
+put av 1 0
+end
+
+fn afix to void
+p = get avp 0
+q = get avl 0
+m = sub sub p q 2
+if gt m 65535
+die ebig
+end
+put av q uchar and m 255
+put av add q 1 uchar shr m 8
+end
+
+fn anew to void
+p = get avp 0
+if gt add p 2 len av
+die ebig
+end
+put avl 0 p
+put avp 0 add p 2
+c = add get avc 0 1
+put avc 0 c
+put av 0 uchar and c 255
+put av 1 uchar shr c 8
+afix
+end
+
+note append the path pb to the current record
+fn apb to void
+p = get avp 0
+n = get pbn 0
+if gt add p n len av
+die ebig
+end
+for i ulong n
+put av add p i get pb i
+end
+put avp 0 add p n
+afix
+end
+
+note append argument I of this process as a new record
+fn aarg i ulong to void
+anew
+p = get avp 0
+n = argread i av p sub len av p
+if lt n 0
+die ebig
+end
+put avp 0 add p ulong n
+afix
+end
+
+note ---- children ---------------------------------------------------------------------------
+note run the argument list; a negative descriptor is inherited. Shell-style status.
+fn spawn fi int fo int to ulong
+pid = fork
+if lt pid 0
+die eproc
+end
+if eq pid 0
+if ge fi 0
+r = dupfd fi 0 0
+end
+if ge fo 0
+r = dupfd fo 1 0
+end
+r = execprog av 0 get avp 0
+if eq r -2
+exit 127
+end
+exit 126
+end
+r = waitpid int pid stb 0 4 0
+if ne r pid
+die eproc
+end
+sg = and ulong get stb 0 127
+if eq sg 0
+ret ulong get stb 1
+end
+ret add sg 128
+end
+
+note ---- files ------------------------------------------------------------------------------
+note fb = the bytes of the file pb; false when it cannot be read
+fn rdb to bool
+put fbn 0 0
+fd = opr
+if lt fd 0
+ret false
+end
+n = ulong 0
+while true bound 999999
+if eq n len fb
+die ebig
+end
+r = read int fd fb n sub len fb n
+if lt r 0
+fclo fd
+ret false
+end
+if eq r 0
+break
+end
+n = add n ulong r
+end
+fclo fd
+put fbn 0 n
+ret true
+end
+
+note append the file T to fa; exit 1 when it cannot be read (cat under set -e)
+fn cata t view uchar * to void
+pclear
+pcat t
+fd = opr
+if lt fd 0
+diep eread
+end
+n = get fan 0
+while true bound 999999
+if eq n len fa
+die ebig
+end
+r = read int fd fa n sub len fa n
+if lt r 0
+fclo fd
+diep eread
+end
+if eq r 0
+break
+end
+n = add n ulong r
+end
+fclo fd
+put fan 0 n
+end
+
+note write fa to the file pb
+fn wrfa to void
+fd = opw
+if lt fd 0
+diep ewrite
+end
+n = get fan 0
+o = ulong 0
+while lt o n bound 999999
+r = write int fd fa o sub n o
+if le r 0
+fclo fd
+diep ewrite
+end
+o = add o ulong r
+end
+r = fclose int fd
+if ne r 0
+diep ewrite
+end
+end
+
+note ---- SHA-256 (FIPS 180-4) ----------------------------------------------------------------
+note SHA-256 (FIPS 180-4) constants, copied from om/cache/digest.om kc_k and kc_iv
+fn shainit to void
+put kk 0 1116352408
+put kk 1 1899447441
+put kk 2 3049323471
+put kk 3 3921009573
+put kk 4 961987163
+put kk 5 1508970993
+put kk 6 2453635748
+put kk 7 2870763221
+put kk 8 3624381080
+put kk 9 310598401
+put kk 10 607225278
+put kk 11 1426881987
+put kk 12 1925078388
+put kk 13 2162078206
+put kk 14 2614888103
+put kk 15 3248222580
+put kk 16 3835390401
+put kk 17 4022224774
+put kk 18 264347078
+put kk 19 604807628
+put kk 20 770255983
+put kk 21 1249150122
+put kk 22 1555081692
+put kk 23 1996064986
+put kk 24 2554220882
+put kk 25 2821834349
+put kk 26 2952996808
+put kk 27 3210313671
+put kk 28 3336571891
+put kk 29 3584528711
+put kk 30 113926993
+put kk 31 338241895
+put kk 32 666307205
+put kk 33 773529912
+put kk 34 1294757372
+put kk 35 1396182291
+put kk 36 1695183700
+put kk 37 1986661051
+put kk 38 2177026350
+put kk 39 2456956037
+put kk 40 2730485921
+put kk 41 2820302411
+put kk 42 3259730800
+put kk 43 3345764771
+put kk 44 3516065817
+put kk 45 3600352804
+put kk 46 4094571909
+put kk 47 275423344
+put kk 48 430227734
+put kk 49 506948616
+put kk 50 659060556
+put kk 51 883997877
+put kk 52 958139571
+put kk 53 1322822218
+put kk 54 1537002063
+put kk 55 1747873779
+put kk 56 1955562222
+put kk 57 2024104815
+put kk 58 2227730452
+put kk 59 2361852424
+put kk 60 2428436474
+put kk 61 2756734187
+put kk 62 3204031479
+put kk 63 3329325298
+put ivs 0 1779033703
+put ivs 1 3144134277
+put ivs 2 1013904242
+put ivs 3 2773480762
+put ivs 4 1359893119
+put ivs 5 2600822924
+put ivs 6 528734635
+put ivs 7 1541459225
+end
+
+fn shasched to void
+for i ulong 16
+b = mul i 4
+v = shl uint get blk b 24
+v = or v shl uint get blk add b 1 16
+v = or v shl uint get blk add b 2 8
+v = or v uint get blk add b 3
+put ws i v
+end
+for j ulong 48
+q = add j 16
+x = get ws sub q 15
+y = get ws sub q 2
+s0 = xor xor rotr x 7 rotr x 18 shr x 3
+s1 = xor xor rotr y 17 rotr y 19 shr y 10
+put ws q add add add get ws sub q 16 s0 get ws sub q 7 s1
+end
+end
+
+fn shat1 i ulong to uint
+e = get st 4
+s1 = xor xor rotr e 6 rotr e 11 rotr e 25
+ch = xor and e get st 5 and not e get st 6
+ret add add add add get st 7 s1 ch get kk i get ws i
+end
+
+fn shat2 to uint
+a = get st 0
+b = get st 1
+c = get st 2
+s0 = xor xor rotr a 2 rotr a 13 rotr a 22
+mj = xor xor and a b and a c and b c
+ret add s0 mj
+end
+
+fn shacomp to void
+shasched
+for i ulong 8
+put st i get hv i
+end
+for i ulong 64
+t1 = shat1 i
+t2 = shat2
+put st 7 get st 6
+put st 6 get st 5
+put st 5 get st 4
+put st 4 add get st 3 t1
+put st 3 get st 2
+put st 2 get st 1
+put st 1 get st 0
+put st 0 add t1 t2
+end
+for i ulong 8
+put hv i add get hv i get st i
+end
+end
+
+fn shabyte b uchar to void
+n = get bk 0
+put blk n b
+n = add n 1
+if eq n 64
+shacomp
+n = ulong 0
+end
+put bk 0 n
+put bk 1 add get bk 1 1
+end
+
+fn hexch v uint to uchar
+if lt v 10
+ret uchar add v 48
+end
+ret uchar add v 87
+end
+
+fn shafinal to void
+bits = mul get bk 1 8
+shabyte 128
+while ne get bk 0 56 bound 64
+shabyte 0
+end
+for i ulong 8
+shabyte uchar and shr bits mul sub 7 i 8 255
+end
+for i ulong 8
+v = get hv i
+for j ulong 8
+put hexd add mul i 8 j hexch and shr v mul sub 7 j 4 15
+end
+end
+end
+
+note hexd = sha256 of the file pb; false when it cannot be read
+fn hashpb to bool
+fd = opr
+if lt fd 0
+ret false
+end
+m = new uchar 4096 0
+for i ulong 8
+put hv i get ivs i
+end
+put bk 0 0
+put bk 1 0
+while true
+r = read int fd m 0 len m
+if lt r 0
+fclo fd
+ret false
+end
+if eq r 0
+fclo fd
+shafinal
+ret true
+end
+for i ulong ulong r
+shabyte get m i
+end
+end
+ret false
+end
+
+note print "HEX OUT/NAME" (sha256sum)
+fn sumln t view uchar * to void
+opath t
+if hashpb
+r = write 1 hexd 0 64
+say two
+r = write 1 pb 0 get pbn 0
+say nl
+else
+diep eread
+end
+end
+
+note ---- steps ------------------------------------------------------------------------------
+note cp = the value of OMEGA_OMC (empty when unset)
+fn envomc to void
+put cpn 0 0
+c = envcnt
+for i ulong ulong c
+n = envread i ab 0 len ab
+if gt n long len envkey
+if pfx
+k = sub ulong n len envkey
+for j ulong k
+put cp j get ab add len envkey j
+end
+put cpn 0 k
+ret
+end
+end
+end
+end
+
+note ab starts with OMEGA_OMC=
+fn pfx to bool
+for j ulong len envkey
+if ne get ab j get envkey j
+ret false
+end
+end
+ret true
+end
+
+note ob = argument 1 when it is not empty (${1:-build/abft}), else build/abft
+fn outset to void
+put obn 0 0
+if gt ulong argcnt 1
+n = argread 1 ob 0 len ob
+if lt n 0
+die ebig
+end
+put obn 0 ulong n
+end
+if eq get obn 0 0
+for i ulong len defout
+put ob i get defout i
+end
+put obn 0 len defout
+end
+end
+
+note mkdir -p ob
+fn mkout to void
+n = get obn 0
+for i ulong n
+if eq get ob i 47
+if gt i 0
+r = makedir ob 0 i 511
+end
+end
+end
+r = makedir ob 0 n 511
+if and ne r 0 ne r -17
+for i ulong n
+put pb i get ob i
+end
+put pbn 0 n
+diep emkdir
+end
+end
+
+note one FROZEN line [s, e): the hash of the file fb[s+66 .. e) must equal fb[s .. s+64)
+fn frzone s ulong e ulong to void
+k = sub e add s 66
+if gt k 4095
+die ebig
+end
+for i ulong k
+put pb i get fb add add s 66 i
+end
+put pbn 0 k
+g = false
+if hashpb
+g = true
+for i ulong 64
+if ne get hexd i get fb add s i
+g = false
+end
+end
+end
+if g
+else
+diep efrz
+end
+end
+
+note sha256sum -c tests/abft/FROZEN.sha256: every "HEX PATH" line must match; malformed lines are
+note skipped, and a file with no well-formed line fails
+fn frzchk to void
+pclear
+pcat frozen
+if rdb
+else
+diep eread
+end
+nf = ulong 0
+s = ulong 0
+n = get fbn 0
+while lt s n bound 999999
+e = lend s
+if frzwell s e
+frzone s e
+nf = add nf 1
+end
+s = add e 1
+end
+if eq nf 0
+die enofrz
+end
+end
+
+note index of the next newline at or after s in fb, or the end of fb
+fn lend s ulong to ulong
+n = get fbn 0
+for i ulong sub n s
+if eq get fb add s i 10
+ret add s i
+end
+end
+ret n
+end
+
+note line [s, e) is 64 lowercase hex digits, two spaces and a nonempty path
+fn frzwell s ulong e ulong to bool
+if le e add s 66
+ret false
+end
+for i ulong 64
+c = get fb add s i
+if or lt c 48 gt c 102
+ret false
+end
+if and gt c 57 lt c 97
+ret false
+end
+end
+if ne get fb add s 64 32
+ret false
+end
+ret eq get fb add s 65 32
+end
+
+note compile OUT/SRC (written from fa) with the pinned omc into OUT/TMP, make it executable and
+note rename it to OUT/BIN; a compile failure exits with omc's status
+fn build src view uchar * tmp view uchar * bin view uchar * to void
+opath src
+wrfa
+fi = opr
+if lt fi 0
+diep eread
+end
+opath tmp
+fo = opw
+if lt fo 0
+fclo fi
+diep ewrite
+end
+areset
+anew
+apcp
+s = spawn int fi int fo
+fclo fi
+fclo fo
+if ne s 0
+exit int s
+end
+opath tmp
+r = chmx
+if ne r 0
+diep ewrite
+end
+rnm tmp bin
+end
+
+note chmod +x pb: add every execute bit the umask allows, as the shell does
+fn chmx to long
+um = int umask 18
+r = umask um
+ret chmod pb 0 get pbn 0 and 511 not um
+end
+
+note append the compiler path cp to the current record
+fn apcp to void
+p = get avp 0
+n = get cpn 0
+if gt add p n len av
+die ebig
+end
+for i ulong n
+put av add p i get cp i
+end
+put avp 0 add p n
+afix
+end
+
+note rename OUT/A to OUT/B
+fn rnm a view uchar * b view uchar * to void
+areset
+opath a
+anew
+apb
+opath b
+anew
+apb
+r = renames av 0 get avp 0 0
+if ne r 0
+diep ewrite
+end
+end
+
+note print every line of fb that starts with GATE
+fn gates to void
+n = get fbn 0
+s = ulong 0
+while lt s n bound 999999
+e = lend s
+if gatln s e
+r = write 1 fb s sub e s
+say nl
+end
+s = add e 1
+end
+end
+
+fn gatln s ulong e ulong to bool
+if lt sub e s len gatep
+ret false
+end
+for i ulong len gatep
+if ne get fb add s i get gatep i
+ret false
+end
+end
+ret true
+end
+
+note pb = the compiler; its sha256 must be the pin
+fn pinchk to void
+n = get cpn 0
+for i ulong n
+put pb i get cp i
+end
+put pbn 0 n
+g = false
+if hashpb
+g = true
+for i ulong 64
+if ne get hexd i get pinhex i
+g = false
+end
+end
+end
+if g
+else
+diep epin
+end
+end
+
+fn bldabft to void
+put fan 0 0
+cata p1
+cata p2
+cata p3
+cata p4
+cata p5
+cata p6
+build nabsrc nabtmp nabft
+end
+
+fn bldcul1 to void
+put fan 0 0
+cata q1
+cata q2
+cata q3
+cata q4
+build ncusrc ncutmp nculu
+end
+
+note OUT/abft with the arguments after OUT_DIR, stdout to OUT/abft.log; then the GATE lines
+fn runabft to ulong
+areset
+opath nabft
+anew
+apb
+c = ulong argcnt
+i = ulong 2
+while lt i c bound 65536
+aarg i
+i = add i 1
+end
+opath nlog
+fo = opw
+rc = ulong 1
+if ge fo 0
+rc = spawn -1 int fo
+fclo fo
+end
+opath nlog
+if rdb
+gates
+end
+ret rc
+end
+
+fn main to int
+envomc
+if eq get cpn 0 0
+esay enoomc
+ret 2
+end
+shainit
+outset
+mkout
+pinchk
+frzchk
+bldabft
+bldcul1
+sumln nabft
+sumln nculu
+sumln nabsrc
+sumln ncusrc
+areset
+opath nculu
+anew
+apb
+s = spawn -1 -1
+if ne s 0
+ret int s
+end
+ret int runabft
+end
diff --git a/tests/abft/frozen.om b/tests/abft/frozen.om
new file mode 100644
index 00000000..84b5c527
--- /dev/null
+++ b/tests/abft/frozen.om
@@ -0,0 +1,272 @@
+note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+note Frozen DRA-420/DRA-387 evaluation plan (docs/abft/CONTRACT.md section 6). Its SHA256 is
+note committed in tests/abft/FROZEN.sha256 in the same commit, before any checker or tolerance
+note tuning. The candidate never reads this file; the evaluator owns rows, seeds, S and deadline.
+note Row: 0 id 1 dt 2 m 3 n 4 k 5 w 6 pol 7 tgt 8 site 9 fault 10 sub 11 p1 12 p2 13 seed 14 reps 15 flags
+note dt 0 exact u32 (mod 2^32), 1 bf16 x bf16 -> f32. pol 0 round robin, 1 seeded random, 2 run
+note ahead of tgt, 3 delay tgt at site. site 0 none, 1 load, 2 compute, 3 barrier arrival,
+note 4 intra-unit atomic (unsupported), 5 device instruction stream (unsupported).
+note fault 0 none, 1 single bit p2, 2 multi count p1 class p2 (0 any, 1 bits 23..31, 2 bits 0..7),
+note 3 stale (sub 1 skip init, 2 skip write, 3 identical stale), rows p1..p1+p2-1,
+note 4 index (sub 1 drop K tail, 2 transposed B, 3 row offset, 4 out-of-bounds write),
+note 5 sync (sub 1 no load barrier, 2 no compute barrier, 3 barrier counts workers 0..1 only,
+note 4 worker 0 skips a barrier: hang), 6 known undetected (sub 1 exact 2x2 rectangle of 2^31,
+note sub 3 bf16 2x2 rectangle +e -e -e +e with e = 2^p1), 7 common-mode A corruption at p1 bf16 bit p2.
+note flags bit0 transient fault, bit1 known-bad control (may remove a wait), bit2 timing row,
+note bit3 reduced-concurrency partner of the previous row.
+global pl ulong 1024
+global pn ulong 1
+global pcur ulong 1
+global pcfg ulong 4
+fn prow id ulong dt ulong m ulong n ulong k ulong w ulong to void
+b = mul sub id 1 16
+put pcur 0 b
+put pl b id
+put pl add b 1 dt
+put pl add b 2 m
+put pl add b 3 n
+put pl add b 4 k
+put pl add b 5 w
+put pn 0 id
+end
+fn prpol pol ulong tgt ulong site ulong to void
+b = get pcur 0
+put pl add b 6 pol
+put pl add b 7 tgt
+put pl add b 8 site
+end
+fn prf flt ulong sb ulong p1 ulong p2 ulong to void
+b = get pcur 0
+put pl add b 9 flt
+put pl add b 10 sb
+put pl add b 11 p1
+put pl add b 12 p2
+end
+fn prs seed ulong reps ulong flags ulong to void
+b = get pcur 0
+put pl add b 13 seed
+put pl add b 14 reps
+put pl add b 15 flags
+end
+fn pfill to void
+note config: 0 sampled elements S, 1 child deadline ns, 2 retries after detection, 3 plan version
+put pcfg 0 64
+put pcfg 1 20000000000
+put pcfg 2 1
+put pcfg 3 1
+note fault-free false-positive rows
+prow 1 1 16 16 16 4
+prpol 1 0 0
+prf 0 0 0 0
+prs 1001 100 0
+prow 2 1 64 48 80 4
+prpol 1 0 0
+prf 0 0 0 0
+prs 1002 40 0
+prow 3 1 128 128 128 8
+prpol 1 0 0
+prf 0 0 0 0
+prs 1003 10 0
+prow 4 0 64 48 80 4
+prpol 1 0 0
+prf 0 0 0 0
+prs 1004 40 0
+prow 5 1 33 17 41 4
+prpol 1 0 0
+prf 0 0 0 0
+prs 1005 40 0
+note single-element corruption
+prow 6 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 31
+prs 2001 20 0
+prow 7 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 30
+prs 2002 20 0
+prow 8 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 23
+prs 2003 20 0
+prow 9 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 22
+prs 2004 20 0
+prow 10 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 14
+prs 2005 20 0
+prow 11 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 0
+prs 2006 20 0
+prow 12 0 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 0
+prs 2007 20 0
+prow 13 0 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 17
+prs 2008 20 0
+prow 14 0 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 31
+prs 2009 20 0
+note multi-element corruption
+prow 15 1 64 48 80 4
+prpol 0 0 0
+prf 2 0 2 1
+prs 3001 20 0
+prow 16 1 64 48 80 4
+prpol 0 0 0
+prf 2 0 8 0
+prs 3002 20 0
+prow 17 1 64 48 80 4
+prpol 0 0 0
+prf 2 0 64 2
+prs 3003 20 0
+prow 18 0 64 48 80 4
+prpol 0 0 0
+prf 2 0 8 0
+prs 3004 20 0
+note stale buffers
+prow 19 1 64 48 80 4
+prpol 0 0 0
+prf 3 1 8 4
+prs 4001 5 0
+prow 20 1 64 48 80 4
+prpol 0 0 0
+prf 3 2 8 4
+prs 4002 5 0
+prow 21 1 64 48 80 4
+prpol 0 0 0
+prf 3 3 8 4
+prs 4003 5 0
+prow 22 0 64 48 80 4
+prpol 0 0 0
+prf 3 2 8 4
+prs 4004 5 0
+note indexing faults
+prow 23 1 64 64 64 4
+prpol 0 0 0
+prf 4 1 0 0
+prs 5001 5 0
+prow 24 1 64 64 64 4
+prpol 0 0 0
+prf 4 2 0 0
+prs 5002 5 0
+prow 25 1 64 64 64 4
+prpol 0 0 0
+prf 4 3 0 0
+prs 5003 5 0
+prow 26 1 64 64 64 4
+prpol 0 0 0
+prf 4 4 0 0
+prs 5004 3 0
+prow 27 0 64 64 64 4
+prpol 0 0 0
+prf 4 1 0 0
+prs 5005 5 0
+note synchronization faults (known-bad controls) under default and perturbed schedules
+prow 28 1 64 48 80 4
+prpol 0 0 0
+prf 5 1 0 0
+prs 6001 20 2
+prow 29 1 64 48 80 4
+prpol 1 0 0
+prf 5 1 0 0
+prs 6002 20 2
+prow 30 1 64 48 80 4
+prpol 2 0 1
+prf 5 1 0 0
+prs 6003 5 2
+prow 31 1 64 48 80 4
+prpol 0 0 0
+prf 5 2 0 0
+prs 6004 20 2
+prow 32 1 64 48 80 4
+prpol 1 0 0
+prf 5 2 0 0
+prs 6005 20 2
+prow 33 1 64 48 80 4
+prpol 3 1 2
+prf 5 2 0 0
+prs 6006 5 2
+prow 34 1 64 48 80 8
+prpol 1 0 0
+prf 5 3 0 0
+prs 6007 20 2
+prow 35 1 64 48 80 2
+prpol 1 0 0
+prf 5 3 0 0
+prs 6007 20 10
+prow 36 1 64 48 80 4
+prpol 0 0 0
+prf 5 4 0 0
+prs 6008 2 2
+prow 37 1 64 48 80 4
+prpol 1 0 0
+prf 5 1 0 0
+prs 6009 1 0
+note unsupported perturbation sites
+prow 38 1 64 48 80 4
+prpol 3 1 4
+prf 0 0 0 0
+prs 7001 1 0
+prow 39 1 64 48 80 4
+prpol 3 1 5
+prf 0 0 0 0
+prs 7002 1 0
+note known undetected patterns and common-mode input corruption
+prow 40 0 64 48 80 4
+prpol 0 0 0
+prf 6 1 0 0
+prs 8001 20 0
+prow 41 1 64 48 80 4
+prpol 0 0 0
+prf 6 3 4 0
+prs 8002 200 0
+prow 42 1 64 48 80 4
+prpol 0 0 0
+prf 7 0 100 14
+prs 8003 5 0
+note transient versus persistent fault recovery
+prow 43 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 30
+prs 9001 10 1
+prow 44 1 64 48 80 4
+prpol 0 0 0
+prf 1 0 0 30
+prs 9002 10 0
+note host cost rows (fault free, one worker, round robin)
+prow 45 1 64 64 64 1
+prpol 0 0 0
+prf 0 0 0 0
+prs 10001 10 4
+prow 46 1 128 128 128 1
+prpol 0 0 0
+prf 0 0 0 0
+prs 10002 5 4
+prow 47 1 256 256 256 1
+prpol 0 0 0
+prf 0 0 0 0
+prs 10003 3 4
+prow 48 0 128 128 128 1
+prpol 0 0 0
+prf 0 0 0 0
+prs 10004 5 4
+prow 49 0 256 256 256 1
+prpol 0 0 0
+prf 0 0 0 0
+prs 10005 3 4
+note reduced-concurrency witness pair with a correct barrier
+prow 50 1 64 48 80 8
+prpol 1 0 0
+prf 0 0 0 0
+prs 11001 5 0
+prow 51 1 64 48 80 2
+prpol 1 0 0
+prf 0 0 0 0
+prs 11001 5 8
+end