Halide
Halide::LoopLevel Class Reference

A reference to a site in a Halide statement at the top of the body of a particular for loop. More...

#include <Schedule.h>

Public Member Functions

int stage_index () const
 Return the index of the function stage associated with this loop level. More...
 
 LoopLevel (const Internal::Function &f, const VarOrRVar &v, int stage_index=-1)
 Identify the loop nest corresponding to some dimension of some function. More...
 
 LoopLevel (const Func &f, const VarOrRVar &v, int stage_index=-1)
 
 LoopLevel ()
 Construct an undefined LoopLevel. More...
 
void set (const LoopLevel &other)
 Mutate our contents to match the contents of 'other'. More...
 
LoopLevellock ()
 
std::string func () const
 
VarOrRVar var () const
 
bool defined () const
 
bool is_inlined () const
 
bool is_root () const
 
std::string to_string () const
 
bool match (const std::string &loop) const
 
bool match (const LoopLevel &other) const
 
bool operator== (const LoopLevel &other) const
 
bool operator!= (const LoopLevel &other) const
 

Static Public Member Functions

static LoopLevel inlined ()
 Construct a special LoopLevel value that implies that a function should be inlined away. More...
 
static LoopLevel root ()
 Construct a special LoopLevel value which represents the location outside of all for loops. More...
 

Detailed Description

A reference to a site in a Halide statement at the top of the body of a particular for loop.

Evaluating a region of a halide function is done by generating a loop nest that spans its dimensions. We schedule the inputs to that function by recursively injecting realizations for them at particular sites in this loop nest. A LoopLevel identifies such a site. The site can either be a loop nest within all stages of a function or it can refer to a loop nest within a particular function's stage (initial definition or updates).

Note that a LoopLevel is essentially a pointer to an underlying value; all copies of a LoopLevel refer to the same site, so mutating one copy (via the set() method) will effectively mutate all copies:

Func f;
Var x;
LoopLevel a(f, x);
// Both a and b refer to LoopLevel(f, x)
LoopLevel b = a;
// Now both a and b refer to LoopLevel::root()
a.set(LoopLevel::root());

This is quite useful when splitting Halide code into utility libraries, as it allows a library to schedule code according to a caller's specifications, even if the caller hasn't fully defined its pipeline yet:

Func demosaic(Func input,
LoopLevel intermed_compute_at,
LoopLevel intermed_store_at,
LoopLevel output_compute_at) {
Func intermed = ...;
Func output = ...;
intermed.compute_at(intermed_compute_at).store_at(intermed_store_at);
output.compute_at(output_compute_at);
return output;
}
void process() {
// Note that these LoopLevels are all undefined when we pass them to demosaic()
LoopLevel intermed_compute_at, intermed_store_at, output_compute_at;
Func input = ...;
Func demosaiced = demosaic(input, intermed_compute_at, intermed_store_at, output_compute_at);
Func output = ...;
// We need to ensure all LoopLevels have a well-defined value prior to lowering:
intermed_compute_at.set(LoopLevel(output, y));
intermed_store_at.set(LoopLevel(output, y));
output_compute_at.set(LoopLevel(output, x));
}

Definition at line 176 of file Schedule.h.

Constructor & Destructor Documentation

◆ LoopLevel() [1/3]

Halide::LoopLevel::LoopLevel ( const Internal::Function f,
const VarOrRVar v,
int  stage_index = -1 
)

Identify the loop nest corresponding to some dimension of some function.

◆ LoopLevel() [2/3]

Halide::LoopLevel::LoopLevel ( const Func f,
const VarOrRVar v,
int  stage_index = -1 
)

◆ LoopLevel() [3/3]

Halide::LoopLevel::LoopLevel ( )

Construct an undefined LoopLevel.

Calling any method on an undefined LoopLevel (other than set()) will assert.

Member Function Documentation

◆ stage_index()

int Halide::LoopLevel::stage_index ( ) const

Return the index of the function stage associated with this loop level.

Asserts if undefined

◆ inlined()

static LoopLevel Halide::LoopLevel::inlined ( )
static

Construct a special LoopLevel value that implies that a function should be inlined away.

Referenced by Halide::Internal::GeneratorParam_LoopLevel::set_from_string().

◆ root()

static LoopLevel Halide::LoopLevel::root ( )
static

Construct a special LoopLevel value which represents the location outside of all for loops.

Referenced by Halide::Internal::GeneratorParam_LoopLevel::set_from_string().

◆ set()

void Halide::LoopLevel::set ( const LoopLevel other)

Mutate our contents to match the contents of 'other'.

Referenced by Halide::Internal::GeneratorParam_LoopLevel::get_default_value(), and Halide::Internal::GeneratorParam_LoopLevel::set().

◆ lock()

◆ func()

std::string Halide::LoopLevel::func ( ) const

◆ var()

VarOrRVar Halide::LoopLevel::var ( ) const

◆ defined()

bool Halide::LoopLevel::defined ( ) const

◆ is_inlined()

bool Halide::LoopLevel::is_inlined ( ) const

◆ is_root()

bool Halide::LoopLevel::is_root ( ) const

◆ to_string()

std::string Halide::LoopLevel::to_string ( ) const

◆ match() [1/2]

bool Halide::LoopLevel::match ( const std::string &  loop) const

◆ match() [2/2]

bool Halide::LoopLevel::match ( const LoopLevel other) const

◆ operator==()

bool Halide::LoopLevel::operator== ( const LoopLevel other) const

◆ operator!=()

bool Halide::LoopLevel::operator!= ( const LoopLevel other) const
inline

Definition at line 250 of file Schedule.h.


The documentation for this class was generated from the following file:
Halide::LoopLevel::root
static LoopLevel root()
Construct a special LoopLevel value which represents the location outside of all for loops.
Halide::LoopLevel::LoopLevel
LoopLevel()
Construct an undefined LoopLevel.