Halide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Halide::Var Class Reference

A Halide variable, to be used when defining functions. More...

#include <Var.h>

Public Member Functions

EXPORT Var (const std::string &n)
 Construct a Var with the given name. More...
 
EXPORT Var ()
 Construct a Var with an automatically-generated unique name. More...
 
const std::string & name () const
 Get the name of a Var. More...
 
bool same_as (const Var &other) const
 Test if two Vars are the same. More...
 
bool is_implicit () const
 
int implicit_index () const
 
bool is_placeholder () const
 
 operator Expr () const
 A Var can be treated as an Expr of type Int(32) More...
 

Static Public Member Functions

static EXPORT Var implicit (int n)
 Implicit var constructor. More...
 
static EXPORT bool is_implicit (const std::string &name)
 Return whether a variable name is of the form for an implicit argument. More...
 
static int implicit_index (const std::string &name)
 Return the argument index for a placeholder argument given its name. More...
 
static bool is_placeholder (const std::string &name)
 Test if a var is the placeholder variable _. More...
 
static Var outermost ()
 A Var that represents the location outside the outermost loop. More...
 
static Var gpu_blocks ()
 Vars to use for scheduling producer/consumer pairs on the gpu. More...
 
static Var gpu_threads ()
 Vars to use for scheduling producer/consumer pairs on the gpu. More...
 

Detailed Description

Constructor & Destructor Documentation

EXPORT Halide::Var::Var ( const std::string &  n)

Construct a Var with the given name.

EXPORT Halide::Var::Var ( )

Construct a Var with an automatically-generated unique name.

Referenced by gpu_blocks(), gpu_threads(), and outermost().

Member Function Documentation

const std::string& Halide::Var::name ( ) const
inline

Get the name of a Var.

Definition at line 27 of file Var.h.

Referenced by implicit_index(), is_implicit(), is_placeholder(), Halide::VarOrRVar::name(), and operator Expr().

bool Halide::Var::same_as ( const Var other) const
inline

Test if two Vars are the same.

This simply compares the names.

Definition at line 30 of file Var.h.

static EXPORT Var Halide::Var::implicit ( int  n)
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:

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 = Var::implicit(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 EXPORT bool Halide::Var::is_implicit ( const std::string &  name)
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.

bool Halide::Var::is_implicit ( ) const
inline

Definition at line 119 of file Var.h.

References name().

Referenced by implicit_index().

static int Halide::Var::implicit_index ( const std::string &  name)
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 129 of file Var.h.

References atoi(), and is_implicit().

int Halide::Var::implicit_index ( ) const
inline

Definition at line 132 of file Var.h.

References name().

static bool Halide::Var::is_placeholder ( const std::string &  name)
inlinestatic

Test if a var is the placeholder variable _.

Definition at line 139 of file Var.h.

bool Halide::Var::is_placeholder ( ) const
inline

Definition at line 142 of file Var.h.

References name().

Halide::Var::operator Expr ( ) const
inline

A Var can be treated as an Expr of type Int(32)

Definition at line 148 of file Var.h.

References Halide::Int(), Halide::Internal::Variable::make(), and name().

static Var Halide::Var::gpu_blocks ( )
inlinestatic

Vars to use for scheduling producer/consumer pairs on the gpu.

Deprecated.

Examples:
tutorial/lesson_12_using_the_gpu.cpp.

Definition at line 155 of file Var.h.

References Var().

static Var Halide::Var::gpu_threads ( )
inlinestatic

Vars to use for scheduling producer/consumer pairs on the gpu.

Deprecated.

Examples:
tutorial/lesson_12_using_the_gpu.cpp.

Definition at line 159 of file Var.h.

References Var().

static Var Halide::Var::outermost ( )
inlinestatic

A Var that represents the location outside the outermost loop.

Definition at line 165 of file Var.h.

References Var().

Referenced by Halide::Stage::reorder(), and Halide::Func::reorder().


The documentation for this class was generated from the following file: