Halide
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 <iostream>
12 #include <utility>
13 #include <vector>
14
15 namespace Halide {
16 namespace Internal {
17
18 /**
19  * Represent an associative op with its identity. The op may be multi-dimensional,
20  * e.g. complex multiplication. 'is_commutative' is set to true if the op is also
21  * commutative in addition to being associative.
22  *
23  * For example, complex multiplication is represented as:
24  \code
25  AssociativePattern pattern(
26  {x0 * y0 - x1 * y1, x1 * y0 + x0 * y1},
27  {one, zero},
28  true
29  );
30  \endcode
31  */
33  /** Contain the binary operators for each dimension of the associative op. */
34  std::vector<Expr> ops;
35  /** Contain the identities for each dimension of the associative op. */
36  std::vector<Expr> identities;
37  /** Indicate if the associative op is also commutative. */
39
41  : is_commutative(false) {
42  }
44  : ops(size), identities(size), is_commutative(false) {
45  }
46  AssociativePattern(const std::vector<Expr> &ops, const std::vector<Expr> &ids, bool is_commutative)
48  }
50  : ops({std::move(op)}), identities({std::move(id)}), is_commutative(is_commutative) {
51  }
52
53  bool operator==(const AssociativePattern &other) const {
54  if ((is_commutative != other.is_commutative) || (ops.size() != other.ops.size())) {
55  return false;
56  }
57  for (size_t i = 0; i < size(); ++i) {
58  if (!equal(ops[i], other.ops[i]) || !equal(identities[i], other.identities[i])) {
59  return false;
60  }
61  }
62  return true;
63  }
64  bool operator!=(const AssociativePattern &other) const {
65  return !(*this == other);
66  }
67  size_t size() const {
68  return ops.size();
69  }
70  bool commutative() const {
71  return is_commutative;
72  }
73 };
74
75 const std::vector<AssociativePattern> &get_ops_table(const std::vector<Expr> &exprs);
76
77 } // namespace Internal
78 } // namespace Halide
79
80 #endif
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern(const std::vector< Expr > &ops, const std::vector< Expr > &ids, bool is_commutative)
Definition: AssociativeOpsTable.h:46
Halide::Internal::AssociativePattern::operator!=
bool operator!=(const AssociativePattern &other) const
Definition: AssociativeOpsTable.h:64
IROperator.h
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern()
Definition: AssociativeOpsTable.h:40
Halide::Internal::AssociativePattern::commutative
bool commutative() const
Definition: AssociativeOpsTable.h:70
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern(Expr op, Expr id, bool is_commutative)
Definition: AssociativeOpsTable.h:49
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::get_ops_table
const std::vector< AssociativePattern > & get_ops_table(const std::vector< Expr > &exprs)
Halide::Internal::equal
bool equal(const RDom &bounds0, const RDom &bounds1)
Return true if bounds0 and bounds1 represent the same bounds.
Halide::Internal::AssociativePattern::size
size_t size() const
Definition: AssociativeOpsTable.h:67
Halide::Internal::AssociativePattern::identities
std::vector< Expr > identities
Contain the identities for each dimension of the associative op.
Definition: AssociativeOpsTable.h:36
Halide::Internal::AssociativePattern::is_commutative
bool is_commutative
Indicate if the associative op is also commutative.
Definition: AssociativeOpsTable.h:38
Halide::Internal::AssociativePattern::ops
std::vector< Expr > ops
Contain the binary operators for each dimension of the associative op.
Definition: AssociativeOpsTable.h:34
Halide::Internal::AssociativePattern
Represent an associative op with its identity.
Definition: AssociativeOpsTable.h:32
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
Halide::Internal::AssociativePattern::AssociativePattern
AssociativePattern(size_t size)
Definition: AssociativeOpsTable.h:43
Halide::Internal::AssociativePattern::operator==
bool operator==(const AssociativePattern &other) const
Definition: AssociativeOpsTable.h:53
IREquality.h