Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/gpu/rx/skillroute.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / gpu / rx / skillroute.om` 331 lines ยท 7025 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note gpu/rx/skillroute.om: pure-Omega M20/COMPOSITION-2 Skill Router over Capability Graph 3 note (replaces src/runtime/rx_skillroute.{h,c}). 4 note Admissibility runs before ranking so a cheaper inadmissible provider never hides an admissible one. 5 note Fail-closed route revalidation detects withdrawn, unavailable, stale (gen/ver/digest), or lease-expired routes. 6 note Compose after: si/directives/om2.om gpu/rx/regulate.om 7 8 const SR_MAX_ENTRIES ulong 64 9 const SR_MAX_EXEC ulong 32 10 const SR_MAX_MACHINES ulong 16 11 12 note Capability graph entries (parallel arrays, zero heap) 13 global g_sr_op uint 64 14 global g_sr_sid uint 64 15 global g_sr_ver uint 64 16 global g_sr_dlo ulong 64 17 global g_sr_dhi ulong 64 18 global g_sr_mid uint 64 19 global g_sr_live int 64 20 global g_sr_avail int 64 21 global g_sr_held int 64 22 global g_sr_lat ulong 64 23 global g_sr_cost ulong 64 24 global g_sr_gen ulong 64 25 global g_sr_cnt ulong 4 26 27 note Local executable skill table 28 global g_ex_sid uint 32 29 global g_ex_dlo ulong 32 30 global g_ex_dhi ulong 32 31 32 note Machine table (id, is_self, canonical_known, lease_expiry_us) 33 global g_m_id uint 16 34 global g_m_self int 16 35 global g_m_known int 16 36 global g_m_exp ulong 16 37 38 fn sr_reset to void 39 put g_sr_cnt 0 ulong 0 40 put g_sr_cnt 1 ulong 0 41 put g_sr_cnt 2 ulong 0 42 ret 43 end 44 45 fn sr_add_machine mid uint is_self int known int lease_exp ulong to int 46 n = get g_sr_cnt 2 47 if ge n SR_MAX_MACHINES 48 ret SR_E_ARG 49 end 50 put g_m_id n mid 51 put g_m_self n is_self 52 put g_m_known n known 53 put g_m_exp n lease_exp 54 put g_sr_cnt 2 add n 1 55 ret SR_OK 56 end 57 58 fn sr_find_machine mid uint to int 59 n = get g_sr_cnt 2 60 i = ulong 0 61 while lt i n bound 16 62 if eq get g_m_id i mid 63 ret int i 64 end 65 i = add i 1 66 end 67 ret -1 68 end 69 70 fn sr_add_exec sid uint dlo ulong dhi ulong to int 71 n = get g_sr_cnt 1 72 if ge n SR_MAX_EXEC 73 ret SR_E_ARG 74 end 75 put g_ex_sid n sid 76 put g_ex_dlo n dlo 77 put g_ex_dhi n dhi 78 put g_sr_cnt 1 add n 1 79 ret SR_OK 80 end 81 82 fn sr_find_exec sid uint to int 83 n = get g_sr_cnt 1 84 i = ulong 0 85 while lt i n bound 32 86 if eq get g_ex_sid i sid 87 ret int i 88 end 89 i = add i 1 90 end 91 ret -1 92 end 93 94 fn sr_add_entry op uint sid uint ver uint mid uint lat ulong cost ulong to int 95 n = get g_sr_cnt 0 96 if ge n SR_MAX_ENTRIES 97 ret SR_E_ARG 98 end 99 put g_sr_op n op 100 put g_sr_sid n sid 101 put g_sr_ver n ver 102 put g_sr_dlo n ulong 0 103 put g_sr_dhi n ulong 0 104 put g_sr_mid n mid 105 put g_sr_live n int 1 106 put g_sr_avail n int 1 107 put g_sr_held n int 1 108 put g_sr_lat n lat 109 put g_sr_cost n cost 110 put g_sr_gen n ulong 1 111 put g_sr_cnt 0 add n 1 112 ret int n 113 end 114 115 fn sr_set_entry_digest idx ulong dlo ulong dhi ulong to void 116 put g_sr_dlo idx dlo 117 put g_sr_dhi idx dhi 118 put g_sr_gen idx add get g_sr_gen idx 1 119 ret 120 end 121 122 fn sr_set_entry_flags idx ulong live int avail int held int to void 123 put g_sr_live idx live 124 put g_sr_avail idx avail 125 put g_sr_held idx held 126 put g_sr_gen idx add get g_sr_gen idx 1 127 ret 128 end 129 130 fn sr_check_local_exec idx ulong sid uint to uint 131 ei = sr_find_exec sid 132 if lt ei 0 133 ret SR_WHY_NOT_EXECUTABLE 134 end 135 eu = ulong ei 136 if ne get g_ex_dlo eu get g_sr_dlo idx 137 ret SR_WHY_DIGEST 138 end 139 if ne get g_ex_dhi eu get g_sr_dhi idx 140 ret SR_WHY_DIGEST 141 end 142 ret uint 0 143 end 144 145 note Check admissibility of entry idx against req at now_us. 146 note Returns 0 if admissible, else SR_WHY_* bitmask. 147 fn sr_check_admit idx ulong req view SrReq now_us ulong to uint 148 if eq get g_sr_live idx 0 149 ret SR_WHY_GONE 150 end 151 if eq get g_sr_avail idx 0 152 ret SR_WHY_UNAVAILABLE 153 end 154 if and ne get req req_held 0 eq get g_sr_held idx 0 155 ret SR_WHY_AUTHORITY 156 end 157 sid = get g_sr_sid idx 158 if eq sid 0 159 ret SR_WHY_NOT_SKILL 160 end 161 mi = sr_find_machine get g_sr_mid idx 162 if lt mi 0 163 ret SR_WHY_MACHINE_UNKNOWN 164 end 165 mu = ulong mi 166 if eq get g_m_known mu 0 167 ret SR_WHY_MACHINE_UNKNOWN 168 end 169 if eq get g_m_self mu 0 170 if ge now_us get g_m_exp mu 171 ret SR_WHY_GONE 172 end 173 if ne get req local_only 0 174 ret SR_WHY_REMOTE_REFUSED 175 end 176 else 177 lw = sr_check_local_exec idx sid 178 if ne lw 0 179 ret lw 180 end 181 end 182 if and ne get req pin_ver 0 ne get g_sr_ver idx get req pin_ver 183 ret SR_WHY_PIN 184 end 185 if or ne get req pin_dlo 0 ne get req pin_dhi 0 186 if ne get g_sr_dlo idx get req pin_dlo 187 ret SR_WHY_PIN 188 end 189 if ne get g_sr_dhi idx get req pin_dhi 190 ret SR_WHY_PIN 191 end 192 end 193 if and ne get req pin_mset 0 ne get g_sr_mid idx get req pin_mid 194 ret SR_WHY_MACHINE 195 end 196 ret uint 0 197 end 198 199 note True if candidate a strictly beats candidate b under caller priority + deterministic tie-breaks. 200 fn sr_better a ulong b ulong prio_cost int to bool 201 if ne prio_cost 0 202 if ne get g_sr_cost a get g_sr_cost b 203 ret lt get g_sr_cost a get g_sr_cost b 204 end 205 if ne get g_sr_lat a get g_sr_lat b 206 ret lt get g_sr_lat a get g_sr_lat b 207 end 208 else 209 if ne get g_sr_lat a get g_sr_lat b 210 ret lt get g_sr_lat a get g_sr_lat b 211 end 212 if ne get g_sr_cost a get g_sr_cost b 213 ret lt get g_sr_cost a get g_sr_cost b 214 end 215 end 216 if ne get g_sr_sid a get g_sr_sid b 217 ret lt get g_sr_sid a get g_sr_sid b 218 end 219 ret lt get g_sr_ver a get g_sr_ver b 220 end 221 222 fn sr_route req view SrReq now_us ulong dst edit SrRoute to int 223 put dst verdict SR_E_NO_CANDIDATE 224 put dst entry_idx -1 225 put dst skill_id uint 0 226 put dst ver uint 0 227 put dst machine_id uint 0 228 put dst remote int 0 229 put dst gen ulong 0 230 put dst why uint 0 231 put dst n_adm uint 0 232 if ne get req pin_mset 0 233 pm = sr_find_machine get req pin_mid 234 if lt pm 0 235 put dst verdict SR_E_MACHINE 236 ret SR_E_MACHINE 237 end 238 pmu = ulong pm 239 if eq get g_m_known pmu 0 240 put dst verdict SR_E_MACHINE 241 ret SR_E_MACHINE 242 end 243 if and eq get g_m_self pmu 0 ge now_us get g_m_exp pmu 244 put dst verdict SR_E_MACHINE 245 ret SR_E_MACHINE 246 end 247 end 248 n = get g_sr_cnt 0 249 best = int -1 250 why_acc = uint 0 251 adm = uint 0 252 i = ulong 0 253 while lt i n bound 64 254 if eq get g_sr_op i get req op 255 w = sr_check_admit i req now_us 256 if ne w 0 257 why_acc = or why_acc w 258 else 259 adm = add adm 1 260 if lt best 0 261 best = int i 262 else 263 if sr_better i ulong best get req prio_cost 264 best = int i 265 end 266 end 267 end 268 end 269 i = add i 1 270 end 271 put dst why why_acc 272 put dst n_adm adm 273 if lt best 0 274 put dst verdict SR_E_NO_CANDIDATE 275 ret SR_E_NO_CANDIDATE 276 end 277 bu = ulong best 278 put dst entry_idx best 279 put dst skill_id get g_sr_sid bu 280 put dst ver get g_sr_ver bu 281 put dst machine_id get g_sr_mid bu 282 put dst gen get g_sr_gen bu 283 mi = ulong sr_find_machine get g_sr_mid bu 284 if eq get g_m_self mi 0 285 put dst remote int 1 286 put dst verdict SR_E_REMOTE 287 ret SR_E_REMOTE 288 end 289 put dst remote int 0 290 put dst verdict SR_OK 291 ret SR_OK 292 end 293 294 note COMPOSITION-2: revalidate a held route against the current graph and local executable table. 295 fn sr_route_check rt view SrRoute now_us ulong to int 296 idx_i = get rt entry_idx 297 if or lt idx_i 0 ge ulong idx_i get g_sr_cnt 0 298 ret SR_E_WITHDRAWN 299 end 300 idx = ulong idx_i 301 if eq get g_sr_live idx 0 302 ret SR_E_WITHDRAWN 303 end 304 if eq get g_sr_avail idx 0 305 ret SR_E_UNAVAILABLE 306 end 307 if or ne get g_sr_gen idx get rt gen ne get g_sr_ver idx get rt ver 308 ret SR_E_STALE 309 end 310 if ne get g_sr_sid idx get rt skill_id 311 ret SR_E_STALE 312 end 313 mi = sr_find_machine get g_sr_mid idx 314 if lt mi 0 315 ret SR_E_MACHINE 316 end 317 mu = ulong mi 318 if eq get g_m_known mu 0 319 ret SR_E_MACHINE 320 end 321 if eq get g_m_self mu 0 322 if ge now_us get g_m_exp mu 323 ret SR_E_MACHINE 324 end 325 ret SR_OK 326 end 327 if ne sr_check_local_exec idx get g_sr_sid idx 0 328 ret SR_E_STALE 329 end 330 ret SR_OK 331 end