Var#
-
class 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).
Public Functions
-
Var(const std::string &n)#
Construct a Var with the given name.
Unlike Funcs, this will be treated as the same Var as another other Var with the same name, including implicit Vars.
Public Static Functions
-
static Var implicit(int 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.
For example, consider the definition:
Func f, g; Var x, y; f(x, y) = 3;
A call to f with the placeholder symbol _ will have implicit arguments injected automatically, so f(2, _) is equivalent to f(2, _0), where _0 = ImplicitVar<0>(), and f(_) (and indeed f when cast to an Expr) is equivalent to f(_0, _1). The following definitions are all equivalent, differing only in the variable names.
g(_) = f*3; g(_) = f(_)*3; g(x, _) = f(x, _)*3; g(x, y) = f(x, y)*3;
These are expanded internally as follows:
g(_0, _1) = f(_0, _1)*3; g(_0, _1) = f(_0, _1)*3; g(x, _0) = f(x, _0)*3; g(x, y) = f(x, y)*3;
The following, however, defines g as four dimensional:
g(x, y, _) = f*3;
It is equivalent to:
g(x, y, _0, _1) = f(_0, _1)*3;
Expressions requiring differing numbers of implicit variables can be combined. The left-hand-side of a definition injects enough implicit variables to cover all of them:
Func h; h(x) = x*3; g(x) = h + (f + f(x)) * f(x, y);
expands to:
Func h; h(x) = x*3; g(x, _0, _1) = h(_0) + (f(_0, _1) + f(x, _0)) * f(x, y);
The first ten implicits, _0 through _9, are predeclared in this header and can be used for scheduling. They should never be used as arguments in a declaration or used in a call.
While it is possible to use Var::implicit or the predeclared implicits to create expressions that can be treated as small anonymous functions (e.g. Func(_0 + _1)) this is considered poor style. Instead use lambda.
-
static bool is_implicit(const std::string &name)#
Return whether a variable name is of the form for an implicit argument.
-
static inline int implicit_index(const std::string &name)#
Return the argument index for a placeholder argument given its name.
Returns 0 for _0, 1 for _1, etc. Returns -1 if the variable is not of implicit form.
-
static inline bool is_placeholder(const std::string &name)#
Test if a var is the placeholder variable _.
-
Var(const std::string &n)#