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