code wiki / _hdl_build / nx_autograd_mlp_gate.nx

nx_autograd_mlp_gate.nx

buildroot/runtime/_hdl_build/nx_autograd_mlp_gate.nx

9094 B133 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind gate/prooftopic autograd
docsdependenciesstructsconstsfunctions

about

nx_autograd_mlp_gate.nx -- R3.5->R4 bridge: prove the sovereign autograd trains a MULTI-LAYER MLP (the COOL-CHIC decoder is a tiny MLP, so this is the prerequisite for the lead neural-codec avenue). Builds a 1->4->1 ReLU net + MSE loss entirely from the autograd primitives (define-by-run; rebuilt each step), then: (a) GRADIENT-CHECKS weights across both layers vs central finite differences (proves backprop through the full MLP graph -- the engine), and (b) runs SGD and shows the loss TRAINS DOWN overfitting |x| (a nonlinear target a linear model cannot fit). Fixed-point Q16, no FPU/GPU/3rd-party. license_tier: ORIGINAL

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_gate_emit_lib.nx nx_autograd_mlp_gate.nx

imports: nx_syscalls.nxnx_gate_emit_lib.nx

imported by: nobody (leaf or entry point)

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

main g_puts sys_write sys_mmap build_mlp ag_leaf ag_mul ag_add ag_relu ag_sub ag_backward g_num sys_mmap ↻ sys_write ↻ g_check g_puts ↻ close iabs iabs ↻ sys_openat_append g_w sys_write ↻ g_wn sys_mmap ↻ sys_write ↻ sys_close sys_exit

structs

none

consts

10const Q: i64 = 65536

functions

12func g_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);k=1}; while m>0{t[k]=((48+(m%10)) as u8);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
13func g_w(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main calls 1: sys_write
14func g_wn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);k=1}; while m>0{t[k]=((48+(m%10)) as u8);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
15func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v }
called by 2: closemain
17func ag_leaf(tp: *i64, np: *i64, v: i64) -> i64 { let k: i64=np[0]; tp[k*5]=v; tp[k*5+2]=0; tp[k*5+3]=0-1; tp[k*5+4]=0-1; np[0]=k+1; return k }
called by 1: build_mlp
18func ag_add(tp: *i64, np: *i64, i: i64, j: i64) -> i64 { let k: i64=np[0]; tp[k*5]=tp[i*5]+tp[j*5]; tp[k*5+2]=1; tp[k*5+3]=i; tp[k*5+4]=j; np[0]=k+1; return k }
called by 1: build_mlp
19func ag_sub(tp: *i64, np: *i64, i: i64, j: i64) -> i64 { let k: i64=np[0]; tp[k*5]=tp[i*5]-tp[j*5]; tp[k*5+2]=4; tp[k*5+3]=i; tp[k*5+4]=j; np[0]=k+1; return k }
called by 1: build_mlp
20func ag_mul(tp: *i64, np: *i64, i: i64, j: i64) -> i64 { let k: i64=np[0]; tp[k*5]=(tp[i*5]*tp[j*5])>>16; tp[k*5+2]=2; tp[k*5+3]=i; tp[k*5+4]=j; np[0]=k+1; return k }
called by 1: build_mlp
21func ag_relu(tp: *i64, np: *i64, i: i64) -> i64 { let k: i64=np[0]; var v: i64=tp[i*5]; if v<0 { v=0 } tp[k*5]=v; tp[k*5+2]=3; tp[k*5+3]=i; tp[k*5+4]=0-1; np[0]=k+1; return k }
called by 1: build_mlp
22func ag_backward(tp: *i64, np: *i64, out: i64) -> i64
called by 1: main
38func build_mlp(tp: *i64, np: *i64, w1: *i64, b1: *i64, w2: *i64, b2v: i64, H: i64, xv: i64, tgtv: i64) -> i64
59func close(auto: i64, num: i64) -> i64 { let dd: i64=iabs(auto-num); let tol: i64=(iabs(auto)*8)/100 + 96; if dd<=tol { return 1 } return 0 }
called by 1: main calls 1: iabs
61func main() -> i64