nx_batch_infer.nx
buildroot/runtime/nx_batch_infer.nx
about
nx_batch_infer.nx -- WORKER MESH BACKEND: a sovereign FUSED-BATCH inference kernel that gives the real throughput
win sd.cpp cannot (it runs n>1 sequentially). The core of any forward pass is C = A x W (a batch of A-rows through a
shared weight matrix W). The whole point of batching is WEIGHT REUSE: load each W element ONCE and apply it to the
WHOLE batch. Per-request serving reloads W for every request; a fused batch streams W once.
This proves it MECHANICALLY + MEASURED:
* fused (weight-stationary: for k,for j: w=W[k][j]; for b: C[b][j]+=A[b][k]*w) -> W streamed 1x
* seq (per-request: for b: for j: for k: C[b][j]+=A[b][k]*W[k][j]) -> W streamed B times
Both compute the IDENTICAL result (integer, bit-exact) -- the ONLY difference is memory traffic on W. With W
larger than cache the fused schedule is dramatically faster: THAT is the batching-capable-backend win, on our
own stack, deterministic. Timed with the monotonic clock; the gate refuses to pass unless results are bit-exact
AND fused is at least as fast. license_tier: ORIGINAL
dependencies 3 imports · 0 importers
imports: nx_syscalls.nxnx_runtime.nxnx_clock.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
| 16 | const BI_MAGIC_1024: i64 = 1024 |
| 17 | const BI_MAGIC_1000000: i64 = 1000000 |
| 19 | const BI_B: i64 = 64 // batch size (concurrent requests) |
| 20 | const BI_K: i64 = 512 // input dim |
| 21 | const BI_N: i64 = 512 // output dim (W = K*N*8 = 2MB > L2 -> weight reuse is a real RAM-bandwidth win) |
functions
| 23 | func bi_p(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 24 | func bi_pn(v: i64) -> i64 |
| 41 | func bi_fused(A: *i64, W: *i64, C: *i64, b: i64, kk: i64, n: i64) -> i64 called by 1: main |
| 68 | func bi_seq(A: *i64, W: *i64, C: *i64, b: i64, kk: i64, n: i64) -> i64 called by 1: main |
| 86 | func main() -> i64 |