Halide 22.0.0 Halide compiler and libraries

Definition.h
Go to the documentation of this file.
1#ifndef HALIDE_DEFINITION_H
2#define HALIDE_DEFINITION_H
3
4/** \file
5 * Defines the internal representation of a halide function's definition and related classes
6 */
7
8#include "Expr.h"
9#include "IntrusivePtr.h"
10#include "Schedule.h"
11
12#include <map>
13
14 namespace Halide {
15
16 namespace Internal {
17 struct DefinitionContents;
18 struct FunctionContents;
19 class ReductionDomain;
20} // namespace Internal
21
22 namespace Internal {
23
24 class IRVisitor;
25 class IRMutator;
26 struct Specialization;
27
28/** A Function definition which can either represent a init or an update
29 * definition. A function may have different definitions due to specialization,
30 * which are stored in 'specializations' (Not possible from the front-end, but
31 * some scheduling directives may potentially cause this divergence to occur).
32 * Although init definition may have multiple values (RHS) per specialization, it
33 * must have the same LHS (i.e. same pure dimension variables). The update
34 * definition, on the other hand, may have different LHS/RHS per specialization.
35 * Note that, while the Expr in LHS/RHS may be different across specializations,
36 * they must have the same number of dimensions and the same pure dimensions.
37 */
38 class Definition {
39
40 IntrusivePtr<DefinitionContents> contents;
41
42 public:
43 /** Construct a Definition from an existing DefinitionContents pointer. Must be non-null */
44 explicit Definition(const IntrusivePtr<DefinitionContents> &);
45
46 /** Construct a Definition with the supplied args, values, and reduction domain. */
47 Definition(const std::vector<Expr> &args, const std::vector<Expr> &values,
48 const ReductionDomain &rdom, bool is_init);
49
50 /** Construct a Definition with deserialized data. */
51 Definition(bool is_init, const Expr &predicate, const std::vector<Expr> &args, const std::vector<Expr> &values,
52 const StageSchedule &schedule, const std::vector<Specialization> &specializations);
53
54 /** Construct an undefined Definition object. */
55 Definition();
56
57 /** Return a copy of this Definition. */
58 Definition get_copy() const;
59
60 /** Equality of identity */
61 bool same_as(const Definition &other) const {
62 return contents.same_as(other.contents);
63 }
64
65 /** Definition objects are nullable. Does this definition exist? */
66 bool defined() const;
67
68 /** Is this an init definition; otherwise it's an update definition */
69 bool is_init() const;
70
71 /** Pass an IRVisitor through to all Exprs referenced in the
72 * definition. */
73 void accept(IRVisitor *) const;
74
75 /** Pass an IRMutator through to all Exprs referenced in the
76 * definition. */
77 void mutate(IRMutator *);
78
79 /** Get the default (no-specialization) arguments (left-hand-side) of the definition.
80 *
81 * Warning: Any Vars in the Exprs are not qualified with the Func name, so
82 * the Exprs may contain names which collide with names provided by
83 * unique_name.
84 */
85 // @{
86 const std::vector<Expr> &args() const;
87 std::vector<Expr> &args();
88 // @}
89
90 /** Get the default (no-specialization) right-hand-side of the definition.
91 *
92 * Warning: Any Vars in the Exprs are not qualified with the Func name, so
93 * the Exprs may contain names which collide with names provided by
94 * unique_name.
95 */
96 // @{
97 const std::vector<Expr> &values() const;
98 std::vector<Expr> &values();
99 // @}
100
101 /** Get the predicate on the definition */
102 // @{
103 const Expr &predicate() const;
104 Expr &predicate();
105 // @}
106
107 /** Split predicate into vector of ANDs. If there is no predicate (i.e. this
108 * definition is always valid), this returns an empty vector. */
109 std::vector<Expr> split_predicate() const;
110
111 /** Get the default (no-specialization) stage-specific schedule associated
112 * with this definition. */
113 // @{
114 const StageSchedule &schedule() const;
115 StageSchedule &schedule();
116 // @}
117
118 /** You may create several specialized versions of a func with
119 * different stage-specific schedules. They trigger when the condition is
120 * true. See \ref Func::specialize */
121 // @{
122 const std::vector<Specialization> &specializations() const;
123 std::vector<Specialization> &specializations();
124 const Specialization &add_specialization(Expr condition);
125 // @}
126};
127
128 struct Specialization {
129 Expr condition;
130 Definition definition;
131 std::string failure_message; // If non-empty, this specialization always assert-fails with this message.
132};
133
134} // namespace Internal
135} // namespace Halide
136
137#endif
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
IntrusivePtr.h
Support classes for reference-counting via intrusive shared pointers.
Schedule.h
Defines the internal representation of the schedule for a function.
Halide::Internal::Definition
A Function definition which can either represent a init or an update definition.
Definition: Definition.h:38
Halide::Internal::Definition::values
const std::vector< Expr > & values() const
Get the default (no-specialization) right-hand-side of the definition.
Halide::Internal::Definition::same_as
bool same_as(const Definition &other) const
Equality of identity.
Definition: Definition.h:61
Halide::Internal::Definition::split_predicate
std::vector< Expr > split_predicate() const
Split predicate into vector of ANDs.
Halide::Internal::Definition::predicate
Expr & predicate()
Halide::Internal::Definition::args
std::vector< Expr > & args()
Halide::Internal::Definition::Definition
Definition(bool is_init, const Expr &predicate, const std::vector< Expr > &args, const std::vector< Expr > &values, const StageSchedule &schedule, const std::vector< Specialization > &specializations)
Construct a Definition with deserialized data.
Halide::Internal::Definition::Definition
Definition(const IntrusivePtr< DefinitionContents > &)
Construct a Definition from an existing DefinitionContents pointer.
Halide::Internal::Definition::predicate
const Expr & predicate() const
Get the predicate on the definition.
Halide::Internal::Definition::add_specialization
const Specialization & add_specialization(Expr condition)
Halide::Internal::Definition::Definition
Definition()
Construct an undefined Definition object.
Halide::Internal::Definition::values
std::vector< Expr > & values()
Halide::Internal::Definition::schedule
StageSchedule & schedule()
Halide::Internal::Definition::mutate
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the definition.
Halide::Internal::Definition::args
const std::vector< Expr > & args() const
Get the default (no-specialization) arguments (left-hand-side) of the definition.
Halide::Internal::Definition::is_init
bool is_init() const
Is this an init definition; otherwise it's an update definition.
Halide::Internal::Definition::specializations
const std::vector< Specialization > & specializations() const
You may create several specialized versions of a func with different stage-specific schedules.
Halide::Internal::Definition::schedule
const StageSchedule & schedule() const
Get the default (no-specialization) stage-specific schedule associated with this definition.
Halide::Internal::Definition::defined
bool defined() const
Definition objects are nullable.
Halide::Internal::Definition::accept
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the definition.
Halide::Internal::Definition::get_copy
Definition get_copy() const
Return a copy of this Definition.
Halide::Internal::Definition::specializations
std::vector< Specialization > & specializations()
Halide::Internal::Definition::Definition
Definition(const std::vector< Expr > &args, const std::vector< Expr > &values, const ReductionDomain &rdom, bool is_init)
Construct a Definition with the supplied args, values, and reduction domain.
Halide::Internal::IRMutator
A base class for passes over the IR which modify it (e.g.
Definition: IRMutator.h:26
Halide::Internal::IRVisitor
A base class for algorithms that need to recursively walk over the IR.
Definition: IRVisitor.h:19
Halide::Internal::ReductionDomain
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition: Reduction.h:38
Halide::Internal::StageSchedule
A schedule for a single stage of a Halide pipeline.
Definition: Schedule.h:680
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:258
Halide::Internal::IntrusivePtr< DefinitionContents >
Halide::Internal::IntrusivePtr::same_as
HALIDE_ALWAYS_INLINE bool same_as(const IntrusivePtr &other) const
Definition: IntrusivePtr.h:171
Halide::Internal::Specialization
Definition: Definition.h:128
Halide::Internal::Specialization::condition
Expr condition
Definition: Definition.h:129
Halide::Internal::Specialization::definition
Definition definition
Definition: Definition.h:130
Halide::Internal::Specialization::failure_message
std::string failure_message
Definition: Definition.h:131