interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / spec / mixed-algebra-ma2.md

333 lines · 21558 bytes Raw Blame History Source

Omega mixed algebra MA-2: one exact operation, ten realizations, measured selection

Status: ADR 0019 gate MA-2 (several CPU realizations of one operation with tiered equivalence evidence and measured cost including conversion) and the ADR's first success gate (one Omega operation, at least three verified realizations, one selected with a recorded reason and margin, reproducible from receipts) delivered. It is not ADR gate MA-3 (contract and identity). This work was first labelled "MA-3"; it was renamed to match the ADR gate table. Code: src/algebra/realize_*.{h,c} (realizations), src/algebra/oma_select.{h,c} (MA-2 selector, retired for new decisions; see "Selector"), tests tests/algebra/test_realize.c, tests/algebra/bench_mixed_algebra.c, tests/algebra/bench_select.c. Receipts: evidence/MIXED_ALGEBRA/. Commands: make test-realize (plain + ASan/UBSan), make bench-mixed-algebra (two benchmark runs + selector, about 90 s wall). C11 with NEON/I8MM intrinsics, -O2 -march=armv8.6-a+dotprod+i8mm+sve, no outside dependencies.

Receipts and labels: the two benchmark runs, ma3_bench_run1.json and ma3_bench_run2.json (schema OMEGA_MIXED_ALGEBRA_MA3_BENCH_V1), are the historical measurement records produced under the earlier "MA-3" label; they are kept unchanged. ma2_select_receipt.json was regenerated from them (without rerunning the benchmark) with the amended ADR 9.1 tie rule: `build/tests-algebra/bench_select evidence/MIXED_ALGEBRA/ma2_select_receipt.json evidence/MIXED_ALGEBRA/ma3_bench_run1.json evidence/MIXED_ALGEBRA/ma3_bench_run2.json`. Future make bench-mixed-algebra runs write new files only, under evidence/MIXED_ALGEBRA/runs/<run-id>/ (<run-id> defaults to a UTC timestamp, MA2_RUN_ID=... to set it; an existing run directory is refused): ma2_bench_run{1,2}.json (schema OMEGA_MIXED_ALGEBRA_MA2_BENCH_V1) and a selector receipt ma2_select_receipt.json from those two runs. They never rewrite a committed evidence file; make check-mixed-algebra-evidence fails if a committed evidence/MIXED_ALGEBRA/ file is modified or deleted, and the bench target runs it before and after. The selector reads both schemas.

Outcome in one line: **on the Grace CPU, packed ternary (2 bits/weight) beats the best int8 realization 2.2x to 3.0x when the weight matrix no longer fits in L2 (m = 4096 rows); int8 wins everywhere the weights are cache-resident or the call is a single row, and int8 wins or ties whenever the weights must be packed on every call.**

Operation Omega-X

