code wiki / (root) / nx_swarm_shardserve.nx

nx_swarm_shardserve.nx

buildroot/runtime/nx_swarm_shardserve.nx

24875 B432 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic swarm
docsdependenciesstructsconstsfunctions

about

nx_swarm_shardserve.nx -- SPLIT-MODEL SERVE PIPELINE (F838 keystone): run a stack of N sovereign no-float transformer blocks SPLIT across a contiguous block-range per node (per the nx_swarm_gpu shard plan), passing the hidden-state ACTIVATION between shards over a byte-exact wire format. THE CORRECTNESS INVARIANT proven here = the sovereign EXCEED that exo/Petals/float-split-serve CANNOT offer: split(h0) == whole(h0) BIT- IDENTICAL, regardless of how the stack is sharded, because every block is deterministic integer Q16. The block math (fxmul/relu/isqrt/sqrt_q16/exp_fx/dotp/layernorm/matvec/block) is COPIED byte-faithful from nx_nofloat_transformer.nx (pre-norm block: h=x+SelfAttn(LN(x)); out=h+FFN(LN(h))) -- ⚠DRY debt: extract to nx_nofloat_transformer_lib on next touch (rule 15; that organ carries a main() so it can't be imported = double-main trap). The pipeline + transport + split-equals-whole gate are the NEW capability. nx_swarm_shardserve [gate] -- self-gate: whole==split(2-way,3-way) bit-identical + activation transport byte-exact + LIAR-KILLERS (dropped-block differs, corrupt-transport differs) + determinism. No args = gate. license_tier: ORIGINAL Sovereign: nx_syscalls. expect_exit:0

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_swarm_shardserve.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

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

main sp_eqs sys_mmap ss_seth0 ss_hex_encode sys_write sp_puts sys_write ↻ ss_atoi ss_weights ss_hex_decode ss_hexval ss_range sys_mmap ↻ block sys_mmap ↻ layernorm fxmul sqrt_q16 isqrt dotp fxmul ↻ exp_fx fxmul ↻ fxmul ↻ matvec fxmul ↻ relu ss_path_ok ss_slen ss_write_weights sys_mmap ↻ ss_weights ↻ sys_openat_wr ss_write_all sys_write ↻ sys_close sp_pn nxi_out nxi_fd

structs

none

consts

19const Q: i64 = 16
20const ONE: i64 = 65536
21const D: i64 = 4
22const T: i64 = 2
23const NBLK: i64 = 8 // stack depth (blocks 0..NBLK-1)
24const HID: i64 = 8 // T*D hidden-state size
25const LOG2E: i64 = 94548
26const C1: i64 = 45426
27const C2: i64 = 15743
28const EPS: i64 = 65

functions

30func sp_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 3: ckmainss_gate calls 1: sys_write
35func sp_pn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 2: mainss_gate calls 1: nxi_out
38func fxmul(a: i64, b: i64) -> i64 { return (a*b)>>Q }
39func relu(x: i64) -> i64 { if x>0 { return x } return 0 }
called by 1: block
40func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v }
41func isqrt(n: i64) -> i64 { if n<2 { return n } var x: i64=n; var y: i64=(x+1)/2; while y<x { x=y; y=(x + n/x)/2 } return x }
called by 1: sqrt_q16
42func sqrt_q16(y: i64) -> i64 { return isqrt(y*ONE) }
called by 1: layernorm calls 1: isqrt
43func exp_fx(x: i64) -> i64
called by 1: block calls 1: fxmul
49func dotp(a: *i64, b: *i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { s=s+fxmul(a[i],b[i]); i=i+1 } return s }
called by 1: block calls 1: fxmul
50func layernorm(x: *i64, out: *i64) -> i64
called by 1: block calls 2: fxmulsqrt_q16
56func matvec(W: *i64, v: *i64, out: *i64) -> i64 { var i: i64=0; while i<D { var s: i64=0; var j: i64=0; while j<D { s=s+fxmul(W[i*D+j], v[j]); j=j+1 } out[i]=s; i=i+1 } return 0 }
called by 1: block calls 1: fxmul
57func block(x: *i64, out: *i64, W1: *i64, W2: *i64) -> i64
87func ss_weights(W1s: *i64, W2s: *i64) -> i64
104func ss_write_all(fd: i64, buf: *u8, n: i64) -> i64 { var w: i64=0; while w<n { let r: i64=sys_write(fd, ((buf as i64)+w) as *u8, n-w); if r<=0 { return w } w=w+r } return w }
called by 1: ss_write_weights calls 1: sys_write
105func ss_read_all(fd: i64, buf: *u8, n: i64) -> i64 { var rd: i64=0; while rd<n { let r: i64=sys_read(fd, ((buf as i64)+rd) as *u8, n-rd); if r<=0 { return rd } rd=rd+r } return rd }
called by 1: ss_load_range calls 1: sys_read
107func ss_write_weights(path: *u8) -> i64
123func ss_load_range(path: *u8, a: i64, b: i64, W1s: *i64, W2s: *i64) -> i64
139func ss_range(h: *i64, W1s: *i64, W2s: *i64, a: i64, b: i64) -> i64
152func ss_serialize(h: *i64, buf: *u8) -> i64
called by 2: ss_splitss_gate
162func ss_deserialize(buf: *u8, h: *i64) -> i64
called by 2: ss_splitss_gate
173func ss_copy(src: *i64, dst: *i64) -> i64 { var i: i64=0; while i<HID { dst[i]=src[i]; i=i+1 } return 0 }
174func ss_eq(a: *i64, b: *i64) -> i64 { var i: i64=0; while i<HID { if a[i]!=b[i] { return 0 } i=i+1 } return 1 }
called by 1: ss_gate
176func ss_whole(h0: *i64, out: *i64, W1s: *i64, W2s: *i64) -> i64 { ss_copy(h0, out); ss_range(out, W1s, W2s, 0, NBLK); return 0 }
called by 1: ss_gate calls 2: ss_copyss_range
179func ss_split(h0: *i64, out: *i64, W1s: *i64, W2s: *i64, bnds: *i64, nb: i64) -> i64
201func ck(name: *u8, c: i64) -> i64 { if c==1 { sp_puts(" PASS " as *u8) } else { sp_puts(" FAIL " as *u8) } sp_puts(name); sp_puts("\n" as *u8); return c }
called by 1: ss_gate calls 1: sp_puts
207func ss_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; if s[0]==(45 as u8) { i=1 } while s[i]!=(0 as u8) { let c: i64=s[i] as i64; if c<48 { return v } if c>57 { return v } v=v*10+(c-48); i=i+1 } if s[0]==(45 as u8) { return 0-v } return v }
called by 1: main
209func ss_hex_encode(h: *i64, buf: *u8) -> i64
called by 1: main
221func ss_hexval(c: i64) -> i64 { if c>=48 { if c<=57 { return c-48 } } if c>=97 { if c<=102 { return c-87 } } if c>=65 { if c<=70 { return c-55 } } return 0 }
called by 1: ss_hex_decode
222func ss_hex_decode(s: *u8, h: *i64) -> i64
called by 1: main calls 1: ss_hexval
233func ss_seth0(h0: *i64) -> i64 { h0[0]=ONE; h0[1]=2*ONE; h0[2]=0; h0[3]=ONE; h0[4]=3*ONE; h0[5]=0; h0[6]=ONE; h0[7]=2*ONE; return 0 }
called by 1: main
234func sp_eqs(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8) { if a[i]!=b[i] { return 0 } i=i+1 } if b[i]!=(0 as u8) { return 0 } return 1 }
called by 1: main
235func ss_slen(p: *u8) -> i64 { var n: i64=0; while p[n]!=(0 as u8) { n=n+1 } return n }
called by 1: ss_path_ok
238func ss_path_ok(p: *u8) -> i64
called by 2: mainss_gate calls 1: ss_slen
257func ss_mkmsg(buf: *u8, pfx: *u8, v: i64) -> i64
called by 1: main
264func main(argc: i64, argv: *i64) -> i64
318func ss_gate() -> i64