src/kernels/mir_fa_bwd_cm.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | // 16x16x16 cooperative-matrix FlashAttention backward MIR builder replacing: | ||
| 4 | // fa_bwd_cm.comp (FP16 / BF16, PASS 0 statistics, PASS 1 dK/dV, PASS 2 dQ, | ||
| 5 | // FA_MODE_{ROWS, VARLEN, PACKED}, optional key mask, VEC=0/1, AREG=0/1, | ||
| 6 | // both 16-lane clustered-layout fast path and layout-agnostic path). | ||
| 7 | |||
| 8 | #include "../jit/gpu_mir_emit_detail.h" | ||
| 9 | |||
| 10 | #include <cstdint> | ||
| 11 | |||
| 12 | namespace brotensor::kernels { | ||
| 13 | |||
| 14 | 9 | struct FaBwdCmSpec { | |
| 15 | 9 | Dtype dt = Dtype::FP16; | |
| 16 | 9 | std::uint32_t hd = 64; | |
| 17 | 9 | std::uint32_t nsg = 2; // 2 or 4 (BO = 16 * nsg, WG = 32 * nsg) | |
| 18 | 9 | std::uint32_t bn = 16; // 16 or 32 | |
| 19 | 9 | std::uint32_t mode = 0; // FA_MODE_* | |
| 20 | 9 | std::uint32_t pass = 0; // 0: stats, 1: dK/dV, 2: dQ | |
| 21 | 9 | bool has_mask = false; | |
| 22 | 9 | bool vec = true; | |
| 23 | 9 | bool areg = true; | |
| 24 | 9 | bool agnostic = false; | |
| 25 | }; | ||
| 26 | |||
| 27 | // Params (21): | ||
| 28 | // ptrs[0..9]: q, k, v, g, mask, aux, aux2, stats, o0, o1 | ||
| 29 | // ints[10..18]: lq, lk, ldq, ldk, ldg, ldo, window, causal, nseq | ||
| 30 | // flts[19..20]: scale (log2(e)/sqrt(hd)), oscale (1/sqrt(hd)) | ||
| 31 | brass::Function* build_fa_bwd_cm_mir(brass::Module& mod, const FaBwdCmSpec& spec); | ||
| 32 | |||
| 33 | } // namespace brotensor::kernels | ||
| 34 |