Skip to content

igla race: repair ternary_mac.t27 and ternary_gemm.t27 so both compile and pass under t27c and t27b #10371

Closed

Description

@gHashTag

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 -a in i8, so -(-128) overflows. The negation must be done in i32. The 128 that results does not fit in i8, so the narrow ternary_mul keeps 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 signature ternary_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 test ternary_gemm_2x2_large_activations expects 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 use the 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-report with 0 failed and 0 blocked.
  • FR-002: ternary_gemm.t27 MUST compile and pass t27c test-report with 0 failed and 0 blocked.
  • FR-003: Both specs MUST pass t27b test on the lab, with --overflow trap as well as the default.
  • FR-004: The negation of an i8 activation MUST be done in i32, and the GEMM kernels MUST call ternary_mac with 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 --save on the lab.

Success Criteria

  • t27c test-report specs/igla/race/ternary_mac.t27 and t27c test-report specs/igla/race/ternary_gemm.t27 exit 0 with 0 failed on the Railway lab.
  • t27b test exits 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.json and .trinity/seals/race_igla-race-ternary-gemm.json no longer carry a blocked entry.

Activity

  1. added 18 commits that reference this issue on Oct 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions