code wiki / (root) / nx_q4k_matmul_x4_gate.nx

nx_q4k_matmul_x4_gate.nx

buildroot/runtime/nx_q4k_matmul_x4_gate.nx

11851 B314 linesdepth 9pulls 24 transitivereach 0 importersview sourcekind gate/prooftopic q4k
docsdependenciesstructsconstsfunctions

about

nx_q4k_matmul_x4_gate.nx -- adversarial gate for the PACKED-SIMD Q4_K matmul paths (nx_f32_q4k_matmul_x4 / _pool_x4) against the scalar serial oracle nx_f32_q4k_matmul. NUMERIC REGIME: the x4 path sums each output cell as left-to-right 4-lane dot chunks -- a different f32 rounding order than scalar. This gate therefore constructs data where EVERY intermediate sum is an integer with |sum| < 2^24, so f32 addition is EXACT regardless of order and bit-exact comparison across ALL paths is legitimate: * weights: dense synthetic Q4_K blocks with d=1.0 (f16 0x3C00), dmin=0, all 6-bit scales=1, mins=0, LCG nibble bytes -> every dequantized value is an exact integer 0..15; * A: exact small-int f32 (nx_i32_to_f32 of LCG ints). k=512 lanes, |A|<=512, w<=15 -> |cell| <= 512*15*512 = 3.9M < 2^24. Big shape k=1024, |A|<=512 -> <= 7.9M < 2^24. Exact. (ULP-divergent real-model fidelity is witnessed separately by the argmax probe -- " Paris" -- after the dispatcher flip.) pool-x4 vs serial-x4 equality holds on ANY data (identical per-cell order; column banding never splits a cell) -- asserted here too. Checks (10): 1 scalar serial oracle OK (m=3, k=512, n=37 -- prime n) 2 serial-x4 == scalar bit-exact 3 pool-x4 (auto pool) == serial-x4 bit-exact 4 pool-x4 (3-worker pool, odd banding) == serial-x4 5 pool reuse: second call, new A, same pool == fresh serial-x4 6 m=1 decode shape: serial-x4 == scalar 7 wide-A (+-512 ints): serial-x4 == scalar (exact-regime bound) 8 n=1 single-column edge via pool (band clamp) == scalar 9 SPEEDUP ladder on decode shape m=1 k=1024 n=4864: serial-scalar vs pool-scalar vs pool-x4 (all bit-exact vs each other in this regime); floor: pool-x4 >= 2.5x serial-scalar (measured printed) 10 all three big-shape outputs bit-identical genealogy_id: nx_f32x4_mt_matmul (5.0x packed lever) + q4k_matmul_mt_gate lineage_id: q4k_matmul_x4_gate_v1

dependencies 3 imports · 0 importers

nx_f32_q4k_matmul.nx nx_fmt.nx nx_gate_verdict.nx nx_q4k_matmul_x4_gate.nx

imports: nx_f32_q4k_matmul.nxnx_fmt.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 x_fill_a x_lcg nx_i32_to_f32 x_fill_weights x_lcg ↻ x_block_dense x_lcg ↻ nx_f32_q4k_matmul fq4m_rows sys_mmap _fq4m_pack_a nx_q4k_to_f32_packed nx_q4k_block_to_f32_packed nx_le_read_u16 nx_f16_to_f32 nx_le_read_u8 nx_i32_to_f32 ↻ _q4kp_st4 sys_munmap fmt_puts fmt_puts_fd sys_write x_nl fmt_puts ↻ x_poison nx_f32_q4k_matmul_x4 sys_mmap ↻ _fq4m_pack_a ↻ fq4m_rows_x4 sys_mmap ↻ nx_q4k_to_f32_packed ↻ sys_munmap ↻ sys_munmap ↻ x_same nx_f32_q4k_matmul_pool_x4 sys_mmap ↻ _fq4m_pack_a ↻ nx_pool_n_completed nx_atom_load_i64

structs

none

consts

43const XG_M: i64 = 3
44const XG_K: i64 = 512
45const XG_N: i64 = 37
47const XB_K: i64 = 1024
48const XB_N: i64 = 4864
49const XB_REPS: i64 = 3
51const XG_SPEEDUP_FLOOR_X100: i64 = 250

functions

53func x_lcg(s: i64) -> i64
61func x_block_dense(buf: *u8, off: i64, seed: i64) -> i64
called by 1: x_fill_weights calls 1: x_lcg
84func x_fill_weights(buf: *u8, n_rows: i64, k: i64, seed: i64) -> i64
called by 1: main calls 2: x_lcgx_block_dense
101func x_fill_a(p: *i64, count: i64, seed: i64, half: i64) -> i64
called by 1: main calls 2: x_lcgnx_i32_to_f32
113func x_poison(p: *i64, count: i64) -> i64
called by 1: main
123func x_same(a: *i64, b: *i64, count: i64) -> i64
called by 1: main
132func x_nl() -> i64
called by 1: main calls 1: fmt_puts
137func main() -> i64