Repository navigation
igla race: repair ternary_mac.t27 and ternary_gemm.t27 so both compile and pass under t27c and t27b #10371
Copy link
Copy link
Closed
Description
The two RACE reference specs for the ternary GEMM do not compile under either compiler, so nothing can import them and the arithmetic they claim has never been checked. Found on the Railway lab on 2026-10-18 while writing the GPU kernel spec for #10360 (PR #10362), which had to mirror the correct 8x8 path instead of importing them.
Measured defects (lab, t27c from master 88bfb2b, t27b under qemu-aarch64):
| Spec | t27c | t27b |
|---|---|---|
| ternary_mac.t27 | BLOCKED: spec.zig:201:11 use of undeclared identifier 'acc' (the bench mac_accumulator_nonneg: acc >= 0 names a variable that does not exist) |
type mismatch, expected i8, found struct |
| ternary_gemm.t27 | BLOCKED: spec.zig:504:49 expected '}' (a repeat-initialised array of struct literals is lowered to invalid Zig) | unsupported constructs from line 1522: an array literal with no result type, and calls to ternary_gemm, which is not declared |
Wrong arithmetic found while reading the sources:
ternary_mul(a: i8, w)returns-ain i8, so-(-128)overflows. The negation must be done in i32. The 128 that results does not fit in i8, so the narrowternary_mulkeeps its documented two's-complement wrap (-128), which tools/verify_igla_race.py pins as the reference, and an exact i32 sibling is added next to it for callers that need the true product.- The 2x2 and 4x4 kernels in ternary_gemm.t27 call
ternary_mac(a, w, acc)against the signatureternary_mac(acc, a, w). - Test
ternary_gemm_identity(a = [5, 3, 7, 2], codes [2, 1, 1, 2]) asserts [5, 3, 7, 2]. The true result is [-2, 2, -5, 5]. - The GEMM output is declared
[]i8, but testternary_gemm_2x2_large_activationsexpects 255, which an i8 cannot hold. The output must be i32.
The oracle for the repair is specs/igla/coder/ternary_gemm_gpu.t27 (#10362), which mirrors the correct 8x8 path and is bit-exact in three modes.
Boundary
- specs/igla/race/ternary_mac.t27
- specs/igla/race/ternary_gemm.t27
- .trinity/seals/race_igla-race-ternary-mac.json
- .trinity/seals/race_igla-race-ternary-gemm.json
User Scenarios
- Given the GPU kernel spec author, when they
usethe RACE GEMM as the reference, then it compiles under t27c and t27b and its tests pass. - Given a reviewer reading the ternary_gemm tests, when an expected value is wrong, then the test fails on both compilers (a negative control proves the tests can fail).
- Given an activation of -128 and a weight code of 2, when the exact product is requested, then the result is +128, with no overflow trap.
Requirements
- FR-001: ternary_mac.t27 MUST compile and pass
t27c test-reportwith 0 failed and 0 blocked. - FR-002: ternary_gemm.t27 MUST compile and pass
t27c test-reportwith 0 failed and 0 blocked. - FR-003: Both specs MUST pass
t27b teston the lab, with--overflow trapas well as the default. - FR-004: The negation of an i8 activation MUST be done in i32, and the GEMM kernels MUST call
ternary_macwith the argument order of its signature. - FR-005: Every expected value in the GEMM tests MUST equal the true matrix product, checked against the GPU kernel spec for the 8x8 case.
- FR-006: The change MUST be .t27 only, and both seals MUST be regenerated with
t27c seal --saveon the lab.
Success Criteria
t27c test-report specs/igla/race/ternary_mac.t27andt27c test-report specs/igla/race/ternary_gemm.t27exit 0 with 0 failed on the Railway lab.t27b testexits 0 on both files under qemu-aarch64.- A negative control (one expected value mutated) makes both compilers fail exactly that test.
.trinity/seals/race_igla-race-ternary-mac.jsonand.trinity/seals/race_igla-race-ternary-gemm.jsonno longer carry ablockedentry.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
igla race: ternary_mac benches use the block form (refs #10371)
igla race: ternary_mac wave tests call ternary_mac(acc, a, w) in sign…
igla race: ternary_mac uses struct literals, not nonexistent TernaryW…
igla race: ternary_mac tests state true arithmetic, no cast_ helpers …
igla race: ternary_mul wraps 128 to -128 by hand instead of trapping …
igla race: ternary_mul stays self-contained for the cross-target gate…
igla race: ternary_gemm exact i32 kernels, 8x8 without array concat, …
igla race: ternary_gemm block-form benches, struct-literal weights (r…
igla race: ternary_gemm element-wise array checks, drop undefined 8x8…
igla race: ternary_gemm returns fixed arrays (no dangling slice), dro…
igla race: ternary_gemm fix single-element test, explicit identity we…
igla race: ternary_gemm identity test passes weights, not activations…
igla race: ternary_gemm expectations are the true matrix products, bo…
igla race: ternary_gemm no vacuous shape tests, extreme-activation ca…
igla race: re-bless assertionless baseline, ternary_gemm 144 -> 142 (…
igla race: reseal ternary_mac and ternary_gemm on the lab, no blocked…
igla race: re-bless assertionless baseline after merging master (tern…
igla race: repair ternary_mac and ternary_gemm (compile, pass under t…