code wiki / (root) / nx_matmul_t_pool_gate.nx

nx_matmul_t_pool_gate.nx

buildroot/runtime/nx_matmul_t_pool_gate.nx

6408 B170 linesdepth 8pulls 16 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_matmul_t_pool_gate.nx -- gate + MEASUREMENT for the pooled transposed matmul (nx_f32_matmul_t_pool) that threads lm_head. lm_head is the forward's biggest single matmul: at decode it is nx_f32_matmul_t(A[1,896], B[vocab,896], C[1,vocab], 1, 896, 151936) = 136M MACs, and it ran the SCALAR SERIAL mmt_range every token (fork was disabled in the organ). This gate runs that EXACT shape serial vs pooled so the printed serial_us IS lm_head's real per-token cost, and proves the threaded result bit-identical. BIT-EXACT ON ANY DATA: flat-range banding computes each C[idx] wholly inside one band with the identical accumulation order as serial -- so pool == serial is bit-exact regardless of magnitude. Values are still kept small-int-exact (finite, no NaN) so the bit-compare is clean. Checks (6): 1 small prime shape (m=3, n=37): pool == serial bit-exact (band-boundary correctness -- 37 is not a multiple of 16) 2 serial oracle OK at the real lm_head decode shape 3 pooled result bit-exact vs serial at the real shape 4 auto-worker pool (nx_pool_new(0)) == serial 5 pool reuse (second call, new A) == fresh serial 6 SPEEDUP: pooled >= floor x serial at the real shape (serial_us printed = lm_head's real per-token cost) lineage_id: matmul_t_pool_gate_v1

dependencies 3 imports · 0 importers

nx_f32_matmul_t.nx nx_f32_cvt.nx nx_fmt.nx nx_matmul_t_pool_gate.nx

imports: nx_f32_matmul_t.nxnx_f32_cvt.nxnx_fmt.nx

imported by: nobody (leaf or entry point)

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

main t_fill _tbl nx_i32_to_f32 nx_f32_matmul_t mmt_range sys_mmap_shared sys_fork sys_exit sys_mmap sys_wait4 t_poison nx_f32_matmul_t_pool sys_mmap ↻ nx_pool_n_completed nx_atom_load_i64 nx_pool_submit nx_atom_faa_i64 nx_chan_send nx_chan_try_send _nx_chan_cell nx_thread_yield _pool_futex_wake_all sys_futex_wake nx_pool_wait nx_atom_load_i64 ↻ nx_thread_yield ↻ nx_atom_store_i64 _pool_futex_wait sys_futex_wait sys_munmap t_same fmt_puts fmt_puts_fd sys_write t_nl fmt_puts ↻ nx_pool_shutdown nx_atom_faa_i64 ↻ nx_chan_send ↻

structs

none

consts

33const TG_K: i64 = 896 // Qwen2.5-0.5B hidden
34const TG_VOCAB: i64 = 151936 // real vocab
35const TG_FLOOR_X100: i64 = 300

functions

40func _tbl() -> *i64
called by 1: t_fill calls 1: nx_i32_to_f32
56func t_fill(p: *i64, count: i64, seed: i64) -> i64
called by 1: main calls 1: _tbl
66func t_poison(p: *i64, count: i64) -> i64
called by 1: main
72func t_same(a: *i64, b: *i64, count: i64) -> i64
called by 1: main
78func t_nl() -> i64 { fmt_puts("\n" as *u8); return 0 }
called by 1: main calls 1: fmt_puts
80func main() -> i64