code wiki / _hdl_build / nx_ng_radiance.nx

nx_ng_radiance.nx

buildroot/runtime/_hdl_build/nx_ng_radiance.nx

12042 B212 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tooltopic ng
docsdependenciesstructsconstsfunctions

about

nx_ng_radiance.nx -- CAP-RADIANCE-FIELD, generation 8: a tiny NeRF. The defining recipe of NeRF/instant-ngp: a COORDINATE NETWORK (MLP queried at sample positions) whose outputs are VOLUME-RENDERED into observations, trained by INVERSE-RENDERING loss to recover the field from rendered measurements. Composes the two rungs just built -- the autograd gradient engine (nx_nofloat_autograd) and the volume compositor (nx_ng_volrender) -- on ONE Q16 integer tape: the composite C = sum_i w_i*f(x_i) is nfa_cmul (scale by the fixed transmittance weight) + nfa_vadd, so the WHOLE chain (coord-MLP -> volume render -> loss) backprops end-to-end. No float. Honest gated proof (HARD evidence): a shared MLP f(x)=W2*relu(W1*x+b1)+b2 is applied at N sample coords -> colors c_i; R observations C_r = sum_i w[r][i]*c_i (volume composite, weights = a fixed invertible transmittance matrix) are matched to targets generated from a TRUE field. Gate: T1 LEARNS -- inverse-rendering SSE loss collapses (the gradient flows MLP<-render<-loss), T2 FIELD RECOVERED -- the trained net reproduces the true field at the samples (|f(x_i)-c*_i| small): teeth = it learned the RIGHT field through the renderer, not just any loss drop, T3 BIT-EXACT -- train twice from the same init -> identical integer weights (structural determinism), T4 UNTRAINED -- the initial loss is genuinely large (not vacuous). Sovereign: imports nx_nofloat_autograd + nx_syscalls (no float). license_tier: ORIGINAL expect_exit: 0

dependencies 3 imports · 0 importers

nx_nofloat_autograd.nx nx_itoa_lib.nx nx_syscalls.nx nx_ng_radiance.nx

imports: nx_nofloat_autograd.nxnx_itoa_lib.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 rp sys_write sys_mmap rad_train rad_init sys_mmap ↻ rad_build nfa_leaf nfa_new nfa_matvec nfa_new ↻ nfa_vadd nfa_new ↻ nfa_relu nfa_new ↻ nfa_cmul nfa_new ↻ nfa_qmul nfa_mse nfa_new ↻ nfa_backward nfa_qmul ↻ nfa_silud nfa_sigmoid nfa_fxexp nfa_qmul ↻ nfa_isqrt nfa_fxexp ↻ nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul ↻ nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_val rp ↻ rpn

structs

none

consts

20const K_MAGIC_6553: i64 = 6553
21const K_MAGIC_1311: i64 = 1311
22const K_MAGIC_2048: i64 = 2048
23const K_MAGIC_9830: i64 = 9830
24const K_MAGIC_2000: i64 = 2000
25const K_MAGIC_8192: i64 = 8192
26const K_MAGIC_13107: i64 = 13107
27const K_MAGIC_26214: i64 = 26214
28const K_MAGIC_39321: i64 = 39321
29const K_MAGIC_52429: i64 = 52429
30const K_MAGIC_32768: i64 = 32768
31const K_MAGIC_16384: i64 = 16384
32const K_MAGIC_4096: i64 = 4096
34const RLOG: *u8 = "knowledge/status/ng_radiance.log"
35const Q16: i64 = 65536
36const NC: i64 = 4 // sample coords along the field
37const NH: i64 = 8 // hidden units
38const NR: i64 = 4 // volume-rendered observations (invertible weight matrix -> field recoverable)
39const EPOCHS: i64 = 6000
40const LRQ: i64 = 2048 // 1/32

functions

42func rp(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: rad_trainmain calls 1: sys_write
47func rpn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 2: rad_trainmain calls 1: nxi_out
48func r_abs(v: i64) -> i64 { if v<0 { return 0-v } return v }
called by 1: main
49func rl_ws(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
54func rl_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
58func rad_build(tape: *i64, vals: *i64, st: *i64, W1p: *i64, b1p: *i64, W2p: *i64, b2p: *i64,
95func rad_init(W1p: *i64, b1p: *i64, W2p: *i64, b2p: *i64) -> i64
called by 1: rad_train
108func rad_train(tape: *i64, vals: *i64, grads: *i64, st: *i64, coords: *i64, wmat: *i64, targ: *i64,
138func main() -> i64