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.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #include "omega_attn_views.h" |
| 3 | /* |
| 4 | * omega_gpu_prefill_attn256_api.c: the two launches of the head_dim 256 prefill attention (omega-mv#545; see the |
| 5 | * header). The prep kernel is the decode kernel's own program in prep mode (omega_blackwell_codegen_attn256.h), the |
| 6 | * attend kernel is omega_blackwell_codegen_pattn256.h (SHFL.BFLY and F2FP.BF16.F32.PACK_AB are native encoder entries |
| 7 | * since training R5). Session use mirrors omega_gpu_prefill_attn_api.c. |
| 8 | */ |
| 9 | #include "omega_gpu_prefill_attn256_api.h" |
| 10 | #include "omega_api_shells.h" |
| 11 | #include "omega_blackwell_codegen_pattn256.h" |
| 12 | #include "omega_blackwell_codegen_tc.h" |
| 13 | #include "omega_gpu_session.h" |
| 14 | #include "omega_gpu_cmdlist.h" |
| 15 | #include "omega_gpu_attention_mirror.h" |
| 16 | #include "omega_gpu_prefill.h" |
| 17 | #include "cudapp_native.h" |
| 18 | #include <string.h> |
| 19 | |
| 20 | #define MARKER_TIMEOUT_MS 60000ull |
| 21 | #define POISON_F32 (-999.0f) |
| 22 | enum { KK_PREP, KK_ATTEND, KK_N }; |
| 23 | |
| 24 | typedef struct { |
| 25 | bool valid; |
| 26 | union { OmegaDecodeAttn256Spec prep; OmegaPrefillAttn256Spec att; } spec; |
| 27 | OmegaBlackwellKernel kernel; |
| 28 | OmegaGpuMem code; |
| 29 | uint32_t insns; |
| 30 | } Slot; |
| 31 | |
| 32 | static struct { |
| 33 | bool hooked; |
| 34 | Slot slot[KK_N]; |
| 35 | int prep_mut, att_mut; |
| 36 | OmegaGpuMem qf; size_t qf_size; bool have_qf; /* q' scratch */ |
| 37 | OmegaGpuMem qkv, out; size_t qkv_size, out_size; bool have_bufs; /* host-entry staging */ |
| 38 | OmegaGpuMem mirror; /* one device-private full-copy workspace, no prefix-validity state */ |
| 39 | } g; |
| 40 | |
| 41 | static void bufs_forget(void) { g.have_qf = false; g.qf_size = 0; g.have_bufs = false; g.qkv_size = g.out_size = 0; } |
| 42 | static void on_session_close(void) { av_memset(g.slot, 0, sizeof g.slot); bufs_forget(); av_memset(&g.mirror, 0, sizeof g.mirror); } |
| 43 | static OmegaGpuSession *dev_open_locked(void) { |
| 44 | if (!g.hooked) { |
| 45 | if (omega_gpu_session_on_close(on_session_close) != 0) { omega_gpu_session_set_error("prefill attn256: close hook unavailable"); return NULL; } |
| 46 | g.hooked = true; |
| 47 | } |
| 48 | return omega_gpu_session_open(); |
| 49 | } |
| 50 | static void slots_clear_locked(void) { |
| 51 | for (unsigned k = 0; k < KK_N; k++) { if (g.slot[k].valid) omega_gpu_session_free(&g.slot[k].code); av_memset(&g.slot[k], 0, sizeof g.slot[k]); } |
| 52 | } |
| 53 | void omega_gpu_prefill_attn256_test_set_mutant(int prep_mutant, int attend_mutant) { |
| 54 | omega_gpu_session_lock(); g.prep_mut = prep_mutant; g.att_mut = attend_mutant; slots_clear_locked(); omega_gpu_session_unlock(); |
| 55 | } |
| 56 | void omega_gpu_prefill_attn256_release(void) { |
| 57 | omega_gpu_session_lock(); |
| 58 | if (g.have_qf) omega_gpu_session_free(&g.qf); |
| 59 | if (g.have_bufs) { omega_gpu_session_free(&g.qkv); omega_gpu_session_free(&g.out); } |
| 60 | omega_gpu_session_free(&g.mirror); |
| 61 | bufs_forget(); |
| 62 | omega_gpu_session_unlock(); |
| 63 | } |
| 64 | |
| 65 | /* sh: the cache's head shape (q_heads / kv_heads / q_per_cta; NULL = the 27B) */ |
| 66 | static void spec_of(unsigned kind, const uint32_t *sh, Slot *tmp) { |
| 67 | av_memset(tmp, 0, sizeof *tmp); |
| 68 | if (kind == KK_PREP) { |
| 69 | tmp->spec.prep.depth = OMEGA_GPU_DATTN256_DEPTH; tmp->spec.prep.mutant = g.prep_mut; tmp->spec.prep.prep = 1; |
| 70 | if (sh) { tmp->spec.prep.q_heads = sh[0]; tmp->spec.prep.kv_heads = sh[1]; tmp->spec.prep.q_per_cta = sh[2]; } |
| 71 | } else { |
| 72 | tmp->spec.att.mutant = g.att_mut; |
| 73 | if (sh) { tmp->spec.att.q_heads = sh[0]; tmp->spec.att.kv_heads = sh[1]; } |
| 74 | } |
| 75 | } |
| 76 | static int prog_of(unsigned kind, const Slot *tmp, BlackwellIRProgram *prog) { |
| 77 | return kind == KK_PREP ? omega_blackwell_codegen_decode_attn256_prog(&tmp->spec.prep, prog) |
| 78 | : omega_blackwell_codegen_prefill_attn256_prog(&tmp->spec.att, prog); |
| 79 | } |
| 80 | size_t omega_gpu_prefill_attn256_encode(unsigned kind, uint8_t *code, size_t cap, uint32_t *gprs) { |
| 81 | if (kind >= KK_N) return 0; |
| 82 | Slot tmp; spec_of(kind, NULL, &tmp); |
| 83 | BlackwellIRProgram *prog = omega_gpu_host_calloc(1, sizeof *prog); |
| 84 | if (!prog) return 0; |
| 85 | size_t need = 0; |
| 86 | if (prog_of(kind, &tmp, prog) == 0) need = omega_bw_program_code_bytes(prog); |
| 87 | OmegaBlackwellKernel k; |
| 88 | if (need == 0 || need > cap || omega_blackwell_kernel_encode_into(prog, code, cap, &k) != 0) { omega_gpu_host_free(prog); return 0; } |
| 89 | if (gprs) *gprs = k.gpr_count; |
| 90 | omega_gpu_host_free(prog); |
| 91 | return need; |
| 92 | } |
| 93 | |
| 94 | /* rec: a record call is running (lock held): a miss is refused instead of compiled */ |
| 95 | static int kernel_for(unsigned kind, const uint32_t *sh, int rec, Slot **out, bool *hit) { |
| 96 | Slot tmp; spec_of(kind, sh, &tmp); |
| 97 | Slot *s = &g.slot[kind]; |
| 98 | if (s->valid && memcmp(&s->spec, &tmp.spec, sizeof tmp.spec) == 0) { *out = s; *hit = true; return OMEGA_GPU_DATTN_OK; } |
| 99 | if (rec) { omega_gpu_session_set_error("prefill attn256 record: kernel cache miss (warm up before recording)"); return OMEGA_GPU_DATTN_TOO_LARGE; } |
| 100 | if (s->valid) omega_gpu_session_free(&s->code); |
| 101 | av_memset(s, 0, sizeof *s); |
| 102 | BlackwellIRProgram *prog = omega_gpu_host_calloc(1, sizeof *prog); |
| 103 | if (!prog) { omega_gpu_session_set_error("prefill attn256 codegen: host memory"); return OMEGA_GPU_DATTN_CODEGEN_FAIL; } |
| 104 | int cg = prog_of(kind, &tmp, prog); |
| 105 | size_t need = cg == 0 ? omega_bw_program_code_bytes(prog) : 0; |
| 106 | if (cg != 0 || need == 0) { omega_gpu_host_free(prog); omega_gpu_session_set_error("prefill attn256 codegen refused the spec"); return OMEGA_GPU_DATTN_CODEGEN_FAIL; } |
| 107 | /* both launches run 256 threads per CTA: the declared registers must fit the 64K register file (CUDA Programming |
| 108 | * Guide, Compute Capabilities: "maximum number of 32-bit registers per thread block is 64K") */ |
| 109 | if (!omega_api_regfit(OMEGA_PATTN256_WARPS, omega_bw_gpr_declared(prog->regalloc.peak_gpr_usage))) { omega_gpu_host_free(prog); omega_gpu_session_set_error("prefill attn256: register file"); return OMEGA_GPU_DATTN_TOO_LARGE; } |
| 110 | const uint32_t insns = (uint32_t)prog->count; |
| 111 | OmegaGpuMem code; |
| 112 | if (omega_gpu_session_alloc_code(need, &code) != 0) { omega_gpu_host_free(prog); return OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 113 | OmegaBlackwellKernel kernel; |
| 114 | cg = omega_blackwell_kernel_encode_into(prog, code.cpu, need, &kernel); |
| 115 | omega_gpu_host_free(prog); |
| 116 | if (cg != 0 || !kernel.code || kernel.code_size != need) { omega_gpu_session_free(&code); omega_gpu_session_set_error("prefill attn256 encode"); return OMEGA_GPU_DATTN_CODEGEN_FAIL; } |
| 117 | if (omega_gpu_session_sync_to_gpu(&code) != 0) { omega_gpu_session_free(&code); return OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 118 | av_memset(s, 0, sizeof *s); |
| 119 | s->valid = true; s->spec = tmp.spec; s->kernel = kernel; s->code = code; s->insns = insns; |
| 120 | *out = s; *hit = false; |
| 121 | return OMEGA_GPU_DATTN_OK; |
| 122 | } |
| 123 | |
| 124 | /* q heads: a token pair of q' takes q_heads * 1024 bytes (OMEGA_PATTN256_QF_OFF_SHAPE) */ |
| 125 | static size_t qf_bytes(uint32_t rows, uint32_t q_heads) { return (size_t)omega_api_qfbyt(rows, q_heads); } |
| 126 | static int qf_locked(size_t need) { |
| 127 | if (g.have_qf && g.qf_size >= need) return 0; |
| 128 | if (g.have_qf) { omega_gpu_session_free(&g.qf); g.have_qf = false; g.qf_size = 0; } |
| 129 | if (omega_gpu_session_alloc(need, &g.qf) != 0) return -1; |
| 130 | g.have_qf = true; g.qf_size = need; |
| 131 | return 0; |
| 132 | } |
| 133 | int omega_gpu_prefill_attn256_reserve(uint32_t max_m) { return omega_gpu_prefill_attn256_reserve_for(NULL, max_m); } |
| 134 | int omega_gpu_prefill_attn256_reserve_for(const OmegaGpuDecodeAttn256Cache *c, uint32_t max_m) { |
| 135 | if (omega_api_pa256b(max_m, 0, OMEGA_GPU_PATTN256_MAX_M)) return OMEGA_GPU_DATTN_BAD_ARGS; |
| 136 | OmegaGpuDecodeAttn256CacheView v; |
| 137 | if (c && omega_gpu_decode_attn256_cache_view(c, 0, &v) != OMEGA_GPU_DATTN_OK) return OMEGA_GPU_DATTN_BAD_ARGS; |
| 138 | const uint32_t shv[3] = { c ? v.q_heads : OMEGA_DATTN256_Q_HEADS, c ? v.kv_heads : OMEGA_DATTN256_KV_HEADS, c ? v.q_per_cta : OMEGA_DATTN256_Q_PER_KV }; |
| 139 | const uint32_t *sh = c ? shv : NULL; |
| 140 | omega_gpu_session_lock(); |
| 141 | int rc = dev_open_locked() && qf_locked(qf_bytes(max_m, shv[0])) == 0 ? OMEGA_GPU_DATTN_OK : OMEGA_GPU_DATTN_CHIP_FAIL; |
| 142 | /* and builds both kernels, so a record call after reserve never misses the cache (sc #642 prefill graph) */ |
| 143 | for (unsigned k = 0; k < KK_N && rc == OMEGA_GPU_DATTN_OK; k++) { Slot *s = NULL; bool hit = false; rc = kernel_for(k, sh, 0, &s, &hit); } |
| 144 | omega_gpu_session_unlock(); |
| 145 | return rc; |
| 146 | } |
| 147 | static int bufs_locked(size_t qkv_size, size_t out_size) { |
| 148 | if (g.have_bufs && g.qkv_size >= qkv_size && g.out_size >= out_size) return 0; |
| 149 | if (g.have_bufs) { omega_gpu_session_free(&g.qkv); omega_gpu_session_free(&g.out); g.have_bufs = false; g.qkv_size = g.out_size = 0; } |
| 150 | if (omega_gpu_session_alloc(qkv_size, &g.qkv) != 0) return -1; |
| 151 | if (omega_gpu_session_alloc(out_size, &g.out) != 0) { omega_gpu_session_free(&g.qkv); return -1; } |
| 152 | g.have_bufs = true; g.qkv_size = qkv_size; g.out_size = out_size; |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | /* host != 0: qkv / out are host arrays staged through the module buffers (poison-checked); else qkv_va / out_va are |
| 157 | * device buffers. rec non-NULL: record path (lock held, nothing allocated, compiled or submitted). */ |
| 158 | static int core(OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0, uint32_t m, const float *qkv, float *out, |
| 159 | uint64_t qkv_va, uint64_t out_va, float eps, float out_scale, OmegaGpuPrefillAttn256Info *info, OmegaGpuCmdList *rec, |
| 160 | uint32_t mirror_mode, uint64_t *copy_ns) { |
| 161 | uint64_t t0 = omega_gpu_session_now_ns(); |
| 162 | if (info) av_memset(info, 0, sizeof *info); |
| 163 | if (copy_ns) *copy_ns = 0; |
| 164 | const int host = qkv != NULL; |
| 165 | OmegaGpuDecodeAttn256CacheView v; |
| 166 | if (!c || omega_gpu_decode_attn256_cache_view(c, layer, &v) != OMEGA_GPU_DATTN_OK || |
| 167 | omega_api_pa256b(m, pos0, v.max_pos) || |
| 168 | (host ? !out : (!qkv_va || !out_va || !omega_api_alignok((uint32_t)qkv_va, 15u) || !omega_api_alignok((uint32_t)out_va, 15u)))) return OMEGA_GPU_DATTN_BAD_ARGS; |
| 169 | const uint32_t sh[3] = { v.q_heads, v.kv_heads, v.q_per_cta }, QKVW = v.qkv_words, OUTW = v.out_words; |
| 170 | if (!rec) omega_gpu_session_lock(); |
| 171 | #define UNLOCK() do { if (!rec) omega_gpu_session_unlock(); } while (0) |
| 172 | uint64_t mirror_bytes = 0; |
| 173 | if (mirror_mode) { |
| 174 | const uint64_t request[7] = {mirror_mode, v.q_heads, v.kv_heads, v.max_pos, pos0, m, v.v_va - v.k_va}; |
| 175 | if (rec || v.v_va <= v.k_va || omega_native_attnmirplan(&mirror_bytes, request, 7) != OMEGA_OK || mirror_bytes == UINT64_MAX) |
| 176 | { UNLOCK(); return OMEGA_GPU_DATTN_BAD_ARGS; } |
| 177 | } |
| 178 | if (!dev_open_locked()) { UNLOCK(); return OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 179 | Slot *ks[KK_N] = { NULL, NULL }; bool hit[KK_N] = { false, false }; |
| 180 | int rc = OMEGA_GPU_DATTN_OK; |
| 181 | for (unsigned k = 0; k < KK_N && rc == OMEGA_GPU_DATTN_OK; k++) rc = kernel_for(k, sh, rec != NULL, &ks[k], &hit[k]); |
| 182 | if (rc != OMEGA_GPU_DATTN_OK) { UNLOCK(); return rc; } |
| 183 | if (rec) { if (!g.have_qf || g.qf_size < qf_bytes(m, v.q_heads)) { omega_gpu_session_set_error("prefill attn256 record: q' scratch not reserved for m tokens"); return OMEGA_GPU_DATTN_TOO_LARGE; } } |
| 184 | else if (qf_locked(qf_bytes(m, v.q_heads)) != 0) { UNLOCK(); return OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 185 | if (host) { |
| 186 | if (bufs_locked((size_t)omega_api_hostb(m, QKVW), (size_t)omega_api_hostb(m, OUTW)) != 0) { UNLOCK(); return OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 187 | av_memcpy(g.qkv.cpu, qkv, (size_t)omega_api_hostb(m, QKVW)); |
| 188 | float *od = g.out.cpu; |
| 189 | av_fillf32(od, (size_t)m * OUTW, POISON_F32); |
| 190 | if (omega_gpu_session_sync_to_gpu(&g.qkv) != 0 || omega_gpu_session_sync_to_gpu(&g.out) != 0) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 191 | qkv_va = g.qkv.va; out_va = g.out.va; |
| 192 | } |
| 193 | const uint32_t kvs = omega_api_kvsb(v.max_pos), gx_att = omega_api_gxatt(m); |
| 194 | float fe = eps, f1 = 1.0f, fo = out_scale, fq = (float)(0.0625 * 1.4426950408889634); /* log2(e) / sqrt(256) */ |
| 195 | uint32_t ue, u1, uo, uq; av_memcpy(&ue, &fe, 4); av_memcpy(&u1, &f1, 4); av_memcpy(&uo, &fo, 4); av_memcpy(&uq, &fq, 4); |
| 196 | uint32_t ap[32], aa[32]; |
| 197 | const uint64_t prep[32] = { qkv_va, v.k_va, v.v_va, v.rope_va, v.q_norm_va, v.k_norm_va, |
| 198 | g.qf.va, v.part_va, v.cnt_va, pos0, OMEGA_DATTN256_CHUNK, 1u, kvs, ue, u1, uq }; |
| 199 | uint64_t attend[32] = { g.qf.va, v.k_va, v.v_va, out_va, pos0, m, kvs, uo }; |
| 200 | if (av_args(ap, prep, 9, OMEGA_DATTN256_ARGS_WORDS) || |
| 201 | av_args(aa, attend, 4, OMEGA_PATTN256_ARGS_WORDS)) { UNLOCK(); return OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 202 | uint32_t grid_y = 0; |
| 203 | if (omega_api_qydiv(v.q_heads, v.q_per_cta, &grid_y)) { UNLOCK(); return OMEGA_GPU_DATTN_BAD_ARGS; } |
| 204 | OmegaGpuLaunch L[KK_N] = { |
| 205 | { .code_va = ks[KK_PREP]->code.va, .gpr_count = omega_bw_gpr_declared(ks[KK_PREP]->kernel.gpr_count), |
| 206 | .threads_x = OMEGA_PATTN256_THREADS, .threads_y = 1, .grid_x = m, .grid_y = grid_y, |
| 207 | .num_elements = (size_t)m * QKVW, .args = ap, .n_args = OMEGA_DATTN256_ARGS_WORDS, .timeout_ms = MARKER_TIMEOUT_MS, |
| 208 | .shared_bytes = OMEGA_DATTN256_SHARED_BYTES }, |
| 209 | { .code_va = ks[KK_ATTEND]->code.va, .gpr_count = omega_bw_gpr_declared(ks[KK_ATTEND]->kernel.gpr_count), |
| 210 | .threads_x = OMEGA_PATTN256_THREADS, .threads_y = 1, .grid_x = gx_att, .grid_y = v.kv_heads, |
| 211 | .num_elements = (size_t)m * OUTW, .args = aa, .n_args = OMEGA_PATTN256_ARGS_WORDS, .timeout_ms = MARKER_TIMEOUT_MS, |
| 212 | .shared_bytes = OMEGA_PATTN256_SHARED_BYTES }, |
| 213 | }; |
| 214 | if (info) { |
| 215 | info->layer = layer; info->pos0 = pos0; info->m = m; info->grid_x[0] = m; info->grid_x[1] = gx_att; |
| 216 | for (unsigned k = 0; k < KK_N; k++) { info->insns[k] = ks[k]->insns; info->gprs[k] = ks[k]->kernel.gpr_count; } |
| 217 | const uint32_t hits[KK_N] = {hit[0], hit[1]}; |
| 218 | info->kernel_cache_hits = (uint32_t)av_count32(hits, KK_N, 1); |
| 219 | } |
| 220 | if (mirror_mode) { |
| 221 | uint64_t phase = 0, action = 0; |
| 222 | /* Omega owns allocation admission and PREP -> COPY -> ATTEND order. |
| 223 | * Each transport operation returns only after completion; failure cannot advance. */ |
| 224 | for (unsigned transitions = 0; transitions < 6; transitions++) { |
| 225 | if (omega_native_attnmirnext(&action, phase, mirror_bytes, g.mirror.size, rc == OMEGA_GPU_DATTN_OK) != OMEGA_OK || !action) { |
| 226 | if (rc == OMEGA_GPU_DATTN_OK) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 227 | break; |
| 228 | } |
| 229 | if (action == 5) break; |
| 230 | if (action == 1) { |
| 231 | omega_gpu_session_free(&g.mirror); |
| 232 | if (omega_gpu_pf_alloc_dev_locked((size_t)mirror_bytes, &g.mirror) != OMEGA_GPU_PF_OK) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 233 | } else if (action == 3) { |
| 234 | if (omega_gpu_pf_copy_va_locked(g.mirror.va, v.k_va, (size_t)mirror_bytes, copy_ns) != OMEGA_GPU_PF_OK) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 235 | if (rc == OMEGA_GPU_DATTN_OK) { |
| 236 | attend[1] = g.mirror.va; attend[2] = g.mirror.va + (v.v_va - v.k_va); |
| 237 | if (av_args(aa, attend, 4, OMEGA_PATTN256_ARGS_WORDS)) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 238 | } |
| 239 | } else if (action == 2 || action == 4) { |
| 240 | const unsigned k = action == 2 ? KK_PREP : KK_ATTEND; |
| 241 | if (!omega_bw_gpr_declared_ok(L[k].gpr_count, ks[k]->kernel.gpr_count) || |
| 242 | omega_gpu_session_launch(&L[k], info ? &info->elapsed_ns[k] : NULL, NULL) != 0) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 243 | } else { rc = OMEGA_GPU_DATTN_CHIP_FAIL; break; } |
| 244 | phase = action; |
| 245 | } |
| 246 | if (action != 5 && rc == OMEGA_GPU_DATTN_OK) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 247 | } else for (unsigned k = 0; k < KK_N && rc == OMEGA_GPU_DATTN_OK; k++) { |
| 248 | if (!omega_bw_gpr_declared_ok(L[k].gpr_count, ks[k]->kernel.gpr_count)) { omega_gpu_session_set_error("declared registers below peak + 2: refusing to launch"); rc = OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 249 | else if (rec) { if (omega_gpu_cmdlist_add(rec, &L[k]) < 0) rc = OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 250 | else if (omega_gpu_session_launch(&L[k], info ? &info->elapsed_ns[k] : NULL, NULL) != 0) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 251 | } |
| 252 | if (rc == OMEGA_GPU_DATTN_OK && host) { |
| 253 | if (omega_gpu_session_sync_to_cpu(&g.out) != 0) rc = OMEGA_GPU_DATTN_CHIP_FAIL; |
| 254 | else { |
| 255 | const float *od = g.out.cpu; |
| 256 | size_t unchanged = 0; |
| 257 | unchanged = av_countf32(od, (size_t)m * OUTW, POISON_F32); |
| 258 | if (unchanged) { omega_gpu_session_set_error("prefill attn256: output poison survived"); rc = OMEGA_GPU_DATTN_CHIP_FAIL; } |
| 259 | else av_memcpy(out, od, (size_t)m * OUTW * 4u); |
| 260 | } |
| 261 | } |
| 262 | UNLOCK(); |
| 263 | #undef UNLOCK |
| 264 | if (info) info->call_ns = omega_gpu_session_now_ns() - t0; |
| 265 | return rc; |
| 266 | } |
| 267 | |
| 268 | int omega_gpu_prefill_attn256(OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0, uint32_t m, |
| 269 | const float *qkv, float eps, float out_scale, float *out, OmegaGpuPrefillAttn256Info *info) { |
| 270 | if (!qkv) return OMEGA_GPU_DATTN_BAD_ARGS; |
| 271 | return core(c, layer, pos0, m, qkv, out, 0, 0, eps, out_scale, info, NULL, 0, NULL); |
| 272 | } |
| 273 | int omega_gpu_prefill_attn256_dev(OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0, uint32_t m, |
| 274 | uint64_t qkv_va, float eps, float out_scale, uint64_t out_va, OmegaGpuPrefillAttn256Info *info) { |
| 275 | return core(c, layer, pos0, m, NULL, NULL, qkv_va, out_va, eps, out_scale, info, NULL, 0, NULL); |
| 276 | } |
| 277 | int omega_gpu_prefill_attn256_record(OmegaGpuCmdList *cl, OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0, |
| 278 | uint32_t m, uint64_t qkv_va, float eps, float out_scale, uint64_t out_va) { |
| 279 | if (!cl) return OMEGA_GPU_DATTN_BAD_ARGS; |
| 280 | return core(c, layer, pos0, m, NULL, NULL, qkv_va, out_va, eps, out_scale, NULL, cl, 0, NULL); |
| 281 | } |
| 282 | |
| 283 | int omega_gpu_prefill_attn256_scoped(OmegaGpuDecodeAttn256Cache *c, uint32_t layer, uint32_t pos0, uint32_t m, |
| 284 | const float *qkv, float eps, float out_scale, float *out, OmegaGpuPrefillAttn256Info *info, |
| 285 | uint32_t mode, uint64_t *copy_ns) { |
| 286 | if (!qkv) return OMEGA_GPU_DATTN_BAD_ARGS; |
| 287 | return core(c, layer, pos0, m, qkv, out, 0, 0, eps, out_scale, info, NULL, mode, copy_ns); |
| 288 | } |