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_blackwell_codegen_moe2.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ |
| 2 | #ifndef OMEGA_BLACKWELL_CODEGEN_MOE2_H |
| 3 | #define OMEGA_BLACKWELL_CODEGEN_MOE2_H |
| 4 | /* |
| 5 | * omega_blackwell_codegen_moe2: FP8 (e4m3) block-scaled GEMV, variant 2 ("row-pipelined"), OWN-30B |
| 6 | * W-L2c (2026-10-14). New file: omega_blackwell_codegen_moe.{c,h} (variant 1) are untouched; the API |
| 7 | * (omega_gpu_fp8_api.c) selects the variant (omega_gpu_fp8_set_variant / AIEN_OMEGA_FP8_GEMV=2). |
| 8 | * |
| 9 | * Same contract as variant 1 (same OmegaFp8GemvSpec, argument words, grid, thread mapping, lane |
| 10 | * mapping, group table, x' / S' folding, mutants) and the SAME ARITHMETIC ORDER per output row: |
| 11 | * per lane, per K step: dot = FFMA chain over its lane_bytes weights (word 0..W-1, byte 0..3); |
| 12 | * acc_r = fma(dot, S'_step, acc_r) in K order; then SHFL.DOWN 16, 8, 4, 2, 1 with FADD. |
| 13 | * so y is bit-identical to variant 1 for every input (checked by the simulator battery and on the chip). |
| 14 | * |
| 15 | * What changes is only WHEN the loads are issued (bytes in flight per warp): |
| 16 | * - a warp's unit of work is a whole row group (rows x k bytes): every weight load and scale load of |
| 17 | * the row group is issued back to back (rows * KS LDG.E.64/128 + KS scale words per lane); |
| 18 | * - two register sets: while the warp decodes and multiplies row group i (set A), the loads of row |
| 19 | * group i + stride (set B) are already in flight on their own scoreboard (SB3). Set A is filled by |
| 20 | * register moves from set B after a single wait on SB3, so the arithmetic never waits on the loads |
| 21 | * of the next row group (variant 1 waits for every load of a step before using any of them, and has |
| 22 | * nothing in flight while it computes); |
| 23 | * - x' (the activation row, shared by every row of the group) is staged once per CTA in shared memory |
| 24 | * (variant 1's deep-kernel staging, BAR.SYNC) and read per word with LDS.128 (4 registers), so the |
| 25 | * global loads a lane keeps in flight are weights and scales only. |
| 26 | * Register sets: 2 x (rows * KS * lane_bytes / 4 + KS) registers, plus ~30. The spec is refused unless |
| 27 | * rows * KS * lane_bytes <= 128 (instruction and register budgets) and k <= 512 * warps (staging rounds). |
| 28 | * The register-file rule (32 * warps * declared <= 65536) is checked by the API as for variant 1; the |
| 29 | * intended shapes are 16 warps per CTA (two CTAs per SM) at the OWN-30B widths k = 768, 2048, 4096. |
| 30 | * |
| 31 | * spec->depth is ignored (the whole row group is always in flight); spec->mutant 1, 2, 3 as variant 1. |
| 32 | */ |
| 33 | #include <stdint.h> |
| 34 | #include "omega_blackwell_codegen_moe.h" |
| 35 | |
| 36 | #ifdef __cplusplus |
| 37 | extern "C" { |
| 38 | #endif |
| 39 | |
| 40 | /* 0 on success (prog solved and register-allocated), -1 on a refused spec or an allocator failure. */ |
| 41 | int omega_blackwell_codegen_fp8_gemv2_prog(const OmegaFp8GemvSpec *spec, BlackwellIRProgram *prog); |
| 42 | |
| 43 | /* 1 if the spec is one this variant builds (shape rules above), 0 otherwise. */ |
| 44 | int omega_fp8_gemv2_spec_ok(const OmegaFp8GemvSpec *spec); |
| 45 | |
| 46 | /* Shared memory bytes the launch must declare: k * 4 (the staged x' row) + 16 (a dummy slot, only when the last staging round is partial). 0 when refused. */ |
| 47 | uint32_t omega_fp8_gemv2_shared_bytes(const OmegaFp8GemvSpec *spec); |
| 48 | |
| 49 | /* Hosted build: allocate and encode (omega_blackwell_kernel_free releases). */ |
| 50 | int omega_blackwell_codegen_fp8_gemv2(const OmegaFp8GemvSpec *spec, OmegaBlackwellKernel *kernel); |
| 51 | |
| 52 | /* The IR instruction count and peak GPR count of the solved program (for budgets in tests). */ |
| 53 | int omega_fp8_gemv2_prog_stats(const OmegaFp8GemvSpec *spec, uint32_t *insns, uint32_t *gprs); |
| 54 | |
| 55 | #ifdef __cplusplus |
| 56 | } |
| 57 | #endif |
| 58 | #endif |