code wiki / _hdl_build / nx_nofloat_kvcache_gate.nx

nx_nofloat_kvcache_gate.nx

buildroot/runtime/_hdl_build/nx_nofloat_kvcache_gate.nx

9280 B153 linesdepth 3pulls 7 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_kvcache_gate.nx -- CAP-NF-KVCACHE: a KV-CACHE for O(T) autoregressive decode (vs O(T^2) full-recompute), pure integer Q16. Single-block causal attention model (random weights -- this is about inference CORRECTNESS + EFFICIENCY, not model quality, so no training needed). Two decoders share the SAME primitives: full-recompute re-derives every past K/V each step; cached computes each K/V once and reuses it. T1 CORRECT: cached logits == full-recompute logits at every position (bit-exact, by construction). T2 CHEAPER: cached does far fewer K/V projections (full = T(T+1)/2, cached = T) -- measured counts. T3 TEETH: a CORRUPTED cache (one stale entry) yields DIFFERENT logits -> the cache content is really used. Sovereign: nx_nofloat_autograd (qmul/isqrt/sin/cos/exp) + nx_syscalls. expect_exit: 0

dependencies 4 imports · 0 importers

nx_nofloat_autograd.nx nx_syscalls.nx nx_gate_emit_lib.nx nx_gate_verdict.nx nx_nofloat_kvcache_gate.nx

imports: nx_nofloat_autograd.nxnx_syscalls.nxnx_gate_emit_lib.nxnx_gate_verdict.nx

imported by: nobody (leaf or entry point)

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

main g_puts sys_write 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 ↻ dini decode_full sys_mmap ↻ project sys_mmap ↻ copyv rmsnorm nfa_isqrt vm_isqrt matvec rope nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_qmul ↻ copyv ↻ attend

structs

none

consts

13const Q16: i64 = 65536

functions

16func dini(a: *i64, n: i64, sd: i64) -> i64 { var i: i64=0; while i<n { a[i]=(((i*7+sd*13+1)%11)-5)*9362; i=i+1 } return 0 }
called by 1: main
19func matvec(x: *i64, W: *i64, rows: i64, cols: i64, out: *i64, opc: *i64) -> i64
called by 2: projecthead
25func rmsnorm(x: *i64, n: i64, out: *i64) -> i64
called by 2: projecthead calls 1: nfa_isqrt
33func dotq(a: *i64, b: *i64, n: i64) -> i64 { var acc: i64=0; var i: i64=0; while i<n { acc=acc + a[i]*b[i]; i=i+1 } return acc>>16 }
called by 1: attend
34func copyv(src: *i64, dst: *i64, n: i64) -> i64 { var i: i64=0; while i<n { dst[i]=src[i]; i=i+1 } return 0 }
36func rope(v: *i64, pos: i64, dm: i64) -> i64
called by 1: project calls 3: nfa_cosfnfa_sinfnfa_qmul
49func attend(q: *i64, Kc: *i64, Vc: *i64, t: i64, dm: i64, scale: i64, out: *i64) -> i64
62func project(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, tok: i64, pos: i64, dm: i64, qq: *i64, kk: *i64, vv: *i64, opc: *i64) -> i64
70func head(E: *i64, Wo: *i64, Wlm: *i64, tok: i64, o: *i64, dm: i64, V: i64, logits: *i64, opc: *i64) -> i64
79func decode_cached(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, Wo: *i64, Wlm: *i64, seq: *i64, T: i64, dm: i64, V: i64, scale: i64, logits_out: *i64, opc: *i64, corrupt: i64) -> i64
called by 1: main calls 5: sys_mmapprojectcopyvattendhead
94func decode_full(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, Wo: *i64, Wlm: *i64, seq: *i64, T: i64, dm: i64, V: i64, scale: i64, logits_out: *i64, opc: *i64) -> i64
called by 1: main calls 5: sys_mmapprojectcopyvattendhead
108func main() -> i64