1#ifndef HALIDE_SCHEDULE_H
2#define HALIDE_SCHEDULE_H
27struct FunctionContents;
28struct LoopLevelContents;
207 : contents(std::move(c)) {
287 bool match(
const std::string &loop)
const;
295 return !(*
this == other);
299 void check_defined()
const;
300 void check_locked()
const;
301 void check_defined_and_locked()
const;
310 std::map<std::string, LoopAlignStrategy>
align;
323struct ReductionVariable;
555 FusedPair(
const std::string &f1,
size_t s1,
const std::string &f2,
556 size_t s2,
const std::string &var)
582struct FuncScheduleContents;
583struct StageScheduleContents;
584struct FunctionContents;
595 : contents(std::move(c)) {
608 std::map<FunctionPtr, FunctionPtr> &copied_map)
const;
649 const std::vector<Bound> &
bounds()
const;
666 const std::map<std::string, Internal::FunctionPtr> &
wrappers()
const;
667 std::map<std::string, Internal::FunctionPtr> &
wrappers();
703 : contents(std::move(c)) {
708 const std::vector<Dim> &
dims,
const std::vector<PrefetchDirective> &
prefetches,
727 const std::vector<ReductionVariable> &
rvars()
const;
728 std::vector<ReductionVariable> &
rvars();
734 const std::vector<Split> &
splits()
const;
746 const std::vector<Dim> &
dims()
const;
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines the Partition enum.
Defines the internal representation of parameters to halide piplines.
Defines the PrefetchDirective struct.
A schedule for a Function of a Halide pipeline.
Expr & memoize_eviction_key()
This flag is set to true if the schedule is memoized and has an attached eviction key.
Expr & ring_buffer() const
void add_wrapper(const std::string &f, const Internal::FunctionPtr &wrapper)
const std::vector< Bound > & estimates() const
You may explicitly specify an estimate of some of the function dimensions.
const std::vector< Bound > & bounds() const
You may explicitly bound some of the dimensions of a function, or constrain them to lie on multiples ...
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the Schedule.
Expr memoize_eviction_key() const
bool & async()
Is the production of this Function done asynchronously.
const LoopLevel & hoist_storage_level() const
LoopLevel & hoist_storage_level()
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the Schedule.
const LoopLevel & store_level() const
At what sites should we inject the allocation and the computation of this function?...
MemoryType & memory_type()
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...
LoopLevel & store_level()
MemoryType memory_type() const
The memory type (heap/stack/shared/etc) used to back this Func.
std::vector< StorageDim > & storage_dims()
FuncSchedule(const FuncSchedule &other)=default
FuncSchedule(IntrusivePtr< FuncScheduleContents > c)
std::map< std::string, Internal::FunctionPtr > & wrappers()
FuncSchedule deep_copy(std::map< FunctionPtr, FunctionPtr > &copied_map) const
Return a deep copy of this FuncSchedule.
bool & memoized()
This flag is set to true if the schedule is memoized.
const LoopLevel & compute_level() const
LoopLevel & compute_level()
std::vector< Bound > & estimates()
const std::vector< StorageDim > & storage_dims() const
The list and order of dimensions used to store this function.
std::vector< Bound > & bounds()
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.
StageSchedule(IntrusivePtr< StageScheduleContents > c)
std::vector< PrefetchDirective > & prefetches()
std::vector< ReductionVariable > & rvars()
const std::vector< ReductionVariable > & rvars() const
RVars of reduction domain associated with this schedule if there is any.
StageSchedule get_copy() const
Return a copy of this StageSchedule.
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< FusedPair > & fused_pairs()
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...
std::vector< Split > & splits()
bool allow_race_conditions() const
Are race conditions permitted?
bool & override_atomic_associativity_test()
StageSchedule(const std::vector< ReductionVariable > &rvars, const std::vector< Split > &splits, const std::vector< Dim > &dims, const std::vector< PrefetchDirective > &prefetches, const FuseLoopLevel &fuse_level, const std::vector< FusedPair > &fused_pairs, bool touched, bool allow_race_conditions, bool atomic, bool override_atomic_associativity_test)
const FuseLoopLevel & fuse_level() const
Innermost loop level of fused loop nest for this function stage.
bool atomic() const
Use atomic update?
const std::vector< Split > & splits() const
The traversal of the domain of a function can have some of its dimensions split into sub-dimensions.
std::vector< Dim > & dims()
const std::vector< Dim > & dims() const
The list and ordering of dimensions used to evaluate this function, after all splits have taken place...
FuseLoopLevel & fuse_level()
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the Schedule.
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the Schedule.
const std::vector< PrefetchDirective > & prefetches() const
You may perform prefetching in some of the dimensions of a function.
bool & allow_race_conditions()
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.
int get_stage_index() const
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.
std::string var_name() const
void set(const LoopLevel &other)
Mutate our contents to match the contents of 'other'.
bool match(const LoopLevel &other) const
LoopLevel(const std::string &func_name, const std::string &var_name, bool is_rvar, int stage_index, bool locked=false)
For deserialization only.
bool operator!=(const LoopLevel &other) const
std::string func_name() 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.
@ GuardWithIf
Guard the prefetch with if-guards that ignores the prefetch if any of the prefetched region ever goes...
TailStrategy
Different ways to handle a tail case in a split when the factor does not provably divide the extent.
@ RoundUp
Round up the extent to be a multiple of the split factor.
@ RoundUpAndBlend
Equivalent to RoundUp, but protected values that would be written beyond the end by loading the memor...
@ Predicate
Guard the loads and stores in the loop with an if statement that prevents evaluation beyond the origi...
@ PredicateStores
Guard the stores in the loop with an if statement that prevents evaluation beyond the original extent...
@ ShiftInwardsAndBlend
Equivalent to ShiftInwards, but protects values that would be re-evaluated by loading the memory loca...
@ ShiftInwards
Prevent evaluation beyond the original extent by shifting the tail case inwards, re-evaluating some p...
@ PredicateLoads
Guard the loads in the loop with an if statement that prevents evaluation beyond the original extent.
LoopAlignStrategy
Different ways to handle the case when the start/end of the loops of stages computed with (fused) are...
@ 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.
@ Auto
Let Halide select a storage type automatically.
Partition
Different ways to handle loops with a potentially optimizable boundary conditions.
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).
Partition partition_policy
The strategy for loop partitioning.
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
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself.
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 bound
The bounds allocated (not computed).
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.