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

880 lines · 19669 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note gpu/forge/realize.om: Deterministic FORGE realization planner, AEGIS
3note integrity token sealing/verification, and canonical receipt emitter.
4note Ported from physics-mv (forge/forge_realize.{h,c}, forge/v2/forge_substrate_v2.c).
5note Composable OM-2 library module (compose after hardware.om, envelope.om, provider.om).
6
7note ---- Canonical Output Text Labels ----
8text fg_t_rcpt_hdr "FORGE_RECEIPT_V1\n"
9text fg_t_rcpt_end "FORGE_RECEIPT_END\n"
10text fg_t_dec_adm "decision=ADMITTED\n"
11text fg_t_dec_ref "decision=REFUSED\n"
12text fg_t_status "status="
13text fg_t_viol "violation="
14text fg_t_req_id "req_id="
15text fg_t_sp_op " op="
16text fg_t_sp_dt " dtype="
17text fg_t_sp_sh " shape="
18text fg_t_x "x"
19text fg_t_nl "\n"
20text fg_t_dot "."
21text fg_t_prov "provider="
22text fg_t_sp_hw " hw="
23text fg_t_sp_sub " substrate="
24text fg_t_sp_qual " qual="
25text fg_t_sp_low " lowering="
26text fg_t_geom "geometry tile="
27text fg_t_sp_grid " grid="
28text fg_t_sp_blk " block="
29text fg_t_sp_ctas " ctas="
30text fg_t_sp_wav " waves="
31text fg_t_phys "physics ws_bytes="
32text fg_t_sp_tr " traffic_bytes="
33text fg_t_sp_fl " flops="
34text fg_t_sp_bnd " bound="
35text fg_t_comp "COMPUTE\n"
36text fg_t_bw "BANDWIDTH\n"
37text fg_t_roof "roofline time_us="
38text fg_t_sp_ai " ai_flops_per_byte="
39text fg_t_sp_pw " power_w="
40text fg_t_sp_en " energy_mj="
41text fg_t_reqd "req_digest="
42text fg_t_descd "desc_digest="
43text fg_t_planid "plan_id="
44text fg_t_seal "aegis_seal="
45
46text fg_t_s_ok "OK"
47text fg_t_s_bhw "BLOCKED_HARDWARE"
48text fg_t_s_nr "NOT_RUN"
49text fg_t_s_np "NO_MATCHING_PROVIDER"
50text fg_t_s_env "ENVELOPE_VIOLATION"
51text fg_t_s_cst "CAL_STALE"
52text fg_t_s_cen "CAL_OUT_OF_ENVELOPE"
53text fg_t_s_flt "PROVIDER_FAULTED"
54text fg_t_s_erk "ERROR_KIND_TOO_LOOSE"
55text fg_t_s_ndf "NO_DIGITAL_FALLBACK"
56text fg_t_s_qfl "QUEUE_EXHAUSTED"
57text fg_t_s_unk "UNKNOWN"
58
59text fg_t_v_none "NONE"
60text fg_t_v_ihw "INVALID_HW_DESC"
61text fg_t_v_idim "INVALID_DIMS"
62text fg_t_v_uop "UNSUPPORTED_OP"
63text fg_t_v_udt "UNSUPPORTED_DTYPE"
64text fg_t_v_oom "OOM_WORKING_SET"
65text fg_t_v_smem "SMEM_EXCEEDED"
66text fg_t_v_gpr "GPR_EXCEEDED"
67text fg_t_v_thr "THREADS_EXCEEDED"
68text fg_t_v_wav "WAVE_SM_CAP_EXCEEDED"
69text fg_t_v_thm "THERMAL_CEILING_EXCEEDED"
70text fg_t_v_pwr "POWER_CEILING_EXCEEDED"
71text fg_t_v_lat "LATENCY_BUDGET_EXCEEDED"
72text fg_t_v_eng "ENERGY_BUDGET_EXCEEDED"
73
74text fg_t_op_mv "MATVEC"
75text fg_t_op_mm "MATMUL"
76text fg_t_op_cv "CONV"
77text fg_t_op_ew "ELEMENTWISE"
78text fg_t_op_rd "REDUCTION"
79text fg_t_op_sp "SPIKE_INTEGRATE"
80text fg_t_op_tr "TRANSFORM"
81text fg_t_op_sm "SAMPLE"
82text fg_t_op_gn "GENERAL"
83
84text fg_t_dt_f32 "FP32"
85text fg_t_dt_f16 "FP16"
86text fg_t_dt_bf16 "BF16"
87text fg_t_dt_f8 "FP8"
88text fg_t_dt_i8 "INT8"
89text fg_t_dt_i32 "INT32"
90text fg_t_dt_u64 "U64"
91text fg_t_dt_f64 "FP64"
92
93text fg_t_hw_gb10 "dgx-spark-gb10-sm_121"
94text fg_t_hw_grace "aarch64-grace-cpu"
95text fg_t_hw_gcpu "generic-aarch64-cpu"
96text fg_t_hw_asim "analog-in-memory-sim"
97text fg_t_hw_ugpu "unqualified-discrete-gpu"
98text fg_t_hw_opt "optical-photonic-sim"
99text fg_t_hw_none "none"
100
101text fg_t_sub_cpu "DIGITAL_CPU"
102text fg_t_sub_gpu "DIGITAL_GPU"
103text fg_t_sub_ana "ANALOG_IN_MEMORY"
104text fg_t_sub_neu "NEUROMORPHIC_SPIKING"
105text fg_t_sub_fpg "FPGA_CGRA_DATAFLOW"
106text fg_t_sub_opt "OPTICAL_PHOTONIC"
107
108text fg_t_q_qual "QUALIFIED"
109text fg_t_q_exer "EXERCISED"
110text fg_t_q_sim "SIMULATED"
111text fg_t_q_bhw "BLOCKED_HARDWARE"
112text fg_t_q_nr "NOT_RUN"
113text fg_t_q_flt "FAULTED"
114
115text fg_t_l_none "NONE"
116text fg_t_l_sim "SIMULATED"
117text fg_t_l_cmp "COMPILED"
118
119note ---- Safe I/O & Formatting Helpers ----
120
121fn fg_write_all fd int buf view uchar * to void
122n = len buf
123off = ulong 0
124while lt off n bound 4096
125k = write fd buf off sub n off
126if le k 0
127ret
128end
129off = add off ulong k
130end
131ret
132end
133
134fn fg_write_u64 fd int v ulong to void
135buf = new uchar 24 0
136if eq v 0
137put buf 0 uchar 48
138fg_write_all fd part buf 0 1
139ret
140end
141tmp = new uchar 24 0
142cnt = ulong 0
143x = v
144while gt x 0 bound 24
145d = rem x 10
146put tmp cnt uchar add d 48
147x = div x 10
148cnt = add cnt 1
149end
150i = ulong 0
151while lt i cnt bound 24
152put buf i get tmp sub sub cnt 1 i
153i = add i 1
154end
155fg_write_all fd part buf 0 cnt
156ret
157end
158
159fn fg_write_f64_3 fd int v f64 to void
160val = v
161if lt val 0.0f64
162val = 0.0f64
163end
164sc = ulong add mul val 1000.0f64 0.5f64
165wh = div sc 1000
166fr = rem sc 1000
167fg_write_u64 fd wh
168fg_write_all fd fg_t_dot
169d = new uchar 3 0
170put d 0 uchar add div fr 100 48
171put d 1 uchar add rem div fr 10 10 48
172put d 2 uchar add rem fr 10 48
173fg_write_all fd d
174ret
175end
176
177fn fg_write_f64_2 fd int v f64 to void
178val = v
179if lt val 0.0f64
180val = 0.0f64
181end
182sc = ulong add mul val 100.0f64 0.5f64
183wh = div sc 100
184fr = rem sc 100
185fg_write_u64 fd wh
186fg_write_all fd fg_t_dot
187d = new uchar 2 0
188put d 0 uchar add div fr 10 48
189put d 1 uchar add rem fr 10 48
190fg_write_all fd d
191ret
192end
193
194fn fg_write_hex32 fd int d view uchar 32 to void
195hex = new uchar 64 0
196fg_digest_to_hex d hex
197fg_write_all fd hex
198ret
199end
200
201note ---- Canonical Request, Plan & AEGIS Seal Digests ----
202
203fn fg_req_digest req view ForgeContract bud view ForgeBudget dst edit uchar 32 to void
204buf = new uchar 128 0
205put buf 0 uchar 70
206put buf 1 uchar 71
207put buf 2 uchar 45
208put buf 3 uchar 82
209put buf 4 uchar 69
210put buf 5 uchar 81
211put buf 6 uchar 45
212put buf 7 uchar 49
213fg_put_u64 buf 8 get req req_id
214fg_put_u32 buf 16 get req op_class
215fg_put_u32 buf 20 get req dtype
216fg_put_u64 buf 24 get req dim_m
217fg_put_u64 buf 32 get req dim_n
218fg_put_u64 buf 40 get req dim_k
219fg_put_u64 buf 48 get req batch
220fg_put_u32 buf 56 get req cta_req
221fg_put_u32 buf 60 get req thr_req
222fg_put_u32 buf 64 get req smem_req
223fg_put_u32 buf 68 get req gpr_req
224fg_put_u64 buf 72 get req extra_ws
225fg_put_u32 buf 80 get req error_kind
226fg_put_u32 buf 84 get req req_substrate
227fg_put_u32 buf 88 get req req_qual
228fg_put_u32 buf 92 get req req_wave_cap
229fg_put_u64 buf 96 ulong mul get bud lat_us 1000.0f64
230fg_put_u64 buf 104 ulong mul get bud energy_mj 1000.0f64
231fg_put_u32 buf 112 uint get bud temp_mc
232fg_put_u32 buf 116 uint ulong mul get bud power_w 1000.0f64
233fg_put_u64 buf 120 get bud now_epoch_s
234fg_sha256 buf dst
235ret
236end
237
238note AEGIS domain-separation token matching physics-mv/forge/forge_realize.c:31-51
239fn fg_aegis_compute_token plan view ForgePlan seals view ForgeSeals dst edit uchar 32 to void
240buf = new uchar 116 0
241put buf 0 uchar 0xae
242put buf 1 uchar 0x91
243put buf 2 uchar 0x50
244put buf 3 uchar 0x24
245put buf 4 uchar 0x76
246put buf 5 uchar 0x65
247put buf 6 uchar 0x72
248put buf 7 uchar 0x69
249put buf 8 uchar 0x66
250put buf 9 uchar 0x69
251put buf 10 uchar 0x65
252put buf 11 uchar 0x64
253put buf 12 uchar 0x63
254put buf 13 uchar 0x6f
255put buf 14 uchar 0x64
256put buf 15 uchar 0x65
257pid = new uchar 32 0
258dh = new uchar 32 0
259rh = new uchar 32 0
260fg_seals_get_plan seals pid
261fg_seals_get_desc seals dh
262fg_seals_get_req seals rh
263fg_copy_bytes buf 16 pid 32
264fg_copy_bytes buf 48 dh 32
265fg_copy_bytes buf 80 rh 32
266fg_put_u32 buf 112 get plan lowering_kind
267fg_sha256 buf dst
268ret
269end
270
271fn fg_aegis_verify_seal plan view ForgePlan seals view ForgeSeals to bool
272if ne get plan admitted 1
273ret false
274end
275if gt get plan lowering_kind FG_LOW_COMPILED
276ret false
277end
278exp = new uchar 32 0
279got = new uchar 32 0
280fg_aegis_compute_token plan seals exp
281fg_seals_get_tok seals got
282ret fg_bytes_eq exp got 32
283end
284
285fn fg_plan_compute_id plan view ForgePlan env view ForgeEnvCheck seals edit ForgeSeals to void
286buf = new uchar 160 0
287put buf 0 uchar 70
288put buf 1 uchar 79
289put buf 2 uchar 82
290put buf 3 uchar 71
291put buf 4 uchar 69
292put buf 5 uchar 45
293put buf 6 uchar 80
294put buf 7 uchar 76
295put buf 8 uchar 65
296put buf 9 uchar 78
297put buf 10 uchar 45
298put buf 11 uchar 86
299put buf 12 uchar 49
300put buf 13 uchar 0
301put buf 14 uchar 0
302put buf 15 uchar 0
303rh = new uchar 32 0
304dh = new uchar 32 0
305fg_seals_get_req seals rh
306fg_seals_get_desc seals dh
307fg_copy_bytes buf 16 rh 32
308fg_copy_bytes buf 48 dh 32
309fg_put_u32 buf 80 get plan admitted
310fg_put_u32 buf 84 get plan status
311fg_put_u32 buf 88 get plan violation
312fg_put_u32 buf 92 get plan prov_id
313fg_put_u32 buf 96 get plan hw_id
314fg_put_u32 buf 100 get plan tile_m
315fg_put_u32 buf 104 get plan tile_n
316fg_put_u32 buf 108 get plan tile_k
317fg_put_u32 buf 112 get plan grid_x
318fg_put_u32 buf 116 get plan grid_y
319fg_put_u32 buf 120 get plan block_x
320fg_put_u32 buf 124 get plan waves
321fg_put_u64 buf 128 get env ws_bytes
322fg_put_u64 buf 136 get env traffic_bytes
323fg_put_u64 buf 144 get env flops
324fg_put_u32 buf 152 get plan lowering_kind
325fg_put_u32 buf 156 get plan qual_status
326pid = new uchar 32 0
327fg_sha256 buf pid
328fg_seals_put_plan seals pid
329ret
330end
331
332note ---- Deterministic Tile & Wave Launch Geometry ----
333
334fn fg_plan_reset plan edit ForgePlan to void
335put plan admitted uint 0
336put plan status FG_ADMIT_NO_PROVIDER
337put plan violation FG_ENV_OK
338put plan prov_id uint 0
339put plan hw_id uint 0
340put plan substrate_class uint 0
341put plan qual_status uint 0
342put plan lowering_kind FG_LOW_NONE
343put plan tile_m uint 0
344put plan tile_n uint 0
345put plan tile_k uint 0
346put plan grid_x uint 0
347put plan grid_y uint 0
348put plan block_x uint 0
349put plan waves uint 0
350put plan compute_bound uint 0
351ret
352end
353
354fn fg_seals_zero seals edit ForgeSeals to void
355z = new uchar 32 0
356fg_seals_put_plan seals z
357fg_seals_put_desc seals z
358fg_seals_put_req seals z
359fg_seals_put_tok seals z
360ret
361end
362
363fn fg_plan_tiles hid view ForgeHwId req view ForgeContract plan edit ForgePlan to void
364sc = get hid substrate_class
365dt = get req dtype
366tm = uint 64
367tn = uint 64
368tk = uint 32
369if eq sc FG_SUB_DIGITAL_GPU
370if or eq dt FG_DT_FP8 eq dt FG_DT_INT8
371tm = uint 128
372tn = uint 128
373tk = uint 64
374else
375if or eq dt FG_DT_FP16 eq dt FG_DT_BF16
376tm = uint 128
377tn = uint 128
378tk = uint 32
379else
380if or eq dt FG_DT_FP32 eq dt FG_DT_INT32
381tm = uint 64
382tn = uint 64
383tk = uint 16
384else
385tm = uint 32
386tn = uint 32
387tk = uint 8
388end
389end
390end
391else
392if eq sc FG_SUB_ANALOG_IN_MEMORY
393tm = uint 64
394tn = uint 64
395tk = uint 64
396end
397end
398put plan tile_m tm
399put plan tile_n tn
400put plan tile_k tk
401ret
402end
403
404fn fg_plan_geometry hid view ForgeHwId req view ForgeContract env view ForgeEnvCheck plan edit ForgePlan to void
405fg_plan_tiles hid req plan
406tm = ulong get plan tile_m
407tn = ulong get plan tile_n
408gx64 = div add get req dim_n sub tn 1 tn
409gy64 = div add get req dim_m sub tm 1 tm
410if eq gx64 0
411gx64 = ulong 1
412end
413if eq gy64 0
414gy64 = ulong 1
415end
416gx = uint 65535
417if lt gx64 65535
418gx = uint gx64
419end
420gy = uint 65535
421if lt gy64 65535
422gy = uint gy64
423end
424sm = get hid sm_count
425if eq get req req_wave_cap 1
426if gt mul ulong gx ulong gy ulong sm
427gx = sm
428gy = uint 1
429end
430end
431put plan grid_x gx
432put plan grid_y gy
433put plan block_x get env eff_thr
434put plan waves get env waves
435put plan compute_bound get env compute_bound
436ret
437end
438
439fn fg_realize_finalize req view ForgeContract adm view ForgeAdmit plan edit ForgePlan env view ForgeEnvCheck seals edit ForgeSeals to void
440win = new ForgeProvider 0 0 0 0 0 0 0 0 0 0 0 0 0
441hid = new ForgeHwId 0 0 0 0 0 0 0 0 0 0 0 0
442hcap = new ForgeHwCap 0 0 0 0 0.0f64 0.0f64 0 0 0 0.0f64 0 0
443dh = new uchar 32 0
444tok = new uchar 32 0
445put plan prov_id get adm prov_id
446put plan hw_id get adm hw_id
447if fg_reg_find_by_id get adm prov_id win
448put plan substrate_class get win substrate_class
449put plan qual_status get win qual_status
450put plan lowering_kind get win lowering_kind
451end
452if fg_hw_load_profile get adm hw_id hid hcap
453fg_hw_digest hid hcap dh
454fg_seals_put_desc seals dh
455fg_plan_geometry hid req env plan
456end
457fg_plan_compute_id plan env seals
458fg_aegis_compute_token plan seals tok
459fg_seals_put_tok seals tok
460ret
461end
462
463note Main deterministic realization planner entry point
464fn fg_realize_plan req view ForgeContract bud view ForgeBudget plan edit ForgePlan env edit ForgeEnvCheck seals edit ForgeSeals to uint
465fg_plan_reset plan
466fg_seals_zero seals
467adm = new ForgeAdmit 0 0 0 0 0 0 0
468rh = new uchar 32 0
469rc = fg_prov_admit req bud adm env
470fg_req_digest req bud rh
471fg_seals_put_req seals rh
472put plan admitted get adm admitted
473put plan status get adm status
474put plan violation get adm env_viol
475if eq get adm admitted 1
476fg_realize_finalize req adm plan env seals
477else
478fg_plan_compute_id plan env seals
479end
480ret rc
481end
482
483note ---- Named Token Printers for Canonical Receipts ----
484
485fn fg_emit_status_name fd int st uint to void
486if eq st FG_ADMIT_OK
487fg_write_all fd fg_t_s_ok
488ret
489end
490if eq st FG_ADMIT_BLOCKED_HARDWARE
491fg_write_all fd fg_t_s_bhw
492ret
493end
494if eq st FG_ADMIT_NOT_RUN
495fg_write_all fd fg_t_s_nr
496ret
497end
498if eq st FG_ADMIT_NO_PROVIDER
499fg_write_all fd fg_t_s_np
500ret
501end
502if eq st FG_ADMIT_ENVELOPE_VIOL
503fg_write_all fd fg_t_s_env
504ret
505end
506if eq st FG_ADMIT_CAL_STALE
507fg_write_all fd fg_t_s_cst
508ret
509end
510if eq st FG_ADMIT_CAL_ENVELOPE
511fg_write_all fd fg_t_s_cen
512ret
513end
514if eq st FG_ADMIT_FAULTED
515fg_write_all fd fg_t_s_flt
516ret
517end
518if eq st FG_ADMIT_ERROR_KIND
519fg_write_all fd fg_t_s_erk
520ret
521end
522if eq st FG_ADMIT_NO_DIGITAL_FB
523fg_write_all fd fg_t_s_ndf
524ret
525end
526if eq st FG_ADMIT_QUEUE_FULL
527fg_write_all fd fg_t_s_qfl
528ret
529end
530fg_write_all fd fg_t_s_unk
531ret
532end
533
534fn fg_emit_viol_name fd int v uint to void
535if eq v FG_ENV_OK
536fg_write_all fd fg_t_v_none
537ret
538end
539if eq v FG_ENV_ERR_INVALID_HW
540fg_write_all fd fg_t_v_ihw
541ret
542end
543if eq v FG_ENV_ERR_INVALID_DIMS
544fg_write_all fd fg_t_v_idim
545ret
546end
547if eq v FG_ENV_ERR_UNSUPPORTED_OP
548fg_write_all fd fg_t_v_uop
549ret
550end
551if eq v FG_ENV_ERR_UNSUPPORTED_DTYPE
552fg_write_all fd fg_t_v_udt
553ret
554end
555if eq v FG_ENV_ERR_OOM_WORKING_SET
556fg_write_all fd fg_t_v_oom
557ret
558end
559if eq v FG_ENV_ERR_SMEM_EXCEEDED
560fg_write_all fd fg_t_v_smem
561ret
562end
563if eq v FG_ENV_ERR_GPR_EXCEEDED
564fg_write_all fd fg_t_v_gpr
565ret
566end
567if eq v FG_ENV_ERR_THREADS_EXCEEDED
568fg_write_all fd fg_t_v_thr
569ret
570end
571if eq v FG_ENV_ERR_WAVE_SM_CAP
572fg_write_all fd fg_t_v_wav
573ret
574end
575if eq v FG_ENV_ERR_THERMAL_CEILING
576fg_write_all fd fg_t_v_thm
577ret
578end
579if eq v FG_ENV_ERR_POWER_CEILING
580fg_write_all fd fg_t_v_pwr
581ret
582end
583if eq v FG_ENV_ERR_LATENCY_BUDGET
584fg_write_all fd fg_t_v_lat
585ret
586end
587if eq v FG_ENV_ERR_ENERGY_BUDGET
588fg_write_all fd fg_t_v_eng
589ret
590end
591fg_write_all fd fg_t_s_unk
592ret
593end
594
595fn fg_emit_op_name fd int op uint to void
596if eq op FG_OP_MATVEC
597fg_write_all fd fg_t_op_mv
598ret
599end
600if eq op FG_OP_MATMUL
601fg_write_all fd fg_t_op_mm
602ret
603end
604if eq op FG_OP_CONV
605fg_write_all fd fg_t_op_cv
606ret
607end
608if eq op FG_OP_ELEMENTWISE
609fg_write_all fd fg_t_op_ew
610ret
611end
612if eq op FG_OP_REDUCTION
613fg_write_all fd fg_t_op_rd
614ret
615end
616if eq op FG_OP_SPIKE_INT
617fg_write_all fd fg_t_op_sp
618ret
619end
620if eq op FG_OP_TRANSFORM
621fg_write_all fd fg_t_op_tr
622ret
623end
624if eq op FG_OP_SAMPLE
625fg_write_all fd fg_t_op_sm
626ret
627end
628if eq op FG_OP_GENERAL
629fg_write_all fd fg_t_op_gn
630ret
631end
632fg_write_all fd fg_t_s_unk
633ret
634end
635
636fn fg_emit_dt_name fd int dt uint to void
637if eq dt FG_DT_FP32
638fg_write_all fd fg_t_dt_f32
639ret
640end
641if eq dt FG_DT_FP16
642fg_write_all fd fg_t_dt_f16
643ret
644end
645if eq dt FG_DT_BF16
646fg_write_all fd fg_t_dt_bf16
647ret
648end
649if eq dt FG_DT_FP8
650fg_write_all fd fg_t_dt_f8
651ret
652end
653if eq dt FG_DT_INT8
654fg_write_all fd fg_t_dt_i8
655ret
656end
657if eq dt FG_DT_INT32
658fg_write_all fd fg_t_dt_i32
659ret
660end
661if eq dt FG_DT_U64
662fg_write_all fd fg_t_dt_u64
663ret
664end
665if eq dt FG_DT_FP64
666fg_write_all fd fg_t_dt_f64
667ret
668end
669fg_write_all fd fg_t_s_unk
670ret
671end
672
673fn fg_emit_hw_name fd int hid uint to void
674if eq hid FG_HW_GB10_SM121
675fg_write_all fd fg_t_hw_gb10
676ret
677end
678if eq hid FG_HW_AARCH64_GRACE
679fg_write_all fd fg_t_hw_grace
680ret
681end
682if eq hid FG_HW_GENERIC_CPU
683fg_write_all fd fg_t_hw_gcpu
684ret
685end
686if eq hid FG_HW_ANALOG_SIM
687fg_write_all fd fg_t_hw_asim
688ret
689end
690if eq hid FG_HW_UNQUAL_GPU
691fg_write_all fd fg_t_hw_ugpu
692ret
693end
694if eq hid FG_HW_OPTICAL_SIM
695fg_write_all fd fg_t_hw_opt
696ret
697end
698fg_write_all fd fg_t_hw_none
699ret
700end
701
702fn fg_emit_sub_name fd int sc uint to void
703if eq sc FG_SUB_DIGITAL_CPU
704fg_write_all fd fg_t_sub_cpu
705ret
706end
707if eq sc FG_SUB_DIGITAL_GPU
708fg_write_all fd fg_t_sub_gpu
709ret
710end
711if eq sc FG_SUB_ANALOG_IN_MEMORY
712fg_write_all fd fg_t_sub_ana
713ret
714end
715if eq sc FG_SUB_NEUROMORPHIC
716fg_write_all fd fg_t_sub_neu
717ret
718end
719if eq sc FG_SUB_FPGA_CGRA
720fg_write_all fd fg_t_sub_fpg
721ret
722end
723if eq sc FG_SUB_OPTICAL_PHOTONIC
724fg_write_all fd fg_t_sub_opt
725ret
726end
727fg_write_all fd fg_t_hw_none
728ret
729end
730
731fn fg_emit_qual_name fd int qs uint to void
732if eq qs FG_QUAL_QUALIFIED
733fg_write_all fd fg_t_q_qual
734ret
735end
736if eq qs FG_QUAL_EXERCISED
737fg_write_all fd fg_t_q_exer
738ret
739end
740if eq qs FG_QUAL_SIMULATED
741fg_write_all fd fg_t_q_sim
742ret
743end
744if eq qs FG_QUAL_BLOCKED_HW
745fg_write_all fd fg_t_q_bhw
746ret
747end
748if eq qs FG_QUAL_NOT_RUN
749fg_write_all fd fg_t_q_nr
750ret
751end
752if eq qs FG_QUAL_FAULTED
753fg_write_all fd fg_t_q_flt
754ret
755end
756fg_write_all fd fg_t_hw_none
757ret
758end
759
760fn fg_emit_low_name fd int lk uint to void
761if eq lk FG_LOW_COMPILED
762fg_write_all fd fg_t_l_cmp
763ret
764end
765if eq lk FG_LOW_SIMULATED
766fg_write_all fd fg_t_l_sim
767ret
768end
769fg_write_all fd fg_t_l_none
770ret
771end
772
773fn fg_emit_receipt_seals fd int seals view ForgeSeals to void
774d = new uchar 32 0
775fg_write_all fd fg_t_reqd
776fg_seals_get_req seals d
777fg_write_hex32 fd d
778fg_write_all fd fg_t_nl
779fg_write_all fd fg_t_descd
780fg_seals_get_desc seals d
781fg_write_hex32 fd d
782fg_write_all fd fg_t_nl
783fg_write_all fd fg_t_planid
784fg_seals_get_plan seals d
785fg_write_hex32 fd d
786fg_write_all fd fg_t_nl
787fg_write_all fd fg_t_seal
788fg_seals_get_tok seals d
789fg_write_hex32 fd d
790fg_write_all fd fg_t_nl
791ret
792end
793
794fn fg_emit_receipt_metrics fd int plan view ForgePlan env view ForgeEnvCheck to void
795fg_write_all fd fg_t_prov
796fg_write_u64 fd ulong get plan prov_id
797fg_write_all fd fg_t_sp_hw
798fg_emit_hw_name fd get plan hw_id
799fg_write_all fd fg_t_sp_sub
800fg_emit_sub_name fd get plan substrate_class
801fg_write_all fd fg_t_sp_qual
802fg_emit_qual_name fd get plan qual_status
803fg_write_all fd fg_t_sp_low
804fg_emit_low_name fd get plan lowering_kind
805fg_write_all fd fg_t_nl
806fg_write_all fd fg_t_geom
807fg_write_u64 fd ulong get plan tile_m
808fg_write_all fd fg_t_x
809fg_write_u64 fd ulong get plan tile_n
810fg_write_all fd fg_t_x
811fg_write_u64 fd ulong get plan tile_k
812fg_write_all fd fg_t_sp_grid
813fg_write_u64 fd ulong get plan grid_x
814fg_write_all fd fg_t_x
815fg_write_u64 fd ulong get plan grid_y
816fg_write_all fd fg_t_sp_blk
817fg_write_u64 fd ulong get plan block_x
818fg_write_all fd fg_t_sp_ctas
819fg_write_u64 fd ulong get env eff_ctas
820fg_write_all fd fg_t_sp_wav
821fg_write_u64 fd ulong get plan waves
822fg_write_all fd fg_t_nl
823fg_write_all fd fg_t_phys
824fg_write_u64 fd get env ws_bytes
825fg_write_all fd fg_t_sp_tr
826fg_write_u64 fd get env traffic_bytes
827fg_write_all fd fg_t_sp_fl
828fg_write_u64 fd get env flops
829fg_write_all fd fg_t_sp_bnd
830if eq get plan compute_bound 1
831fg_write_all fd fg_t_comp
832else
833fg_write_all fd fg_t_bw
834end
835fg_write_all fd fg_t_roof
836fg_write_f64_3 fd get env roof_us
837fg_write_all fd fg_t_sp_ai
838fg_write_f64_3 fd get env arith_int
839fg_write_all fd fg_t_sp_pw
840fg_write_f64_2 fd get env est_power_w
841fg_write_all fd fg_t_sp_en
842fg_write_f64_3 fd get env est_energy_mj
843fg_write_all fd fg_t_nl
844ret
845end
846
847note Emit full canonical receipt block to fd
848fn fg_emit_receipt fd int req view ForgeContract plan view ForgePlan env view ForgeEnvCheck seals view ForgeSeals to void
849fg_write_all fd fg_t_rcpt_hdr
850if eq get plan admitted 1
851fg_write_all fd fg_t_dec_adm
852else
853fg_write_all fd fg_t_dec_ref
854end
855fg_write_all fd fg_t_status
856fg_emit_status_name fd get plan status
857fg_write_all fd fg_t_nl
858fg_write_all fd fg_t_viol
859fg_emit_viol_name fd get plan violation
860fg_write_all fd fg_t_nl
861fg_write_all fd fg_t_req_id
862fg_write_u64 fd get req req_id
863fg_write_all fd fg_t_sp_op
864fg_emit_op_name fd get req op_class
865fg_write_all fd fg_t_sp_dt
866fg_emit_dt_name fd get req dtype
867fg_write_all fd fg_t_sp_sh
868fg_write_u64 fd get req dim_m
869fg_write_all fd fg_t_x
870fg_write_u64 fd get req dim_n
871fg_write_all fd fg_t_x
872fg_write_u64 fd get req dim_k
873fg_write_all fd fg_t_x
874fg_write_u64 fd get req batch
875fg_write_all fd fg_t_nl
876fg_emit_receipt_metrics fd plan env
877fg_emit_receipt_seals fd seals
878fg_write_all fd fg_t_rcpt_end
879ret
880end