Halide 22.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
14 namespace Halide {
15 namespace 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 */
31 struct AssociativePattern {
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;
40 AssociativePattern(size_t size)
41 : ops(size), identities(size) {
42 }
43 AssociativePattern(const std::vector<Expr> &ops, const std::vector<Expr> &ids, bool is_commutative)
44 : ops(ops), identities(ids), is_commutative(is_commutative) {
45 }
46 AssociativePattern(Expr op, Expr id, bool is_commutative)
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
72 const std::vector<AssociativePattern> &get_ops_table(const std::vector<Expr> &exprs);
73
74} // namespace Internal
75} // namespace Halide
76
77#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::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::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Internal::AssociativePattern
Represent an associative op with its identity.
Definition AssociativeOpsTable.h:31
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