nx_nofloat_mm_i8_batch_gate.nx
buildroot/runtime/nx_nofloat_mm_i8_batch_gate.nx
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
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
structs
| none |
consts
| none |
functions
| 11 | func 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 } |
| 12 | func gp_n(v: i64) -> i64 |
| 22 | func 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 } |
| 23 | func now_ms() -> i64 { let ts: *i64=sys_mmap(16) as *i64; sys_clock_gettime_mono(ts); return ts[0]*1000 + ts[1]/1000000 } |
| 24 | func lcg(st: *i64) -> i64 { st[0] = (st[0]*6364136223846793005 + 1442695040888963407) & 0x7FFFFFFFFFFFFFFF; return st[0] } called by 1: main |
| 25 | func iabs(x: i64) -> i64 { if x<0 { return 0-x } return x } called by 1: main |
| 28 | func 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 |
| 31 | func quant_row(x: *i64, in_dim: i64, xi8: *u8) -> i64 |
| 40 | func mm_i8_one(xi8: *u8, sx: i64, W: *u8, sw: *i64, dst: *i64, in_dim: i64, out_dim: i64, shift: i64, acc: *u8) -> i64 |
| 54 | func 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 |
| 72 | func main() -> i64 |