Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 2 | // Copyright (c) 2020-2023, ARM Limited. |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | #ifndef OPS_REDUCTION_H |
| 17 | #define OPS_REDUCTION_H |
| 18 | |
| 19 | #include "graph_node.h" |
| 20 | |
| 21 | using namespace tosa; |
| 22 | |
| 23 | namespace TosaReference |
| 24 | { |
| 25 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 26 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 27 | class ReduceNode : public GraphNode |
| 28 | { |
| 29 | public: |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 30 | ReduceNode(SubgraphTraverser* sgt_, const Op& nodeType, TosaAttributeBase* attribute_, const uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 31 | virtual ~ReduceNode(); |
| 32 | virtual int checkTensorAttributes(); |
| 33 | virtual int eval() = 0; |
| 34 | |
| 35 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 36 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 37 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
| 38 | using TOut = Eigen::Tensor<OutEigenType, Rank>; |
| 39 | |
| 40 | protected: |
| 41 | Eigen::array<int, 1> dims; |
| 42 | TosaReference::TensorTemplate<TIn>* in; |
| 43 | TosaReference::TensorTemplate<TOut>* out; |
| 44 | TosaAxisAttribute* attribute; |
| 45 | }; |
| 46 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 47 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 48 | class OpReduceAll : public ReduceNode<Rank, Dtype> |
| 49 | { |
| 50 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 51 | OpReduceAll(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 52 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_ALL, attribute_, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 53 | {} |
| 54 | virtual int eval(); |
| 55 | }; |
| 56 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 57 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 58 | class OpReduceAny : public ReduceNode<Rank, Dtype> |
| 59 | { |
| 60 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 61 | OpReduceAny(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 62 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_ALL, attribute_, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 63 | {} |
| 64 | virtual int eval(); |
| 65 | }; |
| 66 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 67 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 68 | class OpReduceMax : public ReduceNode<Rank, Dtype> |
| 69 | { |
| 70 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 71 | OpReduceMax(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 72 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_MAX, attribute_, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 73 | {} |
| 74 | virtual int eval(); |
| 75 | }; |
| 76 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 77 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 78 | class OpReduceMin : public ReduceNode<Rank, Dtype> |
| 79 | { |
| 80 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 81 | OpReduceMin(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 82 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_MIN, attribute_, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 83 | {} |
| 84 | virtual int eval(); |
| 85 | }; |
| 86 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 87 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 88 | class OpReduceProduct : public ReduceNode<Rank, Dtype> |
| 89 | { |
| 90 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 91 | OpReduceProduct(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 92 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_PRODUCT, attribute_, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 93 | {} |
| 94 | virtual int eval(); |
| 95 | }; |
| 96 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 97 | template <int Rank, TOSA_REF_TYPE Dtype> |
| 98 | class OpReduceProductDouble : public ReduceNode<Rank, Dtype> |
| 99 | { |
| 100 | public: |
| 101 | OpReduceProductDouble(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
| 102 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_PRODUCT, attribute_, id_) |
| 103 | {} |
| 104 | virtual int eval(); |
| 105 | }; |
| 106 | |
| 107 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 108 | class OpReduceSum : public ReduceNode<Rank, Dtype> |
| 109 | { |
| 110 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 111 | OpReduceSum(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 112 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_SUM, attribute_, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 113 | {} |
| 114 | virtual int eval(); |
| 115 | }; |
| 116 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 117 | template <int Rank, TOSA_REF_TYPE Dtype> |
Jeremy Johnson | 7de9b45 | 2022-04-05 14:31:37 +0100 | [diff] [blame] | 118 | class OpReduceSumInt : public ReduceNode<Rank, Dtype> |
| 119 | { |
| 120 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 121 | OpReduceSumInt(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
Jeremy Johnson | 7de9b45 | 2022-04-05 14:31:37 +0100 | [diff] [blame] | 122 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_SUM, attribute_, id_) |
| 123 | {} |
| 124 | virtual int eval(); |
| 125 | }; |
| 126 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 127 | template <int Rank, TOSA_REF_TYPE Dtype> |
| 128 | class OpReduceSumDouble : public ReduceNode<Rank, Dtype> |
| 129 | { |
| 130 | public: |
| 131 | OpReduceSumDouble(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
| 132 | : ReduceNode<Rank, Dtype>(sgt_, Op_REDUCE_SUM, attribute_, id_) |
| 133 | {} |
| 134 | virtual int eval(); |
| 135 | }; |
| 136 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 137 | }; // namespace TosaReference |
| 138 | |
| 139 | #endif |