code wiki / _hdl_build / nx_nofloat_kvcache_gate.nx
nx_nofloat_kvcache_gate.nx
buildroot/runtime/_hdl_build/nx_nofloat_kvcache_gate.nx
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
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
structs
| none |
consts
| 12 | const Q16: i64 = 65536 |
functions
| 15 | func 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 |
| 18 | func matvec(x: *i64, W: *i64, rows: i64, cols: i64, out: *i64, opc: *i64) -> i64 |
| 24 | func rmsnorm(x: *i64, n: i64, out: *i64) -> i64 |
| 32 | func 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 |
| 33 | func copyv(src: *i64, dst: *i64, n: i64) -> i64 { var i: i64=0; while i<n { dst[i]=src[i]; i=i+1 } return 0 } |
| 35 | func rope(v: *i64, pos: i64, dm: i64) -> i64 |
| 48 | func attend(q: *i64, Kc: *i64, Vc: *i64, t: i64, dm: i64, scale: i64, out: *i64) -> i64 |
| 61 | func project(E: *i64, Wq: *i64, Wk: *i64, Wv: *i64, tok: i64, pos: i64, dm: i64, qq: *i64, kk: *i64, vv: *i64, opc: *i64) -> i64 |
| 69 | func head(E: *i64, Wo: *i64, Wlm: *i64, tok: i64, o: *i64, dm: i64, V: i64, logits: *i64, opc: *i64) -> i64 |
| 78 | func 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 |
| 93 | func 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 |
| 107 | func main() -> i64 |