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