nx_swarm_shardserve.nx
buildroot/runtime/nx_swarm_shardserve.nx
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
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
structs
| none |
consts
| 19 | const Q: i64 = 16 |
| 20 | const ONE: i64 = 65536 |
| 21 | const D: i64 = 4 |
| 22 | const T: i64 = 2 |
| 23 | const NBLK: i64 = 8 // stack depth (blocks 0..NBLK-1) |
| 24 | const HID: i64 = 8 // T*D hidden-state size |
| 25 | const LOG2E: i64 = 94548 |
| 26 | const C1: i64 = 45426 |
| 27 | const C2: i64 = 15743 |
| 28 | const EPS: i64 = 65 |
functions
| 30 | func 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 } |
| 35 | func sp_pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 38 | func fxmul(a: i64, b: i64) -> i64 { return (a*b)>>Q } |
| 39 | func relu(x: i64) -> i64 { if x>0 { return x } return 0 } called by 1: block |
| 40 | func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v } |
| 41 | func 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 |
| 42 | func sqrt_q16(y: i64) -> i64 { return isqrt(y*ONE) } |
| 43 | func exp_fx(x: i64) -> i64 |
| 49 | func 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 } |
| 50 | func layernorm(x: *i64, out: *i64) -> i64 |
| 56 | func 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 } |
| 57 | func block(x: *i64, out: *i64, W1: *i64, W2: *i64) -> i64 |
| 87 | func ss_weights(W1s: *i64, W2s: *i64) -> i64 |
| 104 | func 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 } |
| 105 | func 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 } |
| 107 | func ss_write_weights(path: *u8) -> i64 |
| 123 | func ss_load_range(path: *u8, a: i64, b: i64, W1s: *i64, W2s: *i64) -> i64 |
| 139 | func ss_range(h: *i64, W1s: *i64, W2s: *i64, a: i64, b: i64) -> i64 |
| 152 | func ss_serialize(h: *i64, buf: *u8) -> i64 |
| 162 | func ss_deserialize(buf: *u8, h: *i64) -> i64 |
| 173 | func ss_copy(src: *i64, dst: *i64) -> i64 { var i: i64=0; while i<HID { dst[i]=src[i]; i=i+1 } return 0 } |
| 174 | func 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 |
| 176 | func ss_whole(h0: *i64, out: *i64, W1s: *i64, W2s: *i64) -> i64 { ss_copy(h0, out); ss_range(out, W1s, W2s, 0, NBLK); return 0 } |
| 179 | func ss_split(h0: *i64, out: *i64, W1s: *i64, W2s: *i64, bnds: *i64, nb: i64) -> i64 |
| 201 | func 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 } |
| 207 | func 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 |
| 209 | func ss_hex_encode(h: *i64, buf: *u8) -> i64 called by 1: main |
| 221 | func 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 |
| 222 | func ss_hex_decode(s: *u8, h: *i64) -> i64 |
| 233 | func 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 |
| 234 | func 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 |
| 235 | func 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 |
| 238 | func ss_path_ok(p: *u8) -> i64 |
| 257 | func ss_mkmsg(buf: *u8, pfx: *u8, v: i64) -> i64 called by 1: main |
| 264 | func main(argc: i64, argv: *i64) -> i64 |
| 318 | func ss_gate() -> i64 |