forked from halide/Halide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVar.cpp
More file actions
129 lines (104 loc) · 5.96 KB
/
Copy pathVar.cpp
File metadata and controls
129 lines (104 loc) · 5.96 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "Var.h"
// to avoid compiler confusion, python.hpp must be include before Halide headers
#include "add_operators.h"
#include <boost/python.hpp>
#include "../../src/IROperator.h"
#include "../../src/Var.h"
#include <boost/format.hpp>
#include <string>
namespace h = Halide;
bool var_is_implicit0(h::Var &that) {
return that.is_implicit();
}
bool var_is_implicit1(const std::string name) {
return h::Var::is_implicit(name);
}
int var_implicit_index0(h::Var &that) {
return that.is_implicit();
}
int var_implicit_index1(const std::string name) {
return h::Var::is_implicit(name);
}
bool var_is_placeholder0(h::Var &that) {
return that.is_placeholder();
}
bool var_is_placeholder1(const std::string name) {
return h::Var::is_placeholder(name);
}
h::Expr var_as_expr(h::Var &that) {
return static_cast<h::Expr>(that);
}
std::string var_repr(const h::Var &var) {
std::string repr;
boost::format f("<halide.Var '%s'>");
repr = boost::str(f % var.name());
return repr;
}
void defineVar() {
using Halide::Var;
namespace p = boost::python;
auto var_class = p::class_<Var>("Var",
"A Halide variable, to be used when defining functions. It is just"
"a name, and can be reused in places where no name conflict will"
"occur. It can be used in the left-hand-side of a function"
"definition, or as an Expr. As an Expr, it always has type Int(32).\n"
"\n"
"Constructors::\n"
"Var() -- Construct Var with an automatically-generated unique name\n"
"Var(name) -- Construct Var with the given string name.\n",
p::init<std::string>(p::args("self", "name")))
.def(p::init<>(p::arg("self")))
//.add_property("name", &Var::name) // "Get the name of a Var.")
.def("name", &Var::name, p::arg("self"),
p::return_value_policy<p::copy_const_reference>(),
"Get the name of a Var.")
.def("same_as", &Var::same_as, p::args("self", "other"), "Test if two Vars are the same.")
.def("__eq__", &Var::same_as, p::args("self", "other"), "Test if two Vars are the same.")
//.def(self == p::other<Var>())
.def("implicit", &Var::implicit, p::arg("n"),
"Implicit var constructor. Implicit variables are injected "
"automatically into a function call if the number of arguments "
"to the function are fewer than its dimensionality and a "
"placeholder (\"_\") appears in its argument list. Defining a "
"function to equal an expression containing implicit variables "
"similarly appends those implicit variables, in the same order, "
"to the left-hand-side of the definition where the placeholder "
"('_') appears.")
.staticmethod("implicit")
.def("is_implicit", &var_is_implicit0, p::arg("self"),
"Return whether the variable name is of the form for an implicit argument.")
.def("name_is_implicit", &var_is_implicit1, p::arg("name"),
"Return whether a variable name is of the form for an implicit argument.")
.staticmethod("name_is_implicit")
.def("implicit_index", &var_implicit_index0, p::arg("self"),
"Return the argument index for a placeholder argument given its "
"name. Returns 0 for \\ref _0, 1 for \\ref _1, etc. "
"Returns -1 if the variable is not of implicit form. ")
.def("name_implicit_index", &var_implicit_index1, p::arg("name"),
"Return the argument index for a placeholder argument given its "
"name. Returns 0 for \\ref _0, 1 for \\ref _1, etc. "
"Returns -1 if the variable is not of implicit form. ")
.staticmethod("name_implicit_index")
.def("is_placeholder", &var_is_placeholder0, p::arg("self"),
"Test if a var is the placeholder variable \\ref _")
.def("name_is_placeholder", &var_is_placeholder1, p::arg("name"),
"Test if a var is the placeholder variable \\ref _")
.staticmethod("name_is_placeholder")
.def("expr", &var_as_expr, p::arg("self"), //operator Expr() const
"A Var can be treated as an Expr of type Int(32)")
.def("gpu_blocks", &Var::gpu_blocks, // no args
"Vars to use for scheduling producer/consumer pairs on the gpu.")
.staticmethod("gpu_blocks")
.def("gpu_threads", &Var::gpu_threads, // no args
"Vars to use for scheduling producer/consumer pairs on the gpu.")
.staticmethod("gpu_threads")
.def("outermost", &Var::outermost, // no args
"A Var that represents the location outside the outermost loop.")
.staticmethod("outermost")
.def("__repr__", &var_repr, p::arg("self"));
;
add_operators(var_class);
add_operators_with<decltype(var_class), h::Expr>(var_class);
p::implicitly_convertible<Var, h::Expr>();
return;
}