Loading...
Searching...
No Matches
Definition.h
Go to the documentation of this file.
#ifndef HALIDE_DEFINITION_H
#define HALIDE_DEFINITION_H
/** \file
* Defines the internal representation of a halide function's definition and related classes
*/
#include "Expr.h"
#include "IntrusivePtr.h"
#include "Schedule.h"
#include <map>
namespace Halide {
namespace Internal {
struct DefinitionContents;
struct FunctionContents;
class ReductionDomain;
} // namespace Internal
namespace Internal {
class IRVisitor;
class IRMutator;
struct Specialization;
/** A Function definition which can either represent a init or an update
* definition. A function may have different definitions due to specialization,
* which are stored in 'specializations' (Not possible from the front-end, but
* some scheduling directives may potentially cause this divergence to occur).
* Although init definition may have multiple values (RHS) per specialization, it
* must have the same LHS (i.e. same pure dimension variables). The update
* definition, on the other hand, may have different LHS/RHS per specialization.
* Note that, while the Expr in LHS/RHS may be different across specializations,
* they must have the same number of dimensions and the same pure dimensions.
*/
class Definition {
IntrusivePtr<DefinitionContents> contents;
public:
/** Construct a Definition from an existing DefinitionContents pointer. Must be non-null */
explicit Definition(const IntrusivePtr<DefinitionContents> &);
/** Construct a Definition with the supplied args, values, and reduction domain. */
Definition(const std::vector<Expr> &args, const std::vector<Expr> &values,
const ReductionDomain &rdom, bool is_init);
/** Construct a Definition with deserialized data. */
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 an undefined Definition object. */
Definition();
/** Return a copy of this Definition. */
Definition get_copy() const;
/** Equality of identity */
bool same_as(const Definition &other) const {
return contents.same_as(other.contents);
}
/** Definition objects are nullable. Does this definition exist? */
bool defined() const;
/** Is this an init definition; otherwise it's an update definition */
bool is_init() const;
/** Pass an IRVisitor through to all Exprs referenced in the
* definition. */
void accept(IRVisitor *) const;
/** Pass an IRMutator through to all Exprs referenced in the
* definition. */
void mutate(IRMutator *);
/** Get the default (no-specialization) arguments (left-hand-side) of the definition.
*
* Warning: Any Vars in the Exprs are not qualified with the Func name, so
* the Exprs may contain names which collide with names provided by
* unique_name.
*/
// @{
const std::vector<Expr> &args() const;
std::vector<Expr> &args();
// @}
/** Get the default (no-specialization) right-hand-side of the definition.
*
* Warning: Any Vars in the Exprs are not qualified with the Func name, so
* the Exprs may contain names which collide with names provided by
* unique_name.
*/
// @{
const std::vector<Expr> &values() const;
std::vector<Expr> &values();
// @}
/** Get the predicate on the definition */
// @{
const Expr &predicate() const;
Expr &predicate();
// @}
/** Split predicate into vector of ANDs. If there is no predicate (i.e. this
* definition is always valid), this returns an empty vector. */
std::vector<Expr> split_predicate() const;
/** Get the default (no-specialization) stage-specific schedule associated
* with this definition. */
// @{
const StageSchedule &schedule() const;
StageSchedule &schedule();
// @}
/** You may create several specialized versions of a func with
* different stage-specific schedules. They trigger when the condition is
* true. See \ref Func::specialize */
// @{
const std::vector<Specialization> &specializations() const;
std::vector<Specialization> &specializations();
const Specialization &add_specialization(Expr condition);
// @}
};
struct Specialization {
Expr condition;
Definition definition;
std::string failure_message; // If non-empty, this specialization always assert-fails with this message.
};
} // namespace Internal
} // namespace Halide
#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::Internal
Definition AbstractGenerator.h:24
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::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