code wiki / (root) / nx_q4k_matmul_mt_gate.nx

nx_q4k_matmul_mt_gate.nx

buildroot/runtime/nx_q4k_matmul_mt_gate.nx

7861 B240 linesdepth 9pulls 23 transitivereach 0 importersview sourcekind gate/prooftopic q4k
docsdependenciesstructsconstsfunctions

about

nx_q4k_matmul_mt_gate.nx -- adversarial gate for the multi-threaded Q4_K matmul (nx_f32_q4k_matmul_mt / _pool) against the serial oracle nx_f32_q4k_matmul. This is the LLM forward's hot path: the organ recorded "pool (fork-once) is the fix" when fork-per-matmul proved net-slower -- the thread pool IS that fix, landed 2026-07-07. Bit-exactness is a hard requirement and holds by construction (column banding: every C[i,j] computed wholly inside one band, identical accumulation order) -- the gate verifies it with full- buffer i64 compares on POISONED outputs so unwritten columns can never pass. Weight bytes are DUMMY (LCG): nx_q4k_to_f32 decodes any bytes deterministically, so exactness + timing are layout-real without a model file (nx_q4k_matmul_rate precedent). Checks (10): 1 serial oracle OK (m=3, k=512, n=37 -- prime n for band edges) 2..6 MT bit-exact for nworkers in {1,2,3,0=auto,1000=clamp-to-37} 7 m=1 single-token decode shape bit-exact (auto workers) 8..9 caller-owned pool reused across two calls (delta-wait), exact 10 speedup, decode shape m=1 k=1024 n=4864 x6 reps: serial vs POOL path (spawn-once, submit-per-call = the forward's pattern); exact AND wall-time speedup >= floor genealogy_id: substrate_f32_q4k_matmul_v2_parallel + nx_conv2d_mt_gate lineage_id: q4k_matmul_mt_gate_v1

dependencies 2 imports · 0 importers

nx_f32_q4k_matmul.nx nx_fmt.nx nx_q4k_matmul_mt_gate.nx

imports: nx_f32_q4k_matmul.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 q_fill_a q_lcg nx_i32_to_f32 q_fill_b q_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 fmt_putn fmt_putn_fd sys_write ↻ q_nl fmt_puts ↻ q_poison nx_f32_q4k_matmul_mt nx_hw_worker_count nx_hw_cpu_count sys_mmap ↻ sys_munmap ↻ nx_f32_q4k_matmul ↻ nx_pool_new nx_hw_worker_count ↻ sys_mmap ↻ nx_chan_new sys_mmap ↻ _nx_chan_cell sys_thread_create

structs

none

consts

30const QG_M: i64 = 3
31const QG_K: i64 = 512
32const QG_N: i64 = 37
34const QB_K: i64 = 1024
35const QB_N: i64 = 4864
36const QB_REPS: i64 = 6
40const QG_SPEEDUP_FLOOR_X100: i64 = 200

functions

42func q_lcg(s: i64) -> i64
called by 2: q_fill_aq_fill_b
49func q_fill_a(p: *i64, count: i64, seed: i64) -> i64
called by 1: main calls 2: q_lcgnx_i32_to_f32
62func q_fill_b(p: *u8, count: i64, seed: i64) -> i64
called by 1: main calls 1: q_lcg
73func q_poison(p: *i64, count: i64) -> i64
called by 1: main
83func q_same(a: *i64, b: *i64, count: i64) -> i64
called by 1: main
92func q_nl() -> i64
called by 1: main calls 1: fmt_puts
97func main() -> i64