Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/blob/main/src/omega_blackwell_codegen_tc2.h # 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 Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / src / omega_blackwell_codegen_tc2.h` 58 lines · 3761 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ 2 #ifndef OMEGA_BLACKWELL_CODEGEN_TC2_H 3 #define OMEGA_BLACKWELL_CODEGEN_TC2_H 4 /* 5 * omega_blackwell_codegen_tc2: tensor-core grouped FP8 GEMM v2 for the device-resident prefill (OWN-30B T3b, 2026-10-13). 6 * New file. Same fragment layout, weight decode, activation storage ((0,2,1,3)-permuted bf16 * 2^64) and A staging as 7 * cut 1 (omega_blackwell_codegen_tc.h); differences: 8 * - big tiles: up to 16 warps x 16 columns x 128 rows (rt 8, ct 2: 64 accumulator registers per lane); 9 * - the block scale is folded through the accumulator chain: per 128-wide K block kb, acc = acc * R[kb], then the 8 HMMA 10 * steps accumulate straight into acc (no temporary); after the last block acc = acc * R[KB]. R is a per-expert f32 11 * table per 8-row group g of the PHYSICAL weight rows: R[g][0] = 1, R[g][kb] = S'[kb-1] / S'[kb] (RN), R[g][KB] = 12 * S'[KB-1], where S' = scale_inv * 2^56 of the 128-block holding the group's source rows. Stored as pairs 13 * [n/16][KB+1][2] (the warp's two column tiles side by side, one LDG.64 per block: plain LDG.E has no immediate offset); 14 * - rows >= cnt of a partial tile are not stored (one BSSY, forward jumps, one BSYNC); 15 * - epilogue F32: y[row][c] f32 rows of n; epilogue SWIGLU (ct = 2): column tile 0 of each warp is gate, tile 1 up (the 16 * upload interleaves gate and up rows in groups of 8), the lane computes a = g / (1 + ex2(g * -log2e)) * u * 2^64 17 * (MUFU.EX2, FADD, MUFU.RCP, FMUL, FMUL, FMUL x 2^64, in that order; MUFU flushes a subnormal result to +-0, so for 18 * g in (-88.72, -87.34), where 1 / (2^t + 1) is subnormal, the activation is +-0: PTX ISA 9.7.3.13 ftz, chip-observed in 19 * evidence OWN30B-L1G-PFGEMM-SWIGLU-FTZ-`df9bd9c4`) and stores bf16x2 (F2FP RN) at act column n0w/2 + 2t of the 20 * act row (n/2 bf16): with the upload's (0,2,1,3) output-row permutation the act row is directly the next GEMM's 21 * stored activation row; 22 * - direct rows (no row index): the source row of sorted row r is r itself (the down GEMM reading the act rows). 23 * 24 * Tile table entry (32 bytes, ctaid.y): { w_va u64 (expert's n x k e4m3), r_va u64 (expert's (n/8) x (KB+1) f32), row0 u32, 25 * cnt u32 (1 .. 16*rt), pad u64 }. Rows row0 .. row0 + 16*rt - 1 of the row index must be readable (host pads). 26 * Constant bank 0 (cbank + 0x380): tiles u64, rowidx u64 (ignored when direct), x u64, y u64, n u32. 27 * Grid: grid_x = n / span (span = warps * 8 * ct), grid_y = tiles; CTA 32 * warps threads, shared 2 * 16 * rt * 128 bytes. 28 * mutant (tests only): 1 skips the per-block ratio multiply, 2 never advances the ratio pointer, 3 row tile i reads tile 29 * i^1, 4 drops the last 16-element step of every 128 block. 30 */ 31 #include 32 #include "omega_blackwell_codegen.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 enum { OMEGA_TC2_EPI_F32 = 0, OMEGA_TC2_EPI_SWIGLU = 1 }; 38 typedef struct { 39 uint32_t k; /* multiple of 128, 128 .. 16384 */ 40 uint32_t rt; /* row tiles of 16 per CTA: 2, 4 or 8 */ 41 uint32_t ct; /* column tiles of 8 per warp: 2 (the paired ratio load) */ 42 uint32_t warps; /* 4, 8 or 16 */ 43 uint32_t aqn; /* A fragments in flight: 1 or 2 */ 44 uint32_t epi; /* OMEGA_TC2_EPI_* */ 45 uint32_t direct; /* 1: no row index */ 46 uint32_t n; /* output width (weight rows), a multiple of span; fixes the store offsets */ 47 int mutant; 48 } OmegaTc2Spec; 49 #define OMEGA_TC2_ARGS_WORDS 9u 50 #define OMEGA_TC2_TILE_BYTES 32u 51 int omega_tc2_spec_ok(const OmegaTc2Spec *s); 52 uint32_t omega_tc2_shared_bytes(const OmegaTc2Spec *s); 53 uint32_t omega_tc2_span(const OmegaTc2Spec *s); 54 int omega_blackwell_codegen_tc2_prog(const OmegaTc2Spec *s, BlackwellIRProgram *prog); 55 #ifdef __cplusplus 56 } 57 #endif 58 #endif