brotensor/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
49 / 49
100.0%
Branches:
32 / 60
53.3%
Functions:
10 / 10
100.0%

src/backward_shader_audit_extra.cpp
Line Branch Exec Source
1 #include <brotensor/tensor.h>
2
3 #if BROTENSOR_HAS_BRASS_JIT
4 #include "kernels/mir_conv_cm.h"
5 #include "kernels/mir_conv_direct.h"
6 #include "kernels/mir_fa_cm.h"
7 #include "kernels/mir_gemm_cm.h"
8 #include "kernels/mir_gemm_simt.h"
9 #include "vulkan/shaders/op_codes.h"
10 #include <brass/mir/function.hpp>
11 #include <brass/mir/module.hpp>
12 #include <brass/target/spirv_target.hpp>
13
14 #include <functional>
15 #include <string>
16
17 namespace brotensor::verify::extra_audit {
18
19 1 void audit_extra_mir_kernels(
20 const brass::target::SpirvOptions& spv_opts,
21 const std::function<void(const char*, const brass::target::SpirvOptions&,
22 const std::function<brass::Function*(brass::Module&)>&, bool)>& audit_mir_opts) {
23 1 brass::target::SpirvOptions cm_opts = spv_opts;
24 1 cm_opts.local_size_x = 128u;
25
26 // GemmCm swizzle + EPI_RESIDUAL_ADD (direct and shared-scratch epilogue)
27 {
28 1 kernels::GemmCmSpec s;
29 1 s.dt_a = Dtype::FP16; s.dt_b = Dtype::FP16; s.dt_c = Dtype::FP16;
30 1 s.cfg_idx = 1u; s.epi = EPI_STORE; s.direct = true; s.swizzle = true; s.has_bias = true;
31
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
2 audit_mir_opts("gemm_cm_f16_swizzle", cm_opts,
32 2 [s](brass::Module& m) { return kernels::build_gemm_cm_mir(m, s); }, false);
33 }
34 {
35 1 kernels::GemmCmSpec s;
36 1 s.dt_a = Dtype::FP16; s.dt_b = Dtype::FP16; s.dt_c = Dtype::FP16;
37 1 s.cfg_idx = 1u; s.epi = EPI_RESIDUAL_ADD; s.direct = true; s.has_bias = true;
38
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
2 audit_mir_opts("gemm_cm_f16_residual_direct", cm_opts,
39 2 [s](brass::Module& m) { return kernels::build_gemm_cm_mir(m, s); }, false);
40 }
41 {
42 1 kernels::GemmCmSpec s;
43 1 s.dt_a = Dtype::BF16; s.dt_b = Dtype::BF16; s.dt_c = Dtype::BF16;
44 1 s.cfg_idx = 1u; s.epi = EPI_RESIDUAL_ADD; s.direct = false; s.has_bias = true; s.scale_a = true;
45
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
2 audit_mir_opts("gemm_cm_bf16_residual", cm_opts,
46 2 [s](brass::Module& m) { return kernels::build_gemm_cm_mir(m, s); }, false);
47 }
48
49 // FaCm head_swizzle + softcap
50 {
51 1 brass::target::SpirvOptions cm64_opts = spv_opts;
52 1 cm64_opts.local_size_x = 64u;
53 1 kernels::FaCmSpec s;
54 1 s.dt = Dtype::FP16; s.hd = 64u; s.bc = 16u; s.nsg = 2u;
55 1 s.has_mask = true; s.head_swizzle = true; s.has_softcap = true;
56
2/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
2 audit_mir_opts("fa_cm_f16_swizzle_softcap", cm64_opts,
57 2 [s](brass::Module& m) { return kernels::build_fa_cm_mir(m, s); }, false);
58 }
59
60 // GemmSimt fused EPI_SWIGLU (FP32/FP16/BF16) and EPI_RESIDUAL_ADD
61
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
9 for (const auto& [sfx, dt] : std::vector<std::pair<const char*, Dtype>>{
62 3 {"_f32", Dtype::FP32}, {"_f16", Dtype::FP16}, {"_bf16", Dtype::BF16}}) {
63
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 const std::string sw_name = std::string("gemm_simt_swiglu") + sfx;
64
3/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
9 audit_mir_opts(sw_name.c_str(), spv_opts, [dt](brass::Module& m) {
65 3 return kernels::build_gemm_simt_mir(m, dt, dt, dt, dt, false, EPI_SWIGLU, 0u, false, false, true);
66 }, false);
67
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 const std::string res_name = std::string("gemm_simt_residual") + sfx;
68
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
9 audit_mir_opts(res_name.c_str(), spv_opts, [dt](brass::Module& m) {
69 3 return kernels::build_gemm_simt_mir(m, dt, dt, dt, dt, false, EPI_RESIDUAL_ADD, LACT_SILU, false, false, true);
70 }, false);
71 3 }
72
73 // ConvCm / ConvSimt / ConvDirect fused activations
74
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
6 for (const auto& [asfx, act] : std::vector<std::pair<const char*, std::uint32_t>>{
75 2 {"_silu", LACT_SILU}, {"_gelu", LACT_GELU_EXACT}}) {
76 {
77 2 kernels::ConvCmSpec s;
78 4 s.dt = Dtype::FP16; s.cfg_idx = 2u; s.has_bias = true; s.act = act;
79
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 const std::string n = std::string("conv_cm_f16") + asfx;
80
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 audit_mir_opts(n.c_str(), cm_opts,
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
4 [s](brass::Module& m) { return kernels::build_conv_cm_mir(m, s); }, false);
82 2 }
83 {
84
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 const std::string n = std::string("conv_simt_f32") + asfx;
85
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
6 audit_mir_opts(n.c_str(), spv_opts, [act](brass::Module& m) {
86 2 return kernels::build_conv_simt_mir(m, Dtype::FP32, false, false, true, 3, 3, 1, 1, 1, 1, 1, 1, act);
87 }, false);
88 2 }
89 }
90
1/2
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
2 audit_mir_opts("conv_direct_f32_silu", spv_opts, [](brass::Module& m) {
91 1 return kernels::build_conv_direct_mir(m, (LACT_SILU << 4), Dtype::FP32, true);
92 }, false);
93 1 }
94
95 } // namespace brotensor::verify::extra_audit
96 #endif
97