code wiki / (root) / nx_lw_cache_gate.nx

nx_lw_cache_gate.nx

buildroot/runtime/nx_lw_cache_gate.nx

12318 B321 linesdepth 10pulls 31 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_lw_cache_gate.nx -- gate for the packed dequant-once cache in nx_f32_lazy_weight (the m=1 decode lever: stop re-dequanting the same weights every token; cached matmuls are pure packed __f32x4_dot bands). Exact-f32 regime construction as in nx_q4k_matmul_x4_gate (dense d=1.0/sc=1 blocks -> integer dequant values 0..15; int A; all |sums| < 2^24), so bit-exact comparison between the CACHED path (x4 dot order) and the scalar streaming oracle is legitimate. Checks (8): 1 scalar oracle OK (k=512, n=37, m=3) 2 first dispatch fills + matches oracle; pk_state=1; used bytes exact 3 second dispatch (new A) matches fresh oracle (cache reuse + shared-pool delta-wait across fill+dot submissions) 4 m=1 decode shape via dispatcher matches oracle 5 budget refusal: fresh weight + tiny budget -> pk_state=-1 AND result still matches oracle (streamed scalar-pool fallback) 6 stale k=1 shape surfaces NX_LW_ERR_INNER (guard before cache) 7 decode-shape speedup: cached reps vs streamed reps (same data, bit-exact) -- floor cached >= 1.5x streamed; first-call fill overhead printed for the honest record 8 cached and streamed big-shape outputs bit-identical lineage_id: lw_cache_gate_v1

dependencies 3 imports · 0 importers

nx_gate_verdict.nx nx_f32_lazy_weight.nx nx_fmt.nx nx_lw_cache_gate.nx

imports: nx_gate_verdict.nxnx_f32_lazy_weight.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 gv_ctr sys_mmap gv_head gv_puts sys_write lwc_run l_fill_a l_lcg nx_i32_to_f32 l_fill_weights l_lcg ↻ l_block_dense l_lcg ↻ nx_lw_set_cache_budget 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 ↻ l_nl fmt_puts ↻ nx_f32_lazy_weight_new_q4k sys_mmap ↻ l_poison nx_f32_lazy_matmul nx_f32_matmul_t_pool sys_mmap ↻ nx_pool_n_completed nx_atom_load_i64

structs

none

consts

31const LG_M: i64 = 3
32const LG_K: i64 = 512
33const LG_N: i64 = 37
35const LB_K: i64 = 1024
36const LB_N: i64 = 4864
37const LB_REPS: i64 = 3
39const LG_SPEEDUP_FLOOR_X100: i64 = 150

functions

41func l_lcg(s: i64) -> i64
47func l_block_dense(buf: *u8, off: i64, seed: i64) -> i64
called by 1: l_fill_weights calls 1: l_lcg
69func l_fill_weights(buf: *u8, n_rows: i64, k: i64, seed: i64) -> i64
called by 1: lwc_run calls 2: l_lcgl_block_dense
85func l_fill_a(p: *i64, count: i64, seed: i64, half: i64) -> i64
called by 1: lwc_run calls 2: l_lcgnx_i32_to_f32
97func l_poison(p: *i64, count: i64) -> i64
called by 1: lwc_run
107func l_same(a: *i64, b: *i64, count: i64) -> i64
called by 1: lwc_run
116func l_nl() -> i64
called by 1: lwc_run calls 1: fmt_puts
121func lwc_run() -> i64
280func main() -> i64