Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
AssociativeOpsTable.h
Go to the documentation of this file.
1#ifndef HALIDE_ASSOCIATIVE_OPS_TABLE_H
2#define HALIDE_ASSOCIATIVE_OPS_TABLE_H
3
4/** \file
5 * Tables listing associative operators and their identities.
6 */
7
8#include "IREquality.h"
9#include "IROperator.h"
10
11#include <utility>
12#include <vector>
13
14namespace Halide {
15namespace Internal {
16
17/**
18 * Represent an associative op with its identity. The op may be multi-dimensional,
19 * e.g. complex multiplication. 'is_commutative' is set to true if the op is also
20 * commutative in addition to being associative.
21 *
22 * For example, complex multiplication is represented as:
23 \code
24 AssociativePattern pattern(
25 {x0 * y0 - x1 * y1, x1 * y0 + x0 * y1},
26 {one, zero},
27 true
28 );
29 \endcode
30 */
32 /** Contain the binary operators for each dimension of the associative op. */
33 std::vector<Expr> ops;
34 /** Contain the identities for each dimension of the associative op. */
35 std::vector<Expr> identities;
36 /** Indicate if the associative op is also commutative. */
37 bool is_commutative = false;
38
39 AssociativePattern() = default;
43 AssociativePattern(const std::vector<Expr> &ops, const std::vector<Expr> &ids, bool is_commutative)
45 }
47 : ops({std::move(op)}), identities({std::move(id)}), is_commutative(is_commutative) {
48 }
49
50 bool operator==(const AssociativePattern &other) const {
51 if ((is_commutative != other.is_commutative) || (ops.size() != other.ops.size())) {
52 return false;
53 }
54 for (size_t i = 0; i < size(); ++i) {
55 if (!equal(ops[i], other.ops[i]) || !equal(identities[i], other.identities[i])) {
56 return false;
57 }
58 }
59 return true;
60 }
61 bool operator!=(const AssociativePattern &other) const {
62 return !(*this == other);
63 }
64 size_t size() const {
65 return ops.size();
66 }
67 bool commutative() const {
68 return is_commutative;
69 }
70};
71
72const std::vector<AssociativePattern> &get_ops_table(const std::vector<Expr> &exprs);
73
74} // namespace Internal
75} // namespace Halide
76
77#endif
Methods to test Exprs and Stmts for equality of value.
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
bool equal(const RDom &bounds0, const RDom &bounds1)
Return true if bounds0 and bounds1 represent the same bounds.
const std::vector< AssociativePattern > & get_ops_table(const std::vector< Expr > &exprs)
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
Represent an associative op with its identity.
bool operator!=(const AssociativePattern &other) const
bool is_commutative
Indicate if the associative op is also commutative.
std::vector< Expr > identities
Contain the identities for each dimension of the associative op.
AssociativePattern(const std::vector< Expr > &ops, const std::vector< Expr > &ids, bool is_commutative)
AssociativePattern(Expr op, Expr id, bool is_commutative)
std::vector< Expr > ops
Contain the binary operators for each dimension of the associative op.
bool operator==(const AssociativePattern &other) const