code wiki / _hdl_build / nx_ng_lineage.nx
nx_ng_lineage.nx source
↩ module page · 212 lines · 12789 B
1// nx_ng_lineage.nx -- the NEURAL-GRAPHICS frontier lineage emitter: grafts the instant-ngp-class
2// stretch targets onto the genesis family tree (knowledge/registry/genesis_lineage.tsv, the tree
3// nx_genealogy_tree renders + nx_genesis_trace verifies) so every frontier capability has CLEAR
4// PATHING BACK TO GOD (operator 2026-06-22).
5//
6// GROWS THE TEAM (operator: "use the nishi team to grow their capabilities via this work"): this is a
7// NEW genealogist organ -- a sibling of nx_genesis_lineage but for the 7-column genesis tree (id, type,
8// parent_id, axis, sovereignty, label, safety) with a SINGLE parent per node. It mirrors that organ's
9// proven machinery: idempotent (a node already present is SKIPPED), and it REFUSES any node whose parent
10// is not already in the tree or an earlier batch sibling -> it can NEVER author a broken link / floating
11// orphan (the "born with a home or not at all" guard). The independent PROOF the graft actually roots at
12// god is nx_genealogy_tree (V2 orphans==0 + V4 leaf walks to ORIGIN) + nx_genesis_trace -- a wrong edge
13// here cannot go green there.
14//
15// HONEST (operator's first genealogy law = don't lie): these nodes are sovereignty=future -- they are
16// research-grounded TARGETS (cited to knowledge/fetched/ng_*.raw, the 34-source sovereign frontier round),
17// NOT built capabilities. The built sovereign-visual ancestors they descend from are real + gated
18// (CAP-GEOMETRY = nx_gpu_geometry, CAP-RASTERIZER = nx_nishios_raster). Additive-only (append, rule 13).
19// Sovereign syscalls only. license_tier: ORIGINAL expect_exit: 0
20import "nx_syscalls.nx"
21import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
22const NG_MAGIC_1048576: i64 = 1048576
23const NG_MAGIC_1048575: i64 = 1048575
24
25const NG_GEN: *u8 = "knowledge/registry/genesis_lineage.tsv"
26const NG_LOG: *u8 = "knowledge/status/ng_lineage.log"
27const NG_IDCAP: i64 = 48
28
29func ng_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 }
30// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
31// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
32// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
33// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
34func ng_wn(fd: i64, v: i64) -> i64 { nxi_fd(fd, v); return 0 }
35func ng_w1(fd: i64, c: i64) -> i64 { let b: *u8 = sys_mmap(1); b[0] = c as u8; sys_write(fd, b, 1); return 0 }
36
37func ng_streq(a: *u8, b: *u8) -> i64 {
38 var i: i64 = 0
39 while i < 64 { if a[i] != b[i] { return 0 } if a[i] == (0 as u8) { return 1 } i = i + 1 }
40 return 1
41}
42func ng_in_set(arena: i64, cnt: i64, idcap: i64, name: *u8) -> i64 {
43 var i: i64 = 0
44 while i < cnt { if ng_streq((arena + i * idcap) as *u8, name) == 1 { return 1 } i = i + 1 }
45 return 0
46}
47
48// load field0 (node_id) of every non-comment TAB row of genesis_lineage.tsv into arena; returns count.
49func ng_load_ids(path: *u8, arena: i64, idcap: i64, maxc: i64) -> i64 {
50 let buf: *u8 = sys_mmap(NG_MAGIC_1048576)
51 let fd: i64 = sys_openat_rd(path)
52 if fd < 0 { return 0 }
53 var n: i64 = 0
54 var r: i64 = sys_read(fd, buf, NG_MAGIC_1048575)
55 while r > 0 { n = n + r; r = sys_read(fd, buf + n, NG_MAGIC_1048575 - n) }
56 sys_close(fd)
57 var cnt: i64 = 0
58 var i: i64 = 0
59 while i < n {
60 if buf[i] == (35 as u8) {
61 var sk: i64 = 1
62 while sk == 1 { if i >= n { sk = 0 } else { if buf[i] == (10 as u8) { sk = 0 } i = i + 1 } }
63 } else {
64 var fe: i64 = i
65 var scan: i64 = 1
66 while scan == 1 {
67 if fe >= n { scan = 0 } else {
68 if buf[fe] == (9 as u8) { scan = 0 } else { if buf[fe] == (10 as u8) { scan = 0 } else { fe = fe + 1 } }
69 }
70 }
71 let flen: i64 = fe - i
72 if flen > 0 { if flen < idcap { if cnt < maxc {
73 let dst: *u8 = (arena + cnt * idcap) as *u8
74 var k: i64 = 0
75 while k < flen { dst[k] = buf[i + k]; k = k + 1 }
76 dst[flen] = 0 as u8
77 cnt = cnt + 1
78 } } }
79 var le: i64 = fe
80 var s2: i64 = 1
81 while s2 == 1 { if le >= n { s2 = 0 } else { if buf[le] == (10 as u8) { s2 = 0 } else { le = le + 1 } } }
82 i = le + 1
83 }
84 }
85 return cnt
86}
87
88// last byte of a file (for the trailing-newline guard); -1 if empty/missing.
89func ng_last_byte(path: *u8) -> i64 {
90 let b: *u8 = sys_mmap(NG_MAGIC_1048576)
91 let fd: i64 = sys_openat_rd(path)
92 if fd < 0 { return 0 - 1 }
93 var n: i64 = 0
94 var r: i64 = sys_read(fd, b, NG_MAGIC_1048575)
95 while r > 0 { n = n + r; r = sys_read(fd, b + n, NG_MAGIC_1048575 - n) }
96 sys_close(fd)
97 if n <= 0 { return 0 - 1 }
98 return b[n - 1] as i64
99}
100
101// emit one 7-column TAB row + newline.
102func ng_emit(fd: i64, id: *u8, t: *u8, p: *u8, a: *u8, s: *u8, l: *u8, sf: *u8) -> i64 {
103 ng_w(fd, id); ng_w1(fd, 9)
104 ng_w(fd, t); ng_w1(fd, 9)
105 ng_w(fd, p); ng_w1(fd, 9)
106 ng_w(fd, a); ng_w1(fd, 9)
107 ng_w(fd, s); ng_w1(fd, 9)
108 ng_w(fd, l); ng_w1(fd, 9)
109 ng_w(fd, sf); ng_w1(fd, 10)
110 return 0
111}
112
113func ng_report(fd: i64, total: i64, emitted: i64, skipped: i64, refused: i64, ok: i64) -> i64 {
114 ng_w(fd, "NGLIN authored=organ target=genesis_lineage.tsv frontier_nodes=" as *u8); ng_wn(fd, total)
115 ng_w(fd, " emitted=" as *u8); ng_wn(fd, emitted)
116 ng_w(fd, " skipped_idempotent=" as *u8); ng_wn(fd, skipped)
117 ng_w(fd, " refused_broken=" as *u8); ng_wn(fd, refused)
118 if ok == 1 { ng_w(fd, " verdict=GREEN\n" as *u8) } else { ng_w(fd, " verdict=RED\n" as *u8) }
119 return 0
120}
121
122func main() -> i64 {
123 let N: i64 = 10
124 // load the node_ids already in the genesis tree (idempotency + parent-validation universe)
125 let exist: i64 = sys_mmap(512 * NG_IDCAP) as i64
126 var ec: i64 = ng_load_ids(NG_GEN, exist, NG_IDCAP, 512)
127 if ec <= 0 { ng_w(1, "NGLIN verdict=RED reason=genesis-tree-missing\n" as *u8); sys_exit(1); return 1 }
128 ng_w(1, "NGLIN existing genesis nodes=" as *u8); ng_wn(1, ec); ng_w(1, "\n" as *u8)
129
130 // the neural-graphics frontier subtree -- parent-BEFORE-child order so each validates against the
131 // growing set. Root attach = CAP-GEOMETRY (the built sovereign 3D geometry stage, nx_gpu_geometry).
132 let ids: *i64 = sys_mmap(8 * N) as *i64
133 let typ: *i64 = sys_mmap(8 * N) as *i64
134 let par: *i64 = sys_mmap(8 * N) as *i64
135 let axs: *i64 = sys_mmap(8 * N) as *i64
136 let sov: *i64 = sys_mmap(8 * N) as *i64
137 let lab: *i64 = sys_mmap(8 * N) as *i64
138 let saf: *i64 = sys_mmap(8 * N) as *i64
139
140 ids[0] = ("CAP-NEURAL-GFX" as *u8) as i64; typ[0] = ("variant" as *u8) as i64; par[0] = ("CAP-GEOMETRY" as *u8) as i64; axs[0] = ("accel" as *u8) as i64; sov[0] = ("future" as *u8) as i64
141 lab[0] = ("NEURAL-GRAPHICS frontier (instant-ngp class + beyond): the next generation past classical software-raster 3D; research-grounded by 34 sovereign sources (knowledge/fetched/ng_*.raw); children below are TARGETS not yet built" as *u8) as i64; saf[0] = ("-" as *u8) as i64
142
143 ids[1] = ("CAP-DIFF-RENDER" as *u8) as i64; typ[1] = ("variant" as *u8) as i64; par[1] = ("CAP-NEURAL-GFX" as *u8) as i64; axs[1] = ("accel" as *u8) as i64; sov[1] = ("future" as *u8) as i64
144 lab[1] = ("differentiable rendering: gradients through the renderer = the training substrate radiance-fields/3DGS need (src ng_render_rendering, ng_render_lightfield). TARGET" as *u8) as i64; saf[1] = ("-" as *u8) as i64
145
146 ids[2] = ("CAP-RADIANCE-FIELD" as *u8) as i64; typ[2] = ("variant" as *u8) as i64; par[2] = ("CAP-NEURAL-GFX" as *u8) as i64; axs[2] = ("accel" as *u8) as i64; sov[2] = ("future" as *u8) as i64
147 lab[2] = ("radiance field / NeRF: scene as MLP, ray-march + volume render; the instant-ngp home (src ng_spine_nerf, ng_paper_nerf2020 arxiv:2003.08934, US/DE). TARGET" as *u8) as i64; saf[2] = ("-" as *u8) as i64
148
149 ids[3] = ("CAP-HASH-ENCODING" as *u8) as i64; typ[3] = ("variant" as *u8) as i64; par[3] = ("CAP-RADIANCE-FIELD" as *u8) as i64; axs[3] = ("accel" as *u8) as i64; sov[3] = ("future" as *u8) as i64
150 lab[3] = ("instant-ngp multiresolution hash encoding = the speed primitive (seconds not hours) (src ng_paper_instantngp arxiv:2201.05989, NVIDIA/US). TARGET" as *u8) as i64; saf[3] = ("-" as *u8) as i64
151
152 ids[4] = ("CAP-GAUSSIAN-SPLAT" as *u8) as i64; typ[4] = ("variant" as *u8) as i64; par[4] = ("CAP-NEURAL-GFX" as *u8) as i64; axs[4] = ("accel" as *u8) as i64; sov[4] = ("future" as *u8) as i64
153 lab[4] = ("3D Gaussian Splatting: explicit gaussian primitives, real-time rasterized radiance (src ng_spine_3dgs, ng_paper_3dgs arxiv:2308.04079, Inria/FR/EU). TARGET" as *u8) as i64; saf[4] = ("-" as *u8) as i64
154
155 ids[5] = ("CAP-GS-REALTIME" as *u8) as i64; typ[5] = ("variant" as *u8) as i64; par[5] = ("CAP-GAUSSIAN-SPLAT" as *u8) as i64; axs[5] = ("accel" as *u8) as i64; sov[5] = ("future" as *u8) as i64
156 lab[5] = ("real-time gaussian-splat rasterizer/viewer extending the sovereign tile-raster (CAP-GEOMETRY) to splats (src ng_spine_3dgs). TARGET" as *u8) as i64; saf[5] = ("-" as *u8) as i64
157
158 ids[6] = ("CAP-GEN-3D" as *u8) as i64; typ[6] = ("variant" as *u8) as i64; par[6] = ("CAP-NEURAL-GFX" as *u8) as i64; axs[6] = ("accel" as *u8) as i64; sov[6] = ("future" as *u8) as i64
159 lab[6] = ("generative 3D (text/image-to-3D): 2D-diffusion priors -> 3D assets, DreamFusion-class (src ng_paper_dreamfusion arxiv:2209.14988, ng_gen_diffusion). TARGET" as *u8) as i64; saf[6] = ("-" as *u8) as i64
160
161 ids[7] = ("CAP-NEURAL-AVATAR" as *u8) as i64; typ[7] = ("variant" as *u8) as i64; par[7] = ("CAP-GEN-3D" as *u8) as i64; axs[7] = ("accel" as *u8) as i64; sov[7] = ("future" as *u8) as i64
162 lab[7] = ("animatable neural humans / gaussian avatars (src ng_region_ru_neuralavatars Samsung-Moscow lineage, ng_spine_3dgs). TARGET" as *u8) as i64; saf[7] = ("-" as *u8) as i64
163
164 ids[8] = ("CAP-WORLD-MODEL" as *u8) as i64; typ[8] = ("variant" as *u8) as i64; par[8] = ("CAP-NEURAL-GFX" as *u8) as i64; axs[8] = ("accel" as *u8) as i64; sov[8] = ("future" as *u8) as i64
165 lab[8] = ("real-time WORLD MODEL / neural game engine = the canopy past static scenes; the frontier ENDPOINT (src ng_world_t2v, ng_world_sora, ng_world_worldmodel; CN Kling, UK Veo). TARGET" as *u8) as i64; saf[8] = ("-" as *u8) as i64
166
167 // CAP-VOLUME-RENDER -- added after R4 built it (sovereignty=building: gated first rung, not full prod)
168 ids[9] = ("CAP-VOLUME-RENDER" as *u8) as i64; typ[9] = ("variant" as *u8) as i64; par[9] = ("CAP-NEURAL-GFX" as *u8) as i64; axs[9] = ("accel" as *u8) as i64; sov[9] = ("building" as *u8) as i64
169 lab[9] = ("volumetric alpha-over compositing (NeRF/3DGS core render op): forward transmittance-chain + differentiable, gated GREEN nx_ng_volrender. RUNG-1 building" as *u8) as i64; saf[9] = ("-" as *u8) as i64
170
171 // trailing-newline guard: never join the first emitted row onto the last existing row.
172 let lb: i64 = ng_last_byte(NG_GEN)
173 let fd: i64 = sys_openat_append(NG_GEN, 420)
174 if fd < 0 { ng_w(1, "NGLIN verdict=RED reason=tree-unwritable\n" as *u8); sys_exit(1); return 1 }
175 if lb >= 0 { if lb != 10 { ng_w1(fd, 10) } }
176
177 var emitted: i64 = 0
178 var skipped: i64 = 0
179 var refused: i64 = 0
180 var k: i64 = 0
181 while k < N {
182 let id: *u8 = ids[k] as *u8
183 let p: *u8 = par[k] as *u8
184 if ng_in_set(exist, ec, NG_IDCAP, id) == 1 { skipped = skipped + 1 }
185 else {
186 var okp: i64 = 0
187 if p[0] == (45 as u8) { if p[1] == (0 as u8) { okp = 1 } }
188 if okp == 0 { if ng_in_set(exist, ec, NG_IDCAP, p) == 1 { okp = 1 } }
189 if okp == 0 {
190 refused = refused + 1
191 ng_w(1, "NGLIN REFUSE broken-parent child=" as *u8); ng_w(1, id); ng_w(1, " parent=" as *u8); ng_w(1, p); ng_w(1, "\n" as *u8)
192 } else {
193 ng_emit(fd, id, typ[k] as *u8, p, axs[k] as *u8, sov[k] as *u8, lab[k] as *u8, saf[k] as *u8)
194 if ec < 512 { let d: *u8 = (exist + ec * NG_IDCAP) as *u8; var z: i64 = 0; while id[z] != (0 as u8) { d[z] = id[z]; z = z + 1 } d[z] = 0 as u8; ec = ec + 1 }
195 emitted = emitted + 1
196 }
197 }
198 k = k + 1
199 }
200 sys_close(fd)
201
202 var ok: i64 = 1
203 if refused != 0 { ok = 0 }
204 if emitted + skipped != N { ok = 0 }
205
206 ng_report(1, N, emitted, skipped, refused, ok)
207 let glog: i64 = sys_openat_append(NG_LOG, 420)
208 if glog >= 0 { ng_report(glog, N, emitted, skipped, refused, ok); sys_close(glog) }
209
210 if ok == 1 { sys_exit(0); return 0 }
211 sys_exit(1); return 1
212}