1 #include <stdio.h>
2
3 #include "HalideBuffer.h"
4 #include "HalideRuntime.h"
5 #include <assert.h>
6 #include <string.h>
7 #include <string>
8
9 #include "cxx_mangling.h"
10 #ifdef TEST_CUDA
11 #include "cxx_mangling_gpu.h"
12 #endif
13
14 using namespace Halide::Runtime;
15
16 namespace my_namespace {
17 class my_class {
18 public:
19 int foo;
20 };
21 namespace my_subnamespace {
22 struct my_struct {
23 int foo;
24 };
25 } // namespace my_subnamespace
26 } // namespace my_namespace
27 union my_union {
28 float a;
29 int b;
30 };
31
main(int argc,char ** argv)32 int main(int argc, char **argv) {
33 Buffer<uint8_t> input(100);
34
35 for (int32_t i = 0; i < 100; i++) {
36 input(i) = i;
37 }
38
39 Buffer<double> result(100);
40
41 const halide_filter_metadata_t *m = HalideTest::AnotherNamespace::cxx_mangling_metadata();
42 assert(m != NULL);
43 assert(m->version == halide_filter_metadata_t::VERSION);
44 printf("Name is: %s\n", m->name);
45 assert(strcmp(m->name, "cxx_mangling") == 0);
46
47 int ptr_arg = 42;
48 int *int_ptr = &ptr_arg;
49 const int *const_int_ptr = &ptr_arg;
50 void *void_ptr = nullptr;
51 const void *const_void_ptr = nullptr;
52 std::string *string_ptr = nullptr;
53 const std::string *const_string_ptr = nullptr;
54
55 #ifdef TEST_CUDA
56 // Don't bother calling this (we haven't linked in the CUDA support it needs),
57 // just force a reference to ensure it is linked in.
58 int (*f)(halide_buffer_t *,
59 int8_t, uint8_t,
60 int16_t, uint16_t,
61 int32_t, uint32_t,
62 int64_t, uint64_t,
63 bool,
64 float, double,
65 int32_t *, int32_t const *,
66 void *, void const *,
67 void *, void const *,
68 ::my_namespace::my_class const *,
69 struct ::my_namespace::my_subnamespace::my_struct const *,
70 my_union const *,
71 halide_buffer_t *) = HalideTest::cxx_mangling_gpu;
72
73 printf("HalideTest::cxx_mangling is at: %p\n", (void *)f);
74 #else
75 // TODO: split this up and link CUDA
76 printf("TEST_CUDA is disabled, skipping cxx_mangling_gpu test.\n");
77 #endif
78
79 my_namespace::my_class mc;
80 my_namespace::my_subnamespace::my_struct ms;
81 my_union mu;
82
83 int r = HalideTest::AnotherNamespace::cxx_mangling(
84 input, -1, 0xff, -1, 0xffff, -1, 0xffffffff,
85 -1, 0xffffffffffffffffLL, true, 42.0, 4239.0f,
86 int_ptr, const_int_ptr, void_ptr, const_void_ptr,
87 string_ptr, const_string_ptr,
88 &mc, &ms, &mu, result);
89 if (r != 0) {
90 fprintf(stderr, "Failure!\n");
91 exit(1);
92 }
93 printf("Success!\n");
94 return 0;
95 }
96