Halide 19.0.0
Halide compiler and libraries
|
A Halide variable, to be used when defining functions. More...
#include <Var.h>
Public Member Functions | |
Var (const std::string &n) | |
Construct a Var with the given name. | |
Var () | |
Construct a Var with an automatically-generated unique name. | |
const std::string & | name () const |
Get the name of a Var. | |
bool | same_as (const Var &other) const |
Test if two Vars are the same. | |
bool | is_implicit () const |
int | implicit_index () const |
bool | is_placeholder () const |
operator const Expr & () const | |
A Var can be treated as an Expr of type Int(32) | |
Static Public Member Functions | |
static Var | implicit (int n) |
Implicit var constructor. | |
static bool | is_implicit (const std::string &name) |
Return whether a variable name is of the form for an implicit argument. | |
static int | implicit_index (const std::string &name) |
Return the argument index for a placeholder argument given its name. | |
static bool | is_placeholder (const std::string &name) |
Test if a var is the placeholder variable _. | |
static Var | outermost () |
A Var that represents the location outside the outermost loop. | |
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).
Halide::Var::Var | ( | const std::string & | n | ) |
Construct a Var with the given name.
Halide::Var::Var | ( | ) |
Construct a Var with an automatically-generated unique name.
Referenced by outermost().
const std::string & Halide::Var::name | ( | ) | const |
Get the name of a Var.
Referenced by implicit_index(), implicit_index(), is_implicit(), is_placeholder(), is_placeholder(), Halide::VarOrRVar::name(), and same_as().
|
inline |
|
static |
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:
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.
These are expanded internally as follows:
The following, however, defines g as four dimensional:
It is equivalent to:
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:
expands to:
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.
Referenced by Halide::ImplicitVar< N >::to_var().
|
static |
Return whether a variable name is of the form for an implicit argument.
TODO: This is almost guaranteed to incorrectly fire on user declared variables at some point. We should likely prevent user Var declarations from making names of this form.
|
inline |
Definition at line 129 of file Var.h.
References is_implicit(), and name().
Referenced by implicit_index(), and is_implicit().
|
inlinestatic |
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.
Definition at line 139 of file Var.h.
References atoi(), is_implicit(), and name().
|
inline |
Definition at line 142 of file Var.h.
References implicit_index(), and name().
Referenced by implicit_index().
|
inlinestatic |
|
inline |
Definition at line 152 of file Var.h.
References is_placeholder(), and name().
Referenced by is_placeholder().
|
inline |
|
inlinestatic |