code wiki / (root) / nx_nofloat_q4k_gate.nx

nx_nofloat_q4k_gate.nx

buildroot/runtime/nx_nofloat_q4k_gate.nx

19661 B308 linesdepth 9pulls 24 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_q4k_gate.nx -- the REFEREE for nx_nofloat_q4k (LM4 resident-quant decode, /compare/engineshift 2026-09-02). In-process teeth that need no model: a hand-built Q4_K super-block matrix with d=1.0, dmin=0, every scale 1 and every min 0 makes each dequantised weight EXACTLY its 4-bit code, and the activation is chosen so the dynamic i16 pack is exact, so nq_mm's Q16 output has ONE correct value that an independent i64 reference computes (both shift regimes, and a full-width 18944 row for the overflow headroom); the route decision is a pure function tested on every branch (Q4_K aligned -> in place; Q6_K -> i16; a non-256 width -> i16, never a silent in-place read); the i16 route must equal mm_pool_i8 on the same inputs; the scale must never let max|x| wrap an i16 lane. Neg-control: one post-shift off must NOT match the reference. T0 (gv_need the Q4_K_M fixture) censuses the fixture's tensor types so the model-level serve gate can only claim the fused path where Q4_K tensors exist -- fixture-reached-the-condition. nx_nofloat_q4k_gate [model.gguf] default /home/elderwesto/nx_stage/nx_15b_model.gguf license_tier: ORIGINAL. Writes nothing. No hw writes.

dependencies 12 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_le.nx nx_tensor.nx nx_gguf.nx nx_gguf_load.nx nx_thread_pool.nx nx_gate_verdict.nx nx_gatekit_lib.nx nx_nofloat_llm.nx nx_nofloat_q4k_gate.nx

diagram shows first 10 each side; +2 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_le.nxnx_tensor.nxnx_gguf.nxnx_gguf_load.nxnx_thread_pool.nxnx_gate_verdict.nxnx_gatekit_lib.nxnx_nofloat_llm.nxnx_q4k_dot_simd_lib.nxnx_nofloat_q4k.nx

imported by: nobody (leaf or entry point)

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

main gv_head gv_puts sys_write 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 ↻ nf_pool 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 ↻ sys_mmap ↻ nq_arena sys_mmap ↻ sys_mmap ↻ gq_build_q4k

structs

none

consts

25const GQ_IN: i64 = 256
26const GQ_OUT: i64 = 3
27const GQ_WIDE_IN: i64 = 18944 // Qwen2.5-7B ffn width: the overflow-headroom case
28const GQ_WIDE_OUT: i64 = 2
29const GQ_F16_ONE_LO: i64 = 0 // 0x3C00 = 1.0 in IEEE half, little-endian bytes
30const GQ_F16_ONE_HI: i64 = 60
31const GQ_SB_BYTES: i64 = 144
32const GQ_SCALES_OFF: i64 = 4
33const GQ_QS_OFF: i64 = 16
34const GQ_QS_BYTES: i64 = 128
35const GQ_SCALE_ONE: i64 = 1 // 6-bit scale field = 1 (bytes 0..3); packed form for sub-blocks 4..7 = 0x01 in bytes 8..11
36const GQ_V_MAX: i64 = 32767
37const GQ_V_SHIFT24: i64 = 14 // x = v << 14 in Q24 -> sx = 2^14 exactly when max v = 32767
38const GQ_V_SHIFT16: i64 = 6 // x = v << 6 in Q16 -> sx = 2^6
39const GQ_REF_MUL: i64 = 64 // (q<<16 * v<<14) >> 24 = 64*q*v and (q<<16 * v<<6) >> 16 = 64*q*v
40const GQ_NIBBLES: i64 = 16
41const GQ_LCG_A: i64 = 6364136223846793005
42const GQ_LCG_C: i64 = 1442695040888963407
43const GQ_LCG_MASK: i64 = 0x7FFFFFFFFFFFFFFF
44const GQ_LCG_SEED: i64 = 88172645463325252
45const GQ_SMALL_IN: i64 = 16
46const GQ_SMALL_OUT: i64 = 3
47const GQ_SMALL_W: i64 = 40000
48const GQ_SMALL_X: i64 = 300000
49const GQ_Q24_BITS: i64 = 24
50const GQ_Q8_VALS: i64 = 32
51const GQ_Q8_BYTES: i64 = 34
52const GQ_Q8_SCALE_BYTES: i64 = 2
53const GQ_Q8_CODE_MAX: i64 = 127

functions

57func gq_lcg() -> i64 { g_gq_st = (g_gq_st*GQ_LCG_A + GQ_LCG_C) & GQ_LCG_MASK; return g_gq_st >> 16 }
61func gq_build_q4k(out_dim: i64, in_dim: i64, wref: *i64) -> *u8
called by 1: main calls 2: sys_mmapgq_lcg
91func gq_fill_v(v: *i64, n: i64) -> i64
called by 1: main calls 1: gq_lcg
97func gq_ref(wref: *i64, v: *i64, in_dim: i64, o: i64) -> i64 { var s: i64 = 0; var k: i64 = 0; while k < in_dim { s = s + wref[o*in_dim+k]*v[k]; k = k + 1 } return s*GQ_REF_MUL }
98func gq_all_rows_match(dst: *i64, wref: *i64, v: *i64, in_dim: i64, out_dim: i64) -> i64
called by 1: main calls 1: gq_ref
103func gq_run(buf: *u8, out_dim: i64, in_dim: i64, v: *i64, vshift: i64, shift: i64, dst: *i64) -> i64
called by 1: main calls 3: sys_mmapnq_bind_bufnq_mm
116func gq_build_q8(out_dim: i64, in_dim: i64, wref: *i64) -> *u8
called by 1: main calls 2: sys_mmapgq_lcg
138func gq_run_q8(buf: *u8, out_dim: i64, in_dim: i64, v: *i64, vshift: i64, shift: i64, dst: *i64) -> i64
called by 1: main calls 3: sys_mmapnq_bind_bufnq_mm
149func gq_census(path: *u8, cnt: *i64) -> i64
168func main(argc: i64, argv: *i64) -> i64