code wiki / (root) / nx_ta_parallel_grad_gate.nx

nx_ta_parallel_grad_gate.nx

buildroot/runtime/nx_ta_parallel_grad_gate.nx

9375 B188 linesdepth 7pulls 21 transitivereach 0 importersview sourcekind gate/proof
docsdependenciesstructsconstsfunctions

about

nx_ta_parallel_grad_gate.nx -- KEYSTONE for FAST model training: the f32 tensor autograd (ta_*) trains DATA-PARALLEL on the sovereign thread pool. Each example in a batch runs its OWN forward+backward on a PRIVATE (tape,vals,grads,st) arena; the per-example gradients are then reduced. The soft-float training that bottlenecks the neural reader (and every bigger model the benchmark endgame needs) parallelizes across the 16 hardware workers here -- the conv2d pool already measured 6.76x wall-clock. The liar-kill is STRONG: serial and parallel compute each example's gradient with identical math, so the per-example gradients must be BIT-IDENTICAL (f32 raw equality). ANY race, arena collision, or shared-state bug in the parallel path perturbs a bit and fails. (No f32-associativity fuzz: we compare PER-EXAMPLE grads, not a reordered sum.) T1 parallel per-example grads == serial, BIT-IDENTICAL across all B examples x all NP weights T2 the pool actually ran B tasks (completed counter advanced by B) on > 1 worker T3 deterministic (re-run parallel == identical) expect_exit: 0 license_tier: ORIGINAL Sovereign: nx_thread_pool + nx_autograd_tensor + nx_syscalls.

dependencies 4 imports · 0 importers

nx_thread_pool.nx nx_autograd_tensor.nx nx_hw.nx nx_syscalls.nx nx_ta_parallel_grad_gate.nx

imports: nx_thread_pool.nxnx_autograd_tensor.nxnx_hw.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main pg_puts sys_write sys_mmap ta_constf nx_f32_div nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_i32_to_f32 pg_example ta_leaf ta_new ta_matvec ta_new ↻ nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ ta_relu ta_new ↻ nx_f32_gt nx_f32_lt nx_f32_is_nan nx_f32_classify ↻ nx_f32_is_zero nx_f32_classify ↻ ta_mse ta_new ↻ nx_f32_sub nx_f32_add ↻

structs

33struct PgCtx

consts

24const PG_D: i64 = 8 // input dim
25const PG_H: i64 = 16 // hidden
26const PG_O: i64 = 4 // output
27const PG_NW1: i64 = 128 // H*D
28const PG_NW2: i64 = 64 // O*H
29const PG_NP: i64 = 192 // NW1+NW2
30const PG_B: i64 = 8 // batch
43const PG_CTX_BYTES: i64 = 64

functions

20func pg_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 2: pg_ckmain calls 1: sys_write
21func pg_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 }
called by 1: main calls 2: sys_mmapsys_write
22func pg_ck(name: *u8, c: i64) -> i64 { if c==1 { pg_puts(" PASS " as *u8) } else { pg_puts(" FAIL " as *u8) } pg_puts(name); pg_puts("\n" as *u8); return c }
called by 1: main calls 1: pg_puts
47func pg_example(w: *i64, x: *i64, tgt: *i64, tape: *i64, vals: *i64, grads: *i64, st: *i64, G: *i64) -> i64
69func pg_task(ctx_i: i64) -> i64
calls 1: pg_example
74func main() -> i64