code wiki / (root) / nx_batch_infer.nx

nx_batch_infer.nx

buildroot/runtime/nx_batch_infer.nx

6135 B139 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tooltopic batch
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_runtime.nx nx_clock.nx nx_batch_infer.nx

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

main bi_p sys_write sys_mmap nx_clock_monotonic_ns sys_mmap ↻ sys_clock_gettime_mono bi_fused bi_seq bi_pn sys_mmap ↻ sys_write ↻ sys_openat_wr sys_write ↻ sys_close

structs

none

consts

16const BI_MAGIC_1024: i64 = 1024
17const BI_MAGIC_1000000: i64 = 1000000
19const BI_B: i64 = 64 // batch size (concurrent requests)
20const BI_K: i64 = 512 // input dim
21const BI_N: i64 = 512 // output dim (W = K*N*8 = 2MB > L2 -> weight reuse is a real RAM-bandwidth win)

functions

23func 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 }
called by 1: main calls 1: sys_write
24func bi_pn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
41func bi_fused(A: *i64, W: *i64, C: *i64, b: i64, kk: i64, n: i64) -> i64
called by 1: main
68func bi_seq(A: *i64, W: *i64, C: *i64, b: i64, kk: i64, n: i64) -> i64
called by 1: main
86func main() -> i64