-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect.cpp
47 lines (34 loc) · 1.15 KB
/
select.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Halide.h"
#define NEWER_HALIDE
using namespace Halide;
class SelectErr : public Halide::Generator<SelectErr> {
public:
Input<Buffer<uint8_t>> src{"src", 3};
Input<Buffer<uint8_t>> dst{"dst", 3};
Input<Buffer<uint8_t>> mask{"mask", 2};
Var x{"x"}, y{"y"}, c{"c"};
Output<Buffer<uint8_t>> output{"output", 3};
void generate() {
Expr d = cast<int16_t>(src(x, y, c) - 128);
Expr a = cast<uint8_t>(d + (d/64));
Expr b = select(dst(x, y, c) < a, mask(x, y), dst(x, y, c));
output(x, y, c) = select(src(x, y, c) > 128, b, dst(x, y, c));
}
void schedule() {
src.dim(0).set_stride(4).dim(2).set_stride(1);
dst.dim(0).set_stride(4).dim(2).set_stride(1);
src.dim(2).set_bounds(0, 3);
dst.dim(2).set_bounds(0, 3);
output.dim(0).set_stride(4).dim(2).set_stride(1);
output.dim(2).set_bounds(0, 3);
output.reorder(c, x, y).unroll(c);
Var tx, ty;
if (this->get_target().has_gpu_feature())
output.gpu_tile(x, y, tx, ty, 8, 8);
}
};
#ifdef NEWER_HALIDE
HALIDE_REGISTER_GENERATOR(SelectErr, select_err);
#else
RegisterGenerator<SelectErr> select_err{"select_err"};
#endif