interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / src / omega_gpu_prefill_attn256_api.h

62 lines · 4394 bytes Raw Blame History
1#ifndef OMEGA_GPU_PREFILL_ATTN256_API_H
2#define OMEGA_GPU_PREFILL_ATTN256_API_H
3/*
4 * omega_gpu_prefill_attn256_api: causal prefill attention for Qwen3.8-27B (omega-mv#545, 2026-10-18), on the decode
5 * attention's cache (omega_gpu_decode_attn256_api.h); the kernels are described in omega_blackwell_codegen_pattn256.h.
6 *
7 * int omega_gpu_prefill_attn256(c, layer, pos0, m, qkv, eps, out_scale, out, info)
8 * qkv: host f32 [m][8192], one row per token in the decode call's layout (q 24 x 256 permuted, k 4 x 256 permuted,
9 * v 4 x 256; the gate is not part of it), tokens at positions pos0 .. pos0+m-1 (positions 0 .. pos0-1 of `layer`
10 * already in the cache). Appends K and V for those positions with the decode step's instruction sequence (the
11 * rows equal m decode steps' rows on the same chip) and writes out: host f32 [m][6144] (token-major, head h at
12 * h * 256, model dim order) multiplied by out_scale. pos0 + m <= max_pos, 1 <= m <= OMEGA_GPU_PATTN256_MAX_M.
13 * Two launches: prep (grid m x 4), attend (grid ceil(m / 8) x 4). Returns OMEGA_GPU_DATTN_OK or an
14 * OMEGA_GPU_DATTN_* code; the text is in omega_gpu_decode_attn_last_error().
15 * int omega_gpu_prefill_attn256_dev(c, layer, pos0, m, qkv_va, eps, out_scale, out_va, info)
16 * The same with device buffers (qkv_va: f32 [m][8192], out_va: f32 [m][6144], 16-byte aligned GPU VAs in the
17 * session); no host copies and no poison check (the caller's download path is the check).
18 * int omega_gpu_prefill_attn256_record(cl, c, layer, pos0, m, qkv_va, eps, out_scale, out_va)
19 * Record path (omega_gpu_cmdlist.h): both launches appended to cl. The caller holds omega_gpu_session_lock(), has
20 * reserved the q' scratch for m tokens (omega_gpu_prefill_attn256_reserve) and warmed both kernels with one
21 * non-record call (a kernel cache miss is refused, never compiled while recording).
22 * int omega_gpu_prefill_attn256_reserve(max_m): allocates the q' scratch for max_m tokens now (ceil(max_m / 2) x
23 * 24576 bytes) and builds both kernels (the warm-up the record path needs; sc #642); calls beyond it grow the
24 * scratch (host and dev paths) or are refused (record path: TOO_LARGE).
25 * void omega_gpu_prefill_attn256_release(void): frees the module's buffers (also released when the session closes).
26 *
27 * Every buffer is GPU-uncached host-visible session memory (nvos.h:1117 rule), launched through
28 * omega_gpu_session_launch.
29 */
30#include "omega_gpu_decode_attn256_api.h"
31#include "omega_blackwell_codegen_pattn256.h"
32#include <stdint.h>
33
34#define OMEGA_GPU_PATTN256_MAX_M 32768u
35
36typedef struct {
37 uint32_t layer, pos0, m;
38 uint32_t grid_x[2]; /* prep, attend */
39 uint32_t insns[2], gprs[2]; /* allocator peak registers */
40 uint64_t elapsed_ns[2]; /* marker-to-marker chip time of each launch (host and dev paths) */
41 uint64_t call_ns;
42 uint32_t kernel_cache_hits; /* 0..2 */
43} OmegaGpuPrefillAttn256Info;
44
45int omega_gpu_prefill_attn256(OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0, uint32_t m,
46 const float *qkv, float eps, float out_scale, float *out, OmegaGpuPrefillAttn256Info *info);
47int omega_gpu_prefill_attn256_dev(OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0, uint32_t m,
48 uint64_t qkv_va, float eps, float out_scale, uint64_t out_va, OmegaGpuPrefillAttn256Info *info);
49struct OmegaGpuCmdList;
50int omega_gpu_prefill_attn256_record(struct OmegaGpuCmdList *cl, OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0,
51 uint32_t m, uint64_t qkv_va, float eps, float out_scale, uint64_t out_va);
52int omega_gpu_prefill_attn256_reserve(uint32_t max_m);
53/* the same for the head shape of cache c (the q' scratch is q_heads * 512 bytes per token; reserve(m) = the 27B) */
54int omega_gpu_prefill_attn256_reserve_for(const OmegaGpuDecodeAttn256Cache *c, uint32_t max_m);
55void omega_gpu_prefill_attn256_release(void);
56
57/* ---- tests ---- */
58void omega_gpu_prefill_attn256_test_set_mutant(int prep_mutant, int attend_mutant); /* OmegaDecodeAttn256Spec / OmegaPrefillAttn256Spec .mutant */
59/* host: build + encode a kernel (0 prep, 1 attend) into code (cap bytes); returns the code size or 0 */
60size_t omega_gpu_prefill_attn256_encode(unsigned kind, uint8_t *code, size_t cap, uint32_t *gprs);
61
62#endif