brotensor/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
10 / 10
100.0%
Branches:
-
-%
Functions:
3 / 3
100.0%

src/kernels/mir_fa_fused_mma.h
Line Branch Exec Source
1 #pragma once
2
3 // Register-only FlashAttention-2 MIR builder (mma.sync.m16n8k16 + ldmatrix +
4 // cp.async + ex2 online softmax, zero S/P shared memory) replacing
5 // flash_attention_fused.cu.
6
7 #include "../jit/gpu_mir_emit_detail.h"
8
9 #include <cstdint>
10
11 namespace brotensor::kernels {
12
13 1 struct FaFusedMmaSpec {
14 1 Dtype dt = Dtype::FP16;
15 1 std::uint32_t hd = 64u;
16 1 bool causal = false;
17 1 bool has_mask = false;
18 1 bool is_split = false;
19 };
20
21 2 inline std::uint32_t fa_fused_pad_hd(std::uint32_t hd) noexcept {
22 2 return ((hd + 15u) / 16u) * 16u;
23 }
24
25 1 inline std::uint32_t fa_fused_bc(std::uint32_t hd) noexcept {
26 1 return (fa_fused_pad_hd(hd) <= 64u) ? 64u : 32u;
27 }
28
29 // BR = 64 (128 threads, 4 warps) across all supported head dims keeps static
30 // shared memory <= 43 KB and eliminates S/P shared memory traffic.
31 inline constexpr std::uint32_t kFaFusedBr = 64u;
32 inline constexpr std::uint32_t kFaFusedThreads = 128u;
33
34 // Params:
35 // ptrs[0..6]: Q, K, V, mask, O, part_o, part_ml
36 // ints[7..14]: Lq, Lk, D, Dkv, group, splits, qtiles, heads
37 // flts[15]: scale_log2
38 brass::Function* build_fa_fused_mma_mir(brass::Module& mod, const FaFusedMmaSpec& spec);
39
40 } // namespace brotensor::kernels
41