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