1 #include "Halide.h"
2 #include "gpu_object_lifetime_tracker.h"
3
4 #include <iostream>
5
6 using namespace Halide;
7
8 Internal::GpuObjectLifetimeTracker tracker;
9
halide_print(void * user_context,const char * str)10 void halide_print(void *user_context, const char *str) {
11 printf("%s", str);
12
13 tracker.record_gpu_debug(str);
14 }
15
main(int argc,char * argv[])16 int main(int argc, char *argv[]) {
17 Var x, xi;
18
19 Internal::JITHandlers handlers;
20 handlers.custom_print = halide_print;
21 Internal::JITSharedRuntime::set_default_handlers(handlers);
22
23 Target target = get_jit_target_from_environment();
24
25 // We need debug output to record object creation.
26 target.set_feature(Target::Debug);
27
28 {
29 // Verify that internal buffers are released.
30 Func f, g, h;
31 f(x) = x;
32 g(x) = f(x);
33 h(x) = g(x);
34
35 f.compute_root();
36 g.compute_root();
37
38 if (target.has_gpu_feature()) {
39 g.gpu_tile(x, xi, 32);
40 } else if (target.features_any_of({Target::HVX_64, Target::HVX_128})) {
41 g.hexagon();
42 }
43 h.set_custom_print(halide_print);
44
45 h.realize(256, target);
46 }
47
48 Internal::JITSharedRuntime::release_all();
49
50 int ret = tracker.validate_gpu_object_lifetime(true /* allow_globals */, true /* allow_none */, 1 /* max_globals */);
51 if (ret != 0) {
52 return ret;
53 }
54
55 printf("Success!\n");
56 return 0;
57 }
58