| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#include "mir_gemv_q.h" |
| 2 |
|
|
|
| 3 |
|
|
#include "mir_common.h" |
| 4 |
|
|
#include "mir_math.h" |
| 5 |
|
|
#include "mir_quant_helpers.h" |
| 6 |
|
|
#include "../vulkan/shaders/op_codes.h" |
| 7 |
|
|
|
| 8 |
|
|
#include <algorithm> |
| 9 |
|
|
#include <stdexcept> |
| 10 |
|
|
#include <string> |
| 11 |
|
|
#include <vector> |
| 12 |
|
|
|
| 13 |
|
|
namespace brotensor::kernels { |
| 14 |
|
|
|
| 15 |
|
|
namespace { |
| 16 |
|
|
|
| 17 |
|
604 |
std::vector<Value*> load_x_slice8(Ctx& c, Dtype dt, Value* base, Value* elem_idx, int count, bool aligned_vec) { |
| 18 |
2/4
✓ Branch 0 taken 604 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 604 times.
|
604 |
if (aligned_vec && count == 8) { |
| 19 |
|
604 |
return load_lanes(c, dt, 8, ptr_at(c, base, elem_idx, 2)); |
| 20 |
|
|
} |
| 21 |
|
✗ |
std::vector<Value*> out(static_cast<std::size_t>(count)); |
| 22 |
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
✗ |
for (int e = 0; e < count; ++e) { |
| 23 |
0/6
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
✗ |
out[static_cast<std::size_t>(e)] = load_elem_dt(c, dt, base, c.b.build_add(elem_idx, c.i32(e))); |
| 24 |
|
✗ |
} |
| 25 |
|
✗ |
return out; |
| 26 |
|
604 |
} |
| 27 |
|
|
|
| 28 |
|
24 |
std::vector<Value*> load_u16_bytes(Ctx& c, Value* ptr, int nu16) { |
| 29 |
|
24 |
std::vector<Value*> bytes(static_cast<std::size_t>(nu16 * 2)); |
| 30 |
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 288 times.
|
312 |
for (int i = 0; i < nu16; ++i) { |
| 31 |
4/6
✓ Branch 0 taken 264 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 264 times.
✗ Branch 5 not taken.
|
288 |
Value* p_i = (i == 0) ? ptr : c.b.build_add(ptr, c.kb.const_i64(i * 2)); |
| 32 |
1/2
✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
|
288 |
Value* u = c.kb.load_u16(p_i); |
| 33 |
2/4
✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 288 times.
✗ Branch 3 not taken.
|
288 |
bytes[static_cast<std::size_t>(2 * i)] = c.b.build_and(u, c.i32(0xff)); |
| 34 |
2/4
✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 288 times.
✗ Branch 3 not taken.
|
288 |
bytes[static_cast<std::size_t>(2 * i + 1)] = c.b.build_lshr(u, c.i32(8)); |
| 35 |
|
288 |
} |
| 36 |
|
24 |
return bytes; |
| 37 |
|
24 |
} |
| 38 |
|
|
|
| 39 |
|
|
} // namespace |
| 40 |
|
|
|
| 41 |
|
48 |
brass::Function* build_gemv_q_mir(brass::Module& mod, Dtype dt, std::uint32_t fmt, |
| 42 |
|
|
std::uint32_t mb, std::uint32_t lpr, bool vec, bool has_bias, |
| 43 |
|
|
std::uint32_t unr, std::uint32_t nr, |
| 44 |
|
|
std::uint32_t act, std::uint32_t epi) { |
| 45 |
3/4
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
|
48 |
if (dt != Dtype::FP16 && dt != Dtype::BF16) { |
| 46 |
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
✗ |
throw std::runtime_error("brotensor: mir_gemv_q: only FP16 and BF16 activations are supported"); |
| 47 |
|
|
} |
| 48 |
5/6
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 36 times.
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 34 times.
|
48 |
if (mb < 1u || mb > 8u || (lpr != 16u && lpr != 32u && lpr != 64u) || nr < 1u || nr > 8u) { |
| 49 |
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
✗ |
throw std::runtime_error("brotensor: mir_gemv_q: invalid geometry"); |
| 50 |
|
|
} |
| 51 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 46 times.
|
48 |
const bool glu = (epi == EPI_GEGLU || epi == EPI_SWIGLU); |
| 52 |
3/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
48 |
if (glu && (nr < 2u || (nr & 1u) != 0u)) { |
| 53 |
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
✗ |
throw std::runtime_error("brotensor: mir_gemv_q: GLU epilogue requires even nr >= 2"); |
| 54 |
|
|
} |
| 55 |
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 29 times.
|
48 |
const bool byte_fmt = (fmt == QF_INT8 || fmt == QF_FP8); |
| 56 |
7/8
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
48 |
if (!byte_fmt && fmt != QF_Q8_0 && fmt != QF_Q4K && fmt != QF_Q6K) { |
| 57 |
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
✗ |
throw std::runtime_error("brotensor: mir_gemv_q: unknown quant format"); |
| 58 |
|
|
} |
| 59 |
4/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 4 times.
|
48 |
const std::uint32_t eff_unr = (byte_fmt && !vec) ? 1u : std::max(1u, unr); |
| 60 |
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
96 |
const std::string name = std::string("mir_gemv_q_") + (dt == Dtype::FP16 ? "f16" : "bf16") + |
| 61 |
6/12
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
|
48 |
"_fmt" + std::to_string(fmt) + "_m" + std::to_string(mb) + |
| 62 |
6/10
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 44 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
|
48 |
"_l" + std::to_string(lpr) + (vec ? "_v" : "_s") + |
| 63 |
4/8
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
|
48 |
(has_bias ? "_b" : "") + "_u" + std::to_string(eff_unr) + |
| 64 |
6/12
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
|
48 |
"_r" + std::to_string(nr) + "_a" + std::to_string(act) + |
| 65 |
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 |
"_e" + std::to_string(epi); |
| 66 |
|
|
|
| 67 |
10/20
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 48 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 48 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 48 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 48 times.
✗ Branch 19 not taken.
|
480 |
std::vector<Type> params = { |
| 68 |
|
240 |
Type::ptr(), Type::ptr(), Type::ptr(), Type::ptr(), Type::ptr(), |
| 69 |
|
240 |
Type::i32(), Type::i32(), Type::i32(), Type::i32(), Type::i32(), |
| 70 |
|
|
}; |
| 71 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
Function* fn = mod.create_function(name, Type::void_type(), brass::Span<const Type>(params)); |
| 72 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
brass::codegen::KernelBuilder kb(mod, fn); |
| 73 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
Ctx c(kb); |
| 74 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
auto p = entry_params(c, fn); |
| 75 |
|
|
// p[0..4] = x, w, y, bias, scale; p[5..9] = n, k, ldx, ldy, rowbytes |
| 76 |
|
|
|
| 77 |
|
48 |
const std::uint32_t ng = 256u / lpr; |
| 78 |
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 46 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
48 |
Value* s_part = (lpr == 64u) ? kb.shared_alloc_f32(ng * 2u * nr * mb) : nullptr; |
| 79 |
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 30 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
48 |
Value* s_fp8 = (fmt == QF_FP8) ? kb.shared_alloc_f32(256u) : nullptr; |
| 80 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
Value* tid = kb.tid_x(); |
| 81 |
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 30 times.
|
48 |
if (s_fp8) { |
| 82 |
2/4
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
|
18 |
kb.shared_store_f32_indexed(s_fp8, tid, emit_fp8_e4m3_to_f32(c, tid)); |
| 83 |
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 |
kb.sync(); |
| 84 |
|
18 |
} |
| 85 |
|
2168 |
auto decode_byte = [&](Value* qb) -> Value* { |
| 86 |
2/2
✓ Branch 0 taken 1028 times.
✓ Branch 1 taken 1092 times.
|
2120 |
if (s_fp8) return kb.shared_load_f32_indexed(s_fp8, c.b.build_and(qb, c.i32(0xff))); |
| 87 |
|
1092 |
return emit_s8_byte_to_f32(c, qb); |
| 88 |
|
2120 |
}; |
| 89 |
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 |
Value* unit = c.b.build_udiv(tid, c.i32(static_cast<int>(lpr))); |
| 90 |
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 |
Value* lane = c.b.build_umod(tid, c.i32(static_cast<int>(lpr))); |
| 91 |
5/10
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
|
48 |
Value* wg = c.b.build_add(kb.ctaid_x(), c.b.build_mul(kb.ctaid_y(), kb.nctaid_x())); |
| 92 |
3/6
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
|
48 |
Value* rowgroup = c.b.build_add(c.b.build_mul(wg, c.i32(static_cast<int>(ng))), unit); |
| 93 |
|
|
|
| 94 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
std::vector<Value*> wrow(nr); |
| 95 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
std::vector<Value*> row_ok(nr); |
| 96 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 42 times.
|
48 |
if (epi == EPI_SWIGLU) { |
| 97 |
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 |
Value* half_n = c.b.build_lshr(p[5], c.i32(1)); |
| 98 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
|
12 |
for (std::uint32_t q = 0; q < nr / 2u; ++q) { |
| 99 |
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
12 |
Value* oc = c.b.build_add(c.b.build_mul(rowgroup, c.i32(static_cast<int>(nr / 2u))), |
| 100 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 |
c.i32(static_cast<int>(q))); |
| 101 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 |
Value* ok = c.b.build_ult(oc, half_n); |
| 102 |
|
6 |
wrow[2u * q] = oc; |
| 103 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 |
wrow[2u * q + 1u] = c.b.build_add(oc, half_n); |
| 104 |
|
6 |
row_ok[2u * q] = ok; |
| 105 |
|
6 |
row_ok[2u * q + 1u] = ok; |
| 106 |
|
6 |
} |
| 107 |
|
6 |
} else { |
| 108 |
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 42 times.
|
130 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 109 |
3/6
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 88 times.
✗ Branch 5 not taken.
|
176 |
wrow[r] = c.b.build_add(c.b.build_mul(rowgroup, c.i32(static_cast<int>(nr))), |
| 110 |
1/2
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 |
c.i32(static_cast<int>(r))); |
| 111 |
1/2
✓ Branch 0 taken 88 times.
✗ Branch 1 not taken.
|
88 |
row_ok[r] = c.b.build_ult(wrow[r], p[5]); |
| 112 |
|
88 |
} |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
2/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
|
48 |
std::vector<Value*> acc_init(nr * mb, c.f32(0.0f)); |
| 116 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
std::vector<Value*> acc = emit_if_else_values( |
| 117 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
c, row_ok[0], std::vector<Type>(nr * mb, Type::f32()), |
| 118 |
|
96 |
[&]() -> std::vector<Value*> { |
| 119 |
|
48 |
std::vector<Value*> row_ptrs(nr); |
| 120 |
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 100 times.
|
148 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 121 |
3/4
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
|
100 |
Value* safe_r = (r == 0) ? wrow[0] : c.b.build_select(row_ok[r], wrow[r], wrow[0]); |
| 122 |
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
|
200 |
row_ptrs[r] = c.b.build_add( |
| 123 |
3/6
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
100 |
p[1], c.b.build_mul(c.b.build_zext_i64(safe_r), c.b.build_zext_i64(p[9]))); |
| 124 |
|
100 |
} |
| 125 |
|
|
|
| 126 |
4/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 33 times.
|
48 |
if (byte_fmt && !vec) { |
| 127 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
8 |
std::vector<Value*> res = kb.for_range_reduce_n( |
| 128 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 |
lane, p[6], c.i32(static_cast<int>(lpr)), acc_init, |
| 129 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
8 |
[&](Value* col, const std::vector<Value*>& cur) -> std::vector<Value*> { |
| 130 |
|
4 |
std::vector<Value*> next = cur; |
| 131 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 |
std::vector<Value*> xv(mb); |
| 132 |
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 4 times.
|
13 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 133 |
4/8
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 9 times.
✗ Branch 7 not taken.
|
9 |
xv[b] = load_elem_dt(c, dt, p[0], c.b.build_add(c.b.build_mul(c.i32(static_cast<int>(b)), p[7]), col)); |
| 134 |
|
9 |
} |
| 135 |
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 136 |
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 |
Value* qb = kb.load_u8(c.b.build_add(row_ptrs[r], c.b.build_zext_i64(col))); |
| 137 |
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 |
Value* wv = decode_byte(qb); |
| 138 |
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 18 times.
|
26 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 139 |
|
18 |
std::size_t idx = r * mb + b; |
| 140 |
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 |
next[idx] = c.b.build_fma_f32(xv[b], wv, next[idx]); |
| 141 |
|
18 |
} |
| 142 |
|
8 |
} |
| 143 |
|
4 |
return next; |
| 144 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 |
}); |
| 145 |
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 8 times.
|
12 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 146 |
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
8 |
Value* safe_r = (r == 0) ? wrow[0] : c.b.build_select(row_ok[r], wrow[r], wrow[0]); |
| 147 |
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 |
Value* sc = kb.load_f32(ptr_at(c, p[4], safe_r, 4)); |
| 148 |
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
|
26 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 149 |
|
18 |
std::size_t idx = r * mb + b; |
| 150 |
1/2
✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
|
18 |
res[idx] = c.b.build_mul(res[idx], sc); |
| 151 |
|
18 |
} |
| 152 |
|
8 |
} |
| 153 |
|
4 |
return res; |
| 154 |
|
4 |
} |
| 155 |
|
|
|
| 156 |
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 11 times.
|
44 |
const int ie_shift = (byte_fmt || fmt == QF_Q8_0) ? 4 : 5; |
| 157 |
2/4
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 44 times.
✗ Branch 3 not taken.
|
44 |
Value* nitems = c.b.build_lshr(p[6], c.i32(ie_shift)); |
| 158 |
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
88 |
std::vector<Value*> res = kb.for_range_reduce_n( |
| 159 |
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 |
lane, nitems, c.i32(static_cast<int>(lpr * eff_unr)), acc_init, |
| 160 |
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
88 |
[&](Value* c0, const std::vector<Value*>& cur) -> std::vector<Value*> { |
| 161 |
|
44 |
std::vector<Value*> next = cur; |
| 162 |
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 11 times.
|
44 |
if (byte_fmt) { |
| 163 |
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 |
std::vector<Value*> ok_fs(eff_unr); |
| 164 |
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 |
std::vector<Value*> col_elems(eff_unr); |
| 165 |
1/2
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
|
33 |
std::vector<Value*> wv_all(eff_unr * nr); |
| 166 |
|
|
// Issue all eff_unr * nr weight vector loads up front so they overlap in flight. |
| 167 |
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 33 times.
|
103 |
for (std::uint32_t u = 0; u < eff_unr; ++u) { |
| 168 |
4/6
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
|
70 |
Value* col_u = (u == 0) ? c0 : c.b.build_add(c0, c.i32(static_cast<int>(u * lpr))); |
| 169 |
4/6
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
|
70 |
Value* in_k = (u == 0) ? c.i32(1) : c.b.build_ult(col_u, nitems); |
| 170 |
3/4
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 37 times.
✗ Branch 3 not taken.
|
70 |
Value* cc = (u == 0) ? c0 : c.b.build_select(in_k, col_u, c0); |
| 171 |
6/10
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 37 times.
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 37 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 37 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 37 times.
✗ Branch 9 not taken.
|
70 |
ok_fs[u] = (u == 0) ? c.f32(1.0f) : c.b.build_select(in_k, c.f32(1.0f), c.f32(0.0f)); |
| 172 |
2/4
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 70 times.
✗ Branch 3 not taken.
|
70 |
col_elems[u] = c.b.build_shl(cc, c.i32(ie_shift)); |
| 173 |
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 |
Value* col_off64 = c.b.build_zext_i64(col_elems[u]); |
| 174 |
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 70 times.
|
202 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 175 |
2/4
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
|
132 |
wv_all[u * nr + r] = kb.vload(Type::i32x4(), c.b.build_add(row_ptrs[r], col_off64)); |
| 176 |
|
132 |
} |
| 177 |
|
70 |
} |
| 178 |
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 33 times.
|
103 |
for (std::uint32_t u = 0; u < eff_unr; ++u) { |
| 179 |
1/2
✓ Branch 0 taken 70 times.
✗ Branch 1 not taken.
|
70 |
std::vector<std::vector<Value*>> xs(mb); |
| 180 |
2/2
✓ Branch 0 taken 262 times.
✓ Branch 1 taken 70 times.
|
332 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 181 |
3/6
✓ Branch 0 taken 262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 262 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 262 times.
✗ Branch 5 not taken.
|
262 |
Value* xi = c.b.build_add(c.b.build_mul(c.i32(static_cast<int>(b)), p[7]), col_elems[u]); |
| 182 |
1/2
✓ Branch 0 taken 262 times.
✗ Branch 1 not taken.
|
262 |
auto lo = load_x_slice8(c, dt, p[0], xi, 8, true); |
| 183 |
3/6
✓ Branch 0 taken 262 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 262 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 262 times.
✗ Branch 5 not taken.
|
262 |
auto hi = load_x_slice8(c, dt, p[0], c.b.build_add(xi, c.i32(8)), 8, true); |
| 184 |
1/2
✓ Branch 0 taken 262 times.
✗ Branch 1 not taken.
|
262 |
lo.insert(lo.end(), hi.begin(), hi.end()); |
| 185 |
|
262 |
xs[b] = std::move(lo); |
| 186 |
|
262 |
} |
| 187 |
2/2
✓ Branch 0 taken 70 times.
✓ Branch 1 taken 132 times.
|
202 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 188 |
|
132 |
Value* wv128 = wv_all[u * nr + r]; |
| 189 |
|
132 |
Value* w4[4] = { |
| 190 |
2/4
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
|
132 |
c.b.build_vextract_lane(wv128, 0), c.b.build_vextract_lane(wv128, 1), |
| 191 |
2/4
✓ Branch 0 taken 132 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
|
132 |
c.b.build_vextract_lane(wv128, 2), c.b.build_vextract_lane(wv128, 3), |
| 192 |
|
|
}; |
| 193 |
|
|
Value* wvals[16]; |
| 194 |
2/2
✓ Branch 0 taken 2112 times.
✓ Branch 1 taken 132 times.
|
2244 |
for (int e = 0; e < 16; ++e) { |
| 195 |
4/8
✓ Branch 0 taken 2112 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2112 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2112 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2112 times.
✗ Branch 7 not taken.
|
2112 |
Value* qb = c.b.build_and(c.b.build_lshr(w4[e >> 2], c.i32((e & 3) * 8)), c.i32(0xff)); |
| 196 |
1/2
✓ Branch 0 taken 2112 times.
✗ Branch 1 not taken.
|
2112 |
wvals[e] = decode_byte(qb); |
| 197 |
|
2112 |
} |
| 198 |
2/2
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 516 times.
|
648 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 199 |
1/2
✓ Branch 0 taken 516 times.
✗ Branch 1 not taken.
|
516 |
Value* dot = c.f32(0.0f); |
| 200 |
3/4
✓ Branch 0 taken 8256 times.
✓ Branch 1 taken 516 times.
✓ Branch 2 taken 8256 times.
✗ Branch 3 not taken.
|
8772 |
for (int e = 0; e < 16; ++e) dot = c.b.build_fma_f32(xs[b][e], wvals[e], dot); |
| 201 |
|
516 |
std::size_t idx = r * mb + b; |
| 202 |
3/4
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 260 times.
✓ Branch 2 taken 256 times.
✗ Branch 3 not taken.
|
776 |
next[idx] = (u == 0) ? c.b.build_add(next[idx], dot) |
| 203 |
1/2
✓ Branch 0 taken 260 times.
✗ Branch 1 not taken.
|
260 |
: c.b.build_fma_f32(dot, ok_fs[u], next[idx]); |
| 204 |
|
516 |
} |
| 205 |
|
132 |
} |
| 206 |
|
70 |
} |
| 207 |
|
33 |
return next; |
| 208 |
|
33 |
} |
| 209 |
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 14 times.
|
25 |
for (std::uint32_t u = 0; u < eff_unr; ++u) { |
| 210 |
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
14 |
Value* col_u = (u == 0) ? c0 : c.b.build_add(c0, c.i32(static_cast<int>(u * lpr))); |
| 211 |
4/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
14 |
Value* in_k = (u == 0) ? c.i32(1) : c.b.build_ult(col_u, nitems); |
| 212 |
3/4
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
14 |
Value* cc = (u == 0) ? c0 : c.b.build_select(in_k, col_u, c0); |
| 213 |
6/10
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
14 |
Value* ok_f = (u == 0) ? c.f32(1.0f) : c.b.build_select(in_k, c.f32(1.0f), c.f32(0.0f)); |
| 214 |
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
14 |
Value* col_elem = c.b.build_shl(cc, c.i32(ie_shift)); |
| 215 |
|
|
|
| 216 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 8 times.
|
14 |
if (fmt == QF_Q8_0) { |
| 217 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 |
std::vector<std::vector<Value*>> xs(mb); |
| 218 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
|
18 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 219 |
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
12 |
Value* xi = c.b.build_add(c.b.build_mul(c.i32(static_cast<int>(b)), p[7]), col_elem); |
| 220 |
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 |
auto lo = load_x_slice8(c, dt, p[0], xi, 8, true); |
| 221 |
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
12 |
auto hi = load_x_slice8(c, dt, p[0], c.b.build_add(xi, c.i32(8)), 8, true); |
| 222 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 |
lo.insert(lo.end(), hi.begin(), hi.end()); |
| 223 |
|
12 |
xs[b] = std::move(lo); |
| 224 |
|
12 |
} |
| 225 |
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 |
Value* blk_idx = c.b.build_lshr(cc, c.i32(1)); |
| 226 |
4/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
|
6 |
Value* half_off = c.b.build_shl(c.b.build_and(cc, c.i32(1)), c.i32(4)); |
| 227 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
|
18 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 228 |
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
24 |
Value* blk = c.b.build_add( |
| 229 |
3/6
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
|
12 |
row_ptrs[r], c.b.build_mul(c.b.build_zext_i64(blk_idx), kb.const_i64(34))); |
| 230 |
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
12 |
Value* d = kb.f16_to_f32(kb.load_u16(blk)); |
| 231 |
4/8
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
|
12 |
Value* qp = c.b.build_add(blk, c.b.build_zext_i64(c.b.build_add(c.i32(2), half_off))); |
| 232 |
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 |
auto bytes = load_u16_bytes(c, qp, 8); |
| 233 |
|
|
Value* wvals[16]; |
| 234 |
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
|
204 |
for (int e = 0; e < 16; ++e) wvals[e] = emit_s8_byte_to_f32(c, bytes[e]); |
| 235 |
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 |
Value* d_ok = c.b.build_mul(d, ok_f); |
| 236 |
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 24 times.
|
36 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 237 |
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 |
Value* dot = c.f32(0.0f); |
| 238 |
3/4
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 384 times.
✓ Branch 2 taken 384 times.
✗ Branch 3 not taken.
|
408 |
for (int e = 0; e < 16; ++e) dot = c.b.build_fma_f32(xs[b][e], wvals[e], dot); |
| 239 |
|
24 |
std::size_t idx = r * mb + b; |
| 240 |
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 |
next[idx] = c.b.build_fma_f32(dot, d_ok, next[idx]); |
| 241 |
|
24 |
} |
| 242 |
|
12 |
} |
| 243 |
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 3 times.
|
14 |
} else if (fmt == QF_Q4K) { |
| 244 |
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 |
std::vector<std::vector<Value*>> xs(mb); |
| 245 |
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 8 times.
|
13 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 246 |
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 |
xs[b].reserve(32); |
| 247 |
3/6
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
✗ Branch 5 not taken.
|
8 |
Value* xi = c.b.build_add(c.b.build_mul(c.i32(static_cast<int>(b)), p[7]), col_elem); |
| 248 |
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
|
40 |
for (int ch = 0; ch < 32; ch += 8) { |
| 249 |
3/6
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 32 times.
✗ Branch 5 not taken.
|
32 |
auto sl = load_x_slice8(c, dt, p[0], c.b.build_add(xi, c.i32(ch)), 8, true); |
| 250 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 |
xs[b].insert(xs[b].end(), sl.begin(), sl.end()); |
| 251 |
|
32 |
} |
| 252 |
|
8 |
} |
| 253 |
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 |
std::vector<Value*> sum_x(mb); |
| 254 |
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 8 times.
|
13 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 255 |
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 |
Value* s = c.f32(0.0f); |
| 256 |
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 256 times.
✓ Branch 2 taken 256 times.
✗ Branch 3 not taken.
|
264 |
for (int e = 0; e < 32; ++e) s = c.b.build_add(s, xs[b][e]); |
| 257 |
|
8 |
sum_x[b] = s; |
| 258 |
|
8 |
} |
| 259 |
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 |
Value* sb = c.b.build_lshr(cc, c.i32(3)); |
| 260 |
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 |
Value* j = c.b.build_and(cc, c.i32(7)); |
| 261 |
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 |
Value* low_j = c.b.build_ult(j, c.i32(4)); |
| 262 |
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 |
Value* j4 = c.b.build_add(j, c.i32(4)); |
| 263 |
2/4
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 |
Value* jm4 = c.b.build_sub(j, c.i32(4)); |
| 264 |
6/12
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 5 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 5 times.
✗ Branch 11 not taken.
|
5 |
Value* q_off = c.b.build_add(c.i32(16), c.b.build_shl(c.b.build_lshr(j, c.i32(1)), c.i32(5))); |
| 265 |
4/8
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✗ Branch 7 not taken.
|
5 |
Value* sh = c.b.build_shl(c.b.build_and(j, c.i32(1)), c.i32(2)); |
| 266 |
|
|
|
| 267 |
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 5 times.
|
21 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 268 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
32 |
Value* blk = c.b.build_add( |
| 269 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 |
row_ptrs[r], c.b.build_mul(c.b.build_zext_i64(sb), kb.const_i64(144))); |
| 270 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 |
Value* hdr = kb.vload(Type::i32x4(), blk); |
| 271 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 |
Value* a0 = c.b.build_vextract_lane(hdr, 0); |
| 272 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 |
Value* s0 = c.b.build_vextract_lane(hdr, 1); |
| 273 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 |
Value* s1 = c.b.build_vextract_lane(hdr, 2); |
| 274 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 |
Value* s2 = c.b.build_vextract_lane(hdr, 3); |
| 275 |
4/8
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
|
16 |
Value* bs_j = emit_extract_byte(c, emit_sel_word3(c, c.b.build_lshr(j, c.i32(2)), s0, s1, s2), j); |
| 276 |
4/8
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
|
16 |
Value* bs_j4 = emit_extract_byte(c, emit_sel_word3(c, c.b.build_lshr(j4, c.i32(2)), s0, s1, s2), j4); |
| 277 |
4/8
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
|
16 |
Value* bs_jm4 = emit_extract_byte(c, emit_sel_word3(c, c.b.build_lshr(jm4, c.i32(2)), s0, s1, s2), jm4); |
| 278 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
32 |
Value* sc = c.b.build_select( |
| 279 |
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 |
low_j, c.b.build_and(bs_j, c.i32(63)), |
| 280 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
32 |
c.b.build_or(c.b.build_and(bs_j4, c.i32(15)), |
| 281 |
4/8
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
|
16 |
c.b.build_shl(c.b.build_lshr(bs_jm4, c.i32(6)), c.i32(4)))); |
| 282 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
32 |
Value* mn = c.b.build_select( |
| 283 |
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 |
low_j, c.b.build_and(bs_j4, c.i32(63)), |
| 284 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
32 |
c.b.build_or(c.b.build_lshr(bs_j4, c.i32(4)), |
| 285 |
4/8
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 16 times.
✗ Branch 7 not taken.
|
16 |
c.b.build_shl(c.b.build_lshr(bs_j, c.i32(6)), c.i32(4)))); |
| 286 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 |
Value* d = kb.f16_to_f32(c.b.build_and(a0, c.i32(0xffff))); |
| 287 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 |
Value* dmin = kb.f16_to_f32(c.b.build_lshr(a0, c.i32(16))); |
| 288 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 |
Value* ws = c.b.build_mul(c.b.build_mul(kb.u32_to_f32(sc), d), ok_f); |
| 289 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 |
Value* wm = c.b.build_mul(c.b.build_mul(kb.u32_to_f32(mn), dmin), ok_f); |
| 290 |
|
|
|
| 291 |
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 |
Value* q_base = c.b.build_add(blk, c.b.build_zext_i64(q_off)); |
| 292 |
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
|
16 |
Value* qv0 = kb.vload(Type::i32x4(), q_base); |
| 293 |
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 16 times.
✗ Branch 5 not taken.
|
16 |
Value* qv1 = kb.vload(Type::i32x4(), c.b.build_add(q_base, kb.const_i64(16))); |
| 294 |
|
16 |
Value* qw[8] = { |
| 295 |
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 |
c.b.build_vextract_lane(qv0, 0), c.b.build_vextract_lane(qv0, 1), |
| 296 |
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 |
c.b.build_vextract_lane(qv0, 2), c.b.build_vextract_lane(qv0, 3), |
| 297 |
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 |
c.b.build_vextract_lane(qv1, 0), c.b.build_vextract_lane(qv1, 1), |
| 298 |
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
|
16 |
c.b.build_vextract_lane(qv1, 2), c.b.build_vextract_lane(qv1, 3), |
| 299 |
|
|
}; |
| 300 |
|
|
Value* qvals[32]; |
| 301 |
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 16 times.
|
528 |
for (int e = 0; e < 32; ++e) { |
| 302 |
1/2
✓ Branch 0 taken 512 times.
✗ Branch 1 not taken.
|
1024 |
Value* q4 = c.b.build_and( |
| 303 |
3/6
✓ Branch 0 taken 512 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 512 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 512 times.
✗ Branch 5 not taken.
|
512 |
c.b.build_lshr(qw[e >> 2], c.b.build_add(sh, c.i32((e & 3) * 8))), |
| 304 |
1/2
✓ Branch 0 taken 512 times.
✗ Branch 1 not taken.
|
512 |
c.i32(0x0f)); |
| 305 |
1/2
✓ Branch 0 taken 512 times.
✗ Branch 1 not taken.
|
512 |
qvals[e] = kb.u32_to_f32(q4); |
| 306 |
|
512 |
} |
| 307 |
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 28 times.
|
44 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 308 |
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 |
Value* dot = c.f32(0.0f); |
| 309 |
3/4
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 896 times.
✓ Branch 2 taken 896 times.
✗ Branch 3 not taken.
|
924 |
for (int e = 0; e < 32; ++e) dot = c.b.build_fma_f32(xs[b][e], qvals[e], dot); |
| 310 |
|
28 |
std::size_t idx = r * mb + b; |
| 311 |
1/2
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 |
Value* t = c.b.build_fma_f32(ws, dot, next[idx]); |
| 312 |
2/4
✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28 times.
✗ Branch 3 not taken.
|
28 |
next[idx] = c.b.build_fma_f32(c.b.build_neg(wm), sum_x[b], t); |
| 313 |
|
28 |
} |
| 314 |
|
16 |
} |
| 315 |
|
5 |
} else { |
| 316 |
|
|
// QF_Q6K: 32 elements = (g, quad) within 210-byte superblock |
| 317 |
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 |
std::vector<std::vector<Value*>> xs(mb); |
| 318 |
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
|
9 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 319 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 |
xs[b].reserve(32); |
| 320 |
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 |
Value* xi = c.b.build_add(c.b.build_mul(c.i32(static_cast<int>(b)), p[7]), col_elem); |
| 321 |
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
|
30 |
for (int ch = 0; ch < 32; ch += 8) { |
| 322 |
3/6
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
|
24 |
auto sl = load_x_slice8(c, dt, p[0], c.b.build_add(xi, c.i32(ch)), 8, true); |
| 323 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 |
xs[b].insert(xs[b].end(), sl.begin(), sl.end()); |
| 324 |
|
24 |
} |
| 325 |
|
6 |
} |
| 326 |
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 |
Value* sb = c.b.build_lshr(cc, c.i32(3)); |
| 327 |
4/8
✓ 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.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
3 |
Value* g = c.b.build_and(c.b.build_lshr(cc, c.i32(2)), c.i32(1)); |
| 328 |
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 |
Value* quad = c.b.build_and(cc, c.i32(3)); |
| 329 |
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.
|
6 |
Value* ql_off = c.b.build_add(c.b.build_shl(g, c.i32(6)), |
| 330 |
4/8
✓ 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.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
3 |
c.b.build_shl(c.b.build_and(quad, c.i32(1)), c.i32(5))); |
| 331 |
4/8
✓ 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.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
3 |
Value* qh_off = c.b.build_add(c.i32(128), c.b.build_shl(g, c.i32(5))); |
| 332 |
5/10
✓ 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.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
6 |
Value* sc_off = c.b.build_add(c.i32(192), c.b.build_add(c.b.build_shl(g, c.i32(3)), |
| 333 |
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 |
c.b.build_shl(quad, c.i32(1)))); |
| 334 |
5/10
✓ 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.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 3 times.
✗ Branch 9 not taken.
|
3 |
Value* ql_sh = c.b.build_select(c.b.build_uge(quad, c.i32(2)), c.i32(4), c.i32(0)); |
| 335 |
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 |
Value* qh_sh = c.b.build_shl(quad, c.i32(1)); |
| 336 |
|
|
|
| 337 |
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
|
9 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 338 |
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
12 |
Value* blk = c.b.build_add( |
| 339 |
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 |
row_ptrs[r], c.b.build_mul(c.b.build_zext_i64(sb), kb.const_i64(210))); |
| 340 |
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 |
Value* sc_pair = kb.load_u16(c.b.build_add(blk, c.b.build_zext_i64(sc_off))); |
| 341 |
5/10
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 6 times.
✗ Branch 9 not taken.
|
6 |
Value* d = c.b.build_mul(kb.f16_to_f32(kb.load_u16(c.b.build_add(blk, kb.const_i64(208)))), ok_f); |
| 342 |
4/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
|
6 |
Value* s0 = c.b.build_mul(d, emit_s8_byte_to_f32(c, c.b.build_and(sc_pair, c.i32(0xff)))); |
| 343 |
4/8
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
|
6 |
Value* s1 = c.b.build_mul(d, emit_s8_byte_to_f32(c, c.b.build_lshr(sc_pair, c.i32(8)))); |
| 344 |
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 |
auto ql_b = load_u16_bytes(c, c.b.build_add(blk, c.b.build_zext_i64(ql_off)), 16); |
| 345 |
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
6 |
auto qh_b = load_u16_bytes(c, c.b.build_add(blk, c.b.build_zext_i64(qh_off)), 16); |
| 346 |
|
|
Value* qvals[32]; |
| 347 |
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 6 times.
|
198 |
for (int e = 0; e < 32; ++e) { |
| 348 |
3/6
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 192 times.
✗ Branch 5 not taken.
|
192 |
Value* nib = c.b.build_and(c.b.build_lshr(ql_b[e], ql_sh), c.i32(0x0f)); |
| 349 |
5/10
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 192 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 192 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 192 times.
✗ Branch 9 not taken.
|
192 |
Value* hb = c.b.build_shl(c.b.build_and(c.b.build_lshr(qh_b[e], qh_sh), c.i32(0x03)), c.i32(4)); |
| 350 |
4/8
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 192 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 192 times.
✗ Branch 7 not taken.
|
192 |
qvals[e] = c.b.build_sub(kb.u32_to_f32(c.b.build_or(nib, hb)), c.f32(32.0f)); |
| 351 |
|
192 |
} |
| 352 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 12 times.
|
18 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 353 |
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 |
Value* dot0 = c.f32(0.0f); |
| 354 |
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
|
12 |
Value* dot1 = c.f32(0.0f); |
| 355 |
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
|
204 |
for (int e = 0; e < 16; ++e) dot0 = c.b.build_fma_f32(xs[b][e], qvals[e], dot0); |
| 356 |
3/4
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 192 times.
✗ Branch 3 not taken.
|
204 |
for (int e = 16; e < 32; ++e) dot1 = c.b.build_fma_f32(xs[b][e], qvals[e], dot1); |
| 357 |
|
12 |
std::size_t idx = r * mb + b; |
| 358 |
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
|
12 |
next[idx] = c.b.build_fma_f32(s1, dot1, c.b.build_fma_f32(s0, dot0, next[idx])); |
| 359 |
|
12 |
} |
| 360 |
|
6 |
} |
| 361 |
|
3 |
} |
| 362 |
|
14 |
} |
| 363 |
|
11 |
return next; |
| 364 |
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
44 |
}); |
| 365 |
|
|
|
| 366 |
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 33 times.
|
44 |
if (byte_fmt) { |
| 367 |
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 64 times.
|
97 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 368 |
3/4
✓ Branch 0 taken 31 times.
✓ Branch 1 taken 33 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
|
64 |
Value* safe_r = (r == 0) ? wrow[0] : c.b.build_select(row_ok[r], wrow[r], wrow[0]); |
| 369 |
2/4
✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
|
64 |
Value* sc = kb.load_f32(ptr_at(c, p[4], safe_r, 4)); |
| 370 |
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 64 times.
|
320 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 371 |
|
256 |
std::size_t idx = r * mb + b; |
| 372 |
1/2
✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
|
256 |
res[idx] = c.b.build_mul(res[idx], sc); |
| 373 |
|
256 |
} |
| 374 |
|
64 |
} |
| 375 |
|
33 |
} |
| 376 |
|
44 |
return res; |
| 377 |
1/2
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
|
92 |
}, |
| 378 |
|
96 |
[&]() -> std::vector<Value*> { return acc_init; }); |
| 379 |
|
|
|
| 380 |
|
|
// Reduce across `lpr` lanes cleanly in 32-lane slices; when lpr == 64, combine the two halves via shared memory. |
| 381 |
|
48 |
const std::uint32_t shfl_start = (lpr == 16u) ? 8u : 16u; |
| 382 |
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 326 times.
|
374 |
for (std::uint32_t q = 0; q < nr * mb; ++q) { |
| 383 |
|
326 |
Value* s = acc[q]; |
| 384 |
2/2
✓ Branch 0 taken 326 times.
✓ Branch 1 taken 1562 times.
|
1888 |
for (std::uint32_t m = shfl_start; m >= 1u; m >>= 1) { |
| 385 |
2/4
✓ Branch 0 taken 1562 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1562 times.
✗ Branch 3 not taken.
|
1562 |
s = c.b.build_add(s, kb.shfl_bfly_f32(s, m)); |
| 386 |
|
1562 |
} |
| 387 |
|
326 |
acc[q] = s; |
| 388 |
|
326 |
} |
| 389 |
|
|
|
| 390 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 46 times.
|
48 |
if (lpr == 64u) { |
| 391 |
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 |
Value* lane32 = c.b.build_and(lane, c.i32(31)); |
| 392 |
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 |
Value* half = c.b.build_lshr(lane, c.i32(5)); |
| 393 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
4 |
Value* slot_base = c.b.build_mul( |
| 394 |
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 |
c.b.build_add(c.b.build_shl(unit, c.i32(1)), half), |
| 395 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
c.i32(static_cast<int>(nr * mb))); |
| 396 |
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
4 |
kb.if_then(c.b.build_eq(lane32, c.i32(0)), [&] { |
| 397 |
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 |
for (std::uint32_t q = 0; q < nr * mb; ++q) { |
| 398 |
|
4 |
kb.shared_store_f32_indexed(s_part, c.b.build_add(slot_base, c.i32(static_cast<int>(q))), acc[q]); |
| 399 |
|
4 |
} |
| 400 |
|
2 |
}); |
| 401 |
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 |
kb.sync(); |
| 402 |
|
2 |
} |
| 403 |
|
|
|
| 404 |
5/10
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 48 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 48 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 48 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 48 times.
✗ Branch 9 not taken.
|
96 |
kb.if_then(c.b.build_and(c.b.build_eq(lane, c.i32(0)), row_ok[0]), [&] { |
| 405 |
|
48 |
std::vector<Value*> sum(nr * mb); |
| 406 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 46 times.
|
48 |
if (lpr == 64u) { |
| 407 |
4/8
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
|
2 |
Value* b0 = c.b.build_mul(c.b.build_shl(unit, c.i32(1)), c.i32(static_cast<int>(nr * mb))); |
| 408 |
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 |
Value* b1 = c.b.build_add(b0, c.i32(static_cast<int>(nr * mb))); |
| 409 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 |
for (std::uint32_t q = 0; q < nr * mb; ++q) { |
| 410 |
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
8 |
sum[q] = c.b.build_add( |
| 411 |
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 |
kb.shared_load_f32_indexed(s_part, c.b.build_add(b0, c.i32(static_cast<int>(q)))), |
| 412 |
3/6
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
|
4 |
kb.shared_load_f32_indexed(s_part, c.b.build_add(b1, c.i32(static_cast<int>(q))))); |
| 413 |
|
4 |
} |
| 414 |
|
2 |
} else { |
| 415 |
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 |
sum = acc; |
| 416 |
|
|
} |
| 417 |
|
|
|
| 418 |
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 40 times.
|
48 |
if (glu) { |
| 419 |
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
|
16 |
for (std::uint32_t q = 0; q < nr / 2u; ++q) { |
| 420 |
|
8 |
const std::uint32_t r0 = 2u * q, r1 = 2u * q + 1u; |
| 421 |
|
16 |
auto emit_glu_pair = [&] { |
| 422 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 |
Value* b0 = has_bias ? load_elem_dt(c, dt, p[3], wrow[r0]) : nullptr; |
| 423 |
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 |
Value* b1 = has_bias ? load_elem_dt(c, dt, p[3], wrow[r1]) : nullptr; |
| 424 |
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
|
8 |
Value* col_out = (epi == EPI_GEGLU) ? c.b.build_lshr(wrow[r0], c.i32(1)) : wrow[r0]; |
| 425 |
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 8 times.
|
34 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 426 |
|
26 |
Value* v0 = sum[r0 * mb + b]; |
| 427 |
|
26 |
Value* v1 = sum[r1 * mb + b]; |
| 428 |
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
|
26 |
if (has_bias) { |
| 429 |
|
✗ |
v0 = c.b.build_add(v0, b0); |
| 430 |
|
✗ |
v1 = c.b.build_add(v1, b1); |
| 431 |
|
✗ |
} |
| 432 |
|
26 |
v0 = emit_gemm_act(c, act, v0); |
| 433 |
|
26 |
v1 = emit_gemm_act(c, act, v1); |
| 434 |
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 20 times.
|
26 |
Value* out = (epi == EPI_GEGLU) |
| 435 |
|
6 |
? c.b.build_mul(v0, emit_gelu_exact(c, v1)) |
| 436 |
|
20 |
: c.b.build_mul(c.b.build_mul(v0, emit_sigmoid(c, v0)), v1); |
| 437 |
|
26 |
Value* oidx = c.b.build_add(c.b.build_mul(c.i32(static_cast<int>(b)), p[8]), col_out); |
| 438 |
|
26 |
store_elem_dt(c, dt, p[2], oidx, out); |
| 439 |
|
26 |
} |
| 440 |
|
8 |
}; |
| 441 |
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
8 |
if (q == 0) emit_glu_pair(); |
| 442 |
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
✗ |
else kb.if_then(row_ok[r0], emit_glu_pair); |
| 443 |
|
8 |
} |
| 444 |
|
8 |
} else { |
| 445 |
2/2
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 84 times.
|
124 |
for (std::uint32_t r = 0; r < nr; ++r) { |
| 446 |
|
168 |
auto emit_row = [&] { |
| 447 |
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 62 times.
|
84 |
Value* bv = has_bias ? load_elem_dt(c, dt, p[3], wrow[r]) : nullptr; |
| 448 |
2/2
✓ Branch 0 taken 274 times.
✓ Branch 1 taken 84 times.
|
358 |
for (std::uint32_t b = 0; b < mb; ++b) { |
| 449 |
|
274 |
Value* v = sum[r * mb + b]; |
| 450 |
2/2
✓ Branch 0 taken 236 times.
✓ Branch 1 taken 38 times.
|
274 |
if (has_bias) v = c.b.build_add(v, bv); |
| 451 |
|
274 |
v = emit_gemm_act(c, act, v); |
| 452 |
|
274 |
Value* oidx = c.b.build_add(c.b.build_mul(c.i32(static_cast<int>(b)), p[8]), wrow[r]); |
| 453 |
2/2
✓ Branch 0 taken 238 times.
✓ Branch 1 taken 36 times.
|
274 |
if (epi == EPI_ACCUM) v = c.b.build_add(v, load_elem_dt(c, dt, p[2], oidx)); |
| 454 |
|
274 |
store_elem_dt(c, dt, p[2], oidx, v); |
| 455 |
|
274 |
} |
| 456 |
|
84 |
}; |
| 457 |
3/4
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 44 times.
✓ Branch 2 taken 40 times.
✗ Branch 3 not taken.
|
84 |
if (r == 0) emit_row(); |
| 458 |
2/4
✓ Branch 0 taken 44 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 44 times.
|
44 |
else kb.if_then(row_ok[r], emit_row); |
| 459 |
|
84 |
} |
| 460 |
|
|
} |
| 461 |
|
48 |
}); |
| 462 |
|
|
|
| 463 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
c.b.build_ret_void(); |
| 464 |
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
|
48 |
return finalize_fn(fn); |
| 465 |
|
48 |
} |
| 466 |
|
|
|
| 467 |
|
|
} // namespace brotensor::kernels |
| 468 |
|
|
|