code wiki / (root) / nx_paged_kv_gate.nx

nx_paged_kv_gate.nx

buildroot/runtime/nx_paged_kv_gate.nx

9874 B222 linesdepth 8pulls 16 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_paged_kv_gate.nx -- MEASURED gate for the sovereign PAGED KV-cache (nx_kvcache + nx_f32_attn_paged). PURE (no model, fast): KAT pool alloc/refcount/free; fork refcounts; exhaustion fail-fast; truncate unref EQUIV paged attention == contiguous attention BIT-EXACT over 3 append rounds (5-token prefill, 1-token decode, 3-token chunk) x 2 layers x GQA heads FORK fork after prefill; diverge A/RA vs B/RB; copy-on-append fires (refcounts return to 1); BOTH forks bit-exact vs fresh contiguous replays of their histories REWIND truncate A back to the fork point, append RB -> bit-exact == B's outputs (the speculative-decode rewind contract) license_tier: ORIGINAL expect_exit: 0

dependencies 9 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_f32.nx nx_f32_cvt.nx nx_f32_kv_cache.nx nx_f32_attn_cached.nx nx_kvcache.nx nx_f32_attn_paged.nx nx_fmt.nx nx_paged_kv_gate.nx

imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_cvt.nxnx_f32_kv_cache.nxnx_f32_attn_cached.nxnx_kvcache.nxnx_f32_attn_paged.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 nx_pkv_pool_new sys_mmap nx_pkv_alloc_block nx_pkv_unref_block fmt_puts fmt_puts_fd sys_write pg_nl2 fmt_puts ↻ sys_mmap ↻ pg_fill pg_lcg nx_i32_to_f32 nx_f32_kv_cache_alloc sys_mmap ↻ nx_pkv_seq_new sys_mmap ↻ pg_round nx_pkv_ensure_append nx_pkv_alloc_block ↻ _pkv_base nx_pkv_unref_block ↻ nx_f32_attn_with_cache nx_f32_kv_cache_append_lay nx_f32_kv_cache_get_K_laye nx_f32_kv_cache_get_V_laye nx_f32_kv_cache_get_seq_le nx_f32_kv_cache_get_K_laye ↻ nx_f32_kv_cache_get_V_laye ↻ sys_mmap ↻ nx_f32_attn_multi sys_mmap ↻ nx_f32_dot nx_f32_softmax _f32_gt nx_f32_sub nx_f32_classify nx_f32_sign nx_f32_sub ↻

structs

none

consts

27const PG_NL: nx_int = 2 // layers
28const PG_NH: nx_int = 4 // heads
29const PG_NKV: nx_int = 2 // kv heads
30const PG_HD: nx_int = 8 // head dim

functions

33func pg_nl2() -> i64 { fmt_puts("\n" as *u8); return 0 }
called by 1: main calls 1: fmt_puts
34func pg_lcg(s: i64) -> i64 { var v: i64 = s * 1103515245 + 12345; v = v & 2147483647; return v }
called by 1: pg_fill
37func pg_fill(p: *i64, n: nx_int, state: *i64) -> i64
called by 1: main calls 2: pg_lcgnx_i32_to_f32
50func pg_cmp(a: *i64, b: *i64, n: nx_int) -> i64
called by 2: pg_roundmain
57func pg_round(cc: *NxF32KVCache, ps: *NxPagedSeq,
81func pg_round_paged_only(ps: *NxPagedSeq, Q: *i64, K: *i64, V: *i64,
97func pg_round_contig_only(cc: *NxF32KVCache, Q: *i64, K: *i64, V: *i64,
111func main() -> i64