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