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_qg.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* omega_blackwell_codegen_qg.c: native FP8 prefill kernels (W-L1G). |
| 18 | * Implementation lives in pure OM-2 (om/gpu/cg_qg.om); this file is the thin fail-closed C ABI wrapper. */ |
| 19 | #include "omega_blackwell_codegen_qg.h" |
| 20 | #include "omega_bw_om_ir.h" |
| 21 | #include "omega_native.h" |
| 22 | #include <string.h> |
| 23 | |
| 24 | static void pq_pack_spec(const OmegaPqSpec *s, uint64_t sp[8]) { |
| 25 | memset(sp, 0, 8u * sizeof(uint64_t)); |
| 26 | sp[0] = s->k; |
| 27 | sp[1] = s->in_type; |
| 28 | sp[2] = (uint64_t)(int64_t)s->mutant; |
| 29 | sp[3] = s->groups; |
| 30 | } |
| 31 | |
| 32 | int omega_pq_spec_ok(const OmegaPqSpec *s) { |
| 33 | if (!s) return 0; |
| 34 | uint64_t sp[8], ok = 0; |
| 35 | pq_pack_spec(s, sp); |
| 36 | if (omega2_cg_pq_spec_ok(&ok, sp, 8u) != 0) return 0; |
| 37 | return ok != 0 ? 1 : 0; |
| 38 | } |
| 39 | |
| 40 | int omega_blackwell_codegen_pq_prog(const OmegaPqSpec *spec, BlackwellIRProgram *prog) { |
| 41 | if (!prog) return -1; |
| 42 | omega_bw_ir_init(prog); |
| 43 | if (!spec) return -1; |
| 44 | uint64_t sp[8], ins[8192], meta[512], rc = 1; |
| 45 | memset(ins, 0, sizeof ins); |
| 46 | memset(meta, 0, sizeof meta); |
| 47 | pq_pack_spec(spec, sp); |
| 48 | if (omega2_cg_pq_emit(&rc, sp, 8u, ins, 8192u, meta, 512u) != 0 || rc != 0) return -1; |
| 49 | return omega_bw_ir_from_om(ins, meta, prog); |
| 50 | } |
| 51 | |
| 52 | static void qg_pack_spec(const OmegaQgSpec *s, uint64_t sp[10]) { |
| 53 | memset(sp, 0, 10u * sizeof(uint64_t)); |
| 54 | sp[0] = s->k; |
| 55 | sp[1] = s->rt; |
| 56 | sp[2] = s->warps; |
| 57 | sp[3] = s->epi; |
| 58 | sp[4] = s->direct; |
| 59 | sp[5] = s->n; |
| 60 | sp[6] = s->wait; |
| 61 | sp[7] = (uint64_t)(int64_t)s->mutant; |
| 62 | } |
| 63 | |
| 64 | int omega_qg_spec_ok(const OmegaQgSpec *s) { |
| 65 | if (!s) return 0; |
| 66 | uint64_t sp[10], ok = 0; |
| 67 | qg_pack_spec(s, sp); |
| 68 | if (omega2_cg_qg_spec_ok(&ok, sp, 10u) != 0) return 0; |
| 69 | return ok != 0 ? 1 : 0; |
| 70 | } |
| 71 | |
| 72 | uint32_t omega_qg_shared_bytes(const OmegaQgSpec *s) { return omega_qg_spec_ok(s) ? 2u * (16u * s->rt * 64u + 16u * s->rt * 4u) : 0u; } |
| 73 | uint32_t omega_qg_span(const OmegaQgSpec *s) { return omega_qg_spec_ok(s) ? s->warps * 16u : 0u; } |
| 74 | |
| 75 | int omega_blackwell_codegen_qgemm_prog(const OmegaQgSpec *spec, BlackwellIRProgram *prog) { |
| 76 | if (!prog) return -1; |
| 77 | omega_bw_ir_init(prog); |
| 78 | if (!spec) return -1; |
| 79 | uint64_t sp[10], ins[8192], meta[512], rc = 1; |
| 80 | memset(ins, 0, sizeof ins); |
| 81 | memset(meta, 0, sizeof meta); |
| 82 | qg_pack_spec(spec, sp); |
| 83 | if (omega2_cg_qgemm_emit(&rc, sp, 10u, ins, 8192u, meta, 512u) != 0 || rc != 0) return -1; |
| 84 | return omega_bw_ir_from_om(ins, meta, prog); |
| 85 | } |