code wiki / (root) / nx_nofloat_mm_i8_batch_gate.nx

nx_nofloat_mm_i8_batch_gate.nx

buildroot/runtime/nx_nofloat_mm_i8_batch_gate.nx

7424 B129 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_mm_i8_batch_gate.nx -- STEP 1 of the speculative serve integration (operator-approved build): the BATCHED i8 matmul primitive, BIT-EXACT to the per-activation path + AMORTIZED. The serve's forward reads each big weight matrix once per token (m=1, mm_pool_i8). Speculative verify processes K tokens; batching the projection/FFN matmuls (m=K) reads each weight column ONCE and dots it against all K activations -> the 7.2x weight-read amortization proven earlier, now with the REAL i8-matmul math (dynamic per-activation quant, per-col weight scale, shift) so it drops into decode_step_kv_cached_i8. Matches _nfmm_i8_task exactly: dst[m][o] = (sx[m] * sw[o] * Σ_k xi8[m][k]*W[o][k]) >> shift , xi8[m][k]=pack(x[m][k]/sx[m]), sx[m]=max|x[m]|/127. Isolated gate (synthetic weights, same shapes) -- touches NO serve code. license_tier: ORIGINAL expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_nofloat_mm_i8_batch_gate.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap gp_puts sys_write lcg quant_row pack2 now_ms sys_mmap ↻ sys_clock_gettime_mono mm_i8_one i32x8_hsum mm_i8_batch i32x8_hsum ↻ iabs gp_n sys_write ↻ sys_mmap ↻

structs

none

consts

none

functions

11func gp_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){ n=n+1 } sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
12func gp_n(v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
22func i32x8_hsum(acc: *u8) -> i64 { let p: *i32=acc as *i32; var s: i64=0; var i: i64=0; while i<8 { s=s+(p[i] as i64); i=i+1 } return s }
23func now_ms() -> i64 { let ts: *i64=sys_mmap(16) as *i64; sys_clock_gettime_mono(ts); return ts[0]*1000 + ts[1]/1000000 }
called by 1: main calls 2: sys_mmapsys_clock_gettime_mono
24func lcg(st: *i64) -> i64 { st[0] = (st[0]*6364136223846793005 + 1442695040888963407) & 0x7FFFFFFFFFFFFFFF; return st[0] }
called by 1: main
25func iabs(x: i64) -> i64 { if x<0 { return 0-x } return x }
called by 1: main
28func pack2(buf: *u8, k: i64, v: i64) -> i64 { buf[k*2]=(v) as u8; buf[k*2+1]=(v>>8) as u8; return 0 }
called by 1: quant_row
31func quant_row(x: *i64, in_dim: i64, xi8: *u8) -> i64
called by 1: main calls 1: pack2
40func mm_i8_one(xi8: *u8, sx: i64, W: *u8, sw: *i64, dst: *i64, in_dim: i64, out_dim: i64, shift: i64, acc: *u8) -> i64
called by 1: main calls 1: i32x8_hsum
54func mm_i8_batch(xi8K: *u8, sxK: *i64, W: *u8, sw: *i64, dstK: *i64, M: i64, in_dim: i64, out_dim: i64, shift: i64, acc: *u8) -> i64
called by 1: main calls 1: i32x8_hsum
72func main() -> i64