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