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 / forge / provider.om

453 lines · 11689 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/forge/provider.om: Request-bound FORGE provider registry & admission engine.
3note Matches declared computational contracts to eligible hardware providers.
4note Enforces honest qualification discipline (BLOCKED_HARDWARE / NOT_RUN never
5note promoted to QUALIFIED), strict substrate binding (no silent fallback to an
6note unrequested backend), FORGE V2 calibration freshness & envelope checks,
7note error-kind dominance, and eligible-set digital fallback admission.
8note Composable OM-2 library module (compose after hardware.om and envelope.om).
9
10note ---- Provider Qualification Statuses ----
11const FG_QUAL_QUALIFIED uint 1
12const FG_QUAL_EXERCISED uint 2
13const FG_QUAL_SIMULATED uint 3
14const FG_QUAL_BLOCKED_HW uint 4
15const FG_QUAL_NOT_RUN uint 5
16const FG_QUAL_FAULTED uint 6
17
18note ---- FORGE V2 Acceptable Error Kinds ----
19const FG_ERRK_EXACT uint 1
20const FG_ERRK_BOUNDED_DET uint 2
21const FG_ERRK_BOUNDED_STOCH uint 3
22const FG_ERRK_MEASURED_DIST uint 4
23
24note ---- FORGE V2 Fault States ----
25const FG_FAULT_NONE uint 0
26const FG_FAULT_TRANSIENT uint 1
27const FG_FAULT_PERSISTENT uint 2
28const FG_FAULT_UNAVAILABLE uint 3
29
30note ---- FORGE Lowering Kinds (forge_types.h) ----
31const FG_LOW_NONE uint 0
32const FG_LOW_SIMULATED uint 1
33const FG_LOW_COMPILED uint 2
34
35note ---- Admission Decision Status Codes ----
36const FG_ADMIT_OK uint 0
37const FG_ADMIT_BLOCKED_HARDWARE uint 1
38const FG_ADMIT_NOT_RUN uint 2
39const FG_ADMIT_NO_PROVIDER uint 3
40const FG_ADMIT_ENVELOPE_VIOL uint 4
41const FG_ADMIT_CAL_STALE uint 5
42const FG_ADMIT_CAL_ENVELOPE uint 6
43const FG_ADMIT_FAULTED uint 7
44const FG_ADMIT_ERROR_KIND uint 8
45const FG_ADMIT_NO_DIGITAL_FB uint 9
46const FG_ADMIT_QUEUE_FULL uint 10
47
48const FG_MAX_PROVIDERS uint 16
49
50note ---- Provider Registry Storage (globals accessed directly inside module) ----
51global fg_reg_cnt uint 1
52global fg_reg_pid uint 16
53global fg_reg_hwid uint 16
54global fg_reg_sub uint 16
55global fg_reg_qual uint 16
56global fg_reg_errk uint 16
57global fg_reg_creq uint 16
58global fg_reg_cepoch ulong 16
59global fg_reg_cwin ulong 16
60global fg_reg_ctmin int 16
61global fg_reg_ctmax int 16
62global fg_reg_fault uint 16
63global fg_reg_qact uint 16
64global fg_reg_low uint 16
65
66fn fg_reg_clear to void
67put fg_reg_cnt 0 uint 0
68for i ulong 16
69put fg_reg_pid i uint 0
70put fg_reg_hwid i uint 0
71put fg_reg_sub i uint 0
72put fg_reg_qual i uint 0
73put fg_reg_errk i uint 0
74put fg_reg_creq i uint 0
75put fg_reg_cepoch i ulong 0
76put fg_reg_cwin i ulong 0
77put fg_reg_ctmin i int 0
78put fg_reg_ctmax i int 0
79put fg_reg_fault i uint 0
80put fg_reg_qact i uint 0
81put fg_reg_low i uint 0
82end
83ret
84end
85
86fn fg_reg_count to uint
87ret get fg_reg_cnt 0
88end
89
90fn fg_reg_add p view ForgeProvider to bool
91n = get fg_reg_cnt 0
92if ge n FG_MAX_PROVIDERS
93ret false
94end
95idx = ulong n
96put fg_reg_pid idx get p prov_id
97put fg_reg_hwid idx get p hw_id
98put fg_reg_sub idx get p substrate_class
99put fg_reg_qual idx get p qual_status
100put fg_reg_errk idx get p error_kind
101put fg_reg_creq idx get p cal_req
102put fg_reg_cepoch idx get p cal_epoch_s
103put fg_reg_cwin idx get p cal_window_s
104put fg_reg_ctmin idx get p cal_tmin_mc
105put fg_reg_ctmax idx get p cal_tmax_mc
106put fg_reg_fault idx get p fault_state
107put fg_reg_qact idx get p active_queues
108put fg_reg_low idx get p lowering_kind
109put fg_reg_cnt 0 add n 1
110ret true
111end
112
113fn fg_reg_get idx uint dst edit ForgeProvider to bool
114n = get fg_reg_cnt 0
115if ge idx n
116ret false
117end
118k = ulong idx
119put dst prov_id get fg_reg_pid k
120put dst hw_id get fg_reg_hwid k
121put dst substrate_class get fg_reg_sub k
122put dst qual_status get fg_reg_qual k
123put dst error_kind get fg_reg_errk k
124put dst cal_req get fg_reg_creq k
125put dst cal_epoch_s get fg_reg_cepoch k
126put dst cal_window_s get fg_reg_cwin k
127put dst cal_tmin_mc get fg_reg_ctmin k
128put dst cal_tmax_mc get fg_reg_ctmax k
129put dst fault_state get fg_reg_fault k
130put dst active_queues get fg_reg_qact k
131put dst lowering_kind get fg_reg_low k
132ret true
133end
134
135fn fg_reg_find_by_id pid uint dst edit ForgeProvider to bool
136n = get fg_reg_cnt 0
137i = uint 0
138while lt i n bound 16
139if eq get fg_reg_pid ulong i pid
140ret fg_reg_get i dst
141end
142i = add i 1
143end
144ret false
145end
146
147fn fg_reg_set_fault idx uint fstate uint to bool
148if ge idx get fg_reg_cnt 0
149ret false
150end
151put fg_reg_fault ulong idx fstate
152ret true
153end
154
155fn fg_reg_set_queues idx uint qact uint to bool
156if ge idx get fg_reg_cnt 0
157ret false
158end
159put fg_reg_qact ulong idx qact
160ret true
161end
162
163note Populate standard FORGE providers (GB10, Grace CPU, Generic CPU, Analog Sim, Unqual GPU, Optical)
164fn fg_reg_load_defaults to void
165fg_reg_clear
166p = new ForgeProvider 1 FG_HW_GB10_SM121 FG_SUB_DIGITAL_GPU FG_QUAL_QUALIFIED FG_ERRK_EXACT 0 0 0 0 0 FG_FAULT_NONE 0 FG_LOW_COMPILED
167ok = fg_reg_add p
168put p prov_id uint 2
169put p hw_id FG_HW_AARCH64_GRACE
170put p substrate_class FG_SUB_DIGITAL_CPU
171put p qual_status FG_QUAL_QUALIFIED
172put p error_kind FG_ERRK_EXACT
173put p cal_req uint 0
174put p lowering_kind FG_LOW_COMPILED
175ok = and ok fg_reg_add p
176put p prov_id uint 3
177put p hw_id FG_HW_GENERIC_CPU
178put p substrate_class FG_SUB_DIGITAL_CPU
179put p qual_status FG_QUAL_EXERCISED
180put p error_kind FG_ERRK_EXACT
181put p cal_req uint 0
182put p lowering_kind FG_LOW_COMPILED
183ok = and ok fg_reg_add p
184put p prov_id uint 4
185put p hw_id FG_HW_ANALOG_SIM
186put p substrate_class FG_SUB_ANALOG_IN_MEMORY
187put p qual_status FG_QUAL_SIMULATED
188put p error_kind FG_ERRK_BOUNDED_DET
189put p cal_req uint 1
190put p cal_epoch_s ulong 1000
191put p cal_window_s ulong 3600
192put p cal_tmin_mc int 15000
193put p cal_tmax_mc int 65000
194put p lowering_kind FG_LOW_SIMULATED
195ok = and ok fg_reg_add p
196put p prov_id uint 5
197put p hw_id FG_HW_UNQUAL_GPU
198put p substrate_class FG_SUB_DIGITAL_GPU
199put p qual_status FG_QUAL_BLOCKED_HW
200put p error_kind FG_ERRK_EXACT
201put p cal_req uint 0
202put p cal_epoch_s ulong 0
203put p cal_window_s ulong 0
204put p cal_tmin_mc int 0
205put p cal_tmax_mc int 0
206put p lowering_kind FG_LOW_NONE
207ok = and ok fg_reg_add p
208put p prov_id uint 6
209put p hw_id FG_HW_OPTICAL_SIM
210put p substrate_class FG_SUB_OPTICAL_PHOTONIC
211put p qual_status FG_QUAL_NOT_RUN
212put p error_kind FG_ERRK_BOUNDED_STOCH
213put p cal_req uint 1
214put p cal_epoch_s ulong 1000
215put p cal_window_s ulong 600
216put p cal_tmin_mc int 20000
217put p cal_tmax_mc int 40000
218put p lowering_kind FG_LOW_NONE
219ok = and ok fg_reg_add p
220if not ok
221trap 8
222end
223ret
224end
225
226note ---- Calibration & Single-Provider Eligibility Checks (FORGE V2) ----
227
228fn fg_prov_check_cal p view ForgeProvider bud view ForgeBudget to uint
229if eq get p cal_req 0
230ret FG_ADMIT_OK
231end
232now_s = get bud now_epoch_s
233ep = get p cal_epoch_s
234win = get p cal_window_s
235if eq win 0
236ret FG_ADMIT_CAL_STALE
237end
238if lt now_s ep
239ret FG_ADMIT_CAL_STALE
240end
241if ge sub now_s ep win
242ret FG_ADMIT_CAL_STALE
243end
244tmc = get bud temp_mc
245if lt tmc get p cal_tmin_mc
246ret FG_ADMIT_CAL_ENVELOPE
247end
248if gt tmc get p cal_tmax_mc
249ret FG_ADMIT_CAL_ENVELOPE
250end
251ret FG_ADMIT_OK
252end
253
254fn fg_prov_eval_one p view ForgeProvider req view ForgeContract bud view ForgeBudget env edit ForgeEnvCheck to uint
255fg_env_reset env
256if ne get p fault_state FG_FAULT_NONE
257ret FG_ADMIT_FAULTED
258end
259qs = get p qual_status
260if eq qs FG_QUAL_FAULTED
261ret FG_ADMIT_FAULTED
262end
263if eq qs FG_QUAL_BLOCKED_HW
264ret FG_ADMIT_BLOCKED_HARDWARE
265end
266if eq qs FG_QUAL_NOT_RUN
267ret FG_ADMIT_NOT_RUN
268end
269if eq get req req_qual 1
270if ne qs FG_QUAL_QUALIFIED
271ret FG_ADMIT_BLOCKED_HARDWARE
272end
273end
274rk = get req error_kind
275if eq rk 0
276rk = FG_ERRK_EXACT
277end
278if gt get p error_kind rk
279ret FG_ADMIT_ERROR_KIND
280end
281crc = fg_prov_check_cal p bud
282if ne crc FG_ADMIT_OK
283ret crc
284end
285hid = new ForgeHwId 0 0 0 0 0 0 0 0 0 0 0 0
286hcap = new ForgeHwCap 0 0 0 0 0.0f64 0.0f64 0 0 0 0.0f64 0 0
287if not fg_hw_load_profile get p hw_id hid hcap
288ret FG_ADMIT_NO_PROVIDER
289end
290if ge get p active_queues get hcap max_queues
291ret FG_ADMIT_QUEUE_FULL
292end
293erc = fg_env_check hid hcap req bud env
294if ne erc FG_ENV_OK
295ret FG_ADMIT_ENVELOPE_VIOL
296end
297ret FG_ADMIT_OK
298end
299
300fn fg_env_copy dst edit ForgeEnvCheck src view ForgeEnvCheck to void
301put dst ok get src ok
302put dst violation get src violation
303put dst ws_bytes get src ws_bytes
304put dst traffic_bytes get src traffic_bytes
305put dst flops get src flops
306put dst eff_ctas get src eff_ctas
307put dst eff_thr get src eff_thr
308put dst waves get src waves
309put dst arith_int get src arith_int
310put dst comp_us get src comp_us
311put dst bw_us get src bw_us
312put dst roof_us get src roof_us
313put dst est_power_w get src est_power_w
314put dst est_energy_mj get src est_energy_mj
315put dst compute_bound get src compute_bound
316ret
317end
318
319note Refusal priority: prefer specific envelope/cal/error/qual reasons over generic NO_PROVIDER
320fn fg_refuse_prio code uint to uint
321if eq code FG_ADMIT_ENVELOPE_VIOL
322ret uint 10
323end
324if eq code FG_ADMIT_CAL_STALE
325ret uint 9
326end
327if eq code FG_ADMIT_CAL_ENVELOPE
328ret uint 9
329end
330if eq code FG_ADMIT_ERROR_KIND
331ret uint 8
332end
333if eq code FG_ADMIT_QUEUE_FULL
334ret uint 7
335end
336if eq code FG_ADMIT_BLOCKED_HARDWARE
337ret uint 6
338end
339if eq code FG_ADMIT_NOT_RUN
340ret uint 5
341end
342if eq code FG_ADMIT_FAULTED
343ret uint 4
344end
345ret uint 1
346end
347
348note Check whether any registered digital provider can satisfy the contract (FORGE V2 ยง10)
349fn fg_has_digital_fallback req view ForgeContract bud view ForgeBudget to uint
350n = get fg_reg_cnt 0
351p = new ForgeProvider 0 0 0 0 0 0 0 0 0 0 0 0 0
352tmp_env = new ForgeEnvCheck 0 0 0 0 0 0 0 0 0.0f64 0.0f64 0.0f64 0.0f64 0.0f64 0.0f64 0
353i = uint 0
354while lt i n bound 16
355if fg_reg_get i p
356if fg_sub_is_digital get p substrate_class
357rc = fg_prov_eval_one p req bud tmp_env
358if eq rc FG_ADMIT_OK
359ret uint 1
360end
361end
362end
363i = add i 1
364end
365ret uint 0
366end
367
368fn fg_admit_reset adm edit ForgeAdmit to void
369put adm admitted uint 0
370put adm status FG_ADMIT_NO_PROVIDER
371put adm prov_id uint 0
372put adm hw_id uint 0
373put adm env_viol FG_ENV_OK
374put adm has_dig_fb uint 0
375put adm elig_cnt uint 0
376ret
377end
378
379fn fg_prov_better cur view ForgeEnvCheck best view ForgeEnvCheck pid uint best_pid uint ec uint to bool
380if eq ec 0
381ret true
382end
383if lt get cur roof_us get best roof_us
384ret true
385end
386if eq get cur roof_us get best roof_us
387if lt pid best_pid
388ret true
389end
390end
391ret false
392end
393
394fn fg_prov_try_one idx uint req view ForgeContract bud view ForgeBudget adm edit ForgeAdmit best_env edit ForgeEnvCheck to void
395p = new ForgeProvider 0 0 0 0 0 0 0 0 0 0 0 0 0
396if not fg_reg_get idx p
397ret
398end
399if ne get req req_substrate 0
400if ne get p substrate_class get req req_substrate
401ret
402end
403end
404cur_env = new ForgeEnvCheck 0 0 0 0 0 0 0 0 0.0f64 0.0f64 0.0f64 0.0f64 0.0f64 0.0f64 0
405rc = fg_prov_eval_one p req bud cur_env
406if eq rc FG_ADMIT_OK
407ec = get adm elig_cnt
408if fg_prov_better cur_env best_env get p prov_id get adm prov_id ec
409put adm prov_id get p prov_id
410put adm hw_id get p hw_id
411fg_env_copy best_env cur_env
412end
413put adm elig_cnt add ec 1
414else
415if gt fg_refuse_prio rc fg_refuse_prio get adm status
416put adm status rc
417put adm env_viol get cur_env violation
418end
419end
420ret
421end
422
423note Request-bound provider admission engine (deterministic minimum-roofline selection)
424fn fg_prov_admit req view ForgeContract bud view ForgeBudget adm edit ForgeAdmit best_env edit ForgeEnvCheck to uint
425fg_admit_reset adm
426fg_env_reset best_env
427i = uint 0
428while lt i get fg_reg_cnt 0 bound 16
429fg_prov_try_one i req bud adm best_env
430i = add i 1
431end
432dig_fb = fg_has_digital_fallback req bud
433put adm has_dig_fb dig_fb
434if eq get adm elig_cnt 0
435put adm admitted uint 0
436ret get adm status
437end
438win = new ForgeProvider 0 0 0 0 0 0 0 0 0 0 0 0 0
439if fg_reg_find_by_id get adm prov_id win
440if not fg_sub_is_digital get win substrate_class
441if eq dig_fb 0
442put adm admitted uint 0
443put adm status FG_ADMIT_NO_DIGITAL_FB
444put adm env_viol FG_ENV_OK
445ret FG_ADMIT_NO_DIGITAL_FB
446end
447end
448end
449put adm admitted uint 1
450put adm status FG_ADMIT_OK
451put adm env_viol FG_ENV_OK
452ret FG_ADMIT_OK
453end