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 / main.om

464 lines · 8851 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/forge/main.om: FORGE CLI entrypoint.
3note Reads realization requests on stdin (KAT, PROFILES, PLAN, REQ) and emits
4note deterministic plans, physical envelope refusals, and canonical receipts on stdout.
5note Compose as: si/directives/om2.om hardware.om envelope.om provider.om realize.om main.om
6
7text fg_m_kat_pass "FORGE_KAT PASS 10d63d05f888eaba4fe473c5f17febe22f462f543ae0c2b005a9a8e5417e09fd\n"
8text fg_m_kat_fail "FORGE_KAT FAIL\n"
9text fg_m_bad "FORGE_ERROR malformed_request\n"
10text fg_m_prov_hdr "PROVIDER id="
11text fg_m_cmd_kat "KAT"
12text fg_m_cmd_prof "PROFILES"
13text fg_m_cmd_plan "PLAN"
14text fg_m_cmd_req "REQ"
15text fg_m_sub_any "ANY"
16
17fn fg_is_space c uchar to bool
18if eq c 32
19ret true
20end
21if eq c 9
22ret true
23end
24if eq c 13
25ret true
26end
27ret false
28end
29
30fn fg_tok_eq tok view uchar 64 tlen ulong lit view uchar * to bool
31if ne tlen len lit
32ret false
33end
34i = ulong 0
35while lt i tlen bound 64
36if ne get tok i get lit i
37ret false
38end
39i = add i 1
40end
41ret true
42end
43
44fn fg_next_tok line view uchar * cur edit ulong 1 tok edit uchar 64 to ulong
45n = len line
46p = get cur 0
47while lt p n bound 16384
48if not fg_is_space get line p
49break
50end
51p = add p 1
52end
53tlen = ulong 0
54while lt p n bound 16384
55c = get line p
56if fg_is_space c
57break
58end
59if lt tlen 64
60put tok tlen c
61tlen = add tlen 1
62end
63p = add p 1
64end
65put cur 0 p
66ret tlen
67end
68
69fn fg_parse_u64 tok view uchar 64 tlen ulong ok edit uint 1 to ulong
70if eq tlen 0
71put ok 0 uint 0
72ret ulong 0
73end
74v = ulong 0
75i = ulong 0
76while lt i tlen bound 64
77c = get tok i
78if lt c 48
79put ok 0 uint 0
80ret ulong 0
81end
82if gt c 57
83put ok 0 uint 0
84ret ulong 0
85end
86d = ulong sub c 48
87if gt v div sub FG_U64_MAX d 10
88put ok 0 uint 0
89ret ulong 0
90end
91v = add mul v 10 d
92i = add i 1
93end
94put ok 0 uint 1
95ret v
96end
97
98fn fg_parse_op tok view uchar 64 tlen ulong to uint
99if fg_tok_eq tok tlen fg_t_op_mv
100ret FG_OP_MATVEC
101end
102if fg_tok_eq tok tlen fg_t_op_mm
103ret FG_OP_MATMUL
104end
105if fg_tok_eq tok tlen fg_t_op_cv
106ret FG_OP_CONV
107end
108if fg_tok_eq tok tlen fg_t_op_ew
109ret FG_OP_ELEMENTWISE
110end
111if fg_tok_eq tok tlen fg_t_op_rd
112ret FG_OP_REDUCTION
113end
114if fg_tok_eq tok tlen fg_t_op_sp
115ret FG_OP_SPIKE_INT
116end
117if fg_tok_eq tok tlen fg_t_op_tr
118ret FG_OP_TRANSFORM
119end
120if fg_tok_eq tok tlen fg_t_op_sm
121ret FG_OP_SAMPLE
122end
123if fg_tok_eq tok tlen fg_t_op_gn
124ret FG_OP_GENERAL
125end
126ret uint 0
127end
128
129fn fg_parse_dt tok view uchar 64 tlen ulong to uint
130if fg_tok_eq tok tlen fg_t_dt_f32
131ret FG_DT_FP32
132end
133if fg_tok_eq tok tlen fg_t_dt_f16
134ret FG_DT_FP16
135end
136if fg_tok_eq tok tlen fg_t_dt_bf16
137ret FG_DT_BF16
138end
139if fg_tok_eq tok tlen fg_t_dt_f8
140ret FG_DT_FP8
141end
142if fg_tok_eq tok tlen fg_t_dt_i8
143ret FG_DT_INT8
144end
145if fg_tok_eq tok tlen fg_t_dt_i32
146ret FG_DT_INT32
147end
148if fg_tok_eq tok tlen fg_t_dt_u64
149ret FG_DT_U64
150end
151if fg_tok_eq tok tlen fg_t_dt_f64
152ret FG_DT_FP64
153end
154ret uint 0
155end
156
157fn fg_parse_sub tok view uchar 64 tlen ulong ok edit uint 1 to uint
158put ok 0 uint 1
159if fg_tok_eq tok tlen fg_m_sub_any
160ret uint 0
161end
162if fg_tok_eq tok tlen fg_t_sub_cpu
163ret FG_SUB_DIGITAL_CPU
164end
165if fg_tok_eq tok tlen fg_t_sub_gpu
166ret FG_SUB_DIGITAL_GPU
167end
168if fg_tok_eq tok tlen fg_t_sub_ana
169ret FG_SUB_ANALOG_IN_MEMORY
170end
171if fg_tok_eq tok tlen fg_t_sub_neu
172ret FG_SUB_NEUROMORPHIC
173end
174if fg_tok_eq tok tlen fg_t_sub_fpg
175ret FG_SUB_FPGA_CGRA
176end
177if fg_tok_eq tok tlen fg_t_sub_opt
178ret FG_SUB_OPTICAL_PHOTONIC
179end
180put ok 0 uint 0
181ret uint 0
182end
183
184fn fg_cli_profiles to void
185p = new ForgeProvider 0 0 0 0 0 0 0 0 0 0 0 0 0
186n = fg_reg_count
187i = uint 0
188while lt i n bound 16
189if fg_reg_get i p
190fg_write_all 1 fg_m_prov_hdr
191fg_write_u64 1 ulong get p prov_id
192fg_write_all 1 fg_t_sp_hw
193fg_emit_hw_name 1 get p hw_id
194fg_write_all 1 fg_t_sp_sub
195fg_emit_sub_name 1 get p substrate_class
196fg_write_all 1 fg_t_sp_qual
197fg_emit_qual_name 1 get p qual_status
198fg_write_all 1 fg_t_sp_low
199fg_emit_low_name 1 get p lowering_kind
200fg_write_all 1 fg_t_nl
201end
202i = add i 1
203end
204ret
205end
206
207fn fg_cli_run_plan req view ForgeContract bud view ForgeBudget to void
208plan = new ForgePlan 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
209env = new ForgeEnvCheck 0 0 0 0 0 0 0 0 0.0f64 0.0f64 0.0f64 0.0f64 0.0f64 0.0f64 0
210seals = new ForgeSeals 0 0 0 0
211rc = fg_realize_plan req bud plan env seals
212if ne rc FG_ADMIT_OK
213fg_emit_receipt 1 req plan env seals
214ret
215end
216fg_emit_receipt 1 req plan env seals
217ret
218end
219
220fn fg_cli_parse_plan line view uchar * cur edit ulong 1 seq ulong to bool
221tok = new uchar 64 0
222ok = new uint 1 0
223req = new ForgeContract seq 0 0 0 0 0 1 0 0 0 32 0 FG_ERRK_EXACT 0 1 0
224bud = new ForgeBudget 0.0f64 0.0f64 0.0f64 45000 1200 1000000
225tl = fg_next_tok line cur tok
226op = fg_parse_op tok tl
227if eq op 0
228ret false
229end
230put req op_class op
231tl = fg_next_tok line cur tok
232dt = fg_parse_dt tok tl
233if eq dt 0
234ret false
235end
236put req dtype dt
237tl = fg_next_tok line cur tok
238dm = fg_parse_u64 tok tl ok
239if eq get ok 0 0
240ret false
241end
242put req dim_m dm
243tl = fg_next_tok line cur tok
244dn = fg_parse_u64 tok tl ok
245if eq get ok 0 0
246ret false
247end
248put req dim_n dn
249tl = fg_next_tok line cur tok
250dk = fg_parse_u64 tok tl ok
251if eq get ok 0 0
252ret false
253end
254put req dim_k dk
255fg_cli_run_plan req bud
256ret true
257end
258
259fn fg_cli_read_u32 line view uchar * cur edit ulong 1 ok edit uint 1 to uint
260tok = new uchar 64 0
261tl = fg_next_tok line cur tok
262v = fg_parse_u64 tok tl ok
263if eq get ok 0 0
264ret uint 0
265end
266if gt v ulong 0xffffffff
267put ok 0 uint 0
268ret uint 0
269end
270ret uint v
271end
272
273fn fg_cli_read_u64 line view uchar * cur edit ulong 1 ok edit uint 1 to ulong
274tok = new uchar 64 0
275tl = fg_next_tok line cur tok
276ret fg_parse_u64 tok tl ok
277end
278
279fn fg_cli_parse_req_tail line view uchar * cur edit ulong 1 req edit ForgeContract bud edit ForgeBudget to bool
280ok = new uint 1 0
281tok = new uchar 64 0
282put req cta_req fg_cli_read_u32 line cur ok
283if eq get ok 0 0
284ret false
285end
286put req thr_req fg_cli_read_u32 line cur ok
287if eq get ok 0 0
288ret false
289end
290put req smem_req fg_cli_read_u32 line cur ok
291if eq get ok 0 0
292ret false
293end
294put req gpr_req fg_cli_read_u32 line cur ok
295if eq get ok 0 0
296ret false
297end
298put req extra_ws fg_cli_read_u64 line cur ok
299if eq get ok 0 0
300ret false
301end
302tmc = fg_cli_read_u32 line cur ok
303if eq get ok 0 0
304ret false
305end
306if gt tmc uint 200000
307ret false
308end
309put bud temp_mc int tmc
310lat = fg_cli_read_u64 line cur ok
311if eq get ok 0 0
312ret false
313end
314put bud lat_us f64 lat
315eng = fg_cli_read_u64 line cur ok
316if eq get ok 0 0
317ret false
318end
319put bud energy_mj f64 eng
320pw = fg_cli_read_u64 line cur ok
321if eq get ok 0 0
322ret false
323end
324put bud power_w f64 pw
325tl = fg_next_tok line cur tok
326subc = fg_parse_sub tok tl ok
327if eq get ok 0 0
328ret false
329end
330put req req_substrate subc
331put req req_qual fg_cli_read_u32 line cur ok
332if eq get ok 0 0
333ret false
334end
335put req req_wave_cap fg_cli_read_u32 line cur ok
336if eq get ok 0 0
337ret false
338end
339ret true
340end
341
342fn fg_cli_parse_req line view uchar * cur edit ulong 1 to bool
343tok = new uchar 64 0
344ok = new uint 1 0
345req = new ForgeContract 0 0 0 0 0 0 1 0 0 0 0 0 FG_ERRK_EXACT 0 1 0
346bud = new ForgeBudget 0.0f64 0.0f64 0.0f64 45000 1200 1000000
347put req req_id fg_cli_read_u64 line cur ok
348if eq get ok 0 0
349ret false
350end
351tl = fg_next_tok line cur tok
352op = fg_parse_op tok tl
353if eq op 0
354ret false
355end
356put req op_class op
357tl = fg_next_tok line cur tok
358dt = fg_parse_dt tok tl
359if eq dt 0
360ret false
361end
362put req dtype dt
363put req dim_m fg_cli_read_u64 line cur ok
364if eq get ok 0 0
365ret false
366end
367put req dim_n fg_cli_read_u64 line cur ok
368if eq get ok 0 0
369ret false
370end
371put req dim_k fg_cli_read_u64 line cur ok
372if eq get ok 0 0
373ret false
374end
375put req batch fg_cli_read_u64 line cur ok
376if eq get ok 0 0
377ret false
378end
379if not fg_cli_parse_req_tail line cur req bud
380ret false
381end
382fg_cli_run_plan req bud
383ret true
384end
385
386fn fg_cli_handle_line line view uchar * seq ulong to int
387cur = new ulong 1 0
388tok = new uchar 64 0
389tl = fg_next_tok line cur tok
390if eq tl 0
391ret int 0
392end
393if eq get tok 0 35
394ret int 0
395end
396if fg_tok_eq tok tl fg_m_cmd_kat
397if fg_hw_v1_kat
398fg_write_all 1 fg_m_kat_pass
399ret int 0
400end
401fg_write_all 1 fg_m_kat_fail
402ret int 1
403end
404if fg_tok_eq tok tl fg_m_cmd_prof
405fg_cli_profiles
406ret int 0
407end
408if fg_tok_eq tok tl fg_m_cmd_plan
409if fg_cli_parse_plan line cur seq
410ret int 0
411end
412fg_write_all 1 fg_m_bad
413ret int 2
414end
415if fg_tok_eq tok tl fg_m_cmd_req
416if fg_cli_parse_req line cur
417ret int 0
418end
419fg_write_all 1 fg_m_bad
420ret int 2
421end
422fg_write_all 1 fg_m_bad
423ret int 2
424end
425
426fn main to int
427fg_reg_load_defaults
428inbuf = new uchar 16384 0
429got = ulong 0
430while lt got 16384 bound 16384
431k = read 0 inbuf got sub 16384 got
432if lt k 0
433ret int 3
434end
435if eq k 0
436break
437end
438got = add got ulong k
439end
440pos = ulong 0
441seq = ulong 1
442rc = int 0
443while lt pos got bound 16384
444start = pos
445while lt pos got bound 16384
446if eq get inbuf pos 10
447break
448end
449pos = add pos 1
450end
451llen = sub pos start
452if gt llen 0
453lrc = fg_cli_handle_line part inbuf start llen seq
454if ne lrc 0
455rc = lrc
456end
457seq = add seq 1
458end
459if lt pos got
460pos = add pos 1
461end
462end
463ret rc
464end