interplane.Get Omega
Read in your language

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

branch main Branches Tags History

CUDApp / src / omega_blackwell_codegen_pfhost.h

53 lines · 3280 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
2#ifndef OMEGA_BLACKWELL_CODEGEN_PFHOST_H
3#define OMEGA_BLACKWELL_CODEGEN_PFHOST_H
4/*
5 * omega_blackwell_codegen_pfhost: the whole-prompt prefill's former host work on the chip (OWN-30B W-L1G-D, 2026-10-14). New file.
6 * Both kernels reproduce a host loop of the Rust driver (sc qwen3_moe_omega_prefill.rs) BIT FOR BIT: every product is an FMUL
7 * and every sum an FADD (never FFMA), in the host's summation order, so the results equal the host's f32 results exactly.
8 *
9 * ---- router logits (rl) ----
10 * logits[r][ex] = (((-0.0 + w[ex][0] * x[r][0]) + w[ex][1] * x[r][1]) + ...) + w[ex][k-1] * x[r][k-1]
11 * i.e. Rust `router[ex].iter().zip(x[r]).map(|(a, b)| a * b).sum::<f32>()` (a sequential fold from -0.0).
12 * Weights in the PACKED layout R4: wq[g][ex][q] = w[ex][4g + q] (g = 0 .. k/4 - 1), f32, then ONE extra group of e * 4 floats
13 * (any value: the last prefetch reads it, the result never uses it). Total (k/4 + 1) * e * 16 bytes.
14 * x: f32 rows of k (row stride k). Rows 0 .. ceil(rows / t) * t - 1 must be readable (the last CTA reads whole tiles).
15 * logits: f32 rows of e; rows 0 .. ceil(rows / t) * t - 1 are written (rows >= rows hold garbage).
16 * One CTA per t rows (ctaid.x), e threads: thread ex owns expert ex and t accumulators. Per 128-wide chunk of k the CTA stages
17 * the t x 128 activation tile in shared memory (t * 512 bytes), then walks it four k at a time: one LDG.128 of wq (prefetched one
18 * group ahead), one LDS.128 broadcast per row, 4 FMUL + 4 FADD per row.
19 * Arguments (cbank 0x380): x u64, wq u64, logits u64.
20 * mutant (tests only): 1 = FFMA (fused) instead of FMUL + FADD, 2 = the last 128-wide chunk of k is skipped.
21 *
22 * ---- MoE weighted combine (mc) ----
23 * out[r][c] = (((+0.0 + wt[r][0] * down[inv[r][0]][c]) + wt[r][1] * down[inv[r][1]][c]) + ...) (slots 0 .. top_k - 1)
24 * i.e. the driver's combine_rows accumulator (`acc = 0.0; acc += wts[gi] * d` in slot order); the host adds out to x.
25 * down: f32 rows of h (the down GEMM's sorted rows); inv, wt: u32 / f32 [rows][top_k] (row stride top_k, 16-byte aligned rows);
26 * out: f32 rows of h. One CTA per row, h / 4 threads, 4 columns each (LDG.128 per slot).
27 * Arguments (cbank 0x380): down u64, inv u64, wt u64, out u64.
28 * mutant (tests only): 1 = FFMA instead of FMUL + FADD, 2 = the last slot is skipped.
29 *
30 * Builders default to seeded Omega om/codegen/cg_pfhost*.om and checked generic IR replay.
31 * CUDAPP_MIGRATION_PENDING_C_CODEGEN_PFHOST=1 selects the retained C differential oracle.
32 * Public layouts, accepted configurations and function signatures are unchanged.
33 */
34#include <stdint.h>
35#include "omega_blackwell_codegen.h"
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40typedef struct { uint32_t k, e, t; int mutant; } OmegaRlSpec;
41#define OMEGA_RL_ARGS_WORDS 6u
42int omega_rl_spec_ok(const OmegaRlSpec *s);
43uint32_t omega_rl_shared_bytes(const OmegaRlSpec *s);
44int omega_blackwell_codegen_rl_prog(const OmegaRlSpec *s, BlackwellIRProgram *prog);
45
46typedef struct { uint32_t h, top_k; int mutant; } OmegaMcSpec;
47#define OMEGA_MC_ARGS_WORDS 8u
48int omega_mc_spec_ok(const OmegaMcSpec *s);
49int omega_blackwell_codegen_mc_prog(const OmegaMcSpec *s, BlackwellIRProgram *prog);
50#ifdef __cplusplus
51}
52#endif
53#endif