code wiki / _hdl_build / nx_train_int_vs_softfloat_gate.nx
nx_train_int_vs_softfloat_gate.nx
buildroot/runtime/_hdl_build/nx_train_int_vs_softfloat_gate.nx
about
nx_train_int_vs_softfloat_gate.nx -- THE PAYOFF measurement: does INTEGER training actually run FASTER than our
SOFTWARE-FLOAT tape on IDENTICAL work? Trains the SAME 2-layer MLP (W1->ReLU->W2, L=sum(y-t)^2) for the same
number of steps, TWO ways -- (A) software-float via nx_f32_mul/add (what nx_f32_qwen2_train uses), (B) integer
Q16 -- times both with sys_now_us, and reports the speedup. Same algorithm, same MAC count; only the arithmetic
differs, so the ratio IS the software-float tax paid in a real training loop. This is the internal h2h that
justifies porting the trainer to integer (the sovereign path to beat PyTorch CPU). Measured-not-asserted.
ReLU + sign checks read the IEEE sign bit directly ((raw>>31)&1) to avoid nx_int-typed comparisons. license_tier: ORIGINAL
dependencies 4 imports · 0 importers
imports: nx_f32.nxnx_f32_cvt.nxnx_f32_div.nxnx_syscalls.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
| 17 | const S: i64 = 65536 |
| 18 | const K: i64 = 3 |
| 19 | const H: i64 = 8 |
| 20 | const O: i64 = 2 |
| 21 | const NEX: i64 = 3 |
| 22 | const STEPS: i64 = 1500 |
functions
| 13 | func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 14 | func wn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let o: *u8=sys_mmap(24); var q: i64=k-1; var i: i64=0; while q>=0{o[i]=t[q];i=i+1;q=q-1} sys_write(1,o,i); return 0 } |
| 15 | func fneg(raw: i64) -> i64 { return (raw/2147483648)%2 } // IEEE sign bit (1 => negative) |
| 25 | func step_int(W1: *i64, X: *i64, W2: *i64, T: *i64, gW1: *i64, gW2: *i64, hb: *i64, ab: *i64, yb: *i64) -> i64 |
| 43 | func step_sf(W1: *i64, X: *i64, W2: *i64, T: *i64, gW1: *i64, gW2: *i64, hb: *i64, ab: *i64, yb: *i64) -> i64 |
| 61 | func main() -> i64 |