forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvectorize_pred.cpp
More file actions
81 lines (63 loc) · 1.68 KB
/
vectorize_pred.cpp
File metadata and controls
81 lines (63 loc) · 1.68 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "Halide.h"
#include <cstdio>
using namespace Halide;
template<typename T>
T tolerance() {
return 0;
}
template<>
float tolerance<float>() {
return 1e-7f;
}
template<typename T>
bool equals(T a, T b, T epsilon = tolerance<T>()) {
T error = std::abs(a - b);
return error <= epsilon;
}
template<typename A>
bool test(int vec_width) {
int W = vec_width * 4;
int H = 1000;
Buffer<A> input(W, H + 20);
for (int y = 0; y < H + 20; y++) {
for (int x = 0; x < W; x++) {
input(x, y) = (A)((rand() & 0xffff) * 0.125 + 1.0);
}
}
Var x("x"), y("y");
Func f("f"), g("g");
RDom r(0, W, 0, H);
r.where((r.x * r.y) % 8 < 7);
Expr e = input(r.x, r.y);
for (int i = 1; i < 5; i++) {
e = e + input(r.x, r.y + i);
}
for (int i = 5; i >= 0; i--) {
e = e + input(r.x, r.y + i);
}
f(x, y) = cast<A>(0);
f(r.x, r.y) = e;
g(x, y) = cast<A>(0);
g(r.x, r.y) = e;
f.update(0).vectorize(r.x);
Buffer<A> outputg = g.realize({W, H});
Buffer<A> outputf = f.realize({W, H});
for (int j = 0; j < H; j++) {
for (int i = 0; i < W; i++) {
if (!equals(outputf(i, j), outputg(i, j))) {
std::cout << type_of<A>() << " x " << vec_width << " failed at "
<< i << " " << j << ": "
<< outputf(i, j) << " vs " << outputg(i, j) << "\n"
<< "Failure!\n";
return false;
}
}
}
return true;
}
int main(int argc, char **argv) {
if (!test<float>(4)) return 1;
if (!test<float>(8)) return 1;
printf("Success!\n");
return 0;
}