code wiki / _hdl_build / nx_ng_hashenc.nx

nx_ng_hashenc.nx

buildroot/runtime/_hdl_build/nx_ng_hashenc.nx

9586 B165 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind tooltopic ng
docsdependenciesstructsconstsfunctions

about

nx_ng_hashenc.nx -- CAP-HASH-ENCODING, generation 9: the core contribution of Instant-NGP (Mueller et al. 2022, arxiv 2201.05989, the repo the operator linked). The measured CLAIM that justifies the method: a LEARNABLE interpolated FEATURE-GRID encoding represents high-frequency detail that a model of the RAW coordinate cannot -- cheap, fast, "seconds not hours". Honest measured-exceed, isolated on the ENCODING (operator: capability is the exceed, measured, no wave). Two models trained on the SAME maximally-high-frequency target, differing ONLY in how the input coordinate is represented: PLAIN out_i = a*x_i + b -- the raw coordinate (affine). Provably can only draw a LINE, so it cannot fit an oscillating signal. (convex -> trains robustly to its best-line plateau = an honest, non-fragile failure.) HASH out_i = interp(feat[i],feat[i+1]) -- a learnable interpolated feature grid (the encoding core). Linear in the features -> convex -> fits the high-freq field. Gate: T1 HASH FITS (SSE collapses >=95%), T2 PLAIN FAILS (its SSE stays high), T3 MEASURED EXCEED (loss_plain >= 4x loss_hash), T4 BIT-EXACT (train twice -> identical integer features). HONEST: this isolates the encoding; composing it with a trainable MLP readout (proven in nx_ng_radiance) + the MULTI-resolution levels + spatial hashing (3D/high-dim scaling) are the follow-on rungs. Sovereign: nx_nofloat_autograd + 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_hashenc.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 hp sys_write sys_mmap train_plain sys_mmap ↻ plain_build nfa_leaf nfa_new nfa_matvec nfa_new ↻ nfa_vadd nfa_new ↻ 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 nfa_grad nfa_sgd train_hash sys_mmap ↻ hash_build nfa_leaf ↻ nfa_cmul nfa_new ↻

structs

none

consts

22const LR_MAGIC_32768: i64 = 32768
23const LR_MAGIC_6553: i64 = 6553
24const LR_MAGIC_1234: i64 = 1234
25const LR_MAGIC_26000: i64 = 26000
26const LR_MAGIC_1024: i64 = 1024
27const LR_MAGIC_16384: i64 = 16384
28const LR_MAGIC_58982: i64 = 58982
30const HLOG: *u8 = "knowledge/status/ng_hashenc.log"
31const Q16: i64 = 65536
32const NC: i64 = 8 // sample coords (high-frequency target)
33const NG: i64 = 9 // grid vertices (NC+1) for the feature encoding
34const EPOCHS: i64 = 6000
35const LR_PLAIN: i64 = 1024 // raw-coord affine: small lr (it diverges/overflows at high lr) -> stable plateau
36const LR_HASH: i64 = 8192 // convex feature grid: fast. Per-model lr = each trained to its representational best.

functions

38func hp(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 1: main calls 1: sys_write
43func hpn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
44func hl_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
49func hl_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
called by 1: main calls 1: nxi_fd
52func plain_build(tape: *i64, vals: *i64, st: *i64, coords: *i64, targ: *i64, p: *i64, wn: *i64) -> i64
70func hash_build(tape: *i64, vals: *i64, st: *i64, featp: *i64, targ: *i64, fn: *i64) -> i64
87func train_plain(tape: *i64, vals: *i64, grads: *i64, st: *i64, coords: *i64, targ: *i64, lf: *i64, ll: *i64) -> i64
102func train_hash(tape: *i64, vals: *i64, grads: *i64, st: *i64, targ: *i64, featout: *i64, lf: *i64, ll: *i64) -> i64
120func main() -> i64