1 #ifndef HALIDE_SCHEDULE_H
2 #define HALIDE_SCHEDULE_H
26 struct FunctionContents;
27 struct LoopLevelContents;
157 : contents(std::move(c)) {
159 LoopLevel(
const std::string &func_name,
const std::string &var_name,
160 bool is_rvar,
int stage_index,
bool locked =
false);
220 bool match(
const std::string &loop)
const;
228 return !(*
this == other);
232 void check_defined()
const;
233 void check_locked()
const;
234 void check_defined_and_locked()
const;
243 std::map<std::string, LoopAlignStrategy>
align;
256 struct ReductionVariable;
482 FusedPair(
const std::string &f1,
size_t s1,
const std::string &f2,
483 size_t s2,
const std::string &var)
509 struct FuncScheduleContents;
510 struct StageScheduleContents;
511 struct FunctionContents;
522 : contents(std::move(c)) {
535 std::map<FunctionPtr, FunctionPtr> &copied_map)
const;
573 const std::vector<Bound> &
bounds()
const;
590 const std::map<std::string, Internal::FunctionPtr> &
wrappers()
const;
591 std::map<std::string, Internal::FunctionPtr> &
wrappers();
625 : contents(std::move(c)) {
645 const std::vector<ReductionVariable> &
rvars()
const;
646 std::vector<ReductionVariable> &
rvars();
652 const std::vector<Split> &
splits()
const;
664 const std::vector<Dim> &
dims()
const;
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines the internal representation of parameters to halide piplines.
Defines the PrefetchDirective struct.
A schedule for a Function of a Halide pipeline.
const std::vector< Bound > & bounds() const
You may explicitly bound some of the dimensions of a function, or constrain them to lie on multiples ...
const std::map< std::string, Internal::FunctionPtr > & wrappers() const
Mark calls of a function by 'f' to be replaced with its identity wrapper or clone during the lowering...
void add_wrapper(const std::string &f, const Internal::FunctionPtr &wrapper)
std::vector< Bound > & estimates()
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the Schedule.
Expr memoize_eviction_key() const
const std::vector< StorageDim > & storage_dims() const
The list and order of dimensions used to store this function.
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the Schedule.
LoopLevel & store_level()
MemoryType & memory_type()
std::map< std::string, Internal::FunctionPtr > & wrappers()
const LoopLevel & compute_level() const
MemoryType memory_type() const
The memory type (heap/stack/shared/etc) used to back this Func.
FuncSchedule(const FuncSchedule &other)=default
const std::vector< Bound > & estimates() const
You may explicitly specify an estimate of some of the function dimensions.
Expr & memoize_eviction_key()
This flag is set to true if the schedule is memoized and has an attached eviction key.
FuncSchedule(IntrusivePtr< FuncScheduleContents > c)
bool & async()
Is the production of this Function done asynchronously.
LoopLevel & compute_level()
const LoopLevel & store_level() const
At what sites should we inject the allocation and the computation of this function?...
FuncSchedule deep_copy(std::map< FunctionPtr, FunctionPtr > &copied_map) const
Return a deep copy of this FuncSchedule.
std::vector< Bound > & bounds()
std::vector< StorageDim > & storage_dims()
bool & memoized()
This flag is set to true if the schedule is memoized.
A reference-counted handle to Halide's internal representation of a function.
A base class for passes over the IR which modify it (e.g.
A base class for algorithms that need to recursively walk over the IR.
A schedule for a single stage of a Halide pipeline.
const std::vector< FusedPair > & fused_pairs() const
List of function stages that are to be fused with this function stage from the outermost loop to a ce...
StageSchedule(IntrusivePtr< StageScheduleContents > c)
StageSchedule get_copy() const
Return a copy of this StageSchedule.
std::vector< Dim > & dims()
bool & touched()
This flag is set to true if the dims list has been manipulated by the user (or if a ScheduleHandle wa...
std::vector< ReductionVariable > & rvars()
FuseLoopLevel & fuse_level()
const std::vector< Split > & splits() const
The traversal of the domain of a function can have some of its dimensions split into sub-dimensions.
bool allow_race_conditions() const
Are race conditions permitted?
const FuseLoopLevel & fuse_level() const
Innermost loop level of fused loop nest for this function stage.
std::vector< PrefetchDirective > & prefetches()
bool atomic() const
Use atomic update?
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the Schedule.
bool & allow_race_conditions()
bool & override_atomic_associativity_test()
const std::vector< PrefetchDirective > & prefetches() const
You may perform prefetching in some of the dimensions of a function.
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the Schedule.
std::vector< Split > & splits()
std::vector< FusedPair > & fused_pairs()
const std::vector< ReductionVariable > & rvars() const
RVars of reduction domain associated with this schedule if there is any.
const std::vector< Dim > & dims() const
The list and ordering of dimensions used to evaluate this function, after all splits have taken place...
bool override_atomic_associativity_test() const
Atomic updates are only allowed on associative reductions.
StageSchedule(const StageSchedule &other)=default
A reference to a site in a Halide statement at the top of the body of a particular for loop.
std::string to_string() const
static LoopLevel root()
Construct a special LoopLevel value which represents the location outside of all for loops.
LoopLevel(const Internal::Function &f, const VarOrRVar &v, int stage_index=-1)
Identify the loop nest corresponding to some dimension of some function.
static LoopLevel inlined()
Construct a special LoopLevel value that implies that a function should be inlined away.
LoopLevel(const Func &f, const VarOrRVar &v, int stage_index=-1)
bool operator==(const LoopLevel &other) const
int stage_index() const
Return the index of the function stage associated with this loop level.
LoopLevel()
Construct an undefined LoopLevel.
void set(const LoopLevel &other)
Mutate our contents to match the contents of 'other'.
bool match(const LoopLevel &other) const
bool operator!=(const LoopLevel &other) const
bool match(const std::string &loop) const
DimType
Each Dim below has a dim_type, which tells you what transformations are legal on it.
@ ImpureRVar
The dim originated from an RVar.
@ PureRVar
The dim originated from an RVar.
@ PureVar
This dim originated from a Var.
ForType
An enum describing a type of loop traversal.
bool is_unordered_parallel(ForType for_type)
Check if for_type executes for loop iterations in parallel and unordered.
bool is_parallel(ForType for_type)
Returns true if for_type executes for loop iterations in parallel.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
TailStrategy
Different ways to handle a tail case in a split when the factor does not provably divide the extent.
@ Auto
For pure definitions use ShiftInwards.
@ RoundUp
Round up the extent to be a multiple of the split factor.
@ Predicate
Guard the inner loop with an if statement that prevents evaluation beyond the original extent,...
@ GuardWithIf
Guard the inner loop with an if statement that prevents evaluation beyond the original extent.
@ ShiftInwards
Prevent evaluation beyond the original extent by shifting the tail case inwards, re-evaluating some p...
LoopAlignStrategy
Different ways to handle the case when the start/end of the loops of stages computed with (fused) are...
@ Auto
By default, LoopAlignStrategy is set to NoAlign.
@ NoAlign
compute_with will make no attempt to align the start/end of the fused loops.
@ AlignEnd
Shift the end of the fused loops to align.
@ AlignStart
Shift the start of the fused loops to align.
DeviceAPI
An enum describing a type of device API.
MemoryType
An enum describing different address spaces to be used with Func::store_in.
A fragment of Halide syntax.
std::map< std::string, LoopAlignStrategy > align
Contains alignment strategies for the fused dimensions (indexed by the dimension name).
FuseLoopLevel(const LoopLevel &level, const std::map< std::string, LoopAlignStrategy > &align)
A bound on a loop, typically from Func::bound.
Expr min
Declared min and extent of the loop.
std::string var
The loop var being bounded.
Expr modulus
If defined, the number of iterations will be a multiple of "modulus", and the first iteration will be...
The Dim struct represents one loop in the schedule's representation of a loop nest.
std::string var
Name of the loop variable.
DimType dim_type
The DimType tells us what transformations are legal on this loop (see the DimType enum above).
bool is_rvar() const
Did this loop originate from an RVar (in which case the bounds of the loops are algorithmically meani...
ForType for_type
How are the loop values traversed (e.g.
DeviceAPI device_api
On what device does the body of the loop execute (e.g.
bool is_parallel() const
Could multiple iterations of this loop happen at the same time? Vectorized and GPULanes loop types ar...
bool is_unordered_parallel() const
Could multiple iterations of this loop happen at the same time, with reads and writes interleaved in ...
bool is_pure() const
Can this loop be evaluated in any order (including in parallel)? Equivalently, are there no data haza...
A possibly-weak pointer to a Halide function.
This represents two stages with fused loop nests from outermost to a specific loop level.
bool operator==(const FusedPair &other) const
FusedPair(const std::string &f1, size_t s1, const std::string &f2, size_t s2, const std::string &var)
bool operator<(const FusedPair &other) const
Properties of one axis of the storage of a Func.
std::string var
The var in the pure definition corresponding to this axis.
Expr alignment
The bounds allocated (not computed) must be a multiple of "alignment".
Expr fold_factor
If the Func is explicitly folded along this axis (with Func::fold_storage) this gives the extent of t...
A class that can represent Vars or RVars.