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 / live / arboris_spec.om

920 lines · 21354 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note seed/ng/live/arboris_spec.om: Live Arboris Specialization & Self-Healing Controller.
3note Pure seeded OM-2 library unit (no om2 header, no fn main).
4note Integrates target_desc.om + isel.om + sm121_pe.om + fabric.om + crystallize.om into:
5note 1. O(1) bounded associative co-activation graph (as_coact) with spreading-activation prediction
6note 2. Hot-shape observation (as_observe) -> TID_A725 background specialization queue (TASK_BG_METABOLIC)
7note 3. 3-bit proof-gated specialization (as_specialize_slot): Contract(1) | EGP3(2) | Antibody#13-15+ORACLE(4) == 7
8note 4. Live ORACLE out-of-domain guard & automatic atomic fabWtbl rollback (as_dispatch_checked)
9note 5. Full telemetry counters (dispatches, spec hits, coact hits, refusals, rollbacks, latency saved)
10
11note 3-bit proof gate mask constants:
12const AS_PROOF_CONTRACT ulong 1
13const AS_PROOF_EGP3 ulong 2
14const AS_PROOF_ANTIBODY ulong 4
15const AS_PROOF_ALL ulong 7
16
17note Specialization kinds:
18const AS_KIND_GPU_GEMM ulong 1
19const AS_KIND_CRYSTALLIZE ulong 2
20
21note Specialization result / refusal codes:
22const AS_OK ulong 0
23const AS_ERR_SLOT ulong 1
24const AS_ERR_PROOF_CONTRACT ulong 2
25const AS_ERR_PROOF_EGP3 ulong 3
26const AS_ERR_PROOF_ANTIBODY ulong 4
27const AS_ERR_CONTRACT_SMEM ulong 5
28const AS_ERR_CONTRACT_OTHER ulong 6
29const AS_ERR_SYNTH_FAIL ulong 7
30const AS_ERR_SWAP_FAIL ulong 8
31
32note Last dispatch outcome codes:
33const AS_DISP_BASELINE ulong 0
34const AS_DISP_SPECIALIZED ulong 1
35const AS_DISP_ROLLBACK ulong 2
36
37note Alarm reason codes:
38const AS_ALARM_OOD ulong 1
39const AS_ALARM_ORACLE_MISMATCH ulong 2
40
41note Table capacities & sentinels:
42const AS_COACT_CAP ulong 64
43const AS_COACT_MASK ulong 63
44const AS_COACT_PROBES ulong 8
45const AS_JOB_CAP ulong 32
46const AS_ALARM_CAP ulong 32
47const AS_DEFAULT_THRESH ulong 4
48const AS_NONE ulong 999999
49
50note ---- Verified baseline mirror per fabWtbl slot (supports atomic rollback) ----
51global as_base_valid ulong 32
52global as_base_sem ulong 32
53global as_base_ptr ulong 32
54global as_base_tid ulong 32
55global as_base_mode ulong 32
56global as_base_cost ulong 32
57global as_slot_kind ulong 32
58global as_slot_spec_tid ulong 32
59global as_slot_m ulong 32
60global as_slot_k ulong 32
61global as_slot_n ulong 32
62global as_slot_dom_max ulong 32
63global as_slot_rolled ulong 32
64
65note ---- O(1) bounded associative co-activation graph (caller_sem -> callee_sem) ----
66global as_ca_used ulong 64
67global as_ca_src ulong 64
68global as_ca_dst ulong 64
69global as_ca_wt ulong 64
70
71note ---- O(1) per-caller top-prediction cache (Arboris spreading activation) ----
72global as_pred_used ulong 64
73global as_pred_src ulong 64
74global as_pred_dst ulong 64
75global as_pred_wt ulong 64
76global as_pred_tot ulong 64
77
78note ---- Live co-activation stream tracker ----
79global as_last_sem ulong 1
80global as_pending_pred ulong 1
81
82note ---- Background TID_A725 specialization job queue ----
83global as_hot_thresh ulong 1
84global as_job_cnt ulong 1
85global as_job_slot ulong 32
86global as_job_sem ulong 32
87global as_job_kind ulong 32
88global as_job_m ulong 32
89global as_job_k ulong 32
90global as_job_n ulong 32
91global as_job_exec_tid ulong 32
92global as_job_done ulong 32
93
94note ---- Alarm ring log (bounded 32 entries) ----
95global as_alarm_cnt ulong 1
96global as_alarm_slot ulong 32
97global as_alarm_x0 ulong 32
98global as_alarm_x1 ulong 32
99global as_alarm_code ulong 32
100
101note ---- Diagnostic & telemetry counters ----
102global as_last_status ulong 1
103global as_last_contract_err ulong 1
104global as_dispatches ulong 1
105global as_spec_hits ulong 1
106global as_coact_preds ulong 1
107global as_coact_hits ulong 1
108global as_coact_misses ulong 1
109global as_prefetch_cues ulong 1
110global as_swaps ulong 1
111global as_refusals ulong 1
112global as_alarms ulong 1
113global as_rollbacks ulong 1
114global as_latency_saved_ns ulong 1
115global as_jobs_scheduled ulong 1
116
117fn as_init to void
118for i ulong FAB_SLOTS
119put as_base_valid i 0
120put as_base_sem i 0
121put as_base_ptr i 0
122put as_base_tid i 0
123put as_base_mode i FAB_MODE_NONE
124put as_base_cost i 0
125put as_slot_kind i 0
126put as_slot_spec_tid i AS_NONE
127put as_slot_m i 0
128put as_slot_k i 0
129put as_slot_n i 0
130put as_slot_dom_max i 100
131put as_slot_rolled i 0
132end
133for j ulong AS_COACT_CAP
134put as_ca_used j 0
135put as_ca_src j 0
136put as_ca_dst j 0
137put as_ca_wt j 0
138put as_pred_used j 0
139put as_pred_src j 0
140put as_pred_dst j AS_NONE
141put as_pred_wt j 0
142put as_pred_tot j 0
143end
144for k ulong AS_JOB_CAP
145put as_job_slot k 0
146put as_job_sem k 0
147put as_job_kind k 0
148put as_job_m k 0
149put as_job_k k 0
150put as_job_n k 0
151put as_job_exec_tid k 0
152put as_job_done k 0
153end
154for m ulong AS_ALARM_CAP
155put as_alarm_slot m 0
156put as_alarm_x0 m 0
157put as_alarm_x1 m 0
158put as_alarm_code m 0
159end
160put as_last_sem 0 AS_NONE
161put as_pending_pred 0 AS_NONE
162put as_hot_thresh 0 AS_DEFAULT_THRESH
163put as_job_cnt 0 0
164put as_alarm_cnt 0 0
165put as_last_status 0 AS_DISP_BASELINE
166put as_last_contract_err 0 TDK_OK
167put as_dispatches 0 0
168put as_spec_hits 0 0
169put as_coact_preds 0 0
170put as_coact_hits 0 0
171put as_coact_misses 0 0
172put as_prefetch_cues 0 0
173put as_swaps 0 0
174put as_refusals 0 0
175put as_alarms 0 0
176put as_rollbacks 0 0
177put as_latency_saved_ns 0 0
178put as_jobs_scheduled 0 0
179end
180
181fn as_set_threshold thresh ulong to void
182if eq thresh 0
183put as_hot_thresh 0 1
184ret
185end
186put as_hot_thresh 0 thresh
187end
188
189fn as_set_slot_target slot ulong targetTid ulong to void
190if lt slot FAB_SLOTS
191put as_slot_spec_tid slot targetTid
192end
193end
194
195fn as_set_slot_dom slot ulong domMax ulong to void
196if lt slot FAB_SLOTS
197put as_slot_dom_max slot domMax
198end
199end
200
201note Register a verified cold baseline realization in fabWtbl and snapshot it for rollback!
202fn as_register_baseline slot ulong semId ulong codePtr ulong tid ulong mode ulong kind ulong to bool
203if ge slot FAB_SLOTS
204ret false
205end
206if not fabHotSwap slot semId codePtr tid mode AS_PROOF_ALL
207ret false
208end
209put as_base_valid slot 1
210put as_base_sem slot semId
211put as_base_ptr slot codePtr
212put as_base_tid slot tid
213put as_base_mode slot mode
214put as_base_cost slot get fabCostNs slot
215put as_slot_kind slot kind
216if eq kind AS_KIND_GPU_GEMM
217put as_slot_spec_tid slot TID_SM121
218else
219put as_slot_spec_tid slot TID_X925
220end
221put as_slot_dom_max slot get crDomMax 0
222ret true
223end
224
225note ---- Subsystem 1: Associative Co-Activation Graph (O(1) bounded) ----
226fn as_coact_hash2 a ulong b ulong to ulong
227h1 = mul a 2654435761
228h2 = mul b 2246822519
229ret and xor h1 h2 AS_COACT_MASK
230end
231
232fn as_coact_hash1 a ulong to ulong
233ret and mul a 2654435761 AS_COACT_MASK
234end
235
236fn as_coact_update_pred callerSem ulong calleeSem ulong wt ulong to void
237base = as_coact_hash1 callerSem
238for p ulong AS_COACT_PROBES
239idx = and add base p AS_COACT_MASK
240u = get as_pred_used idx
241if eq u 0
242put as_pred_used idx 1
243put as_pred_src idx callerSem
244put as_pred_dst idx calleeSem
245put as_pred_wt idx wt
246put as_pred_tot idx 1
247ret
248end
249if eq get as_pred_src idx callerSem
250put as_pred_tot idx add get as_pred_tot idx 1
251if ge wt get as_pred_wt idx
252put as_pred_dst idx calleeSem
253put as_pred_wt idx wt
254end
255ret
256end
257end
258end
259
260fn as_coact_has_cold_slot semId ulong to bool
261for i ulong FAB_SLOTS
262if eq get fabSem i semId
263if eq get fabMode i FAB_MODE_NEURAL
264ret true
265end
266end
267end
268ret false
269end
270
271note Record live (caller_sem, callee_sem) transition in O(1) associative table; returns new edge weight.
272fn as_coact callerSem ulong calleeSem ulong to ulong
273base = as_coact_hash2 callerSem calleeSem
274wt = ulong 0
275for p ulong AS_COACT_PROBES
276idx = and add base p AS_COACT_MASK
277u = get as_ca_used idx
278if eq u 0
279put as_ca_used idx 1
280put as_ca_src idx callerSem
281put as_ca_dst idx calleeSem
282put as_ca_wt idx 1
283wt = ulong 1
284break
285end
286if eq get as_ca_src idx callerSem
287if eq get as_ca_dst idx calleeSem
288wt = add get as_ca_wt idx 1
289put as_ca_wt idx wt
290break
291end
292end
293end
294if gt wt 0
295as_coact_update_pred callerSem calleeSem wt
296if as_coact_has_cold_slot calleeSem
297put as_prefetch_cues 0 add get as_prefetch_cues 0 1
298end
299end
300ret wt
301end
302
303note O(1) spreading-activation prediction: returns predicted next callee_sem or AS_NONE.
304fn as_coact_predict callerSem ulong to ulong
305base = as_coact_hash1 callerSem
306for p ulong AS_COACT_PROBES
307idx = and add base p AS_COACT_MASK
308if eq get as_pred_used idx 0
309ret AS_NONE
310end
311if eq get as_pred_src idx callerSem
312ret get as_pred_dst idx
313end
314end
315ret AS_NONE
316end
317
318note O(1) lookup of current transition weight for (callerSem, calleeSem).
319fn as_coact_weight callerSem ulong calleeSem ulong to ulong
320base = as_coact_hash2 callerSem calleeSem
321for p ulong AS_COACT_PROBES
322idx = and add base p AS_COACT_MASK
323if eq get as_ca_used idx 0
324ret 0
325end
326if eq get as_ca_src idx callerSem
327if eq get as_ca_dst idx calleeSem
328ret get as_ca_wt idx
329end
330end
331end
332ret 0
333end
334
335fn as_coact_reset_seq to void
336put as_last_sem 0 AS_NONE
337put as_pending_pred 0 AS_NONE
338end
339
340fn as_coact_reset_stats to void
341put as_coact_preds 0 0
342put as_coact_hits 0 0
343put as_coact_misses 0 0
344end
345
346note Advance live co-activation stream: score prior prediction, learn edge, emit next prefetch cue!
347fn as_coact_step curSem ulong to ulong
348pend = get as_pending_pred 0
349if ne pend AS_NONE
350put as_coact_preds 0 add get as_coact_preds 0 1
351if eq curSem pend
352put as_coact_hits 0 add get as_coact_hits 0 1
353else
354put as_coact_misses 0 add get as_coact_misses 0 1
355end
356end
357prev = get as_last_sem 0
358if ne prev AS_NONE
359if ne prev curSem
360w = as_coact prev curSem
361end
362end
363put as_last_sem 0 curSem
364nxt = as_coact_predict curSem
365put as_pending_pred 0 nxt
366ret nxt
367end
368
369note ---- Subsystem 2: Hot-Shape Observation -> TID_A725 Background Job Queue ----
370fn as_has_job semId ulong M ulong K ulong N ulong to bool
371cnt = get as_job_cnt 0
372for i ulong cnt bound 32
373if eq get as_job_sem i semId
374if eq get as_job_m i M
375if eq get as_job_k i K
376if eq get as_job_n i N
377ret true
378end
379end
380end
381end
382end
383ret false
384end
385
386note Record live (semId, M, K, N) via fabObserveShape; schedule TID_A725 job when hits >= as_hot_thresh!
387fn as_observe wtblSlot ulong semId ulong M ulong K ulong N ulong to ulong
388hits = fabObserveShape semId M K N
389if ge hits get as_hot_thresh 0
390if not as_has_job semId M K N
391cnt = get as_job_cnt 0
392if lt cnt AS_JOB_CAP
393workerTid = fabScheduleApu TASK_BG_METABOLIC
394kind = ulong AS_KIND_GPU_GEMM
395if lt wtblSlot FAB_SLOTS
396sk = get as_slot_kind wtblSlot
397if ne sk 0
398kind = sk
399end
400end
401put as_job_slot cnt wtblSlot
402put as_job_sem cnt semId
403put as_job_kind cnt kind
404put as_job_m cnt M
405put as_job_k cnt K
406put as_job_n cnt N
407put as_job_exec_tid cnt workerTid
408put as_job_done cnt 0
409put as_job_cnt 0 add cnt 1
410put as_jobs_scheduled 0 add get as_jobs_scheduled 0 1
411end
412end
413end
414ret hits
415end
416
417fn as_pending_jobs to ulong
418cnt = get as_job_cnt 0
419remCnt = ulong 0
420for i ulong cnt bound 32
421if eq get as_job_done i 0
422remCnt = add remCnt 1
423end
424end
425ret remCnt
426end
427
428note ---- Subsystem 3: 3-Bit Proof Gate + Background Specialization ----
429note Antibody #13 (valid 16B SM121 framing, non-zero opcodes), #14 (stall >= 6), #15 (EXIT 0x794d terminator)
430fn as_verify_antibodies to bool
431n = get isLen 0
432if lt n 16
433ret false
434end
435if ne rem n 16 0
436ret false
437end
438if not peVerifySm121Antibodies
439ret false
440end
441insns = div n 16
442for i ulong insns bound 64
443off = mul i 16
444b0 = ulong get isBuf off
445b1 = ulong get isBuf add off 1
446op16 = or b0 shl b1 8
447if eq op16 0
448ret false
449end
450end
451lastOff = sub n 16
452eb0 = ulong get isBuf lastOff
453eb1 = ulong get isBuf add lastOff 1
454exitOp = or eb0 shl eb1 8
455if ne exitOp 31053
456ret false
457end
458exitStall = ulong get isBuf add lastOff 8
459if lt exitStall 6
460ret false
461end
462ret true
463end
464
465fn as_check_elf_magic em ulong to bool
466if ne get elfBuf 0 127
467ret false
468end
469if ne get elfBuf 1 69
470ret false
471end
472if ne get elfBuf 2 76
473ret false
474end
475if ne get elfBuf 3 70
476ret false
477end
478if ne ulong get elfBuf 18 em
479ret false
480end
481if ne get elfBuf 19 0
482ret false
483end
484ret true
485end
486
487note EGP3 structural dual-checker for specialized GPU SM121 realization
488fn as_check_egp3_gpu tid ulong cslot ulong to bool
489if ge cslot RC_CAP
490ret false
491end
492if ne get rcProof cslot AS_PROOF_ALL
493ret false
494end
495if eq isSelect tid OIR_ADD AS_NONE
496ret false
497end
498if eq isSelect tid OIR_MUL AS_NONE
499ret false
500end
501if eq isSelect tid OIR_RET AS_NONE
502ret false
503end
504reg = get peOut 0
505if lt reg PE_REGIME_GEMV_4R
506ret false
507end
508if gt reg PE_REGIME_HMMA_16816
509ret false
510end
511n = get isLen 0
512if lt n 16
513ret false
514end
515ret eq rem n 16 0
516end
517
518note EGP3 structural dual-checker for crystallized multi-ISA realization (A64 + x64 + RV64 + SM121)
519fn as_check_egp3_cryst to bool
520if eq get crFound 0 0
521ret false
522end
523nA64 = crEmitCrystallizedElf TID_X925
524if le nA64 120
525ret false
526end
527if not as_check_elf_magic 183
528ret false
529end
530nX64 = crEmitCrystallizedElf TID_X64_AVX2
531if le nX64 120
532ret false
533end
534if not as_check_elf_magic 62
535ret false
536end
537if not isCompileTestFn TID_RV64_RVV
538ret false
539end
540if ne get isLen 0 12
541ret false
542end
543if not isCompileTestFn TID_SM121
544ret false
545end
546ret eq get isLen 0 48
547end
548
549note ORACLE equivalence check: all live traces + independent in-domain holdout points match crNeuralOracle!
550fn as_check_oracle_equiv to bool
551op1 = get crOp1 0
552op2 = get crOp2 0
553cc = get crConstC 0
554if not crCheckCandAll op1 op2 cc
555ret false
556end
557if ne crEvalCand op1 op2 cc 1 1 crNeuralOracle 1 1
558ret false
559end
560if ne crEvalCand op1 op2 cc 13 17 crNeuralOracle 13 17
561ret false
562end
563ret eq crEvalCand op1 op2 cc 50 50 crNeuralOracle 50 50
564end
565
566fn as_mark_hist_spec semId ulong M ulong K ulong N ulong to void
567for i ulong FAB_HIST_CAP
568if fabMatchHist i semId M K N
569put fabHSpec i 1
570end
571end
572end
573
574fn as_refuse_missing_proof mask ulong to ulong
575if eq and mask AS_PROOF_CONTRACT 0
576ret AS_ERR_PROOF_CONTRACT
577end
578if eq and mask AS_PROOF_EGP3 0
579ret AS_ERR_PROOF_EGP3
580end
581if eq and mask AS_PROOF_ANTIBODY 0
582ret AS_ERR_PROOF_ANTIBODY
583end
584ret AS_OK
585end
586
587fn as_bump_refusal to void
588put as_refusals 0 add get as_refusals 0 1
589end
590
591fn as_gpu_check_contract targetTid ulong M ulong K ulong N ulong to ulong
592pePlanRegime M K N
593crc = tdCheckKernelContract targetTid
594put as_last_contract_err 0 crc
595if eq crc TDK_OK
596ret AS_OK
597end
598if eq crc TDK_ERR_SMEM
599ret AS_ERR_CONTRACT_SMEM
600end
601ret AS_ERR_CONTRACT_OTHER
602end
603
604fn as_gpu_eval_proofs targetTid ulong cslot ulong to ulong
605computed = ulong AS_PROOF_CONTRACT
606if as_check_egp3_gpu targetTid cslot
607computed = or computed AS_PROOF_EGP3
608end
609if as_verify_antibodies
610computed = or computed AS_PROOF_ANTIBODY
611end
612ret computed
613end
614
615fn as_specialize_gpu slot ulong M ulong K ulong N ulong proofMask ulong to ulong
616targetTid = get as_slot_spec_tid slot
617if eq targetTid AS_NONE
618targetTid = TID_SM121
619end
620note Bit 0: ngcheck / TargetDesc physical contract valid (pre-emit!)
621rc = as_gpu_check_contract targetTid M K N
622if ne rc AS_OK
623as_bump_refusal
624ret rc
625end
626rc = as_refuse_missing_proof proofMask
627if ne rc AS_OK
628as_bump_refusal
629ret rc
630end
631rc = peSpecializeW4Gemm get fabSem slot targetTid M K N
632if ne rc TDK_OK
633as_bump_refusal
634if eq rc TDK_ERR_SMEM
635ret AS_ERR_CONTRACT_SMEM
636end
637ret AS_ERR_CONTRACT_OTHER
638end
639cslot = get peOut 4
640note Ensure SM121 SASS buffer is populated for live EGP3 + Antibody #13-15 audit (even on cache hit)
641if not isCompileTestFn targetTid
642as_bump_refusal
643ret AS_ERR_PROOF_EGP3
644end
645eff = and as_gpu_eval_proofs targetTid cslot proofMask
646if ne eff AS_PROOF_ALL
647as_bump_refusal
648ret as_refuse_missing_proof eff
649end
650if not fabHotSwap slot get fabSem slot get rcPtr cslot targetTid FAB_MODE_GPU_NATIVE eff
651as_bump_refusal
652ret AS_ERR_SWAP_FAIL
653end
654put as_slot_m slot M
655put as_slot_k slot K
656put as_slot_n slot N
657as_mark_hist_spec get fabSem slot M K N
658put as_swaps 0 add get as_swaps 0 1
659ret AS_OK
660end
661
662fn as_cryst_check_contract targetTid ulong to ulong
663tdSetReq EXEC_SCALAR_SIMD 0 8 4 0 0
664crc = tdCheckKernelContract targetTid
665put as_last_contract_err 0 crc
666if ne crc TDK_OK
667ret AS_ERR_CONTRACT_OTHER
668end
669tdSetReq EXEC_SIMT_WARP 4096 40 32 0 0
670crc = tdCheckKernelContract TID_SM121
671put as_last_contract_err 0 crc
672if eq crc TDK_OK
673ret AS_OK
674end
675if eq crc TDK_ERR_SMEM
676ret AS_ERR_CONTRACT_SMEM
677end
678ret AS_ERR_CONTRACT_OTHER
679end
680
681fn as_cryst_eval_proofs to ulong
682computed = ulong AS_PROOF_CONTRACT
683if as_check_egp3_cryst
684computed = or computed AS_PROOF_EGP3
685end
686if as_verify_antibodies
687if as_check_oracle_equiv
688computed = or computed AS_PROOF_ANTIBODY
689end
690end
691ret computed
692end
693
694fn as_specialize_cryst slot ulong proofMask ulong to ulong
695targetTid = get as_slot_spec_tid slot
696if eq targetTid AS_NONE
697targetTid = TID_X925
698end
699note Bit 0: TargetDesc physical contract valid for CPU + SM121 targets
700rc = as_cryst_check_contract targetTid
701if ne rc AS_OK
702as_bump_refusal
703ret rc
704end
705rc = as_refuse_missing_proof proofMask
706if ne rc AS_OK
707as_bump_refusal
708ret rc
709end
710if not crSynthesizeFromTraces
711as_bump_refusal
712ret AS_ERR_SYNTH_FAIL
713end
714eff = and as_cryst_eval_proofs proofMask
715if ne eff AS_PROOF_ALL
716as_bump_refusal
717ret as_refuse_missing_proof eff
718end
719cslot = tdCacheInstall get fabSem slot targetTid tdGet targetTid TDF_FEAT 1 131072 eff
720if eq cslot AS_NONE
721as_bump_refusal
722ret AS_ERR_SWAP_FAIL
723end
724if not fabHotSwap slot get fabSem slot 131072 targetTid FAB_MODE_CRYSTALLIZED eff
725as_bump_refusal
726ret AS_ERR_SWAP_FAIL
727end
728put as_swaps 0 add get as_swaps 0 1
729ret AS_OK
730end
731
732note Unified 3-bit proof-gated specialization entry point (6 params).
733fn as_specialize_slot slot ulong kind ulong M ulong K ulong N ulong proofMask ulong to ulong
734if ge slot FAB_SLOTS
735put as_refusals 0 add get as_refusals 0 1
736ret AS_ERR_SLOT
737end
738if eq kind AS_KIND_GPU_GEMM
739ret as_specialize_gpu slot M K N proofMask
740end
741if eq kind AS_KIND_CRYSTALLIZE
742ret as_specialize_cryst slot proofMask
743end
744put as_refusals 0 add get as_refusals 0 1
745ret AS_ERR_SLOT
746end
747
748note Drain pending TID_A725 background specialization queue; returns count of atomic swaps.
749fn as_run_bg_queue proofMask ulong to ulong
750cnt = get as_job_cnt 0
751sw = ulong 0
752for i ulong cnt bound 32
753if eq get as_job_done i 0
754if eq get as_job_exec_tid i TID_A725
755rc = as_specialize_slot get as_job_slot i get as_job_kind i get as_job_m i get as_job_k i get as_job_n i proofMask
756if eq rc AS_OK
757put as_job_done i 1
758sw = add sw 1
759else
760put as_job_done i 2
761end
762end
763end
764end
765ret sw
766end
767
768note ---- Subsystem 4: Live ORACLE Out-of-Domain Guard & Automatic Rollback ----
769fn as_log_alarm slot ulong x0 ulong x1 ulong code ulong to void
770put as_alarms 0 add get as_alarms 0 1
771idx = get as_alarm_cnt 0
772if lt idx AS_ALARM_CAP
773put as_alarm_slot idx slot
774put as_alarm_x0 idx x0
775put as_alarm_x1 idx x1
776put as_alarm_code idx code
777put as_alarm_cnt 0 add idx 1
778end
779end
780
781fn as_rollback_slot slot ulong to bool
782if ge slot FAB_SLOTS
783ret false
784end
785if eq get as_base_valid slot 0
786ret false
787end
788bSem = get as_base_sem slot
789bPtr = get as_base_ptr slot
790bTid = get as_base_tid slot
791bMode = get as_base_mode slot
792if not fabHotSwap slot bSem bPtr bTid bMode AS_PROOF_ALL
793ret false
794end
795put as_rollbacks 0 add get as_rollbacks 0 1
796put as_slot_rolled slot add get as_slot_rolled slot 1
797ret true
798end
799
800fn as_record_savings slot ulong to void
801baseC = get as_base_cost slot
802curC = get fabCostNs slot
803if gt baseC curC
804put as_latency_saved_ns 0 add get as_latency_saved_ns 0 sub baseC curC
805end
806end
807
808fn as_cryst_in_dom slot ulong x0 ulong x1 ulong to bool
809domMax = get as_slot_dom_max slot
810cDom = get crDomMax 0
811if lt cDom domMax
812domMax = cDom
813end
814if gt x0 domMax
815ret false
816end
817ret le x1 domMax
818end
819
820fn as_dispatch_cryst slot ulong x0 ulong x1 ulong to ulong
821if eq get fabMode slot FAB_MODE_CRYSTALLIZED
822if as_cryst_in_dom slot x0 x1
823yFast = crEvalCand get crOp1 0 get crOp2 0 get crConstC 0 x0 x1
824yRef = crNeuralOracle x0 x1
825if eq yFast yRef
826put as_spec_hits 0 add get as_spec_hits 0 1
827as_record_savings slot
828put as_last_status 0 AS_DISP_SPECIALIZED
829ret yFast
830end
831as_log_alarm slot x0 x1 AS_ALARM_ORACLE_MISMATCH
832rb = as_rollback_slot slot
833put as_last_status 0 AS_DISP_ROLLBACK
834ret yRef
835end
836note Out-of-domain alarm: fall back to verified baseline neural oracle and atomically roll back fabWtbl!
837as_log_alarm slot x0 x1 AS_ALARM_OOD
838ySafe = crNeuralOracle x0 x1
839rb = as_rollback_slot slot
840put as_last_status 0 AS_DISP_ROLLBACK
841ret ySafe
842end
843put as_last_status 0 AS_DISP_BASELINE
844ret crCallOracle slot x0 x1
845end
846
847fn as_dispatch_gpu slot ulong x0 ulong x1 ulong to ulong
848mode = get fabMode slot
849yExact = mul x0 x1
850if eq mode FAB_MODE_GPU_NATIVE
851if eq x0 get as_slot_m slot
852if eq x1 get as_slot_k slot
853put as_spec_hits 0 add get as_spec_hits 0 1
854as_record_savings slot
855put as_last_status 0 AS_DISP_SPECIALIZED
856ret yExact
857end
858end
859as_log_alarm slot x0 x1 AS_ALARM_OOD
860rb = as_rollback_slot slot
861put as_last_status 0 AS_DISP_ROLLBACK
862ret yExact
863end
864put as_last_status 0 AS_DISP_BASELINE
865ret yExact
866end
867
868note Checked live dispatch through fabWtbl with co-activation tracking, ORACLE guard, and rollback!
869fn as_dispatch_checked slot ulong x0 ulong x1 ulong to ulong
870if ge slot FAB_SLOTS
871put as_last_status 0 AS_DISP_BASELINE
872ret 0
873end
874put as_dispatches 0 add get as_dispatches 0 1
875sem = get fabSem slot
876cue = as_coact_step sem
877kind = get as_slot_kind slot
878if eq kind AS_KIND_CRYSTALLIZE
879ret as_dispatch_cryst slot x0 x1
880end
881ret as_dispatch_gpu slot x0 x1
882end
883
884note ---- Subsystem 5: Telemetry Summary Getter ----
885fn as_telemetry_get metric ulong to ulong
886if eq metric 0
887ret get as_dispatches 0
888end
889if eq metric 1
890ret get as_spec_hits 0
891end
892if eq metric 2
893ret get as_coact_hits 0
894end
895if eq metric 3
896ret get as_refusals 0
897end
898if eq metric 4
899ret get as_rollbacks 0
900end
901if eq metric 5
902ret get as_latency_saved_ns 0
903end
904if eq metric 6
905ret get as_swaps 0
906end
907if eq metric 7
908ret get as_alarms 0
909end
910if eq metric 8
911ret get as_coact_preds 0
912end
913if eq metric 9
914ret get as_prefetch_cues 0
915end
916if eq metric 10
917ret get as_jobs_scheduled 0
918end
919ret 0
920end