forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchunk.cpp
More file actions
39 lines (29 loc) · 876 Bytes
/
chunk.cpp
File metadata and controls
39 lines (29 loc) · 876 Bytes
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
#include <stdio.h>
#include "Halide.h"
using namespace Halide;
int main(int argc, char **argv) {
Var x, y;
Var xo, xi, yo, yi;
Func f, g;
printf("Defining function...\n");
f(x, y) = cast<float>(x);
g(x, y) = f(x+1, y) + f(x-1, y);
Target target = get_jit_target_from_environment();
if (target.has_gpu_feature() || target.has_feature(Target::OpenGLCompute)) {
Var xi, yi;
g.gpu_tile(x, y, 8, 8);
f.compute_at(g, Var::gpu_blocks()).gpu_threads(x, y);
}
printf("Realizing function...\n");
Image<float> im = g.realize(32, 32, target);
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 32; j++) {
if (im(i,j) != 2*i) {
printf("im[%d, %d] = %f\n", i, j, im(i,j));
return -1;
}
}
}
printf("Success!\n");
return 0;
}