Halide 22.0.0 Halide compiler and libraries

Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Halide::Internal::Closure Class Reference

A helper class to manage closures. More...

`#include <Closure.h>`

Inheritance diagram for Halide::Internal::Closure:

## Classes
struct | Buffer
| Information about a buffer reference from a closure. More...

## Public Member Functions
| Closure ()=default
| Closure (const Closure &)=delete
Closure & | operator= (const Closure &)=delete
| Closure (Closure &&)=default
Closure & | operator= (Closure &&)=default
void | include (const Stmt &s, const std::string &loop_variable="")
| Traverse a statement and find all references to external symbols. More...
Expr | pack_into_struct () const
| Pack a closure into a struct. More...
Stmt | unpack_from_struct (const Expr &, const Stmt &) const
| Unpack a closure around a Stmt, putting all the names in scope. More...
Public Member Functions inherited from Halide::Internal::IRVisitor
| IRVisitor ()=default
virtual | ~IRVisitor ()=default

## Public Attributes
std::map< std::string, Type > | vars
| External variables referenced. More...
std::map< std::string, Buffer > | buffers
| External allocations referenced. More...

## Protected Member Functions
void | visit (const Let *op) override
void | visit (const LetStmt *op) override
void | visit (const For *op) override
void | visit (const Load *op) override
void | visit (const Store *op) override
void | visit (const Allocate *op) override
void | visit (const Variable *op) override
void | visit (const Atomic *op) override
void | found_buffer_ref (const std::string &name, Type type, bool read, bool written, const Halide::Buffer<> &image)
virtual void | visit (const IntImm *)
virtual void | visit (const UIntImm *)
virtual void | visit (const FloatImm *)
virtual void | visit (const StringImm *)
virtual void | visit (const Cast *)
virtual void | visit (const Reinterpret *)
virtual void | visit (const Add *)
virtual void | visit (const Sub *)
virtual void | visit (const Mul *)
virtual void | visit (const Div *)
virtual void | visit (const Mod *)
virtual void | visit (const Min *)
virtual void | visit (const Max *)
virtual void | visit (const EQ *)
virtual void | visit (const NE *)
virtual void | visit (const LT *)
virtual void | visit (const LE *)
virtual void | visit (const GT *)
virtual void | visit (const GE *)
virtual void | visit (const And *)
virtual void | visit (const Or *)
virtual void | visit (const Not *)
virtual void | visit (const Select *)
virtual void | visit (const Load *)
virtual void | visit (const Ramp *)
virtual void | visit (const Broadcast *)
virtual void | visit (const Let *)
virtual void | visit (const LetStmt *)
virtual void | visit (const AssertStmt *)
virtual void | visit (const ProducerConsumer *)
virtual void | visit (const Store *)
virtual void | visit (const Provide *)
virtual void | visit (const Allocate *)
virtual void | visit (const Free *)
virtual void | visit (const Realize *)
virtual void | visit (const Block *)
virtual void | visit (const Fork *)
virtual void | visit (const IfThenElse *)
virtual void | visit (const Evaluate *)
virtual void | visit (const Call *)
virtual void | visit (const Variable *)
virtual void | visit (const For *)
virtual void | visit (const Acquire *)
virtual void | visit (const Shuffle *)
virtual void | visit (const Prefetch *)
virtual void | visit (const HoistedStorage *)
virtual void | visit (const Atomic *)
virtual void | visit (const VectorReduce *)
virtual void | visit (const IntImm *)
virtual void | visit (const UIntImm *)
virtual void | visit (const FloatImm *)
virtual void | visit (const StringImm *)
virtual void | visit (const Cast *)
virtual void | visit (const Reinterpret *)
virtual void | visit (const Add *)
virtual void | visit (const Sub *)
virtual void | visit (const Mul *)
virtual void | visit (const Div *)
virtual void | visit (const Mod *)
virtual void | visit (const Min *)
virtual void | visit (const Max *)
virtual void | visit (const EQ *)
virtual void | visit (const NE *)
virtual void | visit (const LT *)
virtual void | visit (const LE *)
virtual void | visit (const GT *)
virtual void | visit (const GE *)
virtual void | visit (const And *)
virtual void | visit (const Or *)
virtual void | visit (const Not *)
virtual void | visit (const Select *)
virtual void | visit (const Load *)
virtual void | visit (const Ramp *)
virtual void | visit (const Broadcast *)
virtual void | visit (const Let *)
virtual void | visit (const LetStmt *)
virtual void | visit (const AssertStmt *)
virtual void | visit (const ProducerConsumer *)
virtual void | visit (const Store *)
virtual void | visit (const Provide *)
virtual void | visit (const Allocate *)
virtual void | visit (const Free *)
virtual void | visit (const Realize *)
virtual void | visit (const Block *)
virtual void | visit (const Fork *)
virtual void | visit (const IfThenElse *)
virtual void | visit (const Evaluate *)
virtual void | visit (const Call *)
virtual void | visit (const Variable *)
virtual void | visit (const For *)
virtual void | visit (const Acquire *)
virtual void | visit (const Shuffle *)
virtual void | visit (const Prefetch *)
virtual void | visit (const HoistedStorage *)
virtual void | visit (const Atomic *)
virtual void | visit (const VectorReduce *)

