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 / ng / target / gate.om

560 lines · 11035 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/ng/target/gate.om: Pure seeded OM-2 verification gate for Unified TargetDesc + Shared IPRA/RegAlloc +
3note Multi-ISA Table-Driven ISel (AArch64, x86-64, RV64GC, SM121) + Proof-Gated Realization Cache.
4
5global gDig uchar 24
6text gMsgHdr "=== OMEGA NG UNIFIED TARGET-DESC + MULTI-ISA BACKEND GATE ===\n"
7text gMsgPass "NG-TARGET-GATE PASS checks="
8text gMsgCtrl " controls="
9text gMsgNl "\n"
10text gMsgFail "NG-TARGET-GATE FAIL at check="
11
12fn gSay s ulong to void
13if eq s 0
14w = write 1 gMsgHdr 0 len gMsgHdr
15ret
16end
17if eq s 1
18w = write 1 gMsgPass 0 len gMsgPass
19ret
20end
21if eq s 2
22w = write 1 gMsgCtrl 0 len gMsgCtrl
23ret
24end
25if eq s 3
26w = write 1 gMsgNl 0 len gMsgNl
27ret
28end
29w = write 1 gMsgFail 0 len gMsgFail
30end
31
32fn gNum v ulong to void
33x = v
34p = ulong 24
35for i ulong 21
36p = sub p 1
37put gDig p uchar add 48 rem x 10
38x = div x 10
39if eq x 0
40w = write 1 gDig p sub 24 p
41ret
42end
43end
44end
45
46fn gFail id ulong to int
47gSay 4
48gNum id
49gSay 3
50ret int id
51end
52
53fn gGetU32 off ulong to ulong
54b0 = ulong get isBuf off
55b1 = shl ulong get isBuf add off 1 8
56b2 = shl ulong get isBuf add off 2 16
57b3 = shl ulong get isBuf add off 3 24
58ret or or b0 b1 or b2 b3
59end
60
61note Populate 16 overlapping SSA live intervals to stress-test 12, 15, 30, and 64-register files!
62fn gBuildStressIntervals to void
63raReset
64for i ulong 16
65id = raAddInterval i add i 15 RA_SPILL
66end
67end
68
69global gChk ulong 1
70global gCtrl ulong 1
71
72fn gAddChk n ulong to void
73put gChk 0 add get gChk 0 n
74end
75
76fn gAddCtrl n ulong to void
77put gCtrl 0 add get gCtrl 0 n
78end
79
80fn gTestTargets to int
81if ne get tdCount 0 10
82ret gFail 1
83end
84if ne tdGet TID_X925 TDF_OOO 10
85ret gFail 2
86end
87if ne tdGet TID_A725 TDF_OOO 5
88ret gFail 3
89end
90if ne tdGet TID_X64_AVX2 TDF_TWOADDR 1
91ret gFail 4
92end
93if ne tdGet TID_SM121 TDF_SMEM 101376
94ret gFail 5
95end
96if ne tdGet TID_SPARK_RING TDF_COHNS 4500
97ret gFail 6
98end
99gAddChk 6
100note 2. Compile-Time Physical Contract Checker + Negative Controls
101tdSetReq EXEC_SIMT_WARP 16384 64 32 MMA_16816_BF16 FEAT_HMMA16816
102if ne tdCheckKernelContract TID_SM121 TDK_OK
103ret gFail 10
104end
105tdSet TID_SM121 TDF_SMEM 8192
106if ne tdCheckKernelContract TID_SM121 TDK_ERR_SMEM
107ret gFail 11
108end
109tdSet TID_SM121 TDF_SMEM 101376
110gAddCtrl 1
111tdSetReq EXEC_SIMT_WARP 0 16 32 0 0
112if ne tdCheckKernelContract TID_X925 TDK_ERR_EXEC
113ret gFail 12
114end
115gAddCtrl 1
116tdSetReq EXEC_SCALAR_SIMD 0 12 8 MMA_161616_AMX 0
117if ne tdCheckKernelContract TID_X64_AVX2 TDK_ERR_MMA
118ret gFail 13
119end
120gAddCtrl 1
121gAddChk 4
122note 3. Target-Parameterized Tile/Blocking Planner
123tdDeriveTilePlan TID_X925 4
124x925Nc = get tdTileOut 2
125tdDeriveTilePlan TID_A725 4
126a725Nc = get tdTileOut 2
127if le x925Nc a725Nc
128ret gFail 20
129end
130tdDeriveTilePlan TID_X64_AVX512 4
131if ne get tdTileOut 3 16
132ret gFail 21
133end
134tdDeriveTilePlan TID_SM121 2
135if ne get tdTileOut 0 64
136ret gFail 22
137end
138gAddChk 3
139ret 0
140end
141
142fn gTestRegAlloc to int
143gBuildStressIntervals
144spCm55 = raRunForTarget TID_CM55
145if or eq spCm55 0 ne raVerifyColoring 0
146ret gFail 30
147end
148spX64 = raRunForTarget TID_X64_AVX2
149if or ne spX64 1 ne raVerifyColoring 0
150ret gFail 31
151end
152spA64 = raRunForTarget TID_X925
153if or ne spA64 0 ne raVerifyColoring 0
154ret gFail 32
155end
156spSm121 = raRunForTarget TID_SM121
157if or ne spSm121 0 ne raVerifyColoring 0
158ret gFail 33
159end
160put raPhys 1 get raPhys 0
161if eq raVerifyColoring 0
162ret gFail 34
163end
164gAddCtrl 1
165gAddChk 5
166note 5. Whole-Program IPRA
167raIpraReset 3
168raIpraSetDirect 2 3
169raIpraSetDirect 1 4
170raIpraSetDirect 0 8
171raIpraAddCall 0 1
172raIpraAddCall 1 2
173raIpraSolve
174if ne get raFnProp 0 15
175ret gFail 40
176end
177if ne raPopcount get raFnProp 1 3
178ret gFail 41
179end
180if ge raPopcount get raFnProp 1 raPopcount tdGet TID_X925 TDF_CSAVE
181ret gFail 42
182end
183gAddChk 3
184ret 0
185end
186
187fn gTestIsel to int
188if ne isSelect TID_X925 OIR_FMA 104
189ret gFail 50
190end
191if ne isSelect TID_X925 OIR_SHA256 106
192ret gFail 51
193end
194if ne isSelect TID_X64_AVX2 OIR_FMA 204
195ret gFail 52
196end
197if ne isSelect TID_RV64_RVV OIR_SHA256 305
198ret gFail 53
199end
200gAddChk 4
201note 7a. AArch64: ADD x0,x0,x1; MUL x0,x0,x2; RET
202if not isCompileTestFn TID_X925
203ret gFail 60
204end
205if ne get isLen 0 12
206ret gFail 61
207end
208if ne gGetU32 0 2332098560
209ret gFail 62
210end
211if ne gGetU32 4 2600631296
212ret gFail 62
213end
214if ne gGetU32 8 3596551104
215ret gFail 62
216end
217note 7b. Register-Allocated x86-64: 48 01 f8; 48 0f af c6; c3
218if not isCompileTestFn TID_X64_AVX2
219ret gFail 63
220end
221if ne get isLen 0 8
222ret gFail 64
223end
224if ne get isBuf 0 72
225ret gFail 65
226end
227if ne get isBuf 1 1
228ret gFail 65
229end
230if ne get isBuf 2 248
231ret gFail 65
232end
233if ne get isBuf 7 195
234ret gFail 65
235end
236if ne get isBuf 3 72
237ret gFail 66
238end
239if ne get isBuf 4 15
240ret gFail 66
241end
242if ne get isBuf 5 175
243ret gFail 66
244end
245if ne get isBuf 6 198
246ret gFail 66
247end
248note 7c. RV64GC: ADD a0,a0,a1; MUL a0,a0,a2; RET
249if not isCompileTestFn TID_RV64_RVV
250ret gFail 67
251end
252if ne get isLen 0 12
253ret gFail 68
254end
255if ne gGetU32 0 11863347
256ret gFail 69
257end
258if ne gGetU32 4 46466355
259ret gFail 69
260end
261if ne gGetU32 8 32871
262ret gFail 69
263end
264note 7d. SM121 Blackwell 128-bit SASS (48 B, Antibody #14 stall>=6)
265if not isCompileTestFn TID_SM121
266ret gFail 70
267end
268if ne get isLen 0 48
269ret gFail 71
270end
271if ne gGetU32 8 6
272ret gFail 72
273end
274if ne gGetU32 24 6
275ret gFail 72
276end
277gAddChk 12
278ret 0
279end
280
281fn gTestCache to int
282if ne tdCacheInstall 12345 TID_SM121 3081 4 4096 3 999999
283ret gFail 80
284end
285gAddCtrl 1
286slot = tdCacheInstall 12345 TID_SM121 3081 4 4096 7
287if eq slot 999999
288ret gFail 81
289end
290slot2 = tdCacheInstall 12345 TID_SM121 3081 4 8192 7
291if or ne slot2 slot or ne get rcPtr slot 8192 ne get rcVer slot 2
292ret gFail 82
293end
294gAddChk 3
295ret 0
296end
297
298fn gTestSm121Pe to int
299note 9. Runtime Shape Partial Evaluator across M=1, M=4, M=8, M=512 + Cache Hit + SMEM Negative Control!
300if ne peSpecializeW4Gemm 9001 TID_SM121 1 2048 9216 TDK_OK
301ret gFail 90
302end
303if or ne get peOut 0 PE_REGIME_GEMV_4R ne get peOut 1 8192
304ret gFail 91
305end
306s1 = get peOut 4
307note M=4 MTP decode-verify -> auto-selects REG_TILE_M with exact SMEM=32768 B (zero HMMA padding waste!)
308if ne peSpecializeW4Gemm 9001 TID_SM121 4 2048 9216 TDK_OK
309ret gFail 92
310end
311if or ne get peOut 0 PE_REGIME_REG_TILE_M ne get peOut 1 32768
312ret gFail 93
313end
314s4 = get peOut 4
315if eq s4 s1
316ret gFail 94
317end
318note Repeat M=4 lookup -> O(1) Realization Cache hit returns identical slot!
319if ne peSpecializeW4Gemm 9001 TID_SM121 4 2048 9216 TDK_OK
320ret gFail 95
321end
322if ne get peOut 4 s4
323ret gFail 96
324end
325note M=512 chunked prefill -> auto-selects HMMA_16816 Tensor Core regime!
326if ne peSpecializeW4Gemm 9001 TID_SM121 512 2048 9216 TDK_OK
327ret gFail 97
328end
329if ne get peOut 0 PE_REGIME_HMMA_16816
330ret gFail 98
331end
332note Negative control F: illegal M=8, K=4096 (reqSmem = 131072 > SM121 101376) MUST be refused pre-emit!
333if ne peSpecializeW4Gemm 9001 TID_SM121 8 4096 2048 TDK_ERR_SMEM
334ret gFail 99
335end
336gAddCtrl 1
337note Negative control G: inject Antibody #14 violation (stall=2 < 6) -> peVerifySm121Antibodies MUST catch!
338put isBuf 8 2
339if peVerifySm121Antibodies
340ret gFail 100
341end
342gAddCtrl 1
343gAddChk 8
344note 10. Orthogonal ELF64 container plugin across AArch64 (EM=183), x86-64 (EM=62), and RV64GC (EM=243)
345if eq elfBuildExecDemo TID_X925 0
346ret gFail 101
347end
348if ne get elfBuf 18 183
349ret gFail 102
350end
351if eq elfBuildExecDemo TID_X64_AVX2 0
352ret gFail 103
353end
354if ne get elfBuf 18 62
355ret gFail 104
356end
357if not isCompileTestFn TID_RV64_RVV
358ret gFail 105
359end
360if eq elfEmitStatic TID_RV64_RVV 0
361ret gFail 106
362end
363if ne get elfBuf 18 243
364ret gFail 107
365end
366gAddChk 6
367ret 0
368end
369
370fn gTestFabric to int
371fabInit
372note 11. Heterogeneous apu-gb10 scheduler routes X925 / A725 / SM121 / Spark Ring
373if ne fabScheduleApu TASK_CTRL_LATENCY TID_X925
374ret gFail 110
375end
376if ne fabScheduleApu TASK_BG_METABOLIC TID_A725
377ret gFail 111
378end
379if ne fabScheduleApu TASK_TENSOR_LOCAL TID_SM121
380ret gFail 112
381end
382if ne fabScheduleApu TASK_TENSOR_MULTI_SPARK TID_SPARK_RING
383ret gFail 113
384end
385note Negative control H: unverified fabWtbl hot-swap (proofMask=5, missing ngrun bit1) MUST be refused!
386if fabHotSwap 0 7777 4096 TID_SM121 FAB_MODE_GPU_NATIVE 5
387ret gFail 114
388end
389if ne get fabVer 0 0
390ret gFail 115
391end
392gAddCtrl 1
393note Install baseline neural/generic entry at slot 0, then trigger A725 Arboris metabolic specialization on M=4!
394if not fabHotSwap 0 7777 4096 TID_SM121 FAB_MODE_NEURAL 7
395ret gFail 116
396end
397for k ulong 4
398h = fabObserveShape 7777 4 2048 9216
399end
400if ne fabMetabolicTick 0 TID_SM121 1
401ret gFail 117
402end
403if or ne get fabMode 0 FAB_MODE_GPU_NATIVE ne get fabVer 0 2
404ret gFail 118
405end
406gAddChk 8
407ret 0
408end
409
410fn gTestCrystallize to int
411crInit
412note 12. ΩIR v2 SLAB contracts: immutable write refused, alarmed slab rolls back on overflow!
413crRegSlab 0 SLAB_IMMUTABLE 0 TID_SM121
414crRegSlab 1 SLAB_MUTABLE_ALARMED 100 TID_SM121
415crRegSlab 2 SLAB_SHARDED 0 TID_SPARK_RING
416note Negative control I: write to immutable W4 core weight slab MUST fail!
417if ne crUpdateSlab 0 1 CR_ERR_IMMUTABLE
418ret gFail 120
419end
420gAddCtrl 1
421note Alarmed fast-weight slab accepts bounded update, then trips alarm + rolls back on spike!
422if ne crUpdateSlab 1 40 CR_OK
423ret gFail 121
424end
425if ne crUpdateSlab 1 80 CR_ERR_ALARM
426ret gFail 122
427end
428if ne get crSlabNorm 1 40
429ret gFail 123
430end
431gAddCtrl 1
432note 13. Live Neural -> Portable ΩIR Crystallization Loop!
433if not fabHotSwap 1 8888 8192 TID_SM121 FAB_MODE_NEURAL 7
434ret gFail 124
435end
436if ne crCallOracle 1 2 3 15
437ret gFail 125
438end
439if ne crCallOracle 1 4 1 15
440ret gFail 126
441end
442if ne crCallOracle 1 7 5 36
443ret gFail 127
444end
445if ne crCallOracle 1 10 2 36
446ret gFail 128
447end
448if not crCrystallizeAndSwap 1 8888
449ret gFail 129
450end
451if or ne get crOp1 0 OIR_ADD or ne get crOp2 0 OIR_MUL ne get crConstC 0 3
452ret gFail 130
453end
454if or ne get fabMode 1 FAB_MODE_CRYSTALLIZED ge get fabCostNs 1 1000
455ret gFail 131
456end
457note In-domain call hits crystallized exact path; out-of-domain (x0=200 > 100) trips alarm & falls back cleanly!
458if ne crCallOracle 1 7 5 36
459ret gFail 132
460end
461if ne crCallOracle 1 200 1 603
462ret gFail 133
463end
464gAddChk 11
465ret 0
466end
467
468fn gDumpElf tid ulong to int
469n = elfBuildExecDemo tid
470if eq n 0
471ret 1
472end
473w = write 1 elfBuf 0 n
474if ne w long n
475ret 2
476end
477ret 0
478end
479
480fn gDumpCrystElf tid ulong to int
481fabInit
482crInit
483ok = fabHotSwap 1 8888 8192 TID_SM121 FAB_MODE_NEURAL 7
484y = crCallOracle 1 2 3
485y = crCallOracle 1 7 5
486y = crCallOracle 1 10 2
487if not crSynthesizeFromTraces
488ret 3
489end
490n = crEmitCrystallizedElf tid
491if eq n 0
492ret 4
493end
494w = write 1 elfBuf 0 n
495if ne w long n
496ret 5
497end
498ret 0
499end
500
501fn main to int
502arg = new uchar 16 0
503tdInitAll
504isInitRules
505tdCacheInit
506if gt argcnt 1
507al = argread 1 arg 0 16
508if and ge al 3 eq get arg 0 97
509ret gDumpElf TID_X925
510end
511if and ge al 3 eq get arg 0 120
512ret gDumpElf TID_X64_AVX2
513end
514if and ge al 4 eq get arg 0 99
515if eq get arg 1 97
516ret gDumpCrystElf TID_X925
517end
518if eq get arg 1 120
519ret gDumpCrystElf TID_X64_AVX2
520end
521end
522end
523gSay 0
524put gChk 0 0
525put gCtrl 0 0
526r = gTestTargets
527if ne r 0
528ret r
529end
530r = gTestRegAlloc
531if ne r 0
532ret r
533end
534r = gTestIsel
535if ne r 0
536ret r
537end
538r = gTestCache
539if ne r 0
540ret r
541end
542r = gTestSm121Pe
543if ne r 0
544ret r
545end
546r = gTestFabric
547if ne r 0
548ret r
549end
550r = gTestCrystallize
551if ne r 0
552ret r
553end
554gSay 1
555gNum get gChk 0
556gSay 2
557gNum get gCtrl 0
558gSay 3
559ret 0
560end