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