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 / target / fabric.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note seed/ng/target/fabric.om: Step 3 -- Live Realization Cache <-> QDI_WTBL Dispatch Fabric |
| 3 | note + Heterogeneous apu-gb10 Scheduler (X925 / A725 / SM121 / Spark Ring) + Arboris Metabolic Re-Specialization. |
| 4 | |
| 5 | const FAB_SLOTS ulong 32 |
| 6 | |
| 7 | note Dispatch execution modes: |
| 8 | const FAB_MODE_NONE ulong 0 |
| 9 | const FAB_MODE_NEURAL ulong 1 |
| 10 | const FAB_MODE_CPU_NATIVE ulong 2 |
| 11 | const FAB_MODE_GPU_NATIVE ulong 3 |
| 12 | const FAB_MODE_CRYSTALLIZED ulong 4 |
| 13 | |
| 14 | note Live dispatch table (software mirror of GPU QDI_WTBL + CPU indirect dispatch table) |
| 15 | global fabSem ulong 32 |
| 16 | global fabPtr ulong 32 |
| 17 | global fabTid ulong 32 |
| 18 | global fabVer ulong 32 |
| 19 | global fabMode ulong 32 |
| 20 | global fabCostNs ulong 32 |
| 21 | |
| 22 | note Arboris live shape trace histogram (tracks hot (semId, M, K, N) calls for A725 background specialization) |
| 23 | const FAB_HIST_CAP ulong 16 |
| 24 | global fabHUsed ulong 16 |
| 25 | global fabHSem ulong 16 |
| 26 | global fabHM ulong 16 |
| 27 | global fabHK ulong 16 |
| 28 | global fabHN ulong 16 |
| 29 | global fabHHits ulong 16 |
| 30 | global fabHSpec ulong 16 |
| 31 | |
| 32 | note Heterogeneous apu-gb10 task kinds: |
| 33 | const TASK_CTRL_LATENCY ulong 1 |
| 34 | const TASK_BG_METABOLIC ulong 2 |
| 35 | const TASK_TENSOR_LOCAL ulong 3 |
| 36 | const TASK_TENSOR_MULTI_SPARK ulong 4 |
| 37 | |
| 38 | fn fabInit to void |
| 39 | for i ulong FAB_SLOTS |
| 40 | put fabSem i 0 |
| 41 | put fabPtr i 0 |
| 42 | put fabTid i 0 |
| 43 | put fabVer i 0 |
| 44 | put fabMode i FAB_MODE_NONE |
| 45 | put fabCostNs i 0 |
| 46 | end |
| 47 | for j ulong FAB_HIST_CAP |
| 48 | put fabHUsed j 0 |
| 49 | put fabHHits j 0 |
| 50 | put fabHSpec j 0 |
| 51 | end |
| 52 | end |
| 53 | |
| 54 | note Heterogeneous apu-gb10 scheduler: routes each task kind to its optimal TargetDesc! |
| 55 | fn fabScheduleApu taskKind ulong to ulong |
| 56 | if eq taskKind TASK_CTRL_LATENCY |
| 57 | ret TID_X925 |
| 58 | end |
| 59 | if eq taskKind TASK_BG_METABOLIC |
| 60 | ret TID_A725 |
| 61 | end |
| 62 | if eq taskKind TASK_TENSOR_LOCAL |
| 63 | ret TID_SM121 |
| 64 | end |
| 65 | if eq taskKind TASK_TENSOR_MULTI_SPARK |
| 66 | ret TID_SPARK_RING |
| 67 | end |
| 68 | ret TID_X925 |
| 69 | end |
| 70 | |
| 71 | note Proof-gated atomic hot-swap into fabWtbl (QDI_WTBL mirror): requires proofMask == 7! |
| 72 | fn fabHotSwap slot ulong semId ulong codePtr ulong tid ulong mode ulong proofMask ulong to bool |
| 73 | if ge slot FAB_SLOTS |
| 74 | ret false |
| 75 | end |
| 76 | if ne and proofMask 7 7 |
| 77 | ret false |
| 78 | end |
| 79 | put fabSem slot semId |
| 80 | put fabPtr slot codePtr |
| 81 | put fabTid slot tid |
| 82 | put fabMode slot mode |
| 83 | put fabVer slot add get fabVer slot 1 |
| 84 | if eq mode FAB_MODE_NEURAL |
| 85 | put fabCostNs slot 15000000 |
| 86 | else |
| 87 | if eq mode FAB_MODE_CRYSTALLIZED |
| 88 | put fabCostNs slot 500 |
| 89 | else |
| 90 | put fabCostNs slot 20000 |
| 91 | end |
| 92 | end |
| 93 | ret true |
| 94 | end |
| 95 | |
| 96 | fn fabMatchHist i ulong semId ulong M ulong K ulong N ulong to bool |
| 97 | if ne get fabHUsed i 1 |
| 98 | ret false |
| 99 | end |
| 100 | if ne get fabHSem i semId |
| 101 | ret false |
| 102 | end |
| 103 | if ne get fabHM i M |
| 104 | ret false |
| 105 | end |
| 106 | if ne get fabHK i K |
| 107 | ret false |
| 108 | end |
| 109 | ret eq get fabHN i N |
| 110 | end |
| 111 | |
| 112 | note Record a live (semId, M, K, N) observation from Arboris traces |
| 113 | fn fabObserveShape semId ulong M ulong K ulong N ulong to ulong |
| 114 | for i ulong FAB_HIST_CAP |
| 115 | if fabMatchHist i semId M K N |
| 116 | h = add get fabHHits i 1 |
| 117 | put fabHHits i h |
| 118 | ret h |
| 119 | end |
| 120 | end |
| 121 | for j ulong FAB_HIST_CAP |
| 122 | if eq get fabHUsed j 0 |
| 123 | put fabHUsed j 1 |
| 124 | put fabHSem j semId |
| 125 | put fabHM j M |
| 126 | put fabHK j K |
| 127 | put fabHN j N |
| 128 | put fabHHits j 1 |
| 129 | put fabHSpec j 0 |
| 130 | ret 1 |
| 131 | end |
| 132 | end |
| 133 | ret 0 |
| 134 | end |
| 135 | |
| 136 | note A725 background metabolic tick: specializes any hot shape (hits >= 4) and hot-swaps fabWtbl[wtblSlot]! |
| 137 | fn fabMetabolicTick wtblSlot ulong targetTid ulong to ulong |
| 138 | swaps = ulong 0 |
| 139 | for i ulong FAB_HIST_CAP |
| 140 | if and eq get fabHUsed i 1 eq get fabHSpec i 0 |
| 141 | if ge get fabHHits i 4 |
| 142 | sem = get fabHSem i |
| 143 | rc = peSpecializeW4Gemm sem targetTid get fabHM i get fabHK i get fabHN i |
| 144 | if eq rc TDK_OK |
| 145 | cslot = get peOut 4 |
| 146 | ptr = get rcPtr cslot |
| 147 | if fabHotSwap wtblSlot sem ptr targetTid FAB_MODE_GPU_NATIVE 7 |
| 148 | put fabHSpec i 1 |
| 149 | swaps = add swaps 1 |
| 150 | end |
| 151 | end |
| 152 | end |
| 153 | end |
| 154 | end |
| 155 | ret swaps |
| 156 | end |