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/src/omega_blackwell_codegen_attn256.c # 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 / src / omega_blackwell_codegen_attn256.c` 66 lines ยท 2791 bytes Raw Blame History 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_attn256.c: the one-launch decode attention kernel for head_dim 256. 18 * Implementation lives in pure OM-2 (om/gpu/cg_attn256.om); this file is the thin fail-closed C ABI wrapper. */ 19 #include "omega_blackwell_codegen_attn256.h" 20 #include "omega_bw_om_ir.h" 21 #include "omega_native.h" 22 #include 23 24 static void attn256_pack_spec(const OmegaDecodeAttn256Spec *s, uint64_t sp[8]) { 25 memset(sp, 0, 8u * sizeof(uint64_t)); 26 sp[0] = s->depth; 27 sp[1] = (uint64_t)(int64_t)s->mutant; 28 sp[2] = s->prep; 29 sp[3] = s->q_heads; 30 sp[4] = s->kv_heads; 31 sp[5] = s->q_per_cta; 32 sp[6] = s->multi; 33 } 34 35 int omega_dattn256_shape(const OmegaDecodeAttn256Spec *spec, OmegaDattn256Shape *s) { 36 if (!spec || !s) return -1; 37 const uint32_t qh = spec->q_heads ? spec->q_heads : OMEGA_DATTN256_Q_HEADS; 38 const uint32_t kvh = spec->kv_heads ? spec->kv_heads : OMEGA_DATTN256_KV_HEADS; 39 const uint32_t h = spec->q_per_cta ? spec->q_per_cta : OMEGA_DATTN256_Q_PER_KV; 40 if (h < 1u || h > 6u || qh % h || kvh == 0 || (qh / h) % kvh) return -1; 41 const uint32_t g = (qh / h) / kvh; 42 if (g != 1u && g != 2u) return -1; 43 s->qh = qh; s->kvh = kvh; s->h = h; s->vy = qh / h; s->g = g; 44 s->qkv_words = (qh + 2u * kvh) * 256u; s->out_words = qh * 256u; 45 return 0; 46 } 47 48 int omega_blackwell_codegen_decode_attn256_prog(const OmegaDecodeAttn256Spec *spec, BlackwellIRProgram *prog) { 49 if (!prog) return -1; 50 omega_bw_ir_init(prog); 51 if (!spec) return -1; 52 uint64_t sp[8], ins[8192], meta[512], rc = 1; 53 memset(ins, 0, sizeof ins); 54 memset(meta, 0, sizeof meta); 55 attn256_pack_spec(spec, sp); 56 if (omega2_cg_attn256_emit(&rc, sp, 8u, ins, 8192u, meta, 512u) != 0 || rc != 0) return -1; 57 return omega_bw_ir_from_om(ins, meta, prog); 58 } 59 60 int omega_decode_attn256_prog_stats(const OmegaDecodeAttn256Spec *spec, uint32_t *insns, uint32_t *gprs) { 61 static BlackwellIRProgram prog; 62 if (omega_blackwell_codegen_decode_attn256_prog(spec, &prog) != 0) return -1; 63 if (insns) *insns = (uint32_t)prog.count; 64 if (gprs) *gprs = prog.regalloc.peak_gpr_usage; 65 return 0; 66 }