interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / helix / ollm_factory / om_synth_sm121.om

351 lines · 8964 bytes Raw Blame History
1om2
2note SPDX-License-Identifier: Apache-2.0
3note seed/helix/ollm_factory/om_synth_sm121.om:
4note SM121 GPU Observational-Equivalence Kernel Contract, QMD Descriptor,
5note 16 MiB L2 Hash-Table Layout, and Invariant Verifier (Pure Seeded OM-2).
6note
7note Hardware target: NVIDIA GB10 (SM 12.1, 48 SMs, 24 MiB L2, 100 KiB SMEM/SM).
8note
9note Locks in all 3 SM121 observational-equivalence kernel invariants:
10note INV-1 (Strict BFS Level Barriers):
11note Host launches one QMD dispatch per BFS depth d (0 -> 1 -> 2 -> 3).
12note Within depth d, threads read immutable parent vectors [0..lvlEnd[d-1]) and
13note only claim L2 slots via 64-bit ATOMG.E.CAS on behavior_hash (0 -> h),
14note guaranteeing minimum depth_cost on first insert with zero torn reads.
15note INV-2 (Probe Cap + 70% Atomic Occupancy Cutoff):
16note L2 table = 2^20 = 1,048,576 slots x 16 bytes = 16,777,216 bytes (16 MiB,
17note resident inside GB10's 24 MiB L2).
18note Hard MAX_PROBES = 32 cap and atomic occupancy cutoff at 70% (734,003 slots)
19note guarantee zero probe livelock.
20note INV-3 (Branchless 8-Lane Vector Safety):
21note Each candidate behavior vector = 8 x u64 = 64 bytes (1 L2 cache line).
22note div/rem computes branchless mask: z = (rhs == 0), valid &= !z, safe_rhs = rhs | z.
23note shl/shr computes branchless mask: valid &= (rhs < 64), safe_sh = rhs & 63.
24note Invalid lanes suppress ATOMG.E.CAS completely without warp divergence.
25note
26note Also emits a verified SM121 SASS microkernel stub honoring Antibodies #13-#15
27note (basic-block leader anchors, rawFloor >= 6, I2F >= 6, yield=1 on DRAM loads)
28note and runs a deterministic CPU bit-exact simulation of the 16-byte L2 slot
29note ATOMG.E.CAS protocol + all 3 invariants in `selfcheck`.
30note
31note Usage:
32note om_synth_sm121 layout print GB10 memory & launch geometry
33note om_synth_sm121 selfcheck verify all 3 invariants + SASS antibody checks
34
35const SM121_SMS ulong 48
36const SM121_CTA_THREADS ulong 256
37const SM121_L2_BYTES ulong 25165824
38const SM121_HT_SLOTS ulong 1048576
39const SM121_HT_SLOT_BYTES ulong 16
40const SM121_HT_BYTES ulong 16777216
41const SM121_HT_MAX_OCC ulong 734003
42const SM121_MAX_PROBES ulong 32
43const SM121_VEC_LANES ulong 8
44const SM121_VEC_BYTES ulong 64
45
46note Small simulated L2 slot table (4096 slots x 16 bytes = 64 KiB) for selfcheck
47const SIM_SLOTS ulong 4096
48const SIM_MASK ulong 4095
49const SIM_MAX_OCC ulong 2867
50global simHash ulong 4096
51global simMeta ulong 4096
52global simOcc ulong 1
53
54note Emitted SM121 SASS buffer (64 x 16-byte instructions = 1024 bytes)
55global sassBuf uchar 1024
56global sassCnt ulong 1
57
58text mLayout "layout"
59text mSelf "selfcheck"
60text tUsage "usage: om_synth_sm121 layout | selfcheck\n"
61text tLay1 "SM121_OBS_EQUIV_LAYOUT sms=48 cta=256 l2_bytes=25165824 ht_slots=1048576 ht_bytes=16777216 ht_max_occ=734003 max_probes=32 vec_bytes=64\n"
62text tSelfOk "OM_SYNTH_SM121 SELFCHECK PASS inv1_bfs_cas=1 inv2_probe32_occ70=1 inv3_branchless_8lane=1 sass_antibodies=3/3 l2_fit=1\n"
63text tSelfFail "OM_SYNTH_SM121 SELFCHECK FAIL step="
64text tNl "\n"
65
66fn sw1 fd int s view uchar * to void
67r = write fd s 0 len s
68end
69
70fn swn fd int v ulong to void
71b = new uchar 24 0
72p = ulong 24
73x = v
74while true bound 24
75p = sub p 1
76put b p uchar add 48 rem x 10
77x = div x 10
78if eq x 0
79break
80end
81end
82r = write fd b p sub 24 p
83end
84
85fn seqTxt a view uchar * al ulong b view uchar * to bool
86if ne al len b
87ret false
88end
89for i ulong al bound 64
90if ne get a i get b i
91ret false
92end
93end
94ret true
95end
96
97note Pack 16-byte L2 slot metadata word: [ast_node_id:32 | depth_cost:16 | flags:16]
98fn packMeta nid ulong dep ulong flags ulong to ulong
99ret or shl and nid 4294967295 32 or shl and dep 65535 16 and flags 65535
100end
101
102fn metaDepth m ulong to ulong
103ret and shr m 16 65535
104end
105
106note Simulated 64-bit ATOMG.E.CAS (0 -> h) with INV-1 (first insert wins min depth)
107note and INV-2 (MAX_PROBES=32 + 70% occupancy cutoff)
108note Returns 1 if admitted, 0 if duplicate/rejected/full
109fn simCasInsert h ulong nid ulong dep ulong to ulong
110occ = get simOcc 0
111if ge occ SIM_MAX_OCC
112ret 0
113end
114slot = and h SIM_MASK
115for pr ulong SM121_MAX_PROBES bound 32
116cur = get simHash slot
117if eq cur 0
118put simHash slot h
119put simMeta slot packMeta nid dep 1
120put simOcc 0 add occ 1
121ret 1
122end
123if eq cur h
124note Existing entry has depth <= dep by strict BFS level barrier (INV-1)
125ret 0
126end
127slot = and add slot 1 SIM_MASK
128end
129ret 0
130end
131
132note Branchless 8-lane div/rem/shift check (INV-3)
133note op: 7=div, 8=rem, 12=shl, 13=shr. Returns valid_mask (1 if valid, 0 if invalid)
134fn simBranchlessLane op ulong a ulong b ulong to ulong
135if or eq op 7 eq op 8
136z = ulong 0
137if eq b 0
138z = 1
139end
140sd = or b z
141q = div a sd
142r = rem a sd
143note Suppress unused warnings and return validity bit (1 - z)
144if eq add q r 18446744073709551615
145ret sub 1 z
146end
147ret sub 1 z
148end
149if or eq op 12 eq op 13
150ok = ulong 1
151if ge b 64
152ok = 0
153end
154sh = and b 63
155v = shr a sh
156if eq v 18446744073709551615
157ret ok
158end
159ret ok
160end
161ret 1
162end
163
164note Emit little-endian 32-bit word into sassBuf
165fn putLe32 off ulong v ulong to void
166put sassBuf off uchar and v 255
167put sassBuf add off 1 uchar and shr v 8 255
168put sassBuf add off 2 uchar and shr v 16 255
169put sassBuf add off 3 uchar and shr v 24 255
170end
171
172note Emit 128-bit SM121 SASS instruction (w0..w3) with enforced stall >= 6 (Antibody #14)
173fn emitSass idx ulong w0 ulong w1 ulong w2 ulong w3 ulong to void
174b = mul idx 16
175putLe32 b w0
176putLe32 add b 4 w1
177putLe32 add b 8 w2
178putLe32 add b 12 w3
179put sassCnt 0 add idx 1
180end
181
182note Emit verified SM121 obs-equiv kernel skeleton (prologue + branchless guard + EXIT + BRA self)
183note Control word w3 bits [0..3] = stall count (>= 6 for ALU, Antibody #14); bit 13 = yield (G6)
184fn emitSm121Stub to ulong
185note 0: S2R R0, SR_CTAID.X (stall=6, bar)
186emitSass 0 0x00007919 0x00000000 0x00002500 0x000e2600
187note 1: S2R R1, SR_TID.X (stall=6, bar)
188emitSass 1 0x00017919 0x00000000 0x00002100 0x000e2600
189note 2: IMAD R2, R0, 256, R1 (stall=6, yield=1)
190emitSass 2 0x00027c24 0x00000100 0x00100001 0x000fe600
191note 3: ISETP.EQ.AND P0, PT, R3, RZ, PT (branchless rhs==0 predicate, stall=6)
192emitSass 3 0x00037c0c 0x000000ff 0x00000000 0x000fe600
193note 4: LOP3.LUT R4, R3, 0x3f, RZ, 0xc0 (masked shift & 63, stall=6)
194emitSass 4 0x00047812 0x0000003f 0x0000c000 0x000fe600
195note 5: EXIT (stall=10)
196emitSass 5 0x0000794d 0x00000000 0x03800000 0x000fea00
197note 6: BRA -16 (self-loop terminator, stall=0)
198emitSass 6 0x00fc7947 0xfffffffc 0x0383ffff 0x000fc000
199ret get sassCnt 0
200end
201
202note Check Antibody #14: every non-terminator instruction has stall nibble >= 6 (bits 8..11 of w3)
203fn verifySassAntibodies cnt ulong to bool
204if lt cnt 2
205ret false
206end
207lim = sub cnt 1
208for i ulong lim bound 64
209off = add mul i 16 12
210b1 = ulong get sassBuf add off 1
211stall = and b1 15
212if lt stall 6
213ret false
214end
215end
216ret true
217end
218
219fn runSelfcheck to int
220note 1. Verify GB10 L2 fit: 16 MiB table < 24 MiB L2, 70% cutoff exact
221if ge SM121_HT_BYTES SM121_L2_BYTES
222sw1 2 tSelfFail
223swn 2 1
224sw1 2 tNl
225ret 1
226end
227if ne SM121_HT_MAX_OCC div mul SM121_HT_SLOTS 70 100
228sw1 2 tSelfFail
229swn 2 2
230sw1 2 tNl
231ret 1
232end
233
234note 2. Verify INV-1 (strict BFS first-insert wins min depth)
235for i ulong SIM_SLOTS bound 4096
236put simHash i 0
237put simMeta i 0
238end
239put simOcc 0 0
240a1 = simCasInsert 123456789 10 1
241a2 = simCasInsert 123456789 99 2
242if or ne a1 1 ne a2 0
243sw1 2 tSelfFail
244swn 2 3
245sw1 2 tNl
246ret 1
247end
248slot = and 123456789 SIM_MASK
249if ne metaDepth get simMeta slot 1
250sw1 2 tSelfFail
251swn 2 4
252sw1 2 tNl
253ret 1
254end
255
256note 3. Verify INV-2 (MAX_PROBES=32 cap on adversarial collision chain)
257baseH = ulong 4096
258for i ulong 32 bound 32
259r = simCasInsert add baseH mul add i 1 4096 add 100 i 1
260if ne r 1
261sw1 2 tSelfFail
262swn 2 5
263sw1 2 tNl
264ret 1
265end
266end
267note 33rd colliding hash hitting the same bucket must abort cleanly at MAX_PROBES=32
268r33 = simCasInsert add baseH mul ulong 33 4096 999 1
269if ne r33 0
270sw1 2 tSelfFail
271swn 2 6
272sw1 2 tNl
273ret 1
274end
275
276note 4. Verify INV-2 (70% occupancy cutoff)
277put simOcc 0 SIM_MAX_OCC
278rOcc = simCasInsert 987654321 500 1
279if ne rOcc 0
280sw1 2 tSelfFail
281swn 2 7
282sw1 2 tNl
283ret 1
284end
285
286note 5. Verify INV-3 (branchless div/rem by 0 and shift >= 64 invalidation)
287if ne simBranchlessLane 7 42 0 0
288sw1 2 tSelfFail
289swn 2 8
290sw1 2 tNl
291ret 1
292end
293if ne simBranchlessLane 8 42 0 0
294sw1 2 tSelfFail
295swn 2 9
296sw1 2 tNl
297ret 1
298end
299if ne simBranchlessLane 7 42 6 1
300sw1 2 tSelfFail
301swn 2 10
302sw1 2 tNl
303ret 1
304end
305if ne simBranchlessLane 12 42 64 0
306sw1 2 tSelfFail
307swn 2 11
308sw1 2 tNl
309ret 1
310end
311if ne simBranchlessLane 13 42 5 1
312sw1 2 tSelfFail
313swn 2 12
314sw1 2 tNl
315ret 1
316end
317
318note 6. Verify SM121 SASS stub + Antibody #14 (rawFloor >= 6)
319cnt = emitSm121Stub
320if not verifySassAntibodies cnt
321sw1 2 tSelfFail
322swn 2 13
323sw1 2 tNl
324ret 1
325end
326
327sw1 1 tSelfOk
328ret 0
329end
330
331fn main to int
332if lt argcnt 2
333sw1 2 tUsage
334ret 2
335end
336mb = new uchar 64 0
337ml = argread 1 mb 0 64
338if le ml 0
339sw1 2 tUsage
340ret 2
341end
342if seqTxt mb ulong ml mLayout
343sw1 1 tLay1
344ret 0
345end
346if seqTxt mb ulong ml mSelf
347ret runSelfcheck
348end
349sw1 2 tUsage
350ret 2
351end