Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
Halide::Var Class Reference

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.

## Detailed Description

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).

Examples
  tutorial/lesson_01_basics.cpp, tutorial/lesson_02_input_image.cpp, tutorial/lesson_03_debugging_1.cpp, tutorial/lesson_04_debugging_2.cpp, tutorial/lesson_05_scheduling_1.cpp, tutorial/lesson_06_realizing_over_shifted_domains.cpp, tutorial/lesson_07_multi_stage_pipelines.cpp, tutorial/lesson_08_scheduling_2.cpp, tutorial/lesson_09_update_definitions.cpp, tutorial/lesson_10_aot_compilation_generate.cpp, tutorial/lesson_11_cross_compilation.cpp, tutorial/lesson_12_using_the_gpu.cpp, tutorial/lesson_13_tuples.cpp, tutorial/lesson_14_types.cpp, and tutorial/lesson_15_generators.cpp.

Definition at line 19 of file Var.h.

## Constructor & Destructor Documentation

## ◆ Var() [1/2]

Halide::Var::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.

## ◆ Var() [2/2]

Halide::Var::Var | ( |  | ) |

Construct a Var with an automatically-generated unique name.

Referenced by outermost().

## Member Function Documentation

## ◆ name()

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().

## ◆ same_as()

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 40 of file Var.h.

References Halide::cast(), and name().

## ◆ implicit()

static 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;
Halide::Func
A halide function.
Definition Func.h:728
Halide::Var
A Halide variable, to be used when defining functions.
Definition Var.h:19

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);
Halide::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.

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.

Referenced by Halide::ImplicitVar< N >::to_var().

## ◆ is_implicit() [1/2]

static bool Halide::Var::is_implicit | ( | const std::string & | name | ) |
| static

Return whether a variable name is of the form for an implicit argument.

## ◆ is_implicit() [2/2]

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

Definition at line 128 of file Var.h.

References is_implicit(), and name().

Referenced by implicit_index(), and is_implicit().

## ◆ implicit_index() [1/2]

static int Halide::Var::implicit_index | ( | const std::string & | name | ) |
| inline static

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 138 of file Var.h.

References atoi(), is_implicit(), and name().

## ◆ implicit_index() [2/2]

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

Definition at line 141 of file Var.h.

References implicit_index(), and name().

Referenced by implicit_index().

## ◆ is_placeholder() [1/2]

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

Test if a var is the placeholder variable _.

Definition at line 148 of file Var.h.

References name().

## ◆ is_placeholder() [2/2]

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

Definition at line 151 of file Var.h.

References is_placeholder(), and name().

Referenced by is_placeholder().

## ◆ operator const Expr &()

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

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

Definition at line 157 of file Var.h.

## ◆ outermost()

static Var Halide::Var::outermost | ( |  | ) |
| inline static

A Var that represents the location outside the outermost loop.

Definition at line 162 of file Var.h.

References Var().

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

- src/Var.h