src/kernels/mir_gemm_cm.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | // 16x16x16 cooperative-matrix GEMM MIR builder replacing: | ||
| 4 | // gemm_cm.comp (all 6 dtype variants: f16, bf16, f16_c32, bf16_c32, f32a_w16, f32a_wbf16) | ||
| 5 | // supporting all 4 tile configs, TA/NB layouts, SCALE_A per-row power-of-two scaling, | ||
| 6 | // QB quantized weights (INT8/FP8/Q8_0/Q4_K/Q6_K), DIRECT fragment epilogue, and | ||
| 7 | // shared-scratch general epilogue (STORE/ACCUM/GEGLU/SWIGLU + bias + LACT_*). | ||
| 8 | |||
| 9 | #include "../jit/gpu_mir_emit_detail.h" | ||
| 10 | |||
| 11 | #include <cstdint> | ||
| 12 | |||
| 13 | namespace brotensor::kernels { | ||
| 14 | |||
| 15 | struct GemmCmTile { | ||
| 16 | std::uint32_t bm, bn, bk, wm, wn, wg; | ||
| 17 | }; | ||
| 18 | |||
| 19 | constexpr GemmCmTile kGemmCmTiles[4] = { | ||
| 20 | {256u, 128u, 32u, 64u, 64u, 256u}, | ||
| 21 | {128u, 128u, 32u, 64u, 64u, 128u}, | ||
| 22 | {128u, 64u, 32u, 64u, 32u, 128u}, | ||
| 23 | { 64u, 64u, 32u, 32u, 32u, 128u}, | ||
| 24 | }; | ||
| 25 | |||
| 26 | 105 | struct GemmCmSpec { | |
| 27 | 105 | Dtype dt_a = Dtype::FP16; | |
| 28 | 105 | Dtype dt_b = Dtype::FP16; | |
| 29 | 105 | Dtype dt_c = Dtype::FP16; | |
| 30 | 105 | std::uint32_t cfg_idx = 1; // index into kGemmCmTiles (0..3) | |
| 31 | 105 | std::uint32_t epi = 0; // EPI_* | |
| 32 | 105 | std::uint32_t act = 0; // LACT_* | |
| 33 | 105 | std::uint32_t qb = 0; // 0 or QF_* | |
| 34 | 105 | bool ta = false; | |
| 35 | 105 | bool nb = false; | |
| 36 | 105 | bool vec = true; | |
| 37 | 105 | bool direct = false; | |
| 38 | 105 | bool has_bias = false; | |
| 39 | 105 | bool scale_a = false; | |
| 40 | 105 | bool swizzle = false; // 2D L2 slab swizzle (group_m = 4, disables krot; requires tm0==tn0==0) | |
| 41 | }; | ||
| 42 | |||
| 43 | // Params (18, or 19 with residual ptr at [6] when epi==EPI_RESIDUAL_ADD): | ||
| 44 | // ptrs[0..5]: a, b, c, bias, scale, ascale [, residual] | ||
| 45 | // ints[...]: m, n, k, lda, ldb, ldc, sa, sb, sc, half_n, tm0, tn0 | ||
| 46 | brass::Function* build_gemm_cm_mir(brass::Module& mod, const GemmCmSpec& spec); | ||
| 47 | |||
| 48 | } // namespace brotensor::kernels | ||
| 49 |