File: pipeline_cpp_generator.cpp

package info (click to toggle)
halide 21.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 55,752 kB
  • sloc: cpp: 289,334; ansic: 22,751; python: 7,486; makefile: 4,299; sh: 2,508; java: 1,549; javascript: 282; pascal: 207; xml: 127; asm: 9
file content (86 lines) | stat: -rw-r--r-- 4,142 bytes parent folder | download | duplicates (4)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "Halide.h"

namespace {

using namespace Halide;
using Internal::Call;

// TODO: this is using Halide::Internal, which is naughty for apps outside of Halide proper.
// We should find (or add) a way to do this properly, or move this apps into internal tests.
Expr make_call_cpp_extern_toplevel(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "cpp_extern_toplevel", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}

Expr make_call_cpp_extern_namespace(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace1::cpp_extern", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}

Expr make_call_cpp_extern_shared_namespace_1(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace2::cpp_extern_1", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}
Expr make_call_cpp_extern_shared_namespace_2(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace2::cpp_extern_2", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}
Expr make_call_cpp_extern_shared_namespace_3(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace2::cpp_extern_3", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}

Expr make_call_cpp_extern_nested_namespace_outer(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace_outer::cpp_extern", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}
Expr make_call_cpp_extern_nested_namespace_inner(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace_outer::namespace_inner::cpp_extern", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}

Expr make_call_cpp_extern_shared_nested_1(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace_shared_outer::cpp_extern_1", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}
Expr make_call_cpp_extern_shared_nested_2(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace_shared_outer::cpp_extern_2", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}
Expr make_call_cpp_extern_shared_nested_3(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace_shared_outer::inner::cpp_extern_1", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}
Expr make_call_cpp_extern_shared_nested_4(Expr arg1, Expr arg2) {
    return Call::make(type_of<int>(), "namespace_shared_outer::inner::cpp_extern_2", {cast<int>(arg1), cast<float>(arg2)}, Call::ExternCPlusPlus);
}

// Make sure extern "C" works
HalideExtern_2(int, an_extern_c_func, int, float);

class PipelineCpp : public Halide::Generator<PipelineCpp> {
public:
    Input<Buffer<uint16_t, 2>> input{"input"};
    Output<Buffer<uint16_t, 2>> output{"output"};

    void generate() {
        Var x, y;

        assert(get_target().has_feature(Target::CPlusPlusMangling));

        Expr add_all_the_things = cast<int>(0);
        add_all_the_things += make_call_cpp_extern_toplevel(input(x, y), x + y);

        add_all_the_things += make_call_cpp_extern_namespace(input(x, y), x + y);

        add_all_the_things += make_call_cpp_extern_shared_namespace_1(input(x, y), x + y);
        add_all_the_things += make_call_cpp_extern_shared_namespace_2(input(x, y), x + y);
        add_all_the_things += make_call_cpp_extern_shared_namespace_3(input(x, y), x + y);

        add_all_the_things += make_call_cpp_extern_nested_namespace_outer(input(x, y), x + y);
        add_all_the_things += make_call_cpp_extern_nested_namespace_inner(input(x, y), x + y);

        add_all_the_things += make_call_cpp_extern_shared_nested_1(input(x, y), x + y);
        add_all_the_things += make_call_cpp_extern_shared_nested_2(input(x, y), x + y);
        add_all_the_things += make_call_cpp_extern_shared_nested_3(input(x, y), x + y);
        add_all_the_things += make_call_cpp_extern_shared_nested_4(input(x, y), x + y);

        add_all_the_things += an_extern_c_func(cast<int32_t>(input(x, y)), cast<float>(x + y));

        output(x, y) = cast<uint16_t>(add_all_the_things);
    }
};

}  // namespace

HALIDE_REGISTER_GENERATOR(PipelineCpp, pipeline_cpp)