## Protected Attributes
Scope | ignore

## Detailed Description

A helper class to manage closures.

Walks over a statement and retrieves all the references within it to external symbols (variables and allocations). It then helps you build a struct containing the current values of these symbols that you can use as a closure if you want to migrate the body of the statement to its own function (e.g. because it's the body of a parallel for loop.

Definition at line 26 of file Closure.h.

## Constructor & Destructor Documentation

## ◆ Closure() [1/3]

Halide::Internal::Closure::Closure | ( |  | ) |
| default

## ◆ Closure() [2/3]

Halide::Internal::Closure::Closure | ( | const Closure & |  | ) |
| delete

## ◆ Closure() [3/3]

Halide::Internal::Closure::Closure | ( | Closure && |  | ) |
| default

## Member Function Documentation

## ◆ visit() [1/56]

void Halide::Internal::Closure::visit | ( | const Let * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [2/56]

void Halide::Internal::Closure::visit | ( | const LetStmt * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [3/56]

void Halide::Internal::Closure::visit | ( | const For * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

Reimplemented in Halide::Internal::HostClosure.

## ◆ visit() [4/56]

void Halide::Internal::Closure::visit | ( | const Load * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [5/56]

void Halide::Internal::Closure::visit | ( | const Store * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [6/56]

void Halide::Internal::Closure::visit | ( | const Allocate * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [7/56]

void Halide::Internal::Closure::visit | ( | const Variable * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [8/56]

void Halide::Internal::Closure::visit | ( | const Atomic * | op | ) |
| overrideprotectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ found_buffer_ref()

void Halide::Internal::Closure::found_buffer_ref | ( | const std::string & | name,
|  | Type | type,
|  | bool | read,
|  | bool | written,
|  | const Halide::Buffer<> & | image
| ) |  |
| protected

## ◆ operator=() [1/2]

Closure & Halide::Internal::Closure::operator= | ( | const Closure & |  | ) |
| delete

## ◆ operator=() [2/2]

Closure & Halide::Internal::Closure::operator= | ( | Closure && |  | ) |
| default

## ◆ include()

void Halide::Internal::Closure::include | ( | const Stmt & | s,
|  | const std::string & | loop_variable = `""`
| ) |  |

Traverse a statement and find all references to external symbols.

When the closure encounters a read or write to 'foo', it assumes that the host pointer is found in the symbol table as 'foo.host', and any halide_buffer_t pointer is found under 'foo.buffer'.

Calling this multiple times (on multiple statements) is legal (and will produce a unified closure).

## ◆ pack_into_struct()

Expr Halide::Internal::Closure::pack_into_struct | ( |  | ) | const

Pack a closure into a struct.

## ◆ unpack_from_struct()

Stmt Halide::Internal::Closure::unpack_from_struct | ( | const Expr & | ,
|  | const Stmt & |
| ) |  | const

Unpack a closure around a Stmt, putting all the names in scope.

## ◆ visit() [9/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const IntImm * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [10/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const UIntImm * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [11/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const FloatImm * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [12/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const StringImm * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [13/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Cast * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [14/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Reinterpret * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [15/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Add * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [16/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Sub * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [17/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Mul * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [18/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Div * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [19/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Mod * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [20/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Min * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [21/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Max * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [22/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const EQ * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [23/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const NE * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [24/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const LT * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [25/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const LE * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [26/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const GT * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [27/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const GE * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [28/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const And * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [29/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Or * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [30/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Not * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [31/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Select * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [32/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Load * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [33/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Ramp * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [34/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Broadcast * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [35/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Let * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [36/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const LetStmt * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [37/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const AssertStmt * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [38/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const ProducerConsumer * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [39/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Store * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [40/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Provide * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [41/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Allocate * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [42/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Free * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [43/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Realize * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [44/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Block * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [45/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Fork * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [46/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const IfThenElse * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [47/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Evaluate * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [48/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Call * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [49/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Variable * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [50/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const For * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [51/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Acquire * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [52/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Shuffle * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [53/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Prefetch * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [54/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const HoistedStorage * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [55/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Atomic * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [56/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const VectorReduce * |  | ) |
| protectedvirtual

Reimplemented from Halide::Internal::IRVisitor.

## Member Data Documentation

## ◆ ignore

Scope Halide::Internal::Closure::ignore
| protected

Definition at line 28 of file Closure.h.

## ◆ vars

std::map<std::string, Type> Halide::Internal::Closure::vars

External variables referenced.

There's code that assumes iterating over this repeatedly gives a consistent order, so don't swap out the data type for something non-deterministic.

Definition at line 94 of file Closure.h.

## ◆ buffers

std::map<std::string, Buffer> Halide::Internal::Closure::buffers

External allocations referenced.

Definition at line 97 of file Closure.h.

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

- src/Closure.h