nx_paged_kv_gate.nx
buildroot/runtime/nx_paged_kv_gate.nx
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
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
structs
| none |
consts
| 27 | const PG_NL: nx_int = 2 // layers |
| 28 | const PG_NH: nx_int = 4 // heads |
| 29 | const PG_NKV: nx_int = 2 // kv heads |
| 30 | const PG_HD: nx_int = 8 // head dim |
functions
| 33 | func pg_nl2() -> i64 { fmt_puts("\n" as *u8); return 0 } |
| 34 | func pg_lcg(s: i64) -> i64 { var v: i64 = s * 1103515245 + 12345; v = v & 2147483647; return v } called by 1: pg_fill |
| 37 | func pg_fill(p: *i64, n: nx_int, state: *i64) -> i64 |
| 50 | func pg_cmp(a: *i64, b: *i64, n: nx_int) -> i64 |
| 57 | func pg_round(cc: *NxF32KVCache, ps: *NxPagedSeq, |
| 81 | func pg_round_paged_only(ps: *NxPagedSeq, Q: *i64, K: *i64, V: *i64, |
| 97 | func pg_round_contig_only(cc: *NxF32KVCache, Q: *i64, K: *i64, V: *i64, |
| 111 | func main() -> i64 |