forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfive_d_gpu_buffer.cpp
More file actions
45 lines (32 loc) · 1.14 KB
/
five_d_gpu_buffer.cpp
File metadata and controls
45 lines (32 loc) · 1.14 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
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
int main(int argc, char **argv) {
// Move this test to correctness once we can support >4d buffer_ts on the gpu
if (!get_jit_target_from_environment().has_gpu_feature()) {
printf("No gpu target enabled. Skipping test.\n");
// This test is currently expected to error out.
printf("Error: pretending that there was an error\n");
return -1;
}
Func f;
Var v0, v1, v2, v3, v4;
f(v0, v1, v2, v3, v4) = v0 + 2*v1 + 4*v2 + 8*v3 + 16*v4;
f.compute_root().gpu_blocks(v3, v4).gpu_threads(v1, v2);
// Linearize into an output buffer
Func g;
g(v0) = f(v0 % 2, (v0 / 2) % 2, (v0 / 4) % 2, (v0 / 8) % 2, (v0 / 16) % 2);
Image<int> result = g.realize(32);
// Delete this code once this test works.
printf("Error: I should not have successfully compiled.\n");
return -1;
for (int i = 0; i < result.width(); i++) {
if (i != result(i)) {
printf("result(%d) = %d instead of %d\n",
i, result(i), i);
return -1;
}
}
printf("Success!\n");
return 0;
}