Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [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 TOSA_REFERENCE_TENSOR_H |
| 17 | #define TOSA_REFERENCE_TENSOR_H |
| 18 | |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 19 | #include "array_proxy.h" |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 20 | #include "dtype.h" |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 21 | #include "model_common.h" |
| 22 | #include "ops/template_types.h" |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 23 | #include "tosa_serialization_handler.h" |
| 24 | #include <Eigen/CXX11/Tensor> |
| 25 | #include <list> |
| 26 | #include <vector> |
| 27 | |
| 28 | using namespace tosa; |
| 29 | |
| 30 | namespace TosaReference |
| 31 | { |
| 32 | class GraphNode; |
| 33 | |
| 34 | class Tensor |
| 35 | { |
| 36 | public: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 37 | Tensor(const std::string tensorName_, const DType serializationDtype_, const std::vector<int> shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 38 | |
| 39 | virtual ~Tensor(); |
| 40 | |
| 41 | int setIsSubgraphInput(); |
| 42 | int setIsSubgraphOutput(); |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 43 | int setIsParentGraphOutput(); |
| 44 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 45 | bool getIsParentGraphOutput() const |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 46 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 47 | return isParentGraphOutput; |
| 48 | } |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 49 | int setIsVariable(); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 50 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 51 | bool getIsSubgraphInput() const |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 52 | { |
| 53 | return isSubgraphInput; |
| 54 | } |
| 55 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 56 | bool getIsSubgraphOutput() const |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 57 | { |
| 58 | return isSubgraphOutput; |
| 59 | } |
| 60 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 61 | bool getIsVariable() const |
| 62 | { |
| 63 | return isVariable; |
| 64 | } |
| 65 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 66 | int setProducer(GraphNode* node); |
| 67 | int addConsumer(GraphNode* node); |
| 68 | |
| 69 | int setIsValid() |
| 70 | { |
| 71 | isValid = 1; |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | int clearIsValid() |
| 76 | { |
| 77 | isValid = 0; |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | int getIsValid() const |
| 82 | { |
| 83 | return isValid; |
| 84 | } |
| 85 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 86 | GraphNode* getProducer() |
| 87 | { |
| 88 | return producer; |
| 89 | } |
| 90 | |
| 91 | std::vector<GraphNode*>& getConsumers() |
| 92 | { |
| 93 | return consumers; |
| 94 | } |
| 95 | |
| 96 | const std::string& getName() const |
| 97 | { |
| 98 | return tensorName; |
| 99 | } |
| 100 | |
| 101 | const std::vector<int>& getShape() const |
| 102 | { |
| 103 | return shape; |
| 104 | } |
| 105 | |
Jerry Ge | 264f7fa | 2023-04-21 22:49:57 +0000 | [diff] [blame] | 106 | void setDimSize(size_t dim, uint32_t new_size) |
| 107 | { |
| 108 | this->shape[dim] = new_size; |
| 109 | return; |
| 110 | } |
| 111 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 112 | std::string getShapeAsString() const |
| 113 | { |
| 114 | std::string shape_str("["); |
| 115 | for (auto& dim : shape) |
| 116 | { |
| 117 | shape_str += (std::to_string(dim) + ", "); |
| 118 | } |
| 119 | shape_str.append("]"); |
| 120 | return shape_str; |
| 121 | } |
| 122 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 123 | const uint32_t getElementCount() const |
| 124 | { |
| 125 | uint32_t elements = 1; |
| 126 | for (size_t i = 0; i < shape.size(); i++) |
| 127 | elements *= shape[i]; |
| 128 | |
| 129 | return elements; |
| 130 | } |
| 131 | |
| 132 | // Comparison of rank and type with other tensors |
| 133 | const int matchRank(const Tensor& ref) const |
| 134 | { |
| 135 | return (ref.shape.size() == shape.size()) ? 0 : 1; |
| 136 | } |
| 137 | |
| 138 | const int matchType(const Tensor& ref) const |
| 139 | { |
| 140 | return (ref.tensorDtype == tensorDtype) ? 0 : 1; |
| 141 | } |
| 142 | |
| 143 | const int matchRankType(const Tensor& ref) const |
| 144 | { |
| 145 | return (matchType(ref) || matchRank(ref)); |
| 146 | } |
| 147 | |
| 148 | const int matchRankTypeShape(const Tensor& ref, const bool broadcastOk = false) const |
| 149 | { |
| 150 | if (matchRankType(ref)) |
| 151 | return 1; |
| 152 | |
| 153 | for (size_t i = 0; i < shape.size(); i++) |
| 154 | { |
| 155 | if (shape[i] != ref.shape[i]) |
| 156 | { |
| 157 | if (!broadcastOk || |
Kevin Cheng | 2131a4d | 2021-11-11 19:35:30 +0000 | [diff] [blame] | 158 | // For broadcasts, the order of *this and ref matters. |
| 159 | // *this should be the source tensor. |
| 160 | // ref should be the target tensor. In most of the case, ref is expected to be the output tensor. |
| 161 | // this->shape must have size 1 if they don't match |
| 162 | (broadcastOk && (shape[i] != 1))) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 163 | { |
| 164 | return 1; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Kevin Cheng | 1c3c847 | 2021-11-08 11:19:10 -0800 | [diff] [blame] | 172 | const int matchRankShape(const Tensor& ref, const bool broadcastOk = false) const |
| 173 | { |
| 174 | if (matchRank(ref)) |
| 175 | return 1; |
| 176 | |
| 177 | for (size_t i = 0; i < shape.size(); i++) |
| 178 | { |
| 179 | if (shape[i] != ref.shape[i]) |
| 180 | { |
| 181 | if (!broadcastOk || |
Kevin Cheng | 2131a4d | 2021-11-11 19:35:30 +0000 | [diff] [blame] | 182 | // For broadcasts, the order of *this and ref matters. |
| 183 | // *this should be the source tensor. |
| 184 | // ref should be the target tensor. In most of the case, ref is expected to be the output tensor. |
| 185 | // this->shape must have size 1 if they don't match |
| 186 | (broadcastOk && (shape[i] != 1))) |
Kevin Cheng | 1c3c847 | 2021-11-08 11:19:10 -0800 | [diff] [blame] | 187 | { |
| 188 | return 1; |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 196 | // Sometimes we might want to match several semi-compatible types, |
| 197 | // so just check rank and size here |
| 198 | const int matchRankSize(const Tensor& ref) const |
| 199 | { |
| 200 | if (matchRank(ref)) |
| 201 | return 1; |
| 202 | |
| 203 | for (size_t i = 0; i < shape.size(); i++) |
| 204 | { |
| 205 | if (shape[i] != ref.shape[i]) |
| 206 | return 1; |
| 207 | } |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | // Unary check to make sure rank matches |
Jerry Ge | 0bd4ec8 | 2023-05-01 18:36:43 +0000 | [diff] [blame] | 213 | const int checkRequiredRank(const int minRank) const |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 214 | { |
Jerry Ge | 0bd4ec8 | 2023-05-01 18:36:43 +0000 | [diff] [blame] | 215 | return (shape.size() >= (size_t)minRank) ? 0 : 1; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | const int checkRequiredRank(const int minRank, const int maxRank) const |
| 219 | { |
| 220 | return (shape.size() >= (size_t)minRank && shape.size() <= (size_t)maxRank) ? 0 : 1; |
| 221 | } |
| 222 | |
| 223 | const int getRank() const |
| 224 | { |
| 225 | return shape.size(); |
| 226 | } |
| 227 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 228 | const TOSA_REF_TYPE getDtype() const |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 229 | { |
| 230 | return tensorDtype; |
| 231 | } |
| 232 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 233 | const DType getSerializationDtype() const |
| 234 | { |
| 235 | return serializationDtype; |
| 236 | } |
| 237 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 238 | virtual int dumpTensor(FILE* out) const = 0; |
| 239 | virtual int dumpTensorParams(FILE* out) const; |
| 240 | virtual int dumpTensorParams(std::ostream& out) const; |
| 241 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 242 | virtual int setTensorValueDouble(const size_t bufLen, const double* vals) = 0; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 243 | virtual int setTensorValueFloat(const size_t bufLen, const float* vals) = 0; |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 244 | virtual int setTensorValueInt16(const size_t bufLen, const int16_t* vals) = 0; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 245 | virtual int setTensorValueInt32(const size_t bufLen, const int32_t* vals) = 0; |
| 246 | virtual int setTensorValueInt64(const size_t bufLen, const int64_t* vals) = 0; |
| 247 | virtual int setTensorValueBool(const size_t bufLen, const bool* vals) = 0; |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 248 | virtual int getTensorValueDouble(const size_t bufLen, double* fbuf) const = 0; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 249 | virtual int getTensorValueFloat(const size_t bufLen, float* fbuf) const = 0; |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 250 | virtual int getTensorValueInt16(const size_t bufLen, int16_t* ibuf) const = 0; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 251 | virtual int getTensorValueInt32(const size_t bufLen, int32_t* ibuf) const = 0; |
| 252 | virtual int getTensorValueInt64(const size_t bufLen, int64_t* ibuf) const = 0; |
| 253 | virtual int getTensorValueBool(const size_t bufLen, bool* ibuf) const = 0; |
| 254 | |
| 255 | virtual int readFromNpyFile(const char* filename); |
| 256 | virtual int writeToNpyFile(const char* filename) const; |
| 257 | virtual int copyValueFrom(Tensor* tensor) = 0; |
| 258 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 259 | virtual int readfromVector(const ArrayProxy<double> vals); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 260 | virtual int readfromVector(const ArrayProxy<float> vals); |
| 261 | virtual int readfromVector(const ArrayProxy<half_float::half> vals); |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 262 | virtual int readfromVector(const ArrayProxy<int16_t> vals); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 263 | virtual int readfromVector(const ArrayProxy<int32_t> vals); |
| 264 | virtual int readfromVector(const ArrayProxy<int64_t> vals); |
| 265 | virtual int readfromVector(const ArrayProxy<unsigned char> vals); |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 266 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 267 | virtual int writeToVector(ArrayProxy<double> vals); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 268 | virtual int writeToVector(ArrayProxy<float> vals); |
| 269 | virtual int writeToVector(ArrayProxy<half_float::half> vals); |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 270 | virtual int writeToVector(ArrayProxy<int16_t> vals); |
Grant Watson | 64285a1 | 2022-11-16 15:32:39 +0000 | [diff] [blame] | 271 | virtual int writeToVector(ArrayProxy<int32_t> vals); |
| 272 | virtual int writeToVector(ArrayProxy<int64_t> vals); |
| 273 | virtual int writeToVector(ArrayProxy<unsigned char> vals); |
Matthew Sloyan | ba5fad3 | 2022-09-26 13:31:43 +0100 | [diff] [blame] | 274 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 275 | const char* bool_to_str(bool in) const |
| 276 | { |
| 277 | static const char* true_str = "true"; |
| 278 | static const char* false_str = "false"; |
| 279 | return in ? true_str : false_str; |
| 280 | } |
| 281 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 282 | virtual int allocate() = 0; |
| 283 | virtual int deallocate() = 0; |
| 284 | virtual bool is_allocated() const = 0; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 285 | |
| 286 | protected: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 287 | const std::string tensorName; |
| 288 | const DType serializationDtype; |
Jerry Ge | 264f7fa | 2023-04-21 22:49:57 +0000 | [diff] [blame] | 289 | std::vector<int> shape; |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 290 | const TOSA_REF_TYPE tensorDtype; |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 291 | bool isValid; |
| 292 | bool isSubgraphInput; |
| 293 | bool isSubgraphOutput; |
| 294 | bool isVariable; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 295 | bool isAllocated; |
| 296 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 297 | bool isParentGraphOutput; |
| 298 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 299 | GraphNode* producer; |
| 300 | std::vector<GraphNode*> consumers; |
| 301 | |
| 302 | // Note: the Eigen::Tensor is not declared in Tensor |
| 303 | // Instead, the TensorTemplate class keeps the templated tensor |
| 304 | // declaration so that the graph manipulation tools are isolated |
| 305 | // from the templated tensor type. |
| 306 | // |
| 307 | // Operators need to be aware of the TensorTemplate<EigenTensor<type, rank>> type |
| 308 | // so that they can operate on the right types. |
| 309 | }; |
| 310 | |
| 311 | template <class T> |
| 312 | class TensorTemplate : public Tensor |
| 313 | { |
| 314 | public: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 315 | TensorTemplate(const std::string tensorName_, const DType dtype_, const std::vector<int> shape_) |
| 316 | : Tensor(tensorName_, dtype_, shape_) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 317 | { |
| 318 | tensor = nullptr; |
| 319 | } |
| 320 | |
| 321 | virtual ~TensorTemplate() |
| 322 | { |
| 323 | deallocate(); |
| 324 | } |
| 325 | |
| 326 | virtual int allocate() |
| 327 | { |
| 328 | tensor = new T(); |
| 329 | if (tensor) |
| 330 | return 0; |
| 331 | else |
| 332 | return 1; |
| 333 | } |
| 334 | |
| 335 | virtual int deallocate() |
| 336 | { |
| 337 | if (tensor) |
| 338 | { |
Eric Kunze | 9a36755 | 2023-07-11 13:27:36 -0700 | [diff] [blame] | 339 | DEBUG_INFO(GT, "Deallocating tensor %s", tensorName.c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 340 | delete tensor; |
| 341 | } |
| 342 | tensor = nullptr; |
| 343 | return 0; |
| 344 | } |
| 345 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 346 | virtual bool is_allocated() const |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 347 | { |
| 348 | if (tensor) |
| 349 | { |
| 350 | return true; |
| 351 | } |
| 352 | return false; |
| 353 | } |
| 354 | |
| 355 | T& getTensor() |
| 356 | { |
| 357 | return *tensor; |
| 358 | } |
| 359 | |
| 360 | virtual int dumpTensor(FILE* out) const; |
| 361 | |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 362 | virtual int setTensorValueDouble(const size_t bufLen, const double* vals); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 363 | virtual int setTensorValueFloat(const size_t bufLen, const float* vals); |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 364 | virtual int setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 365 | virtual int setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 366 | virtual int setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 367 | virtual int setTensorValueBool(const size_t bufLen, const bool* vals); |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 368 | |
| 369 | virtual int getTensorValueDouble(const size_t bufLen, double* fbuf) const; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 370 | virtual int getTensorValueFloat(const size_t bufLen, float* fbuf) const; |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 371 | virtual int getTensorValueInt16(const size_t bufLen, int16_t* ibuf) const; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 372 | virtual int getTensorValueInt32(const size_t bufLen, int32_t* ibuf) const; |
| 373 | virtual int getTensorValueInt64(const size_t bufLen, int64_t* ibuf) const; |
| 374 | virtual int getTensorValueBool(const size_t bufLen, bool* bbuf) const; |
| 375 | |
| 376 | virtual int copyValueFrom(Tensor* tensor); |
| 377 | |
| 378 | protected: |
| 379 | T* tensor; |
| 380 | }; |
| 381 | |
| 382 | // allocate() template specializations to allocate the different tensor sizes |
| 383 | // Let the compiler know here before the factory uses them, but define them in the .cc file. |
| 384 | template <> |
| 385 | int Tensor0<float>::allocate(); |
| 386 | template <> |
| 387 | int Tensor1<float>::allocate(); |
| 388 | template <> |
| 389 | int Tensor2<float>::allocate(); |
| 390 | template <> |
| 391 | int Tensor3<float>::allocate(); |
| 392 | template <> |
| 393 | int Tensor4<float>::allocate(); |
| 394 | template <> |
| 395 | int Tensor5<float>::allocate(); |
| 396 | template <> |
| 397 | int Tensor6<float>::allocate(); |
| 398 | |
| 399 | template <> |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 400 | int Tensor0<double>::allocate(); |
| 401 | template <> |
| 402 | int Tensor1<double>::allocate(); |
| 403 | template <> |
| 404 | int Tensor2<double>::allocate(); |
| 405 | template <> |
| 406 | int Tensor3<double>::allocate(); |
| 407 | template <> |
| 408 | int Tensor4<double>::allocate(); |
| 409 | template <> |
| 410 | int Tensor5<double>::allocate(); |
| 411 | template <> |
| 412 | int Tensor6<double>::allocate(); |
| 413 | |
| 414 | template <> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 415 | int Tensor0<int32_t>::allocate(); |
| 416 | template <> |
| 417 | int Tensor1<int32_t>::allocate(); |
| 418 | template <> |
| 419 | int Tensor2<int32_t>::allocate(); |
| 420 | template <> |
| 421 | int Tensor3<int32_t>::allocate(); |
| 422 | template <> |
| 423 | int Tensor4<int32_t>::allocate(); |
| 424 | template <> |
| 425 | int Tensor5<int32_t>::allocate(); |
| 426 | template <> |
| 427 | int Tensor6<int32_t>::allocate(); |
| 428 | |
| 429 | template <> |
| 430 | int Tensor0<int64_t>::allocate(); |
| 431 | template <> |
| 432 | int Tensor1<int64_t>::allocate(); |
| 433 | template <> |
| 434 | int Tensor2<int64_t>::allocate(); |
| 435 | template <> |
| 436 | int Tensor3<int64_t>::allocate(); |
| 437 | template <> |
| 438 | int Tensor4<int64_t>::allocate(); |
| 439 | template <> |
| 440 | int Tensor5<int64_t>::allocate(); |
| 441 | template <> |
| 442 | int Tensor6<int64_t>::allocate(); |
| 443 | |
| 444 | template <> |
| 445 | int Tensor0<bool>::allocate(); |
| 446 | template <> |
| 447 | int Tensor1<bool>::allocate(); |
| 448 | template <> |
| 449 | int Tensor2<bool>::allocate(); |
| 450 | template <> |
| 451 | int Tensor3<bool>::allocate(); |
| 452 | template <> |
| 453 | int Tensor4<bool>::allocate(); |
| 454 | template <> |
| 455 | int Tensor5<bool>::allocate(); |
| 456 | template <> |
| 457 | int Tensor6<bool>::allocate(); |
| 458 | |
| 459 | template <> |
| 460 | int Tensor0<float>::copyValueFrom(Tensor* src); |
| 461 | template <> |
| 462 | int Tensor1<float>::copyValueFrom(Tensor* src); |
| 463 | template <> |
| 464 | int Tensor2<float>::copyValueFrom(Tensor* src); |
| 465 | template <> |
| 466 | int Tensor3<float>::copyValueFrom(Tensor* src); |
| 467 | template <> |
| 468 | int Tensor4<float>::copyValueFrom(Tensor* src); |
| 469 | template <> |
| 470 | int Tensor5<float>::copyValueFrom(Tensor* src); |
| 471 | template <> |
| 472 | int Tensor6<float>::copyValueFrom(Tensor* src); |
| 473 | |
| 474 | template <> |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 475 | int Tensor0<double>::copyValueFrom(Tensor* src); |
| 476 | template <> |
| 477 | int Tensor1<double>::copyValueFrom(Tensor* src); |
| 478 | template <> |
| 479 | int Tensor2<double>::copyValueFrom(Tensor* src); |
| 480 | template <> |
| 481 | int Tensor3<double>::copyValueFrom(Tensor* src); |
| 482 | template <> |
| 483 | int Tensor4<double>::copyValueFrom(Tensor* src); |
| 484 | template <> |
| 485 | int Tensor5<double>::copyValueFrom(Tensor* src); |
| 486 | template <> |
| 487 | int Tensor6<double>::copyValueFrom(Tensor* src); |
| 488 | |
| 489 | template <> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 490 | int Tensor0<int32_t>::copyValueFrom(Tensor* src); |
| 491 | template <> |
| 492 | int Tensor1<int32_t>::copyValueFrom(Tensor* src); |
| 493 | template <> |
| 494 | int Tensor2<int32_t>::copyValueFrom(Tensor* src); |
| 495 | template <> |
| 496 | int Tensor3<int32_t>::copyValueFrom(Tensor* src); |
| 497 | template <> |
| 498 | int Tensor4<int32_t>::copyValueFrom(Tensor* src); |
| 499 | template <> |
| 500 | int Tensor5<int32_t>::copyValueFrom(Tensor* src); |
| 501 | template <> |
| 502 | int Tensor6<int32_t>::copyValueFrom(Tensor* src); |
| 503 | |
| 504 | template <> |
| 505 | int Tensor0<int64_t>::copyValueFrom(Tensor* src); |
| 506 | template <> |
| 507 | int Tensor1<int64_t>::copyValueFrom(Tensor* src); |
| 508 | template <> |
| 509 | int Tensor2<int64_t>::copyValueFrom(Tensor* src); |
| 510 | template <> |
| 511 | int Tensor3<int64_t>::copyValueFrom(Tensor* src); |
| 512 | template <> |
| 513 | int Tensor4<int64_t>::copyValueFrom(Tensor* src); |
| 514 | template <> |
| 515 | int Tensor5<int64_t>::copyValueFrom(Tensor* src); |
| 516 | template <> |
| 517 | int Tensor6<int64_t>::copyValueFrom(Tensor* src); |
| 518 | |
| 519 | template <> |
| 520 | int Tensor0<bool>::copyValueFrom(Tensor* src); |
| 521 | template <> |
| 522 | int Tensor1<bool>::copyValueFrom(Tensor* src); |
| 523 | template <> |
| 524 | int Tensor2<bool>::copyValueFrom(Tensor* src); |
| 525 | template <> |
| 526 | int Tensor3<bool>::copyValueFrom(Tensor* src); |
| 527 | template <> |
| 528 | int Tensor4<bool>::copyValueFrom(Tensor* src); |
| 529 | template <> |
| 530 | int Tensor5<bool>::copyValueFrom(Tensor* src); |
| 531 | template <> |
| 532 | int Tensor6<bool>::copyValueFrom(Tensor* src); |
| 533 | |
| 534 | template <> |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 535 | int Tensor0<int32_t>::setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
| 536 | template <> |
| 537 | int Tensor1<int32_t>::setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
| 538 | template <> |
| 539 | int Tensor2<int32_t>::setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
| 540 | template <> |
| 541 | int Tensor3<int32_t>::setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
| 542 | template <> |
| 543 | int Tensor4<int32_t>::setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
| 544 | template <> |
| 545 | int Tensor5<int32_t>::setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
| 546 | template <> |
| 547 | int Tensor6<int32_t>::setTensorValueInt16(const size_t bufLen, const int16_t* vals); |
| 548 | |
| 549 | template <> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 550 | int Tensor0<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 551 | template <> |
| 552 | int Tensor1<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 553 | template <> |
| 554 | int Tensor2<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 555 | template <> |
| 556 | int Tensor3<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 557 | template <> |
| 558 | int Tensor4<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 559 | template <> |
| 560 | int Tensor5<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 561 | template <> |
| 562 | int Tensor6<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals); |
| 563 | |
| 564 | template <> |
Georgios Pinitas | e905977 | 2023-12-06 18:52:30 +0000 | [diff] [blame^] | 565 | int Tensor0<int32_t>::getTensorValueInt16(const size_t bufLen, int16_t* vals) const; |
| 566 | template <> |
| 567 | int Tensor1<int32_t>::getTensorValueInt16(const size_t bufLen, int16_t* vals) const; |
| 568 | template <> |
| 569 | int Tensor2<int32_t>::getTensorValueInt16(const size_t bufLen, int16_t* vals) const; |
| 570 | template <> |
| 571 | int Tensor3<int32_t>::getTensorValueInt16(const size_t bufLen, int16_t* vals) const; |
| 572 | template <> |
| 573 | int Tensor4<int32_t>::getTensorValueInt16(const size_t bufLen, int16_t* vals) const; |
| 574 | template <> |
| 575 | int Tensor5<int32_t>::getTensorValueInt16(const size_t bufLen, int16_t* vals) const; |
| 576 | template <> |
| 577 | int Tensor6<int32_t>::getTensorValueInt16(const size_t bufLen, int16_t* vals) const; |
| 578 | |
| 579 | template <> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 580 | int Tensor0<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const; |
| 581 | template <> |
| 582 | int Tensor1<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const; |
| 583 | template <> |
| 584 | int Tensor2<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const; |
| 585 | template <> |
| 586 | int Tensor3<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const; |
| 587 | template <> |
| 588 | int Tensor4<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const; |
| 589 | template <> |
| 590 | int Tensor5<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const; |
| 591 | template <> |
| 592 | int Tensor6<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const; |
| 593 | |
| 594 | template <> |
| 595 | int Tensor0<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 596 | template <> |
| 597 | int Tensor1<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 598 | template <> |
| 599 | int Tensor2<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 600 | template <> |
| 601 | int Tensor3<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 602 | template <> |
| 603 | int Tensor4<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 604 | template <> |
| 605 | int Tensor5<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 606 | template <> |
| 607 | int Tensor6<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals); |
| 608 | |
| 609 | template <> |
| 610 | int Tensor0<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const; |
| 611 | template <> |
| 612 | int Tensor1<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const; |
| 613 | template <> |
| 614 | int Tensor2<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const; |
| 615 | template <> |
| 616 | int Tensor3<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const; |
| 617 | template <> |
| 618 | int Tensor4<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const; |
| 619 | template <> |
| 620 | int Tensor5<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const; |
| 621 | template <> |
| 622 | int Tensor6<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const; |
| 623 | |
| 624 | template <> |
| 625 | int Tensor0<float>::setTensorValueFloat(const size_t bufLen, const float* vals); |
| 626 | template <> |
| 627 | int Tensor1<float>::setTensorValueFloat(const size_t bufLen, const float* vals); |
| 628 | template <> |
| 629 | int Tensor2<float>::setTensorValueFloat(const size_t bufLen, const float* vals); |
| 630 | template <> |
| 631 | int Tensor3<float>::setTensorValueFloat(const size_t bufLen, const float* vals); |
| 632 | template <> |
| 633 | int Tensor4<float>::setTensorValueFloat(const size_t bufLen, const float* vals); |
| 634 | template <> |
| 635 | int Tensor5<float>::setTensorValueFloat(const size_t bufLen, const float* vals); |
| 636 | template <> |
| 637 | int Tensor6<float>::setTensorValueFloat(const size_t bufLen, const float* vals); |
| 638 | |
| 639 | template <> |
| 640 | int Tensor0<float>::getTensorValueFloat(const size_t bufLen, float* vals) const; |
| 641 | template <> |
| 642 | int Tensor1<float>::getTensorValueFloat(const size_t bufLen, float* vals) const; |
| 643 | template <> |
| 644 | int Tensor2<float>::getTensorValueFloat(const size_t bufLen, float* vals) const; |
| 645 | template <> |
| 646 | int Tensor3<float>::getTensorValueFloat(const size_t bufLen, float* vals) const; |
| 647 | template <> |
| 648 | int Tensor4<float>::getTensorValueFloat(const size_t bufLen, float* vals) const; |
| 649 | template <> |
| 650 | int Tensor5<float>::getTensorValueFloat(const size_t bufLen, float* vals) const; |
| 651 | template <> |
| 652 | int Tensor6<float>::getTensorValueFloat(const size_t bufLen, float* vals) const; |
| 653 | |
| 654 | template <> |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 655 | int Tensor0<double>::setTensorValueDouble(const size_t bufLen, const double* vals); |
| 656 | template <> |
| 657 | int Tensor1<double>::setTensorValueDouble(const size_t bufLen, const double* vals); |
| 658 | template <> |
| 659 | int Tensor2<double>::setTensorValueDouble(const size_t bufLen, const double* vals); |
| 660 | template <> |
| 661 | int Tensor3<double>::setTensorValueDouble(const size_t bufLen, const double* vals); |
| 662 | template <> |
| 663 | int Tensor4<double>::setTensorValueDouble(const size_t bufLen, const double* vals); |
| 664 | template <> |
| 665 | int Tensor5<double>::setTensorValueDouble(const size_t bufLen, const double* vals); |
| 666 | template <> |
| 667 | int Tensor6<double>::setTensorValueDouble(const size_t bufLen, const double* vals); |
| 668 | |
| 669 | template <> |
| 670 | int Tensor0<double>::getTensorValueDouble(const size_t bufLen, double* vals) const; |
| 671 | template <> |
| 672 | int Tensor1<double>::getTensorValueDouble(const size_t bufLen, double* vals) const; |
| 673 | template <> |
| 674 | int Tensor2<double>::getTensorValueDouble(const size_t bufLen, double* vals) const; |
| 675 | template <> |
| 676 | int Tensor3<double>::getTensorValueDouble(const size_t bufLen, double* vals) const; |
| 677 | template <> |
| 678 | int Tensor4<double>::getTensorValueDouble(const size_t bufLen, double* vals) const; |
| 679 | template <> |
| 680 | int Tensor5<double>::getTensorValueDouble(const size_t bufLen, double* vals) const; |
| 681 | template <> |
| 682 | int Tensor6<double>::getTensorValueDouble(const size_t bufLen, double* vals) const; |
| 683 | |
| 684 | template <> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 685 | int Tensor0<bool>::setTensorValueBool(const size_t bufLen, const bool* vals); |
| 686 | template <> |
| 687 | int Tensor1<bool>::setTensorValueBool(const size_t bufLen, const bool* vals); |
| 688 | template <> |
| 689 | int Tensor2<bool>::setTensorValueBool(const size_t bufLen, const bool* vals); |
| 690 | template <> |
| 691 | int Tensor3<bool>::setTensorValueBool(const size_t bufLen, const bool* vals); |
| 692 | template <> |
| 693 | int Tensor4<bool>::setTensorValueBool(const size_t bufLen, const bool* vals); |
| 694 | template <> |
| 695 | int Tensor5<bool>::setTensorValueBool(const size_t bufLen, const bool* vals); |
| 696 | template <> |
| 697 | int Tensor6<bool>::setTensorValueBool(const size_t bufLen, const bool* vals); |
| 698 | |
| 699 | template <> |
| 700 | int Tensor0<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const; |
| 701 | template <> |
| 702 | int Tensor1<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const; |
| 703 | template <> |
| 704 | int Tensor2<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const; |
| 705 | template <> |
| 706 | int Tensor3<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const; |
| 707 | template <> |
| 708 | int Tensor4<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const; |
| 709 | template <> |
| 710 | int Tensor5<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const; |
| 711 | template <> |
| 712 | int Tensor6<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const; |
| 713 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 714 | template <> |
| 715 | int Tensor0<float>::dumpTensor(FILE* out) const; |
| 716 | template <> |
| 717 | int Tensor1<float>::dumpTensor(FILE* out) const; |
| 718 | template <> |
| 719 | int Tensor2<float>::dumpTensor(FILE* out) const; |
| 720 | template <> |
| 721 | int Tensor3<float>::dumpTensor(FILE* out) const; |
| 722 | template <> |
| 723 | int Tensor4<float>::dumpTensor(FILE* out) const; |
| 724 | template <> |
| 725 | int Tensor5<float>::dumpTensor(FILE* out) const; |
| 726 | template <> |
| 727 | int Tensor6<float>::dumpTensor(FILE* out) const; |
| 728 | template <> |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 729 | int Tensor0<double>::dumpTensor(FILE* out) const; |
| 730 | template <> |
| 731 | int Tensor1<double>::dumpTensor(FILE* out) const; |
| 732 | template <> |
| 733 | int Tensor2<double>::dumpTensor(FILE* out) const; |
| 734 | template <> |
| 735 | int Tensor3<double>::dumpTensor(FILE* out) const; |
| 736 | template <> |
| 737 | int Tensor4<double>::dumpTensor(FILE* out) const; |
| 738 | template <> |
| 739 | int Tensor5<float>::dumpTensor(FILE* out) const; |
| 740 | template <> |
| 741 | int Tensor6<double>::dumpTensor(FILE* out) const; |
| 742 | template <> |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 743 | int Tensor0<int32_t>::dumpTensor(FILE* out) const; |
| 744 | template <> |
| 745 | int Tensor1<int32_t>::dumpTensor(FILE* out) const; |
| 746 | template <> |
| 747 | int Tensor2<int32_t>::dumpTensor(FILE* out) const; |
| 748 | template <> |
| 749 | int Tensor3<int32_t>::dumpTensor(FILE* out) const; |
| 750 | template <> |
| 751 | int Tensor4<int32_t>::dumpTensor(FILE* out) const; |
| 752 | template <> |
| 753 | int Tensor5<int32_t>::dumpTensor(FILE* out) const; |
| 754 | template <> |
| 755 | int Tensor6<int32_t>::dumpTensor(FILE* out) const; |
| 756 | template <> |
| 757 | int Tensor0<int64_t>::dumpTensor(FILE* out) const; |
| 758 | template <> |
| 759 | int Tensor1<int64_t>::dumpTensor(FILE* out) const; |
| 760 | template <> |
| 761 | int Tensor2<int64_t>::dumpTensor(FILE* out) const; |
| 762 | template <> |
| 763 | int Tensor3<int64_t>::dumpTensor(FILE* out) const; |
| 764 | template <> |
| 765 | int Tensor4<int64_t>::dumpTensor(FILE* out) const; |
| 766 | template <> |
| 767 | int Tensor5<int64_t>::dumpTensor(FILE* out) const; |
| 768 | template <> |
| 769 | int Tensor6<int64_t>::dumpTensor(FILE* out) const; |
| 770 | template <> |
| 771 | int Tensor0<bool>::dumpTensor(FILE* out) const; |
| 772 | template <> |
| 773 | int Tensor1<bool>::dumpTensor(FILE* out) const; |
| 774 | template <> |
| 775 | int Tensor2<bool>::dumpTensor(FILE* out) const; |
| 776 | template <> |
| 777 | int Tensor3<bool>::dumpTensor(FILE* out) const; |
| 778 | template <> |
| 779 | int Tensor4<bool>::dumpTensor(FILE* out) const; |
| 780 | template <> |
| 781 | int Tensor5<bool>::dumpTensor(FILE* out) const; |
| 782 | template <> |
| 783 | int Tensor6<bool>::dumpTensor(FILE* out) const; |
| 784 | |
| 785 | class TensorFactory |
| 786 | { |
| 787 | public: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 788 | static Tensor* newTensor(std::string tensorName_, DType dtype_, std::vector<int> shape_, const uint32_t rank) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 789 | { |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 790 | TOSA_REF_TYPE tensorDtype_ = ConvertDType(dtype_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 791 | switch (tensorDtype_) |
| 792 | { |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 793 | case TOSA_REF_TYPE_FP32: |
| 794 | case TOSA_REF_TYPE_FP16: |
| 795 | case TOSA_REF_TYPE_BF16: |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 796 | switch (rank) |
| 797 | { |
| 798 | case 0: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 799 | return new Tensor0<float>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 800 | case 1: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 801 | return new Tensor1<float>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 802 | case 2: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 803 | return new Tensor2<float>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 804 | case 3: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 805 | return new Tensor3<float>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 806 | case 4: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 807 | return new Tensor4<float>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 808 | case 5: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 809 | return new Tensor5<float>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 810 | case 6: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 811 | return new Tensor6<float>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 812 | } |
Kevin Cheng | 989cb05 | 2021-04-28 16:29:44 -0700 | [diff] [blame] | 813 | break; |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 814 | case TOSA_REF_TYPE_INT32: |
| 815 | case TOSA_REF_TYPE_UINT8: |
| 816 | case TOSA_REF_TYPE_INT4: |
| 817 | case TOSA_REF_TYPE_INT8: |
| 818 | case TOSA_REF_TYPE_INT16: |
| 819 | case TOSA_REF_TYPE_UINT16: |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 820 | switch (rank) |
| 821 | { |
| 822 | case 0: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 823 | return new Tensor0<int32_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 824 | case 1: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 825 | return new Tensor1<int32_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 826 | case 2: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 827 | return new Tensor2<int32_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 828 | case 3: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 829 | return new Tensor3<int32_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 830 | case 4: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 831 | return new Tensor4<int32_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 832 | case 5: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 833 | return new Tensor5<int32_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 834 | case 6: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 835 | return new Tensor6<int32_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 836 | } |
Kevin Cheng | 989cb05 | 2021-04-28 16:29:44 -0700 | [diff] [blame] | 837 | break; |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 838 | case TOSA_REF_TYPE_INT48: |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 839 | switch (rank) |
| 840 | { |
| 841 | case 0: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 842 | return new Tensor0<int64_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 843 | case 1: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 844 | return new Tensor1<int64_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 845 | case 2: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 846 | return new Tensor2<int64_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 847 | case 3: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 848 | return new Tensor3<int64_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 849 | case 4: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 850 | return new Tensor4<int64_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 851 | case 5: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 852 | return new Tensor5<int64_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 853 | case 6: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 854 | return new Tensor6<int64_t>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 855 | } |
Kevin Cheng | 989cb05 | 2021-04-28 16:29:44 -0700 | [diff] [blame] | 856 | break; |
Won Jeon | a21b2e8 | 2023-08-10 10:33:01 +0000 | [diff] [blame] | 857 | case TOSA_REF_TYPE_SHAPE: |
Tai Ly | 0913dba | 2023-08-22 22:50:18 +0000 | [diff] [blame] | 858 | assert(rank == 0); |
Won Jeon | a21b2e8 | 2023-08-10 10:33:01 +0000 | [diff] [blame] | 859 | return new Tensor0<int64_t>(tensorName_, dtype_, shape_); |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 860 | case TOSA_REF_TYPE_BOOL: |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 861 | switch (rank) |
| 862 | { |
| 863 | case 0: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 864 | return new Tensor0<bool>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 865 | case 1: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 866 | return new Tensor1<bool>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 867 | case 2: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 868 | return new Tensor2<bool>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 869 | case 3: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 870 | return new Tensor3<bool>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 871 | case 4: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 872 | return new Tensor4<bool>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 873 | case 5: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 874 | return new Tensor5<bool>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 875 | case 6: |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 876 | return new Tensor6<bool>(tensorName_, dtype_, shape_); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 877 | } |
Kevin Cheng | 989cb05 | 2021-04-28 16:29:44 -0700 | [diff] [blame] | 878 | break; |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 879 | case TOSA_REF_TYPE_FP64: |
| 880 | switch (rank) |
| 881 | { |
| 882 | case 0: |
| 883 | return new Tensor0<double>(tensorName_, dtype_, shape_); |
| 884 | case 1: |
| 885 | return new Tensor1<double>(tensorName_, dtype_, shape_); |
| 886 | case 2: |
| 887 | return new Tensor2<double>(tensorName_, dtype_, shape_); |
| 888 | case 3: |
| 889 | return new Tensor3<double>(tensorName_, dtype_, shape_); |
| 890 | case 4: |
| 891 | return new Tensor4<double>(tensorName_, dtype_, shape_); |
| 892 | case 5: |
| 893 | return new Tensor5<double>(tensorName_, dtype_, shape_); |
| 894 | case 6: |
| 895 | return new Tensor6<double>(tensorName_, dtype_, shape_); |
| 896 | } |
| 897 | break; |
| 898 | case TOSA_REF_TYPE_UNKNOWN: |
| 899 | assert(0); // tensorDtype_ is uninitialized |
Kevin Cheng | 989cb05 | 2021-04-28 16:29:44 -0700 | [diff] [blame] | 900 | break; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 901 | } |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 902 | return nullptr; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 903 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 904 | }; |
| 905 | }; // namespace TosaReference |
| 906 | |
| 907 | #endif |