brotensor/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
240 / 243
98.8%
Branches:
91 / 144
63.2%
Functions:
20 / 20
100.0%

src/kernels/mir_resample.cpp
Line Branch Exec Source
1 #include "mir_resample.h"
2
3 #include "mir_math.h"
4 #include "../vulkan/shaders/op_codes.h"
5
6 #include <array>
7 #include <limits>
8 #include <string>
9
10 namespace brotensor::kernels {
11
12 66 FloorDiv emit_floor_div(Ctx& c, Value* num_i64, Value* den_i64) {
13 66 Value* q = c.b.build_sdiv(num_i64, den_i64);
14 66 Value* r = c.b.build_sub(num_i64, c.b.build_mul(q, den_i64));
15 66 Value* neg = c.b.build_slt(r, c.kb.const_i64(0));
16 66 Value* q_adj = c.b.build_select(neg, c.b.build_sub(q, c.kb.const_i64(1)), q);
17 66 Value* rem = c.b.build_select(neg, c.b.build_add(r, den_i64), r);
18 66 return {c.b.build_trunc_i32(q_adj), rem};
19 }
20
21 66 std::pair<Value*, Value*> emit_src_rational(Ctx& c, Value* o_i32, Value* in_dim, Value* out_dim, bool align_corners) {
22
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 54 times.
66 if (align_corners) {
23 12 Value* gt1 = c.b.build_sgt(out_dim, c.i32(1));
24 24 Value* num_gt = c.b.build_mul(c.b.build_zext_i64(o_i32),
25 12 c.b.build_zext_i64(c.b.build_sub(in_dim, c.i32(1))));
26 12 Value* den_gt = c.b.build_zext_i64(c.b.build_sub(out_dim, c.i32(1)));
27 24 return {c.b.build_select(gt1, num_gt, c.kb.const_i64(0)),
28 12 c.b.build_select(gt1, den_gt, c.kb.const_i64(1))};
29 }
30 108 Value* num = c.b.build_sub(
31 108 c.b.build_mul(c.b.build_zext_i64(c.b.build_add(c.b.build_mul(o_i32, c.i32(2)), c.i32(1))),
32 54 c.b.build_zext_i64(in_dim)),
33 54 c.b.build_zext_i64(out_dim));
34 54 Value* den = c.b.build_mul(c.kb.const_i64(2), c.b.build_zext_i64(out_dim));
35 54 return {num, den};
36 66 }
37
38 namespace {
39
40 constexpr int kResampleCpt = 16;
41
42 40 struct AxisTaps {
43 40 std::array<Value*, 4> idx{};
44 40 std::array<Value*, 4> w{};
45 };
46
47 40 AxisTaps emit_axis_taps(Ctx& c, Value* o, Value* in_dim, Value* out_dim, bool align_corners, int imode) {
48 40 AxisTaps taps;
49 120 auto [num, den] = emit_src_rational(c, o, in_dim, out_dim, align_corners);
50 152 auto [i0, rem] = emit_floor_div(c, num, den);
51 40 Value* last = c.b.build_sub(in_dim, c.i32(1));
52 40 Value* zero = c.i32(0);
53
54
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 if (imode == 0) {
55 16 Value* twice = c.b.build_mul(rem, c.kb.const_i64(2));
56 16 Value* gt = c.b.build_sgt(twice, den);
57 16 Value* lt = c.b.build_slt(twice, den);
58 24 Value* tie = c.b.build_add(i0, c.b.build_and(i0, c.i32(1)));
59 24 Value* r = c.b.build_select(gt, c.b.build_add(i0, c.i32(1)), c.b.build_select(lt, i0, tie));
60 8 taps.idx[0] = clamp_i32(c, r, zero, last);
61 8 return taps;
62 }
63
64 96 Value* f = c.b.build_sdiv(c.b.build_sitofp_f32_i64(rem), c.b.build_sitofp_f32_i64(den));
65
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 if (imode == 1) {
66 48 taps.idx[0] = clamp_i32(c, i0, zero, last);
67 48 taps.idx[1] = clamp_i32(c, c.b.build_add(i0, c.i32(1)), zero, last);
68 24 taps.w[0] = f;
69 24 return taps;
70 }
71
72 8 const float a = (imode == 3) ? -0.75f : -0.5f;
73
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 for (int k = 0; k < 4; ++k) {
74 32 Value* t = c.kb.fabs(c.b.build_sub(f, c.f32(static_cast<float>(k - 1))));
75 32 Value* t2 = c.b.build_mul(t, t);
76 64 Value* poly1 = c.b.build_add(
77 32 c.b.build_mul(c.b.build_sub(c.b.build_mul(c.f32(a + 2.0f), t), c.f32(a + 3.0f)), t2),
78 32 c.f32(1.0f));
79 64 Value* poly2 = c.b.build_sub(
80 64 c.b.build_mul(
81 64 c.b.build_add(c.b.build_mul(c.b.build_sub(c.b.build_mul(c.f32(a), t), c.f32(5.0f * a)), t),
82 32 c.f32(8.0f * a)),
83 32 t),
84 32 c.f32(4.0f * a));
85 64 taps.w[k] = c.b.build_select(
86 32 c.b.build_slt(t, c.f32(1.0f)), poly1,
87 32 c.b.build_select(c.b.build_slt(t, c.f32(2.0f)), poly2, c.f32(0.0f)));
88 64 taps.idx[k] = clamp_i32(c, c.b.build_add(i0, c.i32(k - 1)), zero, last);
89 32 }
90 8 return taps;
91 40 }
92
93 6 Value* adaptive_lo(Ctx& c, Value* o, Value* in_dim, Value* out_dim) {
94 6 return c.b.build_udiv(c.b.build_mul(o, in_dim), out_dim);
95 }
96
97 6 Value* adaptive_hi(Ctx& c, Value* o, Value* in_dim, Value* out_dim) {
98 6 Value* num = c.b.build_add(c.b.build_mul(c.b.build_add(o, c.i32(1)), in_dim), c.b.build_sub(out_dim, c.i32(1)));
99 6 return c.b.build_udiv(num, out_dim);
100 }
101
102 } // namespace
103
104 42 brass::Function* build_resample_mir(brass::Module& mod, std::uint32_t mode, Dtype dt,
105 bool align_corners, int imode) {
106
3/6
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
126 const std::string name = "mir_resample_" + std::to_string(mode) + "_dt" +
107
5/10
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 42 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 42 times.
✗ Branch 9 not taken.
84 std::to_string(static_cast<int>(dt)) + "_a" + std::to_string(align_corners ? 1 : 0) +
108
2/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
42 "_i" + std::to_string(imode);
109
2/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
84 auto* fn = mod.create_function(
110 42 name, Type::void_type(),
111 294 {Type::ptr(), Type::ptr(), Type::ptr(), Type::i32(), Type::i32(), Type::i32(), Type::i32(), Type::i32(),
112 252 Type::i32(), Type::i32(), Type::i32(), Type::i32(), Type::i32(), Type::i32()});
113
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 brass::codegen::KernelBuilder kb(mod, fn);
114
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 Ctx c(kb);
115
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 auto p = entry_params(c, fn);
116 42 Value *x = p[0], *y = p[1], *aux = p[2];
117 42 Value *c_dim = p[3], *hi = p[4], *wi = p[5], *ho = p[6], *wo = p[7];
118 42 Value *kh = p[8], *kw = p[9], *sh = p[10], *sw = p[11], *ph = p[12], *pw = p[13];
119
120
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 Value* plane_o = c.b.build_mul(ho, wo);
121
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 Value* plane_i = c.b.build_mul(hi, wi);
122
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 Value* img = c.kb.ctaid_z();
123
3/6
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
42 Value* c0 = c.b.build_mul(c.kb.ctaid_y(), c.i32(kResampleCpt));
124
4/8
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 42 times.
✗ Branch 7 not taken.
84 Value* c1 = c.b.build_select(c.b.build_ult(c.b.build_add(c0, c.i32(kResampleCpt)), c_dim),
125
2/4
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
42 c.b.build_add(c0, c.i32(kResampleCpt)), c_dim);
126
127
4/8
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 42 times.
✗ Branch 7 not taken.
84 c.kb.for_range(c.kb.global_tid_x(), plane_o, grid_stride_ew(c), [&](Value* pos) {
128 42 Value* oh = c.b.build_udiv(pos, wo);
129 42 Value* ow = c.b.build_umod(pos, wo);
130
131
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 20 times.
42 if (mode == RS_INTERP) {
132 20 AxisTaps ty = emit_axis_taps(c, oh, hi, ho, align_corners, imode);
133 20 AxisTaps tx = emit_axis_taps(c, ow, wi, wo, align_corners, imode);
134
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
40 c.kb.for_range(c0, c1, c.i32(1), [&](Value* ch) {
135 20 Value* xb = c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_i);
136 20 Value* v = nullptr;
137
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 if (imode == 0) {
138 8 v = load_elem_dt(c, dt, x,
139 4 c.b.build_add(c.b.build_add(xb, c.b.build_mul(ty.idx[0], wi)), tx.idx[0]));
140
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
20 } else if (imode == 1) {
141 12 Value* row0 = c.b.build_add(xb, c.b.build_mul(ty.idx[0], wi));
142 12 Value* row1 = c.b.build_add(xb, c.b.build_mul(ty.idx[1], wi));
143 12 Value* v00 = load_elem_dt(c, dt, x, c.b.build_add(row0, tx.idx[0]));
144 12 Value* v01 = load_elem_dt(c, dt, x, c.b.build_add(row0, tx.idx[1]));
145 12 Value* v10 = load_elem_dt(c, dt, x, c.b.build_add(row1, tx.idx[0]));
146 12 Value* v11 = load_elem_dt(c, dt, x, c.b.build_add(row1, tx.idx[1]));
147 12 Value* top = c.b.build_add(v00, c.b.build_mul(c.b.build_sub(v01, v00), tx.w[0]));
148 12 Value* bot = c.b.build_add(v10, c.b.build_mul(c.b.build_sub(v11, v10), tx.w[0]));
149 12 v = c.b.build_add(top, c.b.build_mul(c.b.build_sub(bot, top), ty.w[0]));
150 12 } else {
151 4 v = c.f32(0.0f);
152
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for (int j = 0; j < 4; ++j) {
153 16 Value* row_base = c.b.build_add(xb, c.b.build_mul(ty.idx[j], wi));
154 16 Value* row = c.f32(0.0f);
155
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 16 times.
80 for (int i = 0; i < 4; ++i) {
156 64 Value* tap = load_elem_dt(c, dt, x, c.b.build_add(row_base, tx.idx[i]));
157 64 row = c.b.build_add(row, c.b.build_mul(tx.w[i], tap));
158 64 }
159 16 v = c.b.build_add(v, c.b.build_mul(ty.w[j], row));
160 16 }
161 }
162 20 Value* o = c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_o), pos);
163 20 store_elem_dt(c, dt, y, o, v);
164 20 });
165
4/4
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 16 times.
42 } else if (mode == RS_DOWN_AVG2 || mode == RS_UP_NEAREST2_BWD) {
166
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 c.kb.for_range(c0, c1, c.i32(1), [&](Value* ch) {
167 12 Value* b = c.b.build_add(
168 12 c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_i),
169 6 c.b.build_mul(c.b.build_mul(oh, c.i32(2)), wi)),
170 6 c.b.build_mul(ow, c.i32(2)));
171 6 Value* v0 = load_elem_dt(c, dt, x, b);
172 6 Value* v1 = load_elem_dt(c, dt, x, c.b.build_add(b, c.i32(1)));
173 6 Value* v2 = load_elem_dt(c, dt, x, c.b.build_add(b, wi));
174 6 Value* v3 = load_elem_dt(c, dt, x, c.b.build_add(c.b.build_add(b, wi), c.i32(1)));
175 6 Value* s = c.b.build_add(c.b.build_add(c.b.build_add(v0, v1), v2), v3);
176
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (mode == RS_DOWN_AVG2) s = c.b.build_mul(s, c.f32(0.25f));
177 6 Value* o = c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_o), pos);
178 6 store_elem_dt(c, dt, y, o, s);
179 6 });
180
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 13 times.
22 } else if (mode == RS_DOWN_AVG2_BWD) {
181 3 Value* ip = c.b.build_add(c.b.build_mul(c.b.build_lshr(oh, c.i32(1)), wi), c.b.build_lshr(ow, c.i32(1)));
182
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 c.kb.for_range(c0, c1, c.i32(1), [&](Value* ch) {
183 3 Value* src = c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_i), ip);
184 3 Value* g = c.b.build_mul(load_elem_dt(c, dt, x, src), c.f32(0.25f));
185 3 Value* o = c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_o), pos);
186 3 store_elem_dt(c, dt, y, o, g);
187 3 });
188
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 10 times.
16 } else if (mode == RS_ADAPTIVE_AVG) {
189 3 Value* h0 = adaptive_lo(c, oh, hi, ho);
190 3 Value* h1 = adaptive_hi(c, oh, hi, ho);
191 3 Value* w0 = adaptive_lo(c, ow, wi, wo);
192 3 Value* w1 = adaptive_hi(c, ow, wi, wo);
193 3 Value* area = c.b.build_mul(c.b.build_sub(h1, h0), c.b.build_sub(w1, w0));
194 3 Value* inv_area = c.b.build_sdiv(c.f32(1.0f), c.kb.i32_to_f32(area));
195
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 c.kb.for_range(c0, c1, c.i32(1), [&](Value* ch) {
196 3 Value* xb = c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_i);
197
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 Value* sum = c.kb.for_range_reduce(h0, h1, c.i32(1), c.f32(0.0f), [&](Value* h, Value* h_acc) {
198 3 Value* row_b = c.b.build_add(xb, c.b.build_mul(h, wi));
199
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
6 return c.kb.for_range_reduce(w0, w1, c.i32(1), h_acc, [&](Value* w, Value* w_acc) {
200 3 return c.b.build_add(w_acc, load_elem_dt(c, dt, x, c.b.build_add(row_b, w)));
201 });
202 ✗ });
203 3 Value* o = c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_o), pos);
204 3 store_elem_dt(c, dt, y, o, c.b.build_mul(sum, inv_area));
205 3 });
206
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 4 times.
13 } else if (mode == RS_MAXPOOL) {
207 6 Value* hb = c.b.build_sub(c.b.build_mul(oh, sh), ph);
208 6 Value* wb = c.b.build_sub(c.b.build_mul(ow, sw), pw);
209 6 Value* neg_inf = c.f32(-std::numeric_limits<float>::infinity());
210
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 c.kb.for_range(c0, c1, c.i32(1), [&](Value* ch) {
211 6 Value* xb = c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_i);
212
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 auto res = c.kb.for_range_reduce_n(
213 6 c.i32(0), kh, c.i32(1), {neg_inf, c.i32(-1)},
214
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
12 [&](Value* a, const std::vector<Value*>& h_acc) -> std::vector<Value*> {
215 6 Value* ih = c.b.build_add(hb, a);
216 6 Value* h_ok = c.b.build_and(c.b.build_sge(ih, c.i32(0)), c.b.build_slt(ih, hi));
217
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
12 return c.kb.for_range_reduce_n(
218 6 c.i32(0), kw, c.i32(1), h_acc,
219 12 [&](Value* b_idx, const std::vector<Value*>& w_acc) -> std::vector<Value*> {
220 6 Value* iw = c.b.build_add(wb, b_idx);
221 6 Value* w_ok = c.b.build_and(c.b.build_sge(iw, c.i32(0)), c.b.build_slt(iw, wi));
222
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 return emit_if_else_values(
223 6 c, c.b.build_and(h_ok, w_ok), {Type::f32(), Type::i32()},
224 12 [&]() -> std::vector<Value*> {
225 6 Value* lin = c.b.build_add(c.b.build_mul(ih, wi), iw);
226 6 Value* v = load_elem_dt(c, dt, x, c.b.build_add(xb, lin));
227 6 Value* better = c.b.build_sgt(v, w_acc[0]);
228 12 return {c.b.build_select(better, v, w_acc[0]),
229 6 c.b.build_select(better, lin, w_acc[1])};
230 },
231 12 [&]() -> std::vector<Value*> { return {w_acc[0], w_acc[1]}; });
232 ✗ });
233 ✗ });
234
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* o = c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_o), pos);
235
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 store_elem_dt(c, dt, y, o, res[0]);
236
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 c.kb.store_i32(ptr_at(c, aux, o, 4), res[1]);
237 6 });
238 6 } else {
239 4 Value* s = kh;
240 4 Value* kk = c.b.build_mul(s, s);
241 4 Value* py = c.b.build_udiv(oh, s);
242 4 Value* sy = c.b.build_umod(oh, s);
243 4 Value* px = c.b.build_udiv(ow, s);
244 4 Value* sx = c.b.build_umod(ow, s);
245 4 Value* pix = c.b.build_add(c.b.build_mul(py, wi), px);
246 4 Value* sub = c.b.build_add(c.b.build_mul(sy, s), sx);
247 4 Value* mb = c.b.build_mul(c.b.build_mul(img, c.b.build_mul(c.i32(9), kk)), plane_i);
248
249 4 std::array<Value*, 9> m{};
250 4 Value* mx = c.f32(-std::numeric_limits<float>::infinity());
251
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 4 times.
40 for (int j = 0; j < 9; ++j) {
252 72 Value* midx = c.b.build_add(
253 36 c.b.build_add(mb, c.b.build_mul(c.b.build_add(c.b.build_mul(c.i32(j), kk), sub), plane_i)), pix);
254 36 m[j] = load_elem_dt(c, dt, aux, midx);
255 36 mx = c.kb.fmax(mx, m[j]);
256 36 }
257 4 Value* sum = c.f32(0.0f);
258
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 4 times.
40 for (int j = 0; j < 9; ++j) {
259 36 m[j] = emit_exp(c, c.b.build_sub(m[j], mx));
260 36 sum = c.b.build_add(sum, m[j]);
261 36 }
262 4 Value* inv = c.b.build_sdiv(c.f32(1.0f), sum);
263 4 std::array<Value*, 9> nb{};
264 4 Value* h_last = c.b.build_sub(hi, c.i32(1));
265 4 Value* w_last = c.b.build_sub(wi, c.i32(1));
266
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 4 times.
40 for (int j = 0; j < 9; ++j) {
267 36 Value* ny = clamp_i32(c, c.b.build_add(py, c.i32(j / 3 - 1)), c.i32(0), h_last);
268 36 Value* nx = clamp_i32(c, c.b.build_add(px, c.i32(j % 3 - 1)), c.i32(0), w_last);
269 36 nb[j] = c.b.build_add(c.b.build_mul(ny, wi), nx);
270 36 m[j] = c.b.build_mul(m[j], inv);
271 36 }
272
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
8 c.kb.for_range(c0, c1, c.i32(1), [&](Value* ch) {
273 4 Value* xb = c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_i);
274 4 Value* acc = c.f32(0.0f);
275
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 4 times.
40 for (int j = 0; j < 9; ++j) {
276 36 acc = c.b.build_add(acc, c.b.build_mul(m[j], load_elem_dt(c, dt, x, c.b.build_add(xb, nb[j]))));
277 36 }
278 4 Value* o = c.b.build_add(c.b.build_mul(c.b.build_add(c.b.build_mul(img, c_dim), ch), plane_o), pos);
279 4 store_elem_dt(c, dt, y, o, acc);
280 4 });
281 }
282 42 });
283
284
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 c.b.build_ret_void();
285
1/2
✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
42 return finalize_fn(fn);
286 42 }
287
288 } // namespace brotensor::kernels
289