code wiki / (root) / nx_nofloat_w12a12_gate.nx

nx_nofloat_w12a12_gate.nx

buildroot/runtime/nx_nofloat_w12a12_gate.nx

25794 B420 linesdepth 8pulls 20 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_w12a12_gate.nx -- the referee for the W12A12 decode matmul (search R0l attribution, 2026-09-16). SUBJECT: mm_pool_i8 in nx_nofloat_llm (the pooled SIMD matmul every decode projection goes through), driven IN-PROCESS on synthetic data whose shape is the real one (in_dim 8960 = the Qwen2.5-1.5B ffn_down, the widest projection, so the chunk bound is exercised at its limit) with activation OUTLIER channels planted, because a per-tensor scale is exactly the quantiser an outlier defeats. TEETH: the chunk bound is arithmetic (NF_CHUNK_K/8 * QMAX * QMAX <= i32 max) and 2048 is the planted bound- breaker; the kernel's max relative error against the exact i64 dot is BELOW the old 8-bit per-tensor quantiser's error on the same data (the old quantiser is re-implemented here as the CONTROL, so the improvement is measured, never asserted); the kernel is exact on a row the quantisers cannot lose (all values on the grid); and the chunked fold reproduces the unchunked sum on a short row (K < NF_CHUNK_K, one chunk). license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0

dependencies 3 imports · 0 importers

nx_syscalls.nx nx_nofloat_llm.nx nx_gate_verdict.nx nx_nofloat_w12a12_gate.nx

imports: nx_syscalls.nxnx_nofloat_llm.nxnx_gate_verdict.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main gv_ctr sys_mmap nxa_die sys_write sys_exit nxa_lock_take nxa_lock_addr sys_write ↻ nxa_lock_give nxa_lock_addr ↻ nxa_report_overrun sys_write ↻ nxa_dump_printable sys_write ↻ nxa_dump_sizes sys_write ↻ gv_head gv_puts sys_write ↻ gv_check gv_puts ↻ gv_kv gv_puts ↻ gv_num sys_mmap ↻ sys_write ↻ sys_munmap gv_check_eq gv_check ↻ gv_puts ↻ gv_num ↻ nf_qround sys_mmap ↻ wg_fill_x wg_lcg wg_fill_w wg_lcg ↻ wg_exact wg_old_path

structs

none

consts

17const WG_IN: i64 = 8960
18const WG_OUT: i64 = 64
19const WG_SHORT_IN: i64 = 896
20const WG_SEED: i64 = 20260916
21const WG_LCG_A: i64 = 6364136223846793005
22const WG_LCG_C: i64 = 1442695040888963407
23const WG_MASK63: i64 = 0x7FFFFFFFFFFFFFFF
24const WG_X_BODY: i64 = 65536 // typical Q16 activation magnitude (about 1.0)
25const WG_X_OUTLIER: i64 = 4194304 // 64x the body: the outlier channel every Qwen-class model carries
26const WG_OUTLIER_EVERY: i64 = 512
27const WG_W_MAG: i64 = 4096
28const WG_SHIFT: i64 = 16
29const WG_OLD_QMAX: i64 = 127
30const WG_PERMIL: i64 = 1000
31const WG_BREAKER_CHUNK: i64 = 2048
34const WG_GRID_SX: i64 = 16
35const WG_GRID_SPAN: i64 = 8191 // 2*QMAX+1 values, j in [-4095, 4095]
36const WG_GRID_WMAX: i64 = 4095
37const WG_TAIL_IN: i64 = 912 // R0q: 14 x 64 + 16, a width whose last madd goes through the tail loop
38const WG_TIMING_REPS: i64 = 40 // R0q: repeats per task for the printed throughput values
39const WG_OUT_BIG: i64 = 1536 // R0q: the ffn down projection's output rows (27.5 MB of i16 weights per call)
40const WG_BIG_REPS: i64 = 6 // R0q: repeats on the big shape
41const WG_BYTE_SPAN: i64 = 256 // one byte of pseudo-random weight fill
42const WG_BATCH_M: i64 = 32 // R0r: activation rows per batched call (the engine's block)
43const WG_TAIL_M: i64 = 5 // R0r: an odd row count on the tail-width fixture
44const WG_DOT_N: i64 = 1024 // R0r-b: one full chunk of lanes for the builtin KAT
45const WG_DOT_HALF: i64 = 512 // R0r-b: centres the ramp so half the lanes are negative
46const WG_DOT_PLANT: i64 = 777 // R0r-b: the lane the neg-control raises by one
47const WG_DOT_REAL_N: i64 = 512 // R0r-b: lanes of real weight rows in the KAT (64 products per int32 lane, a 2^30 bound)
48const WG_I16_MOD: i64 = 65536
49const WG_I16_HALF: i64 = 32768
50const WG_BYTE: i64 = 256

functions

52func wg_put_i16(p: *u8, i: i64, v: i64) -> i64 { var u: i64 = v; if u < 0 { u = u + WG_I16_MOD } p[i*2] = (u % WG_BYTE) as u8; p[i*2+1] = ((u / WG_BYTE) % WG_BYTE) as u8; return 0 }
called by 1: main
53func wg_get_i16(p: *u8, i: i64) -> i64 { var u: i64 = (p[i*2] as i64) + (p[i*2+1] as i64) * WG_BYTE; if u >= WG_I16_HALF { u = u - WG_I16_MOD } return u }
called by 2: wg_dot_refmain
54func wg_dot_ref(a: *u8, b: *u8, n: i64) -> i64 { var s: i64 = 0; var i: i64 = 0; while i < n { s = s + wg_get_i16(a, i) * wg_get_i16(b, i); i = i + 1 } return s }
called by 1: main calls 1: wg_get_i16
56func wg_lcg(st: *i64) -> i64 { st[0] = (st[0]*WG_LCG_A + WG_LCG_C) & WG_MASK63; return st[0] }
57func wg_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
58func wg_fill_x(x: *i64, n: i64, st: *i64) -> i64
called by 1: main calls 1: wg_lcg
69func wg_fill_w(w: *i64, n: i64, st: *i64) -> i64 { var k: i64 = 0; while k < n { let r: i64 = wg_lcg(st) % (2*WG_W_MAG+1); w[k] = r - WG_W_MAG; k = k + 1 } return 0 }
called by 1: main calls 1: wg_lcg
71func wg_exact(x: *i64, w: *i64, ind: i64, out: i64, dst: *i64) -> i64
called by 1: main
77func wg_old_path(x: *i64, w: *i64, ind: i64, out: i64, dst: *i64) -> i64
called by 1: main calls 1: wg_abs
95func wg_max_err_permil(ref: *i64, got: *i64, n: i64, scored: *i64) -> i64
called by 1: main calls 1: wg_abs
109func wg_quant_weights(w: *i64, ind: i64, out: i64, wi8: *u8, sw: *i64) -> i64 { return nf_quant_w_i8(w, wi8, sw, out, ind) }
called by 1: main calls 1: nf_quant_w_i8
111func main(argc: i64, argv: *i64) -> i64