Loading...
Searching...
No Matches
AssociativeOpsTable.h
Go to the documentation of this file.
#ifndef HALIDE_ASSOCIATIVE_OPS_TABLE_H
#define HALIDE_ASSOCIATIVE_OPS_TABLE_H
/** \file
* Tables listing associative operators and their identities.
*/
#include "IREquality.h"
#include "IROperator.h"
#include <utility>
#include <vector>
namespace Halide {
namespace Internal {
/**
* Represent an associative op with its identity. The op may be multi-dimensional,
* e.g. complex multiplication. 'is_commutative' is set to true if the op is also
* commutative in addition to being associative.
*
* For example, complex multiplication is represented as:
\code
AssociativePattern pattern(
{x0 * y0 - x1 * y1, x1 * y0 + x0 * y1},
{one, zero},
true
);
\endcode
*/
struct AssociativePattern {
/** Contain the binary operators for each dimension of the associative op. */
std::vector<Expr> ops;
/** Contain the identities for each dimension of the associative op. */
std::vector<Expr> identities;
/** Indicate if the associative op is also commutative. */
bool is_commutative = false;
AssociativePattern() = default;
AssociativePattern(size_t size)
: ops(size), identities(size) {
}
AssociativePattern(const std::vector<Expr> &ops, const std::vector<Expr> &ids, bool is_commutative)
: ops(ops), identities(ids), is_commutative(is_commutative) {
}
AssociativePattern(Expr op, Expr id, bool is_commutative)
: ops({std::move(op)}), identities({std::move(id)}), is_commutative(is_commutative) {
}
bool operator==(const AssociativePattern &other) const {
if ((is_commutative != other.is_commutative) || (ops.size() != other.ops.size())) {
return false;
}
for (size_t i = 0; i < size(); ++i) {
if (!equal(ops[i], other.ops[i]) || !equal(identities[i], other.identities[i])) {
return false;
}
}
return true;
}
bool operator!=(const AssociativePattern &other) const {
return !(*this == other);
}
size_t size() const {
return ops.size();
}
bool commutative() const {
return is_commutative;
}
};
const std::vector<AssociativePattern> &get_ops_table(const std::vector<Expr> &exprs);
} // namespace Internal
} // namespace Halide
#endif
IREquality.h
Methods to test Exprs and Stmts for equality of value.
IROperator.h
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
Halide::Internal
Definition AbstractGenerator.h:24
Halide::Internal::equal
bool equal(const RDom &bounds0, const RDom &bounds1)
Return true if bounds0 and bounds1 represent the same bounds.
Halide::Internal::get_ops_table
const std::vector< AssociativePattern > & get_ops_table(const std::vector< Expr > &exprs)
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::AssociativePattern::operator!=
bool operator!=(const AssociativePattern &other) const
Definition AssociativeOpsTable.h:61
Halide::Internal::AssociativePattern::is_commutative
bool is_commutative
Indicate if the associative op is also commutative.
Definition AssociativeOpsTable.h:37
Halide::Internal::AssociativePattern::identities
std::vector< Expr > identities
Contain the identities for each dimension of the associative op.
Definition AssociativeOpsTable.h:35
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern(const std::vector< Expr > &ops, const std::vector< Expr > &ids, bool is_commutative)
Definition AssociativeOpsTable.h:43
Halide::Internal::AssociativePattern::size
size_t size() const
Definition AssociativeOpsTable.h:64
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern(Expr op, Expr id, bool is_commutative)
Definition AssociativeOpsTable.h:46
Halide::Internal::AssociativePattern::ops
std::vector< Expr > ops
Contain the binary operators for each dimension of the associative op.
Definition AssociativeOpsTable.h:33
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern()=default
Halide::Internal::AssociativePattern::operator==
bool operator==(const AssociativePattern &other) const
Definition AssociativeOpsTable.h:50
Halide::Internal::AssociativePattern::commutative
bool commutative() const
Definition AssociativeOpsTable.h:67
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern(size_t size)
Definition AssociativeOpsTable.h:40