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 / gpu / rx / skillroute.om

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