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_attn.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_attn.c: the one-launch decode attention kernel. |
| 18 | * Implementation lives in pure OM-2 (om/gpu/cg_attn.om); this file is the thin fail-closed C ABI wrapper. */ |
| 19 | #include "omega_blackwell_codegen_attn.h" |
| 20 | #include "omega_bw_om_ir.h" |
| 21 | #include "omega_native.h" |
| 22 | #include <string.h> |
| 23 | |
| 24 | static void attn_pack_spec(const OmegaDecodeAttnSpec *s, uint64_t sp[4]) { |
| 25 | memset(sp, 0, 4u * sizeof(uint64_t)); |
| 26 | sp[0] = s->depth; |
| 27 | sp[1] = (uint64_t)(int64_t)s->mutant; |
| 28 | } |
| 29 | |
| 30 | int omega_blackwell_codegen_decode_attn_prog(const OmegaDecodeAttnSpec *spec, BlackwellIRProgram *prog) { |
| 31 | if (!prog) return -1; |
| 32 | omega_bw_ir_init(prog); |
| 33 | if (!spec) return -1; |
| 34 | uint64_t sp[4], ins[8192], meta[512], rc = 1; |
| 35 | memset(ins, 0, sizeof ins); |
| 36 | memset(meta, 0, sizeof meta); |
| 37 | attn_pack_spec(spec, sp); |
| 38 | if (omega2_cg_attn_emit(&rc, sp, 4u, ins, 8192u, meta, 512u) != 0 || rc != 0) return -1; |
| 39 | return omega_bw_ir_from_om(ins, meta, prog); |
| 40 | } |
| 41 | |
| 42 | int omega_decode_attn_prog_stats(const OmegaDecodeAttnSpec *spec, uint32_t *insns, uint32_t *gprs) { |
| 43 | static BlackwellIRProgram prog; |
| 44 | if (omega_blackwell_codegen_decode_attn_prog(spec, &prog) != 0) return -1; |
| 45 | if (insns) *insns = (uint32_t)prog.count; |
| 46 | if (gprs) *gprs = prog.regalloc.peak_gpr_usage; |
| 47 | return 0; |
| 48 | } |