Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame^] | 2 | // Copyright (c) 2020-2024, 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_DATA_LAYOUT_H |
| 17 | #define OPS_DATA_LAYOUT_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 OpConcat : public GraphNode |
| 28 | { |
| 29 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 30 | OpConcat(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 31 | virtual ~OpConcat(); |
| 32 | |
| 33 | virtual int checkTensorAttributes(); |
| 34 | virtual int eval(); |
| 35 | |
| 36 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 37 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 38 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
| 39 | using TOut = Eigen::Tensor<OutEigenType, Rank>; |
| 40 | |
| 41 | protected: |
| 42 | Eigen::array<int, Rank> reverser; |
Kevin Cheng | ad15dfa | 2021-03-04 15:15:03 -0800 | [diff] [blame] | 43 | std::vector<TosaReference::TensorTemplate<TIn>*> ins; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 44 | TosaAxisAttribute* attribute; |
| 45 | TosaReference::TensorTemplate<TOut>* out; |
| 46 | }; |
| 47 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 48 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 49 | class OpPad : public GraphNode |
| 50 | { |
| 51 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 52 | OpPad(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 53 | virtual ~OpPad(); |
| 54 | virtual int checkTensorAttributes(); |
| 55 | virtual int eval(); |
| 56 | |
| 57 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 58 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 59 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
| 60 | using TOut = Eigen::Tensor<OutEigenType, Rank>; |
| 61 | |
| 62 | protected: |
| 63 | Eigen::array<std::pair<ptrdiff_t, ptrdiff_t>, Rank> paddings_array; |
| 64 | TosaReference::TensorTemplate<TIn>* in; |
| 65 | TosaReference::TensorTemplate<TOut>* out; |
Kevin Cheng | fe392ce | 2021-10-18 21:51:55 +0000 | [diff] [blame] | 66 | TosaPadAttribute* attribute; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 67 | }; |
| 68 | |
Won Jeon | a21b2e8 | 2023-08-10 10:33:01 +0000 | [diff] [blame] | 69 | template <int Rank, TOSA_REF_TYPE Dtype> |
| 70 | class OpDim : public GraphNode |
| 71 | { |
| 72 | public: |
| 73 | OpDim(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
| 74 | virtual ~OpDim(); |
| 75 | |
| 76 | virtual int checkTensorAttributes(); |
| 77 | virtual int eval(); |
| 78 | |
| 79 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 80 | using OutEigenType = typename GetEigenType<TOSA_REF_TYPE_SHAPE>::type; |
| 81 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame^] | 82 | using TOut = Eigen::Tensor<OutEigenType, 1>; |
Won Jeon | a21b2e8 | 2023-08-10 10:33:01 +0000 | [diff] [blame] | 83 | |
| 84 | protected: |
| 85 | TosaReference::TensorTemplate<TIn>* in; |
| 86 | TosaReference::TensorTemplate<TOut>* out; |
| 87 | TosaAxisAttribute* attribute; |
| 88 | }; |
| 89 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 90 | template <int InRank, int OutRank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 91 | class OpReshape : public GraphNode |
| 92 | { |
| 93 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 94 | OpReshape(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 95 | virtual ~OpReshape(); |
| 96 | |
| 97 | virtual int checkTensorAttributes(); |
| 98 | virtual int eval(); |
| 99 | |
| 100 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 101 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 102 | using TIn = Eigen::Tensor<InEigenType, InRank>; |
| 103 | using TOut = Eigen::Tensor<OutEigenType, OutRank>; |
| 104 | |
| 105 | protected: |
| 106 | Eigen::array<Eigen::Index, OutRank> array_shape; |
| 107 | Eigen::array<Eigen::Index, InRank> in_reverser; |
| 108 | Eigen::array<Eigen::Index, OutRank> out_reverser; |
| 109 | TosaReference::TensorTemplate<TIn>* in; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 110 | TosaReference::TensorTemplate<TOut>* out; |
| 111 | }; |
| 112 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 113 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 114 | class OpReverse : public GraphNode |
| 115 | { |
| 116 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 117 | OpReverse(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 118 | virtual ~OpReverse(); |
| 119 | |
| 120 | virtual int checkTensorAttributes(); |
| 121 | virtual int eval(); |
| 122 | |
| 123 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 124 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 125 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
| 126 | using TOut = Eigen::Tensor<OutEigenType, Rank>; |
| 127 | |
| 128 | protected: |
| 129 | TosaAxisAttribute* attribute; |
| 130 | TosaReference::TensorTemplate<TIn>* in; |
| 131 | TosaReference::TensorTemplate<TOut>* out; |
| 132 | Eigen::array<bool, Rank> reverse_array; |
| 133 | }; |
| 134 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 135 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 136 | class OpSlice : public GraphNode |
| 137 | { |
| 138 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 139 | OpSlice(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 140 | virtual ~OpSlice(); |
| 141 | |
| 142 | virtual int checkTensorAttributes(); |
| 143 | virtual int eval(); |
| 144 | |
| 145 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 146 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 147 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
| 148 | using TOut = Eigen::Tensor<OutEigenType, Rank>; |
| 149 | |
| 150 | protected: |
| 151 | TosaSliceAttribute* attribute; |
| 152 | Eigen::array<Eigen::Index, Rank> begin_array; |
| 153 | Eigen::array<Eigen::Index, Rank> size_array; |
| 154 | TosaReference::TensorTemplate<TIn>* in; |
| 155 | TosaReference::TensorTemplate<TOut>* out; |
| 156 | }; |
| 157 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 158 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 159 | class OpTileBase : public GraphNode |
| 160 | { |
| 161 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 162 | OpTileBase(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 163 | virtual ~OpTileBase(); |
| 164 | |
| 165 | virtual int checkTensorAttributes(); |
| 166 | |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame^] | 167 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 168 | using InEigenShapeType = typename GetEigenType<TOSA_REF_TYPE_SHAPE>::type; |
| 169 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 170 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
| 171 | using TInMultiples = Eigen::Tensor<InEigenShapeType, 1>; |
| 172 | using TOut = Eigen::Tensor<OutEigenType, Rank>; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 173 | |
| 174 | protected: |
| 175 | TosaTileAttribute* attribute; |
| 176 | TosaReference::TensorTemplate<TIn>* in; |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame^] | 177 | TosaReference::TensorTemplate<TInMultiples>* multiples; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 178 | TosaReference::TensorTemplate<TOut>* out; |
| 179 | }; |
| 180 | |
| 181 | // primary template for op tile |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 182 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 183 | class OpTile : public OpTileBase<Rank, Dtype> |
| 184 | { |
| 185 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 186 | OpTile(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) |
| 187 | : OpTileBase<Rank, Dtype>(sgt_, attribute_, id_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 188 | {} |
| 189 | |
| 190 | protected: |
| 191 | virtual int eval(); |
| 192 | }; |
| 193 | |
| 194 | // partial specialization for specific rank |
| 195 | #define DEF_OP_TILE_RANK(N) \ |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 196 | template <TOSA_REF_TYPE Dtype> \ |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 197 | class OpTile<N, Dtype> : public OpTileBase<N, Dtype> \ |
| 198 | { \ |
| 199 | public: \ |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 200 | OpTile(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_) \ |
| 201 | : OpTileBase<N, Dtype>(sgt_, attribute_, id_) \ |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 202 | {} \ |
| 203 | \ |
| 204 | protected: \ |
| 205 | virtual int eval(); \ |
| 206 | }; |
| 207 | |
| 208 | DEF_OP_TILE_RANK(1) |
| 209 | DEF_OP_TILE_RANK(2) |
| 210 | DEF_OP_TILE_RANK(3) |
| 211 | DEF_OP_TILE_RANK(4) |
Luke Hutton | a4e48ca | 2023-02-22 11:53:48 +0000 | [diff] [blame] | 212 | DEF_OP_TILE_RANK(5) |
| 213 | DEF_OP_TILE_RANK(6) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 214 | |
| 215 | #undef DEF_OP_TILE_RANK |
| 216 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 217 | template <int Rank, TOSA_REF_TYPE Dtype> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 218 | class OpTranspose : public GraphNode |
| 219 | { |
| 220 | public: |
Eric Kunze | b5fabec | 2022-06-07 05:20:44 +0000 | [diff] [blame] | 221 | OpTranspose(SubgraphTraverser* sgt_, TosaAttributeBase* attribute_, uint64_t id_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 222 | virtual ~OpTranspose(); |
| 223 | |
| 224 | virtual int checkTensorAttributes(); |
| 225 | virtual int eval(); |
| 226 | |
| 227 | using InEigenType = typename GetEigenType<Dtype>::type; |
| 228 | using OutEigenType = typename GetEigenType<Dtype>::type; |
| 229 | using TIn = Eigen::Tensor<InEigenType, Rank>; |
| 230 | using TOut = Eigen::Tensor<OutEigenType, Rank>; |
| 231 | |
| 232 | protected: |
| 233 | Eigen::array<int, Rank> perm_array; |
Kevin Cheng | fe392ce | 2021-10-18 21:51:55 +0000 | [diff] [blame] | 234 | TosaTransposeAttribute* attribute; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 235 | TosaReference::TensorTemplate<TIn>* in; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 236 | TosaReference::TensorTemplate<TOut>* out; |
| 237 | }; |
| 238 | }; // namespace TosaReference |
| 239 | |
| 240 | #endif |