forked from victoroliv2/halide-casestudies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_downsample.cpp
44 lines (29 loc) · 943 Bytes
/
test_downsample.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
#include <Halide.h>
using namespace Halide;
int main(int argc, char **argv) {
int W = 1024, H = 1024;
int k = 0;
Image<float> in(W, H);
for (int y = 0; y < H; y++) {
for (int x = 0; x < W; x++) {
in(x, y) = ((float) rand() / (RAND_MAX)) + 1;
}
}
Var x, y;
RDom r(0, 16, 0, 16);
Func down("down");
down(x,y) += ( in(clamp(x+r.x-8, 0, in.width()-1), clamp(y+r.y-8, 0, in.height()-1)) ) / 16.0f;
if (use_gpu()) {
down.root().cudaTile(x, y, 16, 16);
down.update().root().reorder(r.x, r.y, x, y).cudaTile(x, y, 16, 16);
} else {
Var xi, yi;
// Grab a handle to the update step of a reduction for scheduling
// using the "update()" method.
down.update().tile(x, y, xi, yi, 32, 32).vectorize(xi, 4).parallel(y);
}
Image<float> out(W/16, H/16);
down.realize(out);
printf("Success!\n");
return 0;
}