Loading...
Searching...
No Matches
Reduction.h
Go to the documentation of this file.
#ifndef HALIDE_REDUCTION_H
#define HALIDE_REDUCTION_H
/** \file
* Defines internal classes related to Reduction Domains
*/
#include "Expr.h"
namespace Halide {
namespace Internal {
class IRMutator;
/** A single named dimension of a reduction domain */
struct ReductionVariable {
/**
* A variable name for the reduction variable. This name must be a
* valid Var name, i.e. it must not contain a <tt>.</tt> character.
*/
std::string var;
Expr min, extent;
/** This lets you use a ReductionVariable as a key in a map of the form
* map<ReductionVariable, Foo, ReductionVariable::Compare> */
struct Compare {
bool operator()(const ReductionVariable &a, const ReductionVariable &b) const {
return a.var < b.var;
}
};
};
struct ReductionDomainContents;
/** A reference-counted handle on a reduction domain, which is just a
* vector of ReductionVariable. */
class ReductionDomain {
IntrusivePtr<ReductionDomainContents> contents;
public:
/** This lets you use a ReductionDomain as a key in a map of the form
* map<ReductionDomain, Foo, ReductionDomain::Compare> */
struct Compare {
bool operator()(const ReductionDomain &a, const ReductionDomain &b) const {
internal_assert(a.contents.defined() && b.contents.defined());
return a.contents < b.contents;
}
};
/** Construct a new nullptr reduction domain */
ReductionDomain()
: contents(nullptr) {
}
/** Construct a reduction domain that spans the outer product of
* all values of the given ReductionVariable in scanline order,
* with the start of the vector being innermost, and the end of
* the vector being outermost. */
ReductionDomain(const std::vector<ReductionVariable> &domain);
/** Construct a reduction domain from deserialization */
ReductionDomain(const std::vector<ReductionVariable> &domain, const Expr &predicate, bool frozen);
/** Return a deep copy of this ReductionDomain. */
ReductionDomain deep_copy() const;
/** Is this handle non-nullptr */
bool defined() const {
return contents.defined();
}
/** Tests for equality of reference. Only one reduction domain is
* allowed per reduction function, and this is used to verify
* that */
bool same_as(const ReductionDomain &other) const {
return contents.same_as(other.contents);
}
/** Immutable access to the reduction variables. */
const std::vector<ReductionVariable> &domain() const;
/** Add predicate to the reduction domain. See \ref RDom::where
* for more details. */
void where(Expr predicate);
/** Return the predicate defined on this reduction domain. */
Expr predicate() const;
/** Set the predicate, replacing any previously set predicate. */
void set_predicate(const Expr &);
/** Split predicate into vector of ANDs. If there is no predicate (i.e. all
* iteration domain in this reduction domain is valid), this returns an
* empty vector. */
std::vector<Expr> split_predicate() const;
/** Mark RDom as frozen, which means it cannot accept new predicates. An
* RDom is frozen once it is used in a Func's update definition. */
void freeze();
/** Check if a RDom has been frozen. If so, it is an error to add new
* predicates. */
bool frozen() const;
/** Pass an IRVisitor through to all Exprs referenced in the
* ReductionDomain. */
void accept(IRVisitor *) const;
/** Pass an IRMutator through to all Exprs referenced in the
* ReductionDomain. */
void mutate(IRMutator *);
};
void split_predicate_test();
} // namespace Internal
} // namespace Halide
#endif
internal_assert
#define internal_assert(c)
Definition Error.h:218
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt).
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::freeze
void freeze()
Mark RDom as frozen, which means it cannot accept new predicates.
Halide::Internal::ReductionDomain::split_predicate
std::vector< Expr > split_predicate() const
Split predicate into vector of ANDs.
Halide::Internal::ReductionDomain::defined
bool defined() const
Is this handle non-nullptr.
Definition Reduction.h:69
Halide::Internal::ReductionDomain::set_predicate
void set_predicate(const Expr &)
Set the predicate, replacing any previously set predicate.
Halide::Internal::ReductionDomain::deep_copy
ReductionDomain deep_copy() const
Return a deep copy of this ReductionDomain.
Halide::Internal::ReductionDomain::domain
const std::vector< ReductionVariable > & domain() const
Immutable access to the reduction variables.
Halide::Internal::ReductionDomain::ReductionDomain
ReductionDomain(const std::vector< ReductionVariable > &domain, const Expr &predicate, bool frozen)
Construct a reduction domain from deserialization.
Halide::Internal::ReductionDomain::predicate
Expr predicate() const
Return the predicate defined on this reduction domain.
Halide::Internal::ReductionDomain::accept
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the ReductionDomain.
Halide::Internal::ReductionDomain::ReductionDomain
ReductionDomain()
Construct a new nullptr reduction domain.
Definition Reduction.h:52
Halide::Internal::ReductionDomain::ReductionDomain
ReductionDomain(const std::vector< ReductionVariable > &domain)
Construct a reduction domain that spans the outer product of all values of the given ReductionVariabl...
Halide::Internal::ReductionDomain::frozen
bool frozen() const
Check if a RDom has been frozen.
Halide::Internal::ReductionDomain::where
void where(Expr predicate)
Add predicate to the reduction domain.
Halide::Internal::ReductionDomain::mutate
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the ReductionDomain.
Halide::Internal::ReductionDomain::same_as
bool same_as(const ReductionDomain &other) const
Tests for equality of reference.
Definition Reduction.h:76
Halide::Internal
Definition AbstractGenerator.h:24
Halide::Internal::split_predicate_test
void split_predicate_test()
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Internal::IntrusivePtr
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself.
Definition IntrusivePtr.h:71
Halide::Internal::IntrusivePtr::defined
HALIDE_ALWAYS_INLINE bool defined() const
Definition IntrusivePtr.h:164
Halide::Internal::ReductionDomain::Compare
This lets you use a ReductionDomain as a key in a map of the form map<ReductionDomain,...
Definition Reduction.h:44
Halide::Internal::ReductionDomain::Compare::operator()
bool operator()(const ReductionDomain &a, const ReductionDomain &b) const
Definition Reduction.h:45
Halide::Internal::ReductionVariable::Compare
This lets you use a ReductionVariable as a key in a map of the form map<ReductionVariable,...
Definition Reduction.h:27
Halide::Internal::ReductionVariable::Compare::operator()
bool operator()(const ReductionVariable &a, const ReductionVariable &b) const
Definition Reduction.h:28
Halide::Internal::ReductionVariable
A single named dimension of a reduction domain.
Definition Reduction.h:16
Halide::Internal::ReductionVariable::min
Expr min
Definition Reduction.h:23
Halide::Internal::ReductionVariable::var
std::string var
A variable name for the reduction variable.
Definition Reduction.h:21
Halide::Internal::ReductionVariable::extent
Expr extent
Definition Reduction.h:23