y = W . x with W in {-1,0,+1}^(m x n) (row-major int8 source), x in int8^n, y in int32^m, exact: every realization must be bit-identical to the naive integer oracle oma_rz_oracle. |y_i| <= 128 n (x may be -128), so n is limited to 16,777,215 = floor(INT32_MAX / 128) (the same bound as oma_dot_tw_i8; the brief's "n*127" bound is one short for x = -128, so 128 n is enforced). Realizations with narrower index or residue ranges declare a lower max_n and refuse larger n at pack time.

A realization is (pack, run). Pack converts and validates the canonical int8 ternary matrix into its own weight form; run computes y for one x. Pack cost is measured separately.

Realizations

idfamilyweight form (bits/weight)kernel
R1_plainbinaryint8 (8)plain C loop, -O2. Labelled weak baseline.
R1_sdotbinaryint8 row-major (8)NEON SDOT, 4 rows x 64 B/step, 8 accumulators; best for m = 1
R1_sdot_ilbinaryint8, 4-row interleaved tiles (8)NEON SDOT, one sequential stream per 4 rows
R1_smmlabinaryint8, row pairs interleaved in 8-byte pieces (8)I8MM SMMLA; half of each 2x2 result unused for GEMV, useful MACs per instruction equal SDOT
R2_bitplanebitplaneH1 pos/neg planes, bit k of byte j = weight 16k+j (2)vtst byte masks, w = negmask - posmask, SDOT (4 SIMD ops / 16 weights)
R2b_lutlutpos/neg nibble per 4 weights (2) + per-call tablesT-MAC style: per group of 4 activations a 16-entry subset-sum table split lo/hi bytes; vqtbl4q over 4 groups x 4 rows; USDOT/SDOT with +/-1 sums lanes; table build is inside every run
R2c_crumbcrumb22-bit two's-complement codes (+1=01, -1=11), 4 per byte, strided (2)sign-extending shift pair, then SDOT (2.75 SIMD ops / 16 weights)
R3_sparsesparseuint16 +1 and -1 index lists per row (16 per non-zero)scalar gather add/sub, 4 accumulators; max_n 65,536
R4_rnsrnsint8 (8) + per-call residues of xmoduli {256, 255, 253} (M = 16,515,840, all centered residues fit int8), 3 SDOT channels sharing each weight load, per-row mod reduction and mixed-radix CRT inside the run; max_n 64,512
R5_dense5dense55 trits/byte, reference byte rule, strided trit order (1.6)NEON divide-by-3 decode ((b*171)>>9), SDOT on digits d = t+1, then subtract sum(x)

SVE SDOT is not a separate realization: the SVE vector length here is 128 bits (svcntb() == 16), so it does the same work as NEON SDOT.

R2c_crumb was added during the work after R2_bitplane measured compute-bound at 4 SIMD ops per 16 weights. It is a different 2-bit code (not the H1 bitplane code); conversion from int8 is part of its pack.

Correctness evidence

make test-realize: **`MA2 test-realize PASS: 179712 checks, 0 failures, 10 realizations**, and the same line under -fsanitize=address,undefined -fno-sanitize-recover=all`. Coverage:

The benchmark re-verifies every realization bit-exact against the oracle on every grid cell before and after timing: 720 checks per run, 0 mismatches in both runs. The two historical run JSONs predate the top-level oracle_checks / oracle_mismatches fields that the benchmark now writes; for them the counts come from the run logs and from the nested correctness object each file already carries ("runs_checked_against_oracle": 720, "mismatches": 0).

Evidence tiers (ADR 0019 section 8)

Measurement method

Results (amortized: pack once), mean of the two runs

Best binary = best of R1_sdot / R1_sdot_il / R1_smmla. Best ternary = best of R2, R2b, R2c, R3, R5. Ratio > 1 means ternary is faster. The ratio does not change with sparsity except where noted.

nmsparsitybest binary, ns (% floor)best ternary, ns (% floor)binary/ternarywinner
102410-0.6R1_sdot 11.2 (78%)R2_bitplane 23.7 (23%)0.47binary
102410.9R1_sdot 11.2 (79%)R3_sparse 18.2 (29%)0.62binary
102464allR1_smmla 399-404 (121-123%)R2c_crumb 667 (11%)0.60binary
10244096allR1_sdot_il 98,000-101,500 (61-63%)R2c_crumb 43,200-43,900 (20%)2.23-2.32ternary
409610-0.6R1_sdot 35.9 (98%)R2_bitplane 85.5 (26%)0.42binary
409610.9R1_sdot 35.9 (98%)R3_sparse 55.4 (37%)0.65binary
409664allR1_smmla 2,041-2,049 (103%)R2c_crumb 2,624-2,632 (19%)0.78binary
40964096allR1_smmla 502,000-514,000 (83-85%)R2c_crumb 172,500-174,000 (36%)2.90-2.97ternary
1638410-0.6R1_sdot 137.5 (98%)R2_bitplane 337 (25%)0.41binary
1638410.9R1_sdot 137.1 (98%)R3_sparse 230 (35%)0.60binary
1638464allR1_smmla / R1_sdot_il 9,880-9,970 (86-89%)R2c_crumb 10,600-10,650 (21%)0.93-0.94binary (small margin)
163844096allR1_sdot_il / R1_smmla 2,038,000-2,085,000 (93-95%)R2c_crumb 785,000-809,000 (53-55%)2.52-2.66ternary

Full per-realization rows (min, median, q25/q75, bytes read, footprint, floor level, pack cost, per-call total) are in ma3_bench_run{1,2}.json under cost_table; the selector's per-cell decisions and the table above are in ma2_select_receipt.json (decisions, binary_vs_ternary).

R1 against its roofline: 78-98% for m = 1 (L1-resident; 98% from n = 4096 up), 86-123% for m = 64 (above 100% at L2 sizes, see method), 61-63% at 1024 x 4096 (4 MiB, L2/L3 boundary), 83-85% at 4096 x 4096, 93-95% at 16384 x 4096 (64 MiB from DRAM). The int8 champion is memory-bound and close to the floor wherever the matrix streams from outside L2.

Where ternary wins, and why

Only at m = 4096, where the int8 matrix (4, 16 or 64 MiB) streams from L3 or DRAM. R2c_crumb moves a quarter of the bytes and its decode (7 shifts + 4 SDOT per 64 weights per row) keeps up well enough to finish 2.2x to 3.0x sooner, at 20-55% of its own (4x lower) floor: it is compute-bound, the int8 kernel is bandwidth-bound. The win is independent of sparsity (dense 2-bit code).

Where ternary loses, and why

Negative results (recorded, not tuned away)

Selector (RETIRED for new decisions; not wired to rx_costmodel)

Status (2026-09-29): retired for new decisions. The tie rule below (incumbent, then digital reference, then cheapest inside the noise band) failed the pre-registered TURING Wave 1 kill test on the MA-3 receipts: see omega docs/turing/TURING_W0_PROPOSAL.md K.6 (regret numbers) and K.7 (verdict and reframe). oma_select is kept unchanged only to reproduce ma2_select_receipt.json and as a regression test of the retired rule in make test-realize. Do not add new callers. New selections use turing_rank_min_cost in src/turing (lowest measured cost wins; ties are recorded, never change the choice) and are recorded as turing.decision.v1 records via turing-field. The matching ADR 0019 section 9.1 amendment is proposed in aien-architecture and awaits the operator.

oma_select loads MA-2 (and the historical MA-3-label) bench receipts (costs are read from the JSON, never hard-coded), applies the exact-contract filter (registry exact, verified in every run used, query n <= max_n), and ranks the eligible realizations by median cost (plus median pack cost when packing per call), mean over runs. Off-grid queries use the nearest measured cell (log2 distance in n and m, plus 4x the sparsity difference) and say so (exact_cell: false). Each decision record holds the query, the cell, the chosen realization, the cheapest, the runner-up, every candidate with its measured cost, within-run and across-run spread and % of floor (or the reason it was excluded), the margin (runner-up vs cheapest), the noise band, a verdict CHOSEN or TIE, the tied set (tied_set: every eligible candidate whose cost is within the band of the cheapest, the cheapest included), the incumbent given with the query and tie_resolution.

Noise band = max over cheapest and runner-up of (a) the within-run spread (q75 - q25) / median of the timed blocks (pack spread weighted in when packing per call) and (b) the across-run spread (max - min) / mean of the cell's costs over every run in the table. TIE when the tied set has more than one member (equivalently, margin <= band).

Tie rule (ADR 0019 section 9.1, as amended). Without a TIE the cheapest is chosen (tie_resolution: "none"). A TIE is resolved only inside the tied set: the incumbent selection stands if it is in the tied set ("incumbent"); otherwise the digital reference realization, R1_plain (OMA_SEL_REFERENCE), if it is in the tied set ("reference"); otherwise the cheapest member ("cheapest"). A realization outside the tied set, the reference or an incumbent included, is never selected by tie resolution. The receipt's decisions carry no incumbent (there is no prior selection). test-realize checks every branch: reference outside the tied set not chosen (cheapest instead), reference inside the tied set chosen, incumbent inside the tied set stands (also over a reference inside it), incumbent outside the tied set not chosen, unknown or unmeasured incumbent, no TIE, reference unmeasured, reference unverified in one run, TIE from across-run spread alone; every case also checks that the choice is a member of the tied set.

Effect on the receipt (72 decisions over both runs): **38 TIE, 32 per-call and 6 pack-once. Resolution: 32 reference, 6 cheapest, 0 incumbent.** In all 32 per-call ties R1_plain is inside the tied set (1.00x to 1.26x the cheapest) and is selected. The 6 pack-once ties are 1024 x 64 at sparsity 0 and 0.6 and all four 16384 x 64 cells, each a tied set of {R1_smmla, R1_sdot_il} within about 1%; R1_plain is outside it (2.05x to 2.78x the cheapest, for example 1119 ns vs 403 ns at 1024 x 64), so the cheapest member is selected (R1_smmla 3, R1_sdot_il 3). The earlier reading of the rule selected R1_plain in those 6 cells; the amendment removes that. No decision in the receipt (72 grid plus 4 off-grid) selects a realization outside its tied set (decision_summary.chosen_outside_tied_set: 0 for the 72). The 34 non-TIE decisions are unchanged (R1_sdot 16, R1_smmla 6, R2c_crumb 12).

Reproducibility check (MA2_SELECTOR_REPRO): each of the 36 cells x 2 pack modes is decided from run 1 alone and from run 2 alone. 72 decisions: 56 agree, 16 recorded ties, 0 disagree -> PASS, with the amended tie rule applied, and every chosen realization is a member of its tied set (also part of the gate). "Recorded ties" counts only the cells where the two single-run choices differ and one run's tied set contains the other run's choice; it is not the number of ties. Recorded ties rose from 8 to 16 because single-run pack-once ties now keep the cheapest member of each run (R1_smmla in run 1, R1_sdot_il in run 2 at 16384 x 64) and per-call ties with a single-run tied set that does not reach R1_plain pick R1_sdot or R4_rns. Total TIE verdicts in the decisions over both runs: 38 of 72 (32 per-call, 6 pack-once), listed in decision_summary.

Energy (indicative)

The aien_spbm hwmon meter is readable without root (cpu_p = the whole 10-core X925 cluster, microjoules, updates about every 0.1 s). Per realization: 0.4 s idle window, then 0.8 s of back-to-back calls; the receipt lists cluster idle and run power, total and dynamic (run minus idle) energy per call. At 16384 x 4096 (sparsity 0.3), run 1 total energy per call: R2c_crumb 7.5 mJ, R2_bitplane 8.6 mJ, best R1 12.7 mJ, R4_rns 20.9 mJ, R3_sparse 48.8 mJ. At 1024 x 4096 the forms are within about 20% of each other (0.42-0.51 mJ for R1/R2/R2c). Idle power moved between 1.1 and 3.8 W across windows because other sessions share the cluster, so these are not gate-quality numbers; energy is not used by the selector.

Limits