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_pattn.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_pattn.c: causal prefill attention (hd=128) on tensor cores. |
| 18 | * Implementation lives in pure OM-2 (om/gpu/cg_pattn.om); this file is the thin fail-closed C ABI wrapper. */ |
| 19 | #include "omega_blackwell_codegen_pattn.h" |
| 20 | #include "omega_bw_om_ir.h" |
| 21 | #include "omega_native.h" |
| 22 | #include <string.h> |
| 23 | |
| 24 | static void pattn_pack_spec(const OmegaPrefillAttnSpec *s, uint64_t sp[4]) { |
| 25 | memset(sp, 0, 4u * sizeof(uint64_t)); |
| 26 | sp[0] = s->warps; |
| 27 | sp[1] = (uint64_t)(int64_t)s->mutant; |
| 28 | sp[2] = s->mode; |
| 29 | sp[3] = s->mirror; |
| 30 | } |
| 31 | |
| 32 | int omega_pattn_spec_ok(const OmegaPrefillAttnSpec *s) { |
| 33 | if (!s) return 0; |
| 34 | uint64_t sp[4], ok = 0; |
| 35 | pattn_pack_spec(s, sp); |
| 36 | if (omega2_cg_pattn_spec_ok(&ok, sp, 4u) != 0) return 0; |
| 37 | return ok != 0 ? 1 : 0; |
| 38 | } |
| 39 | |
| 40 | int omega_blackwell_codegen_prefill_attn_prog(const OmegaPrefillAttnSpec *spec, BlackwellIRProgram *prog) { |
| 41 | if (!prog) return -1; |
| 42 | omega_bw_ir_init(prog); |
| 43 | if (!spec) return -1; |
| 44 | uint64_t sp[4], ins[8192], meta[512], rc = 1; |
| 45 | memset(ins, 0, sizeof ins); |
| 46 | memset(meta, 0, sizeof meta); |
| 47 | pattn_pack_spec(spec, sp); |
| 48 | if (omega2_cg_pattn_emit(&rc, sp, 4u, ins, 8192u, meta, 512u) != 0 || rc != 0) return -1; |
| 49 | return omega_bw_ir_from_om(ins, meta, prog); |
| 50 | } |
| 51 | |
| 52 | int omega_prefill_attn_prog_stats(const OmegaPrefillAttnSpec *spec, uint32_t *insns, uint32_t *gprs) { |
| 53 | static BlackwellIRProgram p; |
| 54 | if (omega_blackwell_codegen_prefill_attn_prog(spec, &p) != 0) return -1; |
| 55 | if (insns) *insns = (uint32_t)p.count; |
| 56 | if (gprs) *gprs = p.regalloc.peak_gpr_usage; |
| 57 | return 0; |
| 58 | } |