code wiki / (root) / nx_q5_0_threaded_gate.nx

nx_q5_0_threaded_gate.nx

buildroot/runtime/nx_q5_0_threaded_gate.nx

7754 B220 linesdepth 8pulls 18 transitivereach 0 importersview sourcekind gate/prooftopic q5
docsdependenciesstructsconstsfunctions

about

nx_q5_0_threaded_gate.nx -- THE DECISIVE test: does THREADING flip the fused Q5_0 dequant-dot from a loss to a win? Single-thread (nx_q5_0_fused_dot_gate) the fused kernel LOST 2x: compute- bound (dequant overhead > MAC), memory not saturated. But at 16 cores the F32 matmul saturates RAM bandwidth (16 x ~2GB/s > ~20-40GB/s), so reading 11.6x fewer bytes (Q5_0 3MB vs F32 34.9MB) could win THERE even with a scalar dequant. Both paths POOL-threaded, SSE dot (__f32_mul/__f32_add), same run => ratio is host-noise-tolerant. THIS decides whether quantized- read is viable on our CPU substrate or needs SIMD-dequant intrinsics first. NO forward changes. Checks: 1 Q5_0-fused-pool == F32-pool (mmt_range), bit-exact 2 threaded ratio: fused vs F32 at FFN shape (report; not a hard floor -- this is a DECISION measurement, GREEN prints the verdict either way) lineage_id: q5_0_threaded_gate_v1

dependencies 9 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_le.nx nx_f32.nx nx_f32_cvt.nx nx_q5_0_to_f32.nx nx_thread_pool.nx nx_f32_matmul_t.nx nx_fmt.nx nx_q5_0_threaded_gate.nx

imports: nx_syscalls.nxnx_tier.nxnx_le.nxnx_f32.nxnx_f32_cvt.nxnx_q5_0_to_f32.nxnx_thread_pool.nxnx_f32_matmul_t.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 sys_mmap q_fill_weight q_lcg q_fill_a q_lcg ↻ nx_i32_to_f32 nx_q5_0_to_f32 _nx_q5_0_block_to_f32 nx_le_read_u16 nx_f16_to_f32 nx_le_read_u32 nx_le_read_u8 nx_pool_new nx_hw_worker_count nx_hw_cpu_count sys_mmap ↻ sys_munmap sys_mmap ↻ nx_chan_new sys_mmap ↻ _nx_chan_cell sys_thread_create nx_thread_spawn sys_mmap ↻ nx_thread_spawn_fn sys_mmap ↻ 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

structs

36struct Q5Ctx

consts

30const QK: i64 = 896
31const QN: i64 = 4864
32const QREPS: i64 = 120
33const Q5B: i64 = 22
34const Q5V: i64 = 32
45const Q5CTX_BYTES: i64 = 56

functions

47func q_lcg(s: i64) -> i64 { var v: i64 = s * 1103515245 + 12345; v = v & 2147483647; return v }
49func q_fill_weight(w: *u8, seed: i64) -> i64
called by 1: main calls 1: q_lcg
69func q_fill_a(p: *i64, count: i64, seed: i64) -> i64
called by 1: main calls 2: q_lcgnx_i32_to_f32
78func q5_consts() -> *u8
called by 1: q5_0_dot calls 1: sys_mmap
101func q5_0_dot(qbuf: *u8, qoff: i64, Apk: *u8, k: i64, i8scr: *u8) -> i64
119func q5_task(ctx_i: i64) -> i64
135func q5_pool_matmul(pool: *NxThreadPool, qbuf: *u8, Apk: *u8, C: *i64, k: i64, n: i64) -> i64
162func q_nl() -> i64 { fmt_puts("\n" as *u8); return 0 }
called by 1: main calls 1: fmt_puts
164func main() -> i64