Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
Reduction.h
Go to the documentation of this file.
1#ifndef HALIDE_REDUCTION_H
2#define HALIDE_REDUCTION_H
3
4/** \file
5 * Defines internal classes related to Reduction Domains
6 */
7
8#include "Expr.h"
9
10namespace Halide {
11namespace Internal {
12
13class IRMutator;
14
15/** A single named dimension of a reduction domain */
17 std::string var;
19
20 /** This lets you use a ReductionVariable as a key in a map of the form
21 * map<ReductionVariable, Foo, ReductionVariable::Compare> */
22 struct Compare {
23 bool operator()(const ReductionVariable &a, const ReductionVariable &b) const {
24 return a.var < b.var;
25 }
26 };
27};
28
29struct ReductionDomainContents;
30
31/** A reference-counted handle on a reduction domain, which is just a
32 * vector of ReductionVariable. */
35
36public:
37 /** This lets you use a ReductionDomain as a key in a map of the form
38 * map<ReductionDomain, Foo, ReductionDomain::Compare> */
39 struct Compare {
40 bool operator()(const ReductionDomain &a, const ReductionDomain &b) const {
41 internal_assert(a.contents.defined() && b.contents.defined());
42 return a.contents < b.contents;
43 }
44 };
45
46 /** Construct a new nullptr reduction domain */
48 : contents(nullptr) {
49 }
50
51 /** Construct a reduction domain that spans the outer product of
52 * all values of the given ReductionVariable in scanline order,
53 * with the start of the vector being innermost, and the end of
54 * the vector being outermost. */
55 ReductionDomain(const std::vector<ReductionVariable> &domain);
56
57 /** Construct a reduction domain from deserialization */
58 ReductionDomain(const std::vector<ReductionVariable> &domain, const Expr &predicate, bool frozen);
59
60 /** Return a deep copy of this ReductionDomain. */
62
63 /** Is this handle non-nullptr */
64 bool defined() const {
65 return contents.defined();
66 }
67
68 /** Tests for equality of reference. Only one reduction domain is
69 * allowed per reduction function, and this is used to verify
70 * that */
71 bool same_as(const ReductionDomain &other) const {
72 return contents.same_as(other.contents);
73 }
74
75 /** Immutable access to the reduction variables. */
76 const std::vector<ReductionVariable> &domain() const;
77
78 /** Add predicate to the reduction domain. See \ref RDom::where
79 * for more details. */
81
82 /** Return the predicate defined on this reduction domain. */
83 Expr predicate() const;
84
85 /** Set the predicate, replacing any previously set predicate. */
86 void set_predicate(const Expr &);
87
88 /** Split predicate into vector of ANDs. If there is no predicate (i.e. all
89 * iteration domain in this reduction domain is valid), this returns an
90 * empty vector. */
91 std::vector<Expr> split_predicate() const;
92
93 /** Mark RDom as frozen, which means it cannot accept new predicates. An
94 * RDom is frozen once it is used in a Func's update definition. */
95 void freeze();
96
97 /** Check if a RDom has been frozen. If so, it is an error to add new
98 * predicates. */
99 bool frozen() const;
100
101 /** Pass an IRVisitor through to all Exprs referenced in the
102 * ReductionDomain. */
103 void accept(IRVisitor *) const;
104
105 /** Pass an IRMutator through to all Exprs referenced in the
106 * ReductionDomain. */
108};
109
111
112} // namespace Internal
113} // namespace Halide
114
115#endif
#define internal_assert(c)
Definition Errors.h:19
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
A base class for passes over the IR which modify it (e.g.
Definition IRMutator.h:26
A base class for algorithms that need to recursively walk over the IR.
Definition IRVisitor.h:19
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition Reduction.h:33
void freeze()
Mark RDom as frozen, which means it cannot accept new predicates.
std::vector< Expr > split_predicate() const
Split predicate into vector of ANDs.
bool defined() const
Is this handle non-nullptr.
Definition Reduction.h:64
void set_predicate(const Expr &)
Set the predicate, replacing any previously set predicate.
ReductionDomain deep_copy() const
Return a deep copy of this ReductionDomain.
const std::vector< ReductionVariable > & domain() const
Immutable access to the reduction variables.
ReductionDomain(const std::vector< ReductionVariable > &domain, const Expr &predicate, bool frozen)
Construct a reduction domain from deserialization.
Expr predicate() const
Return the predicate defined on this reduction domain.
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the ReductionDomain.
ReductionDomain()
Construct a new nullptr reduction domain.
Definition Reduction.h:47
ReductionDomain(const std::vector< ReductionVariable > &domain)
Construct a reduction domain that spans the outer product of all values of the given ReductionVariabl...
bool frozen() const
Check if a RDom has been frozen.
void where(Expr predicate)
Add predicate to the reduction domain.
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the ReductionDomain.
bool same_as(const ReductionDomain &other) const
Tests for equality of reference.
Definition Reduction.h:71
void split_predicate_test()
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
A fragment of Halide syntax.
Definition Expr.h:258
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself.
HALIDE_ALWAYS_INLINE bool defined() const
HALIDE_ALWAYS_INLINE bool same_as(const IntrusivePtr &other) const
This lets you use a ReductionDomain as a key in a map of the form map<ReductionDomain,...
Definition Reduction.h:39
bool operator()(const ReductionDomain &a, const ReductionDomain &b) const
Definition Reduction.h:40
This lets you use a ReductionVariable as a key in a map of the form map<ReductionVariable,...
Definition Reduction.h:22
bool operator()(const ReductionVariable &a, const ReductionVariable &b) const
Definition Reduction.h:23
A single named dimension of a reduction domain.
Definition Reduction.h:16