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