code wiki / _hdl_build / nx_nofloat_kvcache_gate.nx

nx_nofloat_kvcache_gate.nx

buildroot/runtime/_hdl_build/nx_nofloat_kvcache_gate.nx

8897 B145 linesdepth 3pulls 4 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 3 imports · 0 importers

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

imports: nx_nofloat_autograd.nxnx_syscalls.nxnx_gate_emit_lib.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 dini decode_full sys_mmap ↻ project sys_mmap ↻ copyv rmsnorm nfa_isqrt matvec rope nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_qmul ↻ copyv ↻ attend sys_mmap ↻ nfa_qmul ↻ dotq nfa_fxexp head sys_mmap ↻ matvec ↻ rmsnorm ↻ decode_cached sys_mmap ↻ project ↻ copyv ↻ attend ↻ head ↻ g_pn

structs

none

consts

12const Q16: i64 = 65536

functions

15func 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
18func matvec(x: *i64, W: *i64, rows: i64, cols: i64, out: *i64, opc: *i64) -> i64
called by 2: projecthead
24func rmsnorm(x: *i64, n: i64, out: *i64) -> i64
called by 2: projecthead calls 1: nfa_isqrt
32func 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
33func copyv(src: *i64, dst: *i64, n: i64) -> i64 { var i: i64=0; while i<n { dst[i]=src[i]; i=i+1 } return 0 }
35func rope(v: *i64, pos: i64, dm: i64) -> i64
called by 1: project calls 3: nfa_cosfnfa_sinfnfa_qmul
48func attend(q: *i64, Kc: *i64, Vc: *i64, t: i64, dm: i64, scale: i64, out: *i64) -> i64
61func project(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, tok: i64, pos: i64, dm: i64, qq: *i64, kk: *i64, vv: *i64, opc: *i64) -> i64
69func head(E: *i64, Wo: *i64, Wlm: *i64, tok: i64, o: *i64, dm: i64, V: i64, logits: *i64, opc: *i64) -> i64
78func 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
93func 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
107func main() -> i64