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
omega-mv / src / omega_blackwell_codegen_tgemm.c
| 1 | /* omega_blackwell_codegen_tgemm.c: device-resident bf16 training GEMM (trainer lane E1, cut 1: NN, F32 overwrite). |
| 2 | * Implementation lives in pure OM-2 (om/gpu/cg_tgemm.om); this file is the thin fail-closed C ABI wrapper. */ |
| 3 | #include "omega_blackwell_codegen_tgemm.h" |
| 4 | #include "omega_bw_om_ir.h" |
| 5 | #include "omega_native.h" |
| 6 | #include <string.h> |
| 7 | |
| 8 | static void tgemm_pack_spec(const OmegaTgemmSpec *s, uint64_t sp[10]) { |
| 9 | sp[0] = s->k; |
| 10 | sp[1] = s->n; |
| 11 | sp[2] = s->rt; |
| 12 | sp[3] = s->ct; |
| 13 | sp[4] = s->warps; |
| 14 | sp[5] = s->kc; |
| 15 | sp[6] = s->aqn; |
| 16 | sp[7] = s->layout; |
| 17 | sp[8] = s->epi; |
| 18 | sp[9] = (uint64_t)(int64_t)s->mutant; |
| 19 | } |
| 20 | |
| 21 | int omega_tgemm_spec_ok(const OmegaTgemmSpec *s) { |
| 22 | if (!s) return 0; |
| 23 | uint64_t sp[10], ok = 0; |
| 24 | tgemm_pack_spec(s, sp); |
| 25 | if (omega2_cg_tgemm_spec_ok(&ok, sp, 10u) != 0) return 0; |
| 26 | return ok != 0 ? 1 : 0; |
| 27 | } |
| 28 | |
| 29 | uint32_t omega_tgemm_shared_bytes(const OmegaTgemmSpec *s) { return omega_tgemm_spec_ok(s) ? 2u * 16u * s->rt * s->kc * 2u : 0u; } |
| 30 | uint32_t omega_tgemm_span(const OmegaTgemmSpec *s) { return omega_tgemm_spec_ok(s) ? s->warps * 8u * s->ct : 0u; } |
| 31 | uint32_t omega_tgemm_bm(const OmegaTgemmSpec *s) { return omega_tgemm_spec_ok(s) ? 16u * s->rt : 0u; } |
| 32 | |
| 33 | int omega_blackwell_codegen_tgemm_prog(const OmegaTgemmSpec *spec, BlackwellIRProgram *prog) { |
| 34 | if (!prog) return -1; |
| 35 | omega_bw_ir_init(prog); |
| 36 | if (!spec) return -1; |
| 37 | uint64_t sp[10], ins[8192], meta[512], rc = 1; |
| 38 | memset(ins, 0, sizeof ins); |
| 39 | memset(meta, 0, sizeof meta); |
| 40 | tgemm_pack_spec(spec, sp); |
| 41 | if (omega2_cg_tgemm_emit(&rc, sp, 10u, ins, 8192u, meta, 512u) != 0 || rc != 0) return -1; |
| 42 | if (omega_bw_ir_from_om(ins, meta, prog) != 0) return -1; |
| 43 | if (prog->count > OMEGA_TGEMM_MAX_INSNS) { omega_bw_ir_init(prog); return -1; } |
| 44 | uint32_t decl = omega_bw_gpr_declared(prog->regalloc.peak_gpr_usage); |
| 45 | if (!omega_bw_gpr_declared_ok(decl, prog->regalloc.peak_gpr_usage) || decl > 128u) { |
| 46 | omega_bw_ir_init(prog); |
| 47 | return -1; |
| 48 | } |
| 49 | return 0; |
| 50 | } |