blob: 7cbeb13586eb4b636c4cb8ef7694d03d20432d84 [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001
Kevin Cheng3a478572021-01-22 17:21:02 -08002// Copyright (c) 2020-2021, ARM Limited.
Eric Kunzee5e26762020-10-13 16:11:07 -07003//
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#include "tensor.h"
17#include "arith_util.h"
18
19using namespace TosaReference;
20using namespace Eigen;
21using namespace tosa;
22
Kevin Chengacb550f2021-06-29 15:32:19 -070023TosaReference::Tensor::Tensor(std::string tensorName_, DType tensorDtype_, std::vector<int> shape_)
Eric Kunzee5e26762020-10-13 16:11:07 -070024{
Kevin Chengacb550f2021-06-29 15:32:19 -070025 tensorName = std::string(tensorName_);
26 tensorDtype = tensorDtype_;
27 shape = std::vector<int>(shape_);
28 producer = nullptr;
29 isValid = false;
Eric Kunzee5e26762020-10-13 16:11:07 -070030 consumers.clear();
31 isSubgraphInput = false;
32 isSubgraphOutput = false;
33}
34
35TosaReference::Tensor::~Tensor()
36{}
37
38int TosaReference::Tensor::setIsSubgraphInput()
39{
40 isSubgraphInput = true;
41 return 0;
42}
43
44int TosaReference::Tensor::setIsSubgraphOutput()
45{
46 isSubgraphOutput = true;
47 return 0;
48}
49
50int TosaReference::Tensor::setProducer(GraphNode* node)
51{
52 ASSERT_MSG(node, "Tensor::setProducer: no node passed in");
53 ASSERT_MSG(!producer, "Tensor::setProducer: producer node already set, tensor %s", tensorName.c_str());
54 producer = node;
55
56 return 0;
57}
58
59int TosaReference::Tensor::addConsumer(GraphNode* node)
60{
61 ASSERT_MSG(node, "Tensor::addConsumer: no node passed in");
62 consumers.push_back(node);
63
64 return 0;
65}
66
67int TosaReference::Tensor::dumpTensorParams(FILE* out) const
68{
Kevin Cheng550ccc52021-03-03 11:21:43 -080069 fprintf(out, "Name: %s DType=%s isValid=%d Rank=%d Shape=%s\n", tensorName.c_str(), EnumNamesDType()[getDtype()],
70 getIsValid(), getRank(), getShapeAsString().c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -070071
72 return 0;
73}
74
75int TosaReference::Tensor::dumpTensorParams(std::ostream& out) const
76{
Kevin Cheng550ccc52021-03-03 11:21:43 -080077 out << "Name: " << getName() << " DType=" << EnumNamesDType()[getDtype()] << " isValid=" << getIsValid()
78 << " Rank=" << getRank() << " Shape=" << getShapeAsString() << "\n";
Eric Kunzee5e26762020-10-13 16:11:07 -070079
80 return 0;
81}
82
83int TosaReference::Tensor::readFromNpyFile(const char* filename)
84{
85 uint32_t elements = getElementCount();
86 float* fdatabuf = nullptr;
87 int32_t* i32databuf = nullptr;
88 int64_t* i64databuf = nullptr;
89 bool* bdatabuf = nullptr;
90 NumpyUtilities::NPError nperror;
91
92 switch (getDtype())
93 {
94 case DType_FLOAT:
95 fdatabuf = (float*)calloc(sizeof(float), elements);
96 ASSERT_MEM(fdatabuf);
97
98 nperror = NumpyUtilities::readFromNpyFile(filename, elements, fdatabuf);
99 break;
100 case DType_INT32:
Eric Kunzee5e26762020-10-13 16:11:07 -0700101 case DType_UINT8:
102 case DType_INT4:
103 case DType_INT8:
104 case DType_INT16:
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +0100105 case DType_UINT16:
Eric Kunzee5e26762020-10-13 16:11:07 -0700106 i32databuf = (int32_t*)calloc(sizeof(int32_t), elements);
107 ASSERT_MEM(i32databuf);
108
109 nperror = NumpyUtilities::readFromNpyFile(filename, elements, i32databuf);
110 break;
111 case DType_INT48:
112 i64databuf = (int64_t*)calloc(sizeof(int64_t), elements);
113 ASSERT_MEM(i64databuf);
114
115 nperror = NumpyUtilities::readFromNpyFile(filename, elements, i64databuf);
116 break;
117 case DType_BOOL:
118 bdatabuf = (bool*)calloc(sizeof(bool), elements);
119 ASSERT_MEM(bdatabuf);
120
121 nperror = NumpyUtilities::readFromNpyFile(filename, elements, bdatabuf);
122 break;
123 default:
124 FATAL_ERROR("unsupported tensor type=%s", EnumNamesDType()[getDtype()]);
125 }
126
127 switch (nperror)
128 {
129 case NumpyUtilities::NO_ERROR:
130 break;
131 case NumpyUtilities::FILE_NOT_FOUND:
132 FATAL_ERROR("readFromNpyFile: Cannot open file %s", filename);
133 case NumpyUtilities::FILE_IO_ERROR:
134 FATAL_ERROR("readFromNpyFile: IO error reading file: %s", filename);
135 case NumpyUtilities::FILE_TYPE_MISMATCH:
136 FATAL_ERROR("readFromNpyFile: Tensor type %s and Numpy file type mismatch for tensor %s filename %s",
137 EnumNamesDType()[getDtype()], getName().c_str(), filename);
138 case NumpyUtilities::HEADER_PARSE_ERROR:
139 FATAL_ERROR("Numpy header parsing error for file: %s", filename);
140 case NumpyUtilities::BUFFER_SIZE_MISMATCH:
141 FATAL_ERROR("Buffer size does not match numpy file size for tensor %s filename %s", getName().c_str(),
142 filename);
143 default:
144 FATAL_ERROR("Unknown error parsing Numpy file: %s", filename);
145 }
146
147 switch (getDtype())
148 {
149 case DType_FLOAT:
150 if (setTensorValueFloat(elements, fdatabuf))
151 {
152 free(fdatabuf);
153 return 1;
154 }
155 break;
156 case DType_INT32:
Eric Kunzee5e26762020-10-13 16:11:07 -0700157 case DType_UINT8:
158 case DType_INT4:
159 case DType_INT8:
160 case DType_INT16:
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +0100161 case DType_UINT16:
Eric Kunzee5e26762020-10-13 16:11:07 -0700162 if (setTensorValueInt32(elements, i32databuf))
163 {
164 free(i32databuf);
165 return 1;
166 }
167 break;
168 case DType_INT48:
169 if (setTensorValueInt64(elements, i64databuf))
170 {
171 free(i64databuf);
172 return 1;
173 }
174 break;
175 case DType_BOOL:
176 if (setTensorValueBool(elements, bdatabuf))
177 {
178 free(i32databuf);
179 return 1;
180 }
181 break;
182 default:
183 FATAL_ERROR("unsupported tensor type=%s", EnumNamesDType()[getDtype()]);
184 }
185
186 setIsValid();
187
188 if (fdatabuf)
189 free(fdatabuf);
190 if (i32databuf)
191 free(i32databuf);
192 if (i64databuf)
193 free(i64databuf);
194 if (bdatabuf)
195 free(bdatabuf);
196
197 return 0;
198}
199
200int TosaReference::Tensor::writeToNpyFile(const char* filename) const
201{
202 float* fdatabuf = nullptr;
203 int32_t* i32databuf = nullptr;
204 int64_t* i64databuf = nullptr;
205 bool* bdatabuf = nullptr;
206 NumpyUtilities::NPError nperror;
207 int elements = getElementCount();
208
209 switch (getDtype())
210 {
211 case DType_FLOAT:
212 fdatabuf = (float*)calloc(sizeof(float), elements);
213 ASSERT_MEM(fdatabuf);
214
215 if (getTensorValueFloat(elements, fdatabuf))
216 {
217 free(fdatabuf);
218 return 1;
219 }
220
221 nperror = NumpyUtilities::writeToNpyFile(filename, shape, fdatabuf);
222
223 free(fdatabuf);
224 break;
225 case DType_INT32:
Eric Kunzee5e26762020-10-13 16:11:07 -0700226 case DType_UINT8:
227 case DType_INT4:
228 case DType_INT8:
229 case DType_INT16:
Jeremy Johnsonf7f78ae2022-05-25 15:26:38 +0100230 case DType_UINT16:
Eric Kunzee5e26762020-10-13 16:11:07 -0700231 i32databuf = (int32_t*)calloc(sizeof(int32_t), elements);
232 ASSERT_MEM(i32databuf);
233
234 if (getTensorValueInt32(elements, i32databuf))
235 {
236 free(i32databuf);
237 return 1;
238 }
239
240 nperror = NumpyUtilities::writeToNpyFile(filename, shape, i32databuf);
241
242 free(i32databuf);
243 break;
244 case DType_INT48:
245 i64databuf = (int64_t*)calloc(sizeof(int64_t), elements);
246 ASSERT_MEM(i64databuf);
247
248 if (getTensorValueInt64(elements, i64databuf))
249 {
250 free(i64databuf);
251 return 1;
252 }
253
254 nperror = NumpyUtilities::writeToNpyFile(filename, shape, i64databuf);
255
256 free(i64databuf);
257 break;
258 case DType_BOOL:
259 bdatabuf = (bool*)calloc(sizeof(bool), elements);
260 ASSERT_MEM(bdatabuf);
261
262 if (getTensorValueBool(elements, bdatabuf))
263 {
264 free(bdatabuf);
265 return 1;
266 }
267
268 nperror = NumpyUtilities::writeToNpyFile(filename, shape, bdatabuf);
269
270 free(bdatabuf);
271 break;
272 default:
273 FATAL_ERROR("unsupported tensor type=%s", EnumNamesDType()[getDtype()]);
274 }
275
276 switch (nperror)
277 {
278 case NumpyUtilities::NO_ERROR:
279 break;
280 case NumpyUtilities::FILE_NOT_FOUND:
281 FATAL_ERROR("writeToNpyFile: Cannot open output file %s", filename);
282 case NumpyUtilities::FILE_IO_ERROR:
283 FATAL_ERROR("writeToNpyFile: IO error writing file: %s", filename);
284 case NumpyUtilities::FILE_TYPE_MISMATCH:
285 FATAL_ERROR("writeToNpyFile: Tensor type and Numpy file type mismatch for tensor %s filename %s",
286 getName().c_str(), filename);
287 case NumpyUtilities::HEADER_PARSE_ERROR:
288 FATAL_ERROR("Numpy header parsing error for file: %s", filename);
289 case NumpyUtilities::BUFFER_SIZE_MISMATCH:
290 FATAL_ERROR("Buffer size does not match numpy file size for tensor %s filename %s", getName().c_str(),
291 filename);
292 default:
293 FATAL_ERROR("Unknown error writing Numpy file: %s", filename);
294 }
295
296 return 0;
297}
298
299template <class T>
300int TosaReference::TensorTemplate<T>::copyValueFrom(TosaReference::Tensor* src)
301{
302 FATAL_ERROR("TensorTemplate<T>::copyValueFrom should not be called. "
303 "Implement template specialization version.");
304 return 0;
305}
306
307#define DEF_CTENSOR_COPY_VALUE_FROM(RANK, TYPE) \
308 template <> \
309 int TosaReference::Tensor##RANK<TYPE>::copyValueFrom(TosaReference::Tensor* src) \
310 { \
311 TosaReference::Tensor##RANK<TYPE>* t = dynamic_cast<Tensor##RANK<TYPE>*>(src); \
312 if (!t) \
313 { \
314 WARNING("tensor %s templated class does not match %s", src->getName().c_str(), this->getName().c_str()); \
315 return 1; \
316 } \
317 \
318 uint32_t src_rank = src->getRank(); \
319 uint32_t dst_rank = this->getRank(); \
320 DType src_dtype = src->getDtype(); \
321 DType dst_dtype = this->getDtype(); \
322 bool tensor_match = true; \
323 \
324 if ((src_rank != dst_rank) || (src_dtype != dst_dtype)) \
325 { \
326 tensor_match = false; \
327 } \
328 else \
329 { \
330 for (uint32_t i = 0; i < src_rank; i++) \
331 { \
332 int src_dim = src->getShape()[i]; \
333 int dst_dim = this->getShape()[i]; \
334 if (src_dim != dst_dim) \
335 { \
336 tensor_match = false; \
337 } \
338 } \
339 } \
340 \
341 if (!tensor_match) \
342 { \
343 WARNING("source tensor %s (rank=%u, dtype=%s, shape=%s) doesn't match destination tensor %s (rank=%u, " \
344 "dtype=%s, shape=%s)", \
345 src->getName().c_str(), src_rank, EnumNamesDType()[src_dtype], src->getShapeAsString().c_str(), \
346 this->getName().c_str(), dst_rank, EnumNamesDType()[dst_dtype], this->getShapeAsString().c_str()); \
347 return 1; \
348 } \
349 \
350 this->getTensor() = t->getTensor(); \
351 return 0; \
352 }
353
354DEF_CTENSOR_COPY_VALUE_FROM(0, float)
355DEF_CTENSOR_COPY_VALUE_FROM(1, float)
356DEF_CTENSOR_COPY_VALUE_FROM(2, float)
357DEF_CTENSOR_COPY_VALUE_FROM(3, float)
358DEF_CTENSOR_COPY_VALUE_FROM(4, float)
359DEF_CTENSOR_COPY_VALUE_FROM(5, float)
360DEF_CTENSOR_COPY_VALUE_FROM(6, float)
361DEF_CTENSOR_COPY_VALUE_FROM(0, int32_t)
362DEF_CTENSOR_COPY_VALUE_FROM(1, int32_t)
363DEF_CTENSOR_COPY_VALUE_FROM(2, int32_t)
364DEF_CTENSOR_COPY_VALUE_FROM(3, int32_t)
365DEF_CTENSOR_COPY_VALUE_FROM(4, int32_t)
366DEF_CTENSOR_COPY_VALUE_FROM(5, int32_t)
367DEF_CTENSOR_COPY_VALUE_FROM(6, int32_t)
368DEF_CTENSOR_COPY_VALUE_FROM(0, int64_t)
369DEF_CTENSOR_COPY_VALUE_FROM(1, int64_t)
370DEF_CTENSOR_COPY_VALUE_FROM(2, int64_t)
371DEF_CTENSOR_COPY_VALUE_FROM(3, int64_t)
372DEF_CTENSOR_COPY_VALUE_FROM(4, int64_t)
373DEF_CTENSOR_COPY_VALUE_FROM(5, int64_t)
374DEF_CTENSOR_COPY_VALUE_FROM(6, int64_t)
375DEF_CTENSOR_COPY_VALUE_FROM(0, bool)
376DEF_CTENSOR_COPY_VALUE_FROM(1, bool)
377DEF_CTENSOR_COPY_VALUE_FROM(2, bool)
378DEF_CTENSOR_COPY_VALUE_FROM(3, bool)
379DEF_CTENSOR_COPY_VALUE_FROM(4, bool)
380DEF_CTENSOR_COPY_VALUE_FROM(5, bool)
381DEF_CTENSOR_COPY_VALUE_FROM(6, bool)
382
383#undef DEF_CTENSOR_COPY_VALUE_FROM
384
Matthew Sloyanba5fad32022-09-26 13:31:43 +0100385int TosaReference::Tensor::readfromVector(const std::vector<float>& vals)
386{
387 uint32_t elements = getElementCount();
388 switch (getDtype())
389 {
390 case DType_FLOAT:
391 if (vals.size() != elements)
392 {
393 WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
394 vals.size(), elements);
395 return -1;
396 }
397
398 setTensorValueFloat(elements, vals.data());
399 break;
400 default:
401 WARNING("The input type (float) doesn't match the data type assigned to the tensor (%s).",
402 EnumNameDType(getDtype()));
403 return -2;
404 }
405 setIsValid();
406 return 0;
407}
408
409int TosaReference::Tensor::readfromVector(const std::vector<int32_t>& vals)
410{
411 uint32_t elements = getElementCount();
412 switch (getDtype())
413 {
414 case DType_INT32:
415 case DType_UINT8:
416 case DType_INT4:
417 case DType_INT8:
418 case DType_INT16:
419 case DType_UINT16:
420 if (vals.size() != elements)
421 {
422 WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
423 vals.size(), elements);
424 return -1;
425 }
426
427 setTensorValueInt32(elements, vals.data());
428 break;
429 default:
430 WARNING("The input type doesn't match the data type assigned to the tensor (%s).",
431 EnumNameDType(getDtype()));
432 return -2;
433 }
434 setIsValid();
435 return 0;
436}
437
438int TosaReference::Tensor::readfromVector(const std::vector<int64_t>& vals)
439{
440 uint32_t elements = getElementCount();
441 switch (getDtype())
442 {
443 case DType_INT48:
444 if (vals.size() != elements)
445 {
446 WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
447 vals.size(), elements);
448 return -1;
449 }
450
451 setTensorValueInt64(elements, vals.data());
452 break;
453 default:
454 WARNING("The input type doesn't match the data type assigned to the tensor (%s).",
455 EnumNameDType(getDtype()));
456 return -2;
457 }
458 setIsValid();
459 return 0;
460}
461
462int TosaReference::Tensor::readfromVector(const std::vector<unsigned char>& vals)
463{
464 uint32_t elements = getElementCount();
465
466 switch (getDtype())
467 {
468 case DType_BOOL:
469 if (vals.size() != elements)
470 {
471 WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
472 vals.size(), elements);
473 return -1;
474 }
475
476 setTensorValueBool(elements, reinterpret_cast<const bool*>(vals.data()));
477 break;
478 default:
479 WARNING("The input type (bool) doesn't match the data type assigned to the tensor (%s).",
480 EnumNameDType(getDtype()));
481 return -2;
482 }
483 setIsValid();
484 return 0;
485}
486
487int TosaReference::Tensor::writeToVector(std::vector<float>& vals)
488{
489 uint32_t elements = getElementCount();
490
491 switch (getDtype())
492 {
493 case DType_FLOAT:
494 if (vals.size() != elements)
495 {
496 WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
497 vals.size(), elements);
498 return -1;
499 }
500
501 getTensorValueFloat(elements, vals.data());
502 break;
503 default:
504 WARNING("The output type (float) doesn't match the data type assigned to the tensor (%s).",
505 EnumNameDType(getDtype()));
506 return -2;
507 }
508 return 0;
509}
510
511int TosaReference::Tensor::writeToVector(std::vector<int32_t>& vals)
512{
513 uint32_t elements = getElementCount();
514
515 switch (getDtype())
516 {
517 case DType_INT32:
518 case DType_UINT8:
519 case DType_INT4:
520 case DType_INT8:
521 case DType_INT16:
522 case DType_UINT16:
523 if (vals.size() != elements)
524 {
525 WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
526 vals.size(), elements);
527 return -1;
528 }
529
530 getTensorValueInt32(elements, vals.data());
531 break;
532 default:
533 WARNING("The output type doesn't match the data type assigned to the tensor (%s).",
534 EnumNameDType(getDtype()));
535 return -2;
536 }
537 return 0;
538}
539
540int TosaReference::Tensor::writeToVector(std::vector<int64_t>& vals)
541{
542 uint32_t elements = getElementCount();
543
544 switch (getDtype())
545 {
546 case tosa::DType_INT48:
547 if (vals.size() != elements)
548 {
549 WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
550 vals.size(), elements);
551 return -1;
552 }
553
554 getTensorValueInt64(elements, vals.data());
555 break;
556 default:
557 WARNING("The output type doesn't match the data type assigned to the tensor (%s).",
558 EnumNameDType(getDtype()));
559 return -2;
560 }
561 return 0;
562}
563
564int TosaReference::Tensor::writeToVector(std::vector<unsigned char>& vals)
565{
566 uint32_t elements = getElementCount();
567
568 switch (getDtype())
569 {
570 case tosa::DType_BOOL:
571 if (vals.size() != elements)
572 {
573 WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.",
574 vals.size(), elements);
575 return -1;
576 }
577
578 getTensorValueBool(elements, reinterpret_cast<bool*>(vals.data()));
579 break;
580 default:
581 WARNING("The output type (bool) doesn't match the data type assigned to the tensor (%s).",
582 EnumNameDType(getDtype()));
583 return -2;
584 }
585 return 0;
586}
587
Eric Kunzee5e26762020-10-13 16:11:07 -0700588template <class T>
589int TosaReference::TensorTemplate<T>::setTensorValueFloat(const size_t buflen, const float* vals)
590{
591 FATAL_ERROR("TensorTemplate<T>::setTensorValueFloat should not be called. "
592 "Implement template specialization version.");
593 return 0;
594}
595
596template <>
597int TosaReference::Tensor0<float>::setTensorValueFloat(const size_t bufLen, const float* vals)
598{
599 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
600
601 (*tensor)(0) = vals[0];
602
603 return 0;
604}
605
606template <>
607int TosaReference::Tensor1<float>::setTensorValueFloat(const size_t bufLen, const float* vals)
608{
609 uint32_t idx = 0;
610
611 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
612
613 for (int i0 = 0; i0 < shape[0]; i0++)
614 {
615 (*tensor)(i0) = vals[idx++];
616 }
617
618 return 0;
619}
620
621template <>
622int TosaReference::Tensor2<float>::setTensorValueFloat(const size_t bufLen, const float* vals)
623{
624 uint32_t idx = 0;
625
626 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
627
628 for (int i0 = 0; i0 < shape[0]; i0++)
629 {
630 for (int i1 = 0; i1 < shape[1]; i1++)
631 {
632 (*tensor)(i0, i1) = vals[idx++];
633 }
634 }
635
636 return 0;
637}
638
639template <>
640int TosaReference::Tensor3<float>::setTensorValueFloat(const size_t bufLen, const float* vals)
641{
642 uint32_t idx = 0;
643
644 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
645
646 for (int i0 = 0; i0 < shape[0]; i0++)
647 {
648 for (int i1 = 0; i1 < shape[1]; i1++)
649 {
650 for (int i2 = 0; i2 < shape[2]; i2++)
651 {
652 (*tensor)(i0, i1, i2) = vals[idx++];
653 }
654 }
655 }
656
657 return 0;
658}
659
660template <>
661int TosaReference::Tensor4<float>::setTensorValueFloat(const size_t bufLen, const float* vals)
662{
663 uint32_t idx = 0;
664
665 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
666
667 for (int i0 = 0; i0 < shape[0]; i0++)
668 {
669 for (int i1 = 0; i1 < shape[1]; i1++)
670 {
671 for (int i2 = 0; i2 < shape[2]; i2++)
672 {
673 for (int i3 = 0; i3 < shape[3]; i3++)
674 {
675 (*tensor)(i0, i1, i2, i3) = vals[idx++];
676 }
677 }
678 }
679 }
680
681 return 0;
682}
683
684template <>
685int TosaReference::Tensor5<float>::setTensorValueFloat(const size_t bufLen, const float* vals)
686{
687 uint32_t idx = 0;
688
689 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
690
691 for (int i0 = 0; i0 < shape[0]; i0++)
692 {
693 for (int i1 = 0; i1 < shape[1]; i1++)
694 {
695 for (int i2 = 0; i2 < shape[2]; i2++)
696 {
697 for (int i3 = 0; i3 < shape[3]; i3++)
698 {
699 for (int i4 = 0; i4 < shape[4]; i4++)
700 {
701 (*tensor)(i0, i1, i2, i3, i4) = vals[idx++];
702 }
703 }
704 }
705 }
706 }
707
708 return 0;
709}
710
711template <>
712int TosaReference::Tensor6<float>::setTensorValueFloat(const size_t bufLen, const float* vals)
713{
714 uint32_t idx = 0;
715
716 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
717
718 for (int i0 = 0; i0 < shape[0]; i0++)
719 {
720 for (int i1 = 0; i1 < shape[1]; i1++)
721 {
722 for (int i2 = 0; i2 < shape[2]; i2++)
723 {
724 for (int i3 = 0; i3 < shape[3]; i3++)
725 {
726 for (int i4 = 0; i4 < shape[4]; i4++)
727 {
728 for (int i5 = 0; i5 < shape[5]; i5++)
729 {
730 (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++];
731 }
732 }
733 }
734 }
735 }
736 }
737 return 0;
738}
739
740template <class T>
741int TosaReference::TensorTemplate<T>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
742{
743 FATAL_ERROR("TensorTemplate<T>::setTensorValueInt32 should not be called. "
744 "Implement template specialization version.");
745 return 0;
746}
747
748template <>
749int TosaReference::Tensor0<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
750{
751 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
752
753 (*tensor)(0) = vals[0];
754
755 return 0;
756}
757
758template <>
759int TosaReference::Tensor1<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
760{
761 uint32_t idx = 0;
762
763 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
764
765 for (int i0 = 0; i0 < shape[0]; i0++)
766 {
767 (*tensor)(i0) = vals[idx++];
768 }
769
770 return 0;
771}
772
773template <>
774int TosaReference::Tensor2<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
775{
776 uint32_t idx = 0;
777
778 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
779
780 for (int i0 = 0; i0 < shape[0]; i0++)
781 {
782 for (int i1 = 0; i1 < shape[1]; i1++)
783 {
784 (*tensor)(i0, i1) = vals[idx++];
785 }
786 }
787
788 return 0;
789}
790
791template <>
792int TosaReference::Tensor3<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
793{
794 uint32_t idx = 0;
795
796 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
797
798 for (int i0 = 0; i0 < shape[0]; i0++)
799 {
800 for (int i1 = 0; i1 < shape[1]; i1++)
801 {
802 for (int i2 = 0; i2 < shape[2]; i2++)
803 {
804 (*tensor)(i0, i1, i2) = vals[idx++];
805 }
806 }
807 }
808
809 return 0;
810}
811
812template <>
813int TosaReference::Tensor4<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
814{
815 uint32_t idx = 0;
816
817 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
818
819 for (int i0 = 0; i0 < shape[0]; i0++)
820 {
821 for (int i1 = 0; i1 < shape[1]; i1++)
822 {
823 for (int i2 = 0; i2 < shape[2]; i2++)
824 {
825 for (int i3 = 0; i3 < shape[3]; i3++)
826 {
827 (*tensor)(i0, i1, i2, i3) = vals[idx++];
828 }
829 }
830 }
831 }
832
833 return 0;
834}
835
836template <>
837int TosaReference::Tensor5<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
838{
839 uint32_t idx = 0;
840
841 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
842
843 for (int i0 = 0; i0 < shape[0]; i0++)
844 {
845 for (int i1 = 0; i1 < shape[1]; i1++)
846 {
847 for (int i2 = 0; i2 < shape[2]; i2++)
848 {
849 for (int i3 = 0; i3 < shape[3]; i3++)
850 {
851 for (int i4 = 0; i4 < shape[4]; i4++)
852 {
853 (*tensor)(i0, i1, i2, i3, i4) = vals[idx++];
854 }
855 }
856 }
857 }
858 }
859
860 return 0;
861}
862
863template <>
864int TosaReference::Tensor6<int32_t>::setTensorValueInt32(const size_t bufLen, const int32_t* vals)
865{
866 uint32_t idx = 0;
867
868 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
869
870 for (int i0 = 0; i0 < shape[0]; i0++)
871 {
872 for (int i1 = 0; i1 < shape[1]; i1++)
873 {
874 for (int i2 = 0; i2 < shape[2]; i2++)
875 {
876 for (int i3 = 0; i3 < shape[3]; i3++)
877 {
878 for (int i4 = 0; i4 < shape[4]; i4++)
879 {
880 for (int i5 = 0; i5 < shape[5]; i5++)
881 {
882 (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++];
883 }
884 }
885 }
886 }
887 }
888 }
889 return 0;
890}
891
892template <class T>
893int TosaReference::TensorTemplate<T>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
894{
895 FATAL_ERROR("TensorTemplate<T>::setTensorValueInt64 should not be called. "
896 "Implement template specialization version.");
897 return 0;
898}
899
900template <>
901int TosaReference::Tensor0<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
902{
903 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
904
905 (*tensor)(0) = vals[0];
906
907 return 0;
908}
909
910template <>
911int TosaReference::Tensor1<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
912{
913 uint32_t idx = 0;
914
915 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
916
917 for (int i0 = 0; i0 < shape[0]; i0++)
918 {
919 (*tensor)(i0) = vals[idx++];
920 }
921
922 return 0;
923}
924
925template <>
926int TosaReference::Tensor2<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
927{
928 uint32_t idx = 0;
929
930 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
931
932 for (int i0 = 0; i0 < shape[0]; i0++)
933 {
934 for (int i1 = 0; i1 < shape[1]; i1++)
935 {
936 (*tensor)(i0, i1) = vals[idx++];
937 }
938 }
939
940 return 0;
941}
942
943template <>
944int TosaReference::Tensor3<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
945{
946 uint32_t idx = 0;
947
948 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
949
950 for (int i0 = 0; i0 < shape[0]; i0++)
951 {
952 for (int i1 = 0; i1 < shape[1]; i1++)
953 {
954 for (int i2 = 0; i2 < shape[2]; i2++)
955 {
956 (*tensor)(i0, i1, i2) = vals[idx++];
957 }
958 }
959 }
960
961 return 0;
962}
963
964template <>
965int TosaReference::Tensor4<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
966{
967 uint32_t idx = 0;
968
969 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
970
971 for (int i0 = 0; i0 < shape[0]; i0++)
972 {
973 for (int i1 = 0; i1 < shape[1]; i1++)
974 {
975 for (int i2 = 0; i2 < shape[2]; i2++)
976 {
977 for (int i3 = 0; i3 < shape[3]; i3++)
978 {
979 (*tensor)(i0, i1, i2, i3) = vals[idx++];
980 }
981 }
982 }
983 }
984
985 return 0;
986}
987
988template <>
989int TosaReference::Tensor5<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
990{
991 uint32_t idx = 0;
992
993 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
994
995 for (int i0 = 0; i0 < shape[0]; i0++)
996 {
997 for (int i1 = 0; i1 < shape[1]; i1++)
998 {
999 for (int i2 = 0; i2 < shape[2]; i2++)
1000 {
1001 for (int i3 = 0; i3 < shape[3]; i3++)
1002 {
1003 for (int i4 = 0; i4 < shape[4]; i4++)
1004 {
1005 (*tensor)(i0, i1, i2, i3, i4) = vals[idx++];
1006 }
1007 }
1008 }
1009 }
1010 }
1011
1012 return 0;
1013}
1014
1015template <>
1016int TosaReference::Tensor6<int64_t>::setTensorValueInt64(const size_t bufLen, const int64_t* vals)
1017{
1018 uint32_t idx = 0;
1019
1020 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1021
1022 for (int i0 = 0; i0 < shape[0]; i0++)
1023 {
1024 for (int i1 = 0; i1 < shape[1]; i1++)
1025 {
1026 for (int i2 = 0; i2 < shape[2]; i2++)
1027 {
1028 for (int i3 = 0; i3 < shape[3]; i3++)
1029 {
1030 for (int i4 = 0; i4 < shape[4]; i4++)
1031 {
1032 for (int i5 = 0; i5 < shape[5]; i5++)
1033 {
1034 (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++];
1035 }
1036 }
1037 }
1038 }
1039 }
1040 }
1041 return 0;
1042}
1043
1044template <class T>
1045int TosaReference::TensorTemplate<T>::setTensorValueBool(const size_t buflen, const bool* vals)
1046{
1047 FATAL_ERROR("TensorTemplate<T>::setTensorValueBool should not be called. "
1048 "Implement template specialization version.");
1049 return 0;
1050}
1051
1052template <>
1053int TosaReference::Tensor0<bool>::setTensorValueBool(const size_t bufLen, const bool* vals)
1054{
1055 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1056
1057 (*tensor)(0) = vals[0];
1058
1059 return 0;
1060}
1061
1062template <>
1063int TosaReference::Tensor1<bool>::setTensorValueBool(const size_t bufLen, const bool* vals)
1064{
1065 uint32_t idx = 0;
1066
1067 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1068
1069 for (int i0 = 0; i0 < shape[0]; i0++)
1070 {
1071 (*tensor)(i0) = vals[idx++];
1072 }
1073
1074 return 0;
1075}
1076
1077template <>
1078int TosaReference::Tensor2<bool>::setTensorValueBool(const size_t bufLen, const bool* vals)
1079{
1080 uint32_t idx = 0;
1081
1082 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1083
1084 for (int i0 = 0; i0 < shape[0]; i0++)
1085 {
1086 for (int i1 = 0; i1 < shape[1]; i1++)
1087 {
1088 (*tensor)(i0, i1) = vals[idx++];
1089 }
1090 }
1091
1092 return 0;
1093}
1094
1095template <>
1096int TosaReference::Tensor3<bool>::setTensorValueBool(const size_t bufLen, const bool* vals)
1097{
1098 uint32_t idx = 0;
1099
1100 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1101
1102 for (int i0 = 0; i0 < shape[0]; i0++)
1103 {
1104 for (int i1 = 0; i1 < shape[1]; i1++)
1105 {
1106 for (int i2 = 0; i2 < shape[2]; i2++)
1107 {
1108 (*tensor)(i0, i1, i2) = vals[idx++];
1109 }
1110 }
1111 }
1112
1113 return 0;
1114}
1115
1116template <>
1117int TosaReference::Tensor4<bool>::setTensorValueBool(const size_t bufLen, const bool* vals)
1118{
1119 uint32_t idx = 0;
1120
1121 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1122
1123 for (int i0 = 0; i0 < shape[0]; i0++)
1124 {
1125 for (int i1 = 0; i1 < shape[1]; i1++)
1126 {
1127 for (int i2 = 0; i2 < shape[2]; i2++)
1128 {
1129 for (int i3 = 0; i3 < shape[3]; i3++)
1130 {
1131 (*tensor)(i0, i1, i2, i3) = vals[idx++];
1132 }
1133 }
1134 }
1135 }
1136
1137 return 0;
1138}
1139
1140template <>
1141int TosaReference::Tensor5<bool>::setTensorValueBool(const size_t bufLen, const bool* vals)
1142{
1143 uint32_t idx = 0;
1144
1145 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1146
1147 for (int i0 = 0; i0 < shape[0]; i0++)
1148 {
1149 for (int i1 = 0; i1 < shape[1]; i1++)
1150 {
1151 for (int i2 = 0; i2 < shape[2]; i2++)
1152 {
1153 for (int i3 = 0; i3 < shape[3]; i3++)
1154 {
1155 for (int i4 = 0; i4 < shape[4]; i4++)
1156 {
1157 (*tensor)(i0, i1, i2, i3, i4) = vals[idx++];
1158 }
1159 }
1160 }
1161 }
1162 }
1163
1164 return 0;
1165}
1166
1167template <>
1168int TosaReference::Tensor6<bool>::setTensorValueBool(const size_t bufLen, const bool* vals)
1169{
1170 uint32_t idx = 0;
1171
1172 ASSERT_MSG(bufLen == getElementCount(), "Total elements must match");
1173
1174 for (int i0 = 0; i0 < shape[0]; i0++)
1175 {
1176 for (int i1 = 0; i1 < shape[1]; i1++)
1177 {
1178 for (int i2 = 0; i2 < shape[2]; i2++)
1179 {
1180 for (int i3 = 0; i3 < shape[3]; i3++)
1181 {
1182 for (int i4 = 0; i4 < shape[4]; i4++)
1183 {
1184 for (int i5 = 0; i5 < shape[5]; i5++)
1185 {
1186 (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++];
1187 }
1188 }
1189 }
1190 }
1191 }
1192 }
1193 return 0;
1194}
1195
1196template <class T>
1197int TosaReference::TensorTemplate<T>::getTensorValueFloat(const size_t bufLen, float* vals) const
1198{
1199 FATAL_ERROR("TensorTemplate<T>::getTensorValueFloat should not be called. "
1200 "Implement template specialization version.");
1201 return 0;
1202}
1203
1204template <>
1205int TosaReference::Tensor0<float>::getTensorValueFloat(const size_t bufLen, float* vals) const
1206{
1207 int totalVals = 1;
1208
1209 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1210
1211 vals[0] = (*tensor)(0);
1212
1213 return 0;
1214}
1215
1216template <>
1217int TosaReference::Tensor1<float>::getTensorValueFloat(const size_t bufLen, float* vals) const
1218{
1219 uint32_t idx = 0;
1220 int totalVals = 1;
1221
1222 for (size_t i = 0; i < shape.size(); i++)
1223 {
1224 totalVals *= shape[i];
1225 }
1226
1227 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1228
1229 for (int i0 = 0; i0 < shape[0]; i0++)
1230 {
1231 vals[idx++] = (*tensor)(i0);
1232 }
1233
1234 return 0;
1235}
1236
1237template <>
1238int TosaReference::Tensor2<float>::getTensorValueFloat(const size_t bufLen, float* vals) const
1239{
1240 uint32_t idx = 0;
1241 int totalVals = 1;
1242
1243 for (size_t i = 0; i < shape.size(); i++)
1244 {
1245 totalVals *= shape[i];
1246 }
1247
1248 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1249
1250 for (int i0 = 0; i0 < shape[0]; i0++)
1251 {
1252 for (int i1 = 0; i1 < shape[1]; i1++)
1253 {
1254 vals[idx++] = (*tensor)(i0, i1);
1255 }
1256 }
1257
1258 return 0;
1259}
1260
1261template <>
1262int TosaReference::Tensor3<float>::getTensorValueFloat(const size_t bufLen, float* vals) const
1263{
1264 uint32_t idx = 0;
1265 int totalVals = 1;
1266
1267 for (size_t i = 0; i < shape.size(); i++)
1268 {
1269 totalVals *= shape[i];
1270 }
1271
1272 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1273
1274 for (int i0 = 0; i0 < shape[0]; i0++)
1275 {
1276 for (int i1 = 0; i1 < shape[1]; i1++)
1277 {
1278 for (int i2 = 0; i2 < shape[2]; i2++)
1279 {
1280 vals[idx++] = (*tensor)(i0, i1, i2);
1281 }
1282 }
1283 }
1284
1285 return 0;
1286}
1287
1288template <>
1289int TosaReference::Tensor4<float>::getTensorValueFloat(const size_t bufLen, float* vals) const
1290{
1291 uint32_t idx = 0;
1292 int totalVals = 1;
1293
1294 for (size_t i = 0; i < shape.size(); i++)
1295 {
1296 totalVals *= shape[i];
1297 }
1298
1299 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1300
1301 for (int i0 = 0; i0 < shape[0]; i0++)
1302 {
1303 for (int i1 = 0; i1 < shape[1]; i1++)
1304 {
1305 for (int i2 = 0; i2 < shape[2]; i2++)
1306 {
1307 for (int i3 = 0; i3 < shape[3]; i3++)
1308 {
1309 vals[idx++] = (*tensor)(i0, i1, i2, i3);
1310 }
1311 }
1312 }
1313 }
1314
1315 return 0;
1316}
1317
1318template <>
1319int TosaReference::Tensor5<float>::getTensorValueFloat(const size_t bufLen, float* vals) const
1320{
1321 uint32_t idx = 0;
1322 int totalVals = 1;
1323
1324 for (size_t i = 0; i < shape.size(); i++)
1325 {
1326 totalVals *= shape[i];
1327 }
1328
1329 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1330
1331 for (int i0 = 0; i0 < shape[0]; i0++)
1332 {
1333 for (int i1 = 0; i1 < shape[1]; i1++)
1334 {
1335 for (int i2 = 0; i2 < shape[2]; i2++)
1336 {
1337 for (int i3 = 0; i3 < shape[3]; i3++)
1338 {
1339 for (int i4 = 0; i4 < shape[4]; i4++)
1340 {
1341 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4);
1342 }
1343 }
1344 }
1345 }
1346 }
1347
1348 return 0;
1349}
1350
1351template <>
1352int TosaReference::Tensor6<float>::getTensorValueFloat(const size_t bufLen, float* vals) const
1353{
1354 uint32_t idx = 0;
1355 int totalVals = 1;
1356
1357 for (size_t i = 0; i < shape.size(); i++)
1358 {
1359 totalVals *= shape[i];
1360 }
1361
1362 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1363
1364 for (int i0 = 0; i0 < shape[0]; i0++)
1365 {
1366 for (int i1 = 0; i1 < shape[1]; i1++)
1367 {
1368 for (int i2 = 0; i2 < shape[2]; i2++)
1369 {
1370 for (int i3 = 0; i3 < shape[3]; i3++)
1371 {
1372 for (int i4 = 0; i4 < shape[4]; i4++)
1373 {
1374 for (int i5 = 0; i5 < shape[5]; i5++)
1375 {
1376 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5);
1377 }
1378 }
1379 }
1380 }
1381 }
1382 }
1383 return 0;
1384}
1385
1386template <class T>
1387int TosaReference::TensorTemplate<T>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1388{
1389 FATAL_ERROR("TensorTemplate<T>::getTensorValueInt32 should not be called. "
1390 "Implement template specialization version.");
1391 return 0;
1392}
1393
1394template <>
1395int TosaReference::Tensor0<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1396{
1397 int totalVals = 1;
1398
1399 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1400
1401 vals[0] = (*tensor)(0);
1402
1403 return 0;
1404}
1405
1406template <>
1407int TosaReference::Tensor1<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1408{
1409 uint32_t idx = 0;
1410 int totalVals = 1;
1411
1412 for (size_t i = 0; i < shape.size(); i++)
1413 {
1414 totalVals *= shape[i];
1415 }
1416
1417 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1418
1419 for (int i0 = 0; i0 < shape[0]; i0++)
1420 {
1421 vals[idx++] = (*tensor)(i0);
1422 }
1423
1424 return 0;
1425}
1426
1427template <>
1428int TosaReference::Tensor2<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1429{
1430 uint32_t idx = 0;
1431 int totalVals = 1;
1432
1433 for (size_t i = 0; i < shape.size(); i++)
1434 {
1435 totalVals *= shape[i];
1436 }
1437
1438 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1439
1440 for (int i0 = 0; i0 < shape[0]; i0++)
1441 {
1442 for (int i1 = 0; i1 < shape[1]; i1++)
1443 {
1444 vals[idx++] = (*tensor)(i0, i1);
1445 }
1446 }
1447
1448 return 0;
1449}
1450
1451template <>
1452int TosaReference::Tensor3<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1453{
1454 uint32_t idx = 0;
1455 int totalVals = 1;
1456
1457 for (size_t i = 0; i < shape.size(); i++)
1458 {
1459 totalVals *= shape[i];
1460 }
1461
1462 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1463
1464 for (int i0 = 0; i0 < shape[0]; i0++)
1465 {
1466 for (int i1 = 0; i1 < shape[1]; i1++)
1467 {
1468 for (int i2 = 0; i2 < shape[2]; i2++)
1469 {
1470 vals[idx++] = (*tensor)(i0, i1, i2);
1471 }
1472 }
1473 }
1474
1475 return 0;
1476}
1477
1478template <>
1479int TosaReference::Tensor4<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1480{
1481 uint32_t idx = 0;
1482 int totalVals = 1;
1483
1484 for (size_t i = 0; i < shape.size(); i++)
1485 {
1486 totalVals *= shape[i];
1487 }
1488
1489 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1490
1491 for (int i0 = 0; i0 < shape[0]; i0++)
1492 {
1493 for (int i1 = 0; i1 < shape[1]; i1++)
1494 {
1495 for (int i2 = 0; i2 < shape[2]; i2++)
1496 {
1497 for (int i3 = 0; i3 < shape[3]; i3++)
1498 {
1499 vals[idx++] = (*tensor)(i0, i1, i2, i3);
1500 }
1501 }
1502 }
1503 }
1504
1505 return 0;
1506}
1507
1508template <>
1509int TosaReference::Tensor5<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1510{
1511 uint32_t idx = 0;
1512 int totalVals = 1;
1513
1514 for (size_t i = 0; i < shape.size(); i++)
1515 {
1516 totalVals *= shape[i];
1517 }
1518
1519 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1520
1521 for (int i0 = 0; i0 < shape[0]; i0++)
1522 {
1523 for (int i1 = 0; i1 < shape[1]; i1++)
1524 {
1525 for (int i2 = 0; i2 < shape[2]; i2++)
1526 {
1527 for (int i3 = 0; i3 < shape[3]; i3++)
1528 {
1529 for (int i4 = 0; i4 < shape[4]; i4++)
1530 {
1531 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4);
1532 }
1533 }
1534 }
1535 }
1536 }
1537
1538 return 0;
1539}
1540
1541template <>
1542int TosaReference::Tensor6<int32_t>::getTensorValueInt32(const size_t bufLen, int32_t* vals) const
1543{
1544 uint32_t idx = 0;
1545 int totalVals = 1;
1546
1547 for (size_t i = 0; i < shape.size(); i++)
1548 {
1549 totalVals *= shape[i];
1550 }
1551
1552 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1553
1554 for (int i0 = 0; i0 < shape[0]; i0++)
1555 {
1556 for (int i1 = 0; i1 < shape[1]; i1++)
1557 {
1558 for (int i2 = 0; i2 < shape[2]; i2++)
1559 {
1560 for (int i3 = 0; i3 < shape[3]; i3++)
1561 {
1562 for (int i4 = 0; i4 < shape[4]; i4++)
1563 {
1564 for (int i5 = 0; i5 < shape[5]; i5++)
1565 {
1566 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5);
1567 }
1568 }
1569 }
1570 }
1571 }
1572 }
1573 return 0;
1574}
1575
1576template <class T>
1577int TosaReference::TensorTemplate<T>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1578{
1579 FATAL_ERROR("TensorTemplate<T>::getTensorValueInt64 should not be called. "
1580 "Implement template specialization version.");
1581 return 0;
1582}
1583
1584template <>
1585int TosaReference::Tensor0<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1586{
1587 int totalVals = 1;
1588
1589 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1590
1591 vals[0] = (*tensor)(0);
1592
1593 return 0;
1594}
1595
1596template <>
1597int TosaReference::Tensor1<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1598{
1599 uint32_t idx = 0;
1600 int totalVals = 1;
1601
1602 for (size_t i = 0; i < shape.size(); i++)
1603 {
1604 totalVals *= shape[i];
1605 }
1606
1607 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1608
1609 for (int i0 = 0; i0 < shape[0]; i0++)
1610 {
1611 vals[idx++] = (*tensor)(i0);
1612 }
1613
1614 return 0;
1615}
1616
1617template <>
1618int TosaReference::Tensor2<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1619{
1620 uint32_t idx = 0;
1621 int totalVals = 1;
1622
1623 for (size_t i = 0; i < shape.size(); i++)
1624 {
1625 totalVals *= shape[i];
1626 }
1627
1628 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1629
1630 for (int i0 = 0; i0 < shape[0]; i0++)
1631 {
1632 for (int i1 = 0; i1 < shape[1]; i1++)
1633 {
1634 vals[idx++] = (*tensor)(i0, i1);
1635 }
1636 }
1637
1638 return 0;
1639}
1640
1641template <>
1642int TosaReference::Tensor3<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1643{
1644 uint32_t idx = 0;
1645 int totalVals = 1;
1646
1647 for (size_t i = 0; i < shape.size(); i++)
1648 {
1649 totalVals *= shape[i];
1650 }
1651
1652 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1653
1654 for (int i0 = 0; i0 < shape[0]; i0++)
1655 {
1656 for (int i1 = 0; i1 < shape[1]; i1++)
1657 {
1658 for (int i2 = 0; i2 < shape[2]; i2++)
1659 {
1660 vals[idx++] = (*tensor)(i0, i1, i2);
1661 }
1662 }
1663 }
1664
1665 return 0;
1666}
1667
1668template <>
1669int TosaReference::Tensor4<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1670{
1671 uint32_t idx = 0;
1672 int totalVals = 1;
1673
1674 for (size_t i = 0; i < shape.size(); i++)
1675 {
1676 totalVals *= shape[i];
1677 }
1678
1679 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1680
1681 for (int i0 = 0; i0 < shape[0]; i0++)
1682 {
1683 for (int i1 = 0; i1 < shape[1]; i1++)
1684 {
1685 for (int i2 = 0; i2 < shape[2]; i2++)
1686 {
1687 for (int i3 = 0; i3 < shape[3]; i3++)
1688 {
1689 vals[idx++] = (*tensor)(i0, i1, i2, i3);
1690 }
1691 }
1692 }
1693 }
1694
1695 return 0;
1696}
1697
1698template <>
1699int TosaReference::Tensor5<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1700{
1701 uint32_t idx = 0;
1702 int totalVals = 1;
1703
1704 for (size_t i = 0; i < shape.size(); i++)
1705 {
1706 totalVals *= shape[i];
1707 }
1708
1709 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1710
1711 for (int i0 = 0; i0 < shape[0]; i0++)
1712 {
1713 for (int i1 = 0; i1 < shape[1]; i1++)
1714 {
1715 for (int i2 = 0; i2 < shape[2]; i2++)
1716 {
1717 for (int i3 = 0; i3 < shape[3]; i3++)
1718 {
1719 for (int i4 = 0; i4 < shape[4]; i4++)
1720 {
1721 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4);
1722 }
1723 }
1724 }
1725 }
1726 }
1727
1728 return 0;
1729}
1730
1731template <>
1732int TosaReference::Tensor6<int64_t>::getTensorValueInt64(const size_t bufLen, int64_t* vals) const
1733{
1734 uint32_t idx = 0;
1735 int totalVals = 1;
1736
1737 for (size_t i = 0; i < shape.size(); i++)
1738 {
1739 totalVals *= shape[i];
1740 }
1741
1742 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1743
1744 for (int i0 = 0; i0 < shape[0]; i0++)
1745 {
1746 for (int i1 = 0; i1 < shape[1]; i1++)
1747 {
1748 for (int i2 = 0; i2 < shape[2]; i2++)
1749 {
1750 for (int i3 = 0; i3 < shape[3]; i3++)
1751 {
1752 for (int i4 = 0; i4 < shape[4]; i4++)
1753 {
1754 for (int i5 = 0; i5 < shape[5]; i5++)
1755 {
1756 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5);
1757 }
1758 }
1759 }
1760 }
1761 }
1762 }
1763 return 0;
1764}
1765
1766template <class T>
1767int TosaReference::TensorTemplate<T>::getTensorValueBool(const size_t bufLen, bool* vals) const
1768{
1769 FATAL_ERROR("TensorTemplate<T>::getTensorValueBool should not be called. "
1770 "Implement template specialization version.");
1771 return 0;
1772}
1773
1774template <>
1775int TosaReference::Tensor0<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const
1776{
1777 int totalVals = 1;
1778
1779 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1780
1781 vals[0] = (*tensor)(0);
1782
1783 return 0;
1784}
1785
1786template <>
1787int TosaReference::Tensor1<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const
1788{
1789 uint32_t idx = 0;
1790 int totalVals = 1;
1791
1792 for (size_t i = 0; i < shape.size(); i++)
1793 {
1794 totalVals *= shape[i];
1795 }
1796
1797 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1798
1799 for (int i0 = 0; i0 < shape[0]; i0++)
1800 {
1801 vals[idx++] = (*tensor)(i0);
1802 }
1803
1804 return 0;
1805}
1806
1807template <>
1808int TosaReference::Tensor2<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const
1809{
1810 uint32_t idx = 0;
1811 int totalVals = 1;
1812
1813 for (size_t i = 0; i < shape.size(); i++)
1814 {
1815 totalVals *= shape[i];
1816 }
1817
1818 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1819
1820 for (int i0 = 0; i0 < shape[0]; i0++)
1821 {
1822 for (int i1 = 0; i1 < shape[1]; i1++)
1823 {
1824 vals[idx++] = (*tensor)(i0, i1);
1825 }
1826 }
1827
1828 return 0;
1829}
1830
1831template <>
1832int TosaReference::Tensor3<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const
1833{
1834 uint32_t idx = 0;
1835 int totalVals = 1;
1836
1837 for (size_t i = 0; i < shape.size(); i++)
1838 {
1839 totalVals *= shape[i];
1840 }
1841
1842 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1843
1844 for (int i0 = 0; i0 < shape[0]; i0++)
1845 {
1846 for (int i1 = 0; i1 < shape[1]; i1++)
1847 {
1848 for (int i2 = 0; i2 < shape[2]; i2++)
1849 {
1850 vals[idx++] = (*tensor)(i0, i1, i2);
1851 }
1852 }
1853 }
1854
1855 return 0;
1856}
1857
1858template <>
1859int TosaReference::Tensor4<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const
1860{
1861 uint32_t idx = 0;
1862 int totalVals = 1;
1863
1864 for (size_t i = 0; i < shape.size(); i++)
1865 {
1866 totalVals *= shape[i];
1867 }
1868
1869 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1870
1871 for (int i0 = 0; i0 < shape[0]; i0++)
1872 {
1873 for (int i1 = 0; i1 < shape[1]; i1++)
1874 {
1875 for (int i2 = 0; i2 < shape[2]; i2++)
1876 {
1877 for (int i3 = 0; i3 < shape[3]; i3++)
1878 {
1879 vals[idx++] = (*tensor)(i0, i1, i2, i3);
1880 }
1881 }
1882 }
1883 }
1884
1885 return 0;
1886}
1887
1888template <>
1889int TosaReference::Tensor5<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const
1890{
1891 uint32_t idx = 0;
1892 int totalVals = 1;
1893
1894 for (size_t i = 0; i < shape.size(); i++)
1895 {
1896 totalVals *= shape[i];
1897 }
1898
1899 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1900
1901 for (int i0 = 0; i0 < shape[0]; i0++)
1902 {
1903 for (int i1 = 0; i1 < shape[1]; i1++)
1904 {
1905 for (int i2 = 0; i2 < shape[2]; i2++)
1906 {
1907 for (int i3 = 0; i3 < shape[3]; i3++)
1908 {
1909 for (int i4 = 0; i4 < shape[4]; i4++)
1910 {
1911 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4);
1912 }
1913 }
1914 }
1915 }
1916 }
1917
1918 return 0;
1919}
1920
1921template <>
1922int TosaReference::Tensor6<bool>::getTensorValueBool(const size_t bufLen, bool* vals) const
1923{
1924 uint32_t idx = 0;
1925 int totalVals = 1;
1926
1927 for (size_t i = 0; i < shape.size(); i++)
1928 {
1929 totalVals *= shape[i];
1930 }
1931
1932 ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match");
1933
1934 for (int i0 = 0; i0 < shape[0]; i0++)
1935 {
1936 for (int i1 = 0; i1 < shape[1]; i1++)
1937 {
1938 for (int i2 = 0; i2 < shape[2]; i2++)
1939 {
1940 for (int i3 = 0; i3 < shape[3]; i3++)
1941 {
1942 for (int i4 = 0; i4 < shape[4]; i4++)
1943 {
1944 for (int i5 = 0; i5 < shape[5]; i5++)
1945 {
1946 vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5);
1947 }
1948 }
1949 }
1950 }
1951 }
1952 }
1953 return 0;
1954}
1955
1956template <>
1957int TosaReference::Tensor0<float>::allocate()
1958{
1959 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
1960 tensor = new ETensor0<float>();
1961
1962 if (tensor)
1963 return 0;
1964 else
1965 return 1;
1966}
1967template <>
1968int TosaReference::Tensor1<float>::allocate()
1969{
1970 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
1971 tensor = new ETensor1<float>(shape[0]);
1972 if (tensor)
1973 return 0;
1974 else
1975 return 1;
1976}
1977template <>
1978int TosaReference::Tensor2<float>::allocate()
1979{
1980 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
1981 tensor = new ETensor2<float>(shape[0], shape[1]);
1982 if (tensor)
1983 return 0;
1984 else
1985 return 1;
1986}
1987
1988template <>
1989int TosaReference::Tensor3<float>::allocate()
1990{
1991 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
1992 tensor = new ETensor3<float>(shape[0], shape[1], shape[2]);
1993 if (tensor)
1994 return 0;
1995 else
1996 return 1;
1997}
1998
1999template <>
2000int TosaReference::Tensor4<float>::allocate()
2001{
2002 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2003 tensor = new ETensor4<float>(shape[0], shape[1], shape[2], shape[3]);
2004 if (tensor)
2005 return 0;
2006 else
2007 return 1;
2008}
2009
2010template <>
2011int TosaReference::Tensor5<float>::allocate()
2012{
2013 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2014 tensor = new ETensor5<float>(shape[0], shape[1], shape[2], shape[3], shape[4]);
2015 if (tensor)
2016 return 0;
2017 else
2018 return 1;
2019}
2020
2021template <>
2022int TosaReference::Tensor6<float>::allocate()
2023{
2024 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2025 tensor = new ETensor6<float>(shape[0], shape[1], shape[2], shape[3], shape[4], shape[5]);
2026 if (tensor)
2027 return 0;
2028 else
2029 return 1;
2030}
2031
2032template <>
2033int TosaReference::Tensor0<int32_t>::allocate()
2034{
2035 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2036 tensor = new ETensor0<int32_t>();
2037 if (tensor)
2038 return 0;
2039 else
2040 return 1;
2041}
2042template <>
2043int TosaReference::Tensor1<int32_t>::allocate()
2044{
2045 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2046 tensor = new ETensor1<int32_t>(shape[0]);
2047 if (tensor)
2048 return 0;
2049 else
2050 return 1;
2051}
2052template <>
2053int TosaReference::Tensor2<int32_t>::allocate()
2054{
2055 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2056 tensor = new ETensor2<int32_t>(shape[0], shape[1]);
2057 if (tensor)
2058 return 0;
2059 else
2060 return 1;
2061}
2062
2063template <>
2064int TosaReference::Tensor3<int32_t>::allocate()
2065{
2066 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2067 tensor = new ETensor3<int32_t>(shape[0], shape[1], shape[2]);
2068 if (tensor)
2069 return 0;
2070 else
2071 return 1;
2072}
2073
2074template <>
2075int TosaReference::Tensor4<int32_t>::allocate()
2076{
2077 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2078 tensor = new ETensor4<int32_t>(shape[0], shape[1], shape[2], shape[3]);
2079 if (tensor)
2080 return 0;
2081 else
2082 return 1;
2083}
2084
2085template <>
2086int TosaReference::Tensor5<int32_t>::allocate()
2087{
2088 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2089 tensor = new ETensor5<int32_t>(shape[0], shape[1], shape[2], shape[3], shape[4]);
2090 if (tensor)
2091 return 0;
2092 else
2093 return 1;
2094}
2095
2096template <>
2097int TosaReference::Tensor6<int32_t>::allocate()
2098{
2099 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2100 tensor = new ETensor6<int32_t>(shape[0], shape[1], shape[2], shape[3], shape[4], shape[5]);
2101 if (tensor)
2102 return 0;
2103 else
2104 return 1;
2105}
2106
2107template <>
2108int TosaReference::Tensor0<int64_t>::allocate()
2109{
2110 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2111 tensor = new ETensor0<int64_t>();
2112 if (tensor)
2113 return 0;
2114 else
2115 return 1;
2116}
2117template <>
2118int TosaReference::Tensor1<int64_t>::allocate()
2119{
2120 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2121 tensor = new ETensor1<int64_t>(shape[0]);
2122 if (tensor)
2123 return 0;
2124 else
2125 return 1;
2126}
2127template <>
2128int TosaReference::Tensor2<int64_t>::allocate()
2129{
2130 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2131 tensor = new ETensor2<int64_t>(shape[0], shape[1]);
2132 if (tensor)
2133 return 0;
2134 else
2135 return 1;
2136}
2137
2138template <>
2139int TosaReference::Tensor3<int64_t>::allocate()
2140{
2141 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2142 tensor = new ETensor3<int64_t>(shape[0], shape[1], shape[2]);
2143 if (tensor)
2144 return 0;
2145 else
2146 return 1;
2147}
2148
2149template <>
2150int TosaReference::Tensor4<int64_t>::allocate()
2151{
2152 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2153 tensor = new ETensor4<int64_t>(shape[0], shape[1], shape[2], shape[3]);
2154 if (tensor)
2155 return 0;
2156 else
2157 return 1;
2158}
2159
2160template <>
2161int TosaReference::Tensor5<int64_t>::allocate()
2162{
2163 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2164 tensor = new ETensor5<int64_t>(shape[0], shape[1], shape[2], shape[3], shape[4]);
2165 if (tensor)
2166 return 0;
2167 else
2168 return 1;
2169}
2170
2171template <>
2172int TosaReference::Tensor6<int64_t>::allocate()
2173{
2174 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2175 tensor = new ETensor6<int64_t>(shape[0], shape[1], shape[2], shape[3], shape[4], shape[5]);
2176 if (tensor)
2177 return 0;
2178 else
2179 return 1;
2180}
2181
2182template <>
2183int TosaReference::Tensor0<bool>::allocate()
2184{
2185 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2186 tensor = new ETensor0<bool>();
2187 if (tensor)
2188 return 0;
2189 else
2190 return 1;
2191}
2192template <>
2193int TosaReference::Tensor1<bool>::allocate()
2194{
2195 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2196 tensor = new ETensor1<bool>(shape[0]);
2197 if (tensor)
2198 return 0;
2199 else
2200 return 1;
2201}
2202template <>
2203int TosaReference::Tensor2<bool>::allocate()
2204{
2205 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2206 tensor = new ETensor2<bool>(shape[0], shape[1]);
2207 if (tensor)
2208 return 0;
2209 else
2210 return 1;
2211}
2212
2213template <>
2214int TosaReference::Tensor3<bool>::allocate()
2215{
2216 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2217 tensor = new ETensor3<bool>(shape[0], shape[1], shape[2]);
2218 if (tensor)
2219 return 0;
2220 else
2221 return 1;
2222}
2223
2224template <>
2225int TosaReference::Tensor4<bool>::allocate()
2226{
2227 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2228 tensor = new ETensor4<bool>(shape[0], shape[1], shape[2], shape[3]);
2229 if (tensor)
2230 return 0;
2231 else
2232 return 1;
2233}
2234
2235template <>
2236int TosaReference::Tensor5<bool>::allocate()
2237{
2238 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2239 tensor = new ETensor5<bool>(shape[0], shape[1], shape[2], shape[3], shape[4]);
2240 if (tensor)
2241 return 0;
2242 else
2243 return 1;
2244}
2245
2246template <>
2247int TosaReference::Tensor6<bool>::allocate()
2248{
2249 ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor");
2250 tensor = new ETensor6<bool>(shape[0], shape[1], shape[2], shape[3], shape[4], shape[5]);
2251 if (tensor)
2252 return 0;
2253 else
2254 return 1;
2255}
2256
2257template <>
2258int TosaReference::Tensor0<float>::dumpTensor(FILE* out) const
2259{
Eric Kunze286f8342022-06-22 11:30:23 -07002260 char fp_fmt[32];
2261 snprintf(fp_fmt, sizeof(fp_fmt), "[ %%%sf ]\n", g_func_config.fp_format.c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -07002262
2263 if (tensor == nullptr)
2264 {
2265 fprintf(out, "<Not allocated>\n");
2266 return 0;
2267 }
2268
2269 fprintf(out, fp_fmt, (*tensor)(0));
2270
2271 return 0;
2272}
2273
2274template <>
2275int TosaReference::Tensor1<float>::dumpTensor(FILE* out) const
2276{
Eric Kunze286f8342022-06-22 11:30:23 -07002277 char fp_fmt[32];
2278 snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -07002279
2280 if (tensor == nullptr)
2281 {
2282 fprintf(out, "<Not allocated>\n");
2283 return 0;
2284 }
2285
2286 fprintf(out, "[");
2287 for (int i0 = 0; i0 < shape[0]; i0++)
2288 {
2289 fprintf(out, fp_fmt, (*tensor)(i0));
2290 }
2291 fprintf(out, "]\n");
2292
2293 return 0;
2294}
2295
2296template <>
2297int TosaReference::Tensor2<float>::dumpTensor(FILE* out) const
2298{
Eric Kunze286f8342022-06-22 11:30:23 -07002299 char fp_fmt[32];
2300 snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -07002301
2302 if (tensor == nullptr)
2303 {
2304 fprintf(out, "<Not allocated>\n");
2305 return 0;
2306 }
2307
2308 fprintf(out, "[");
2309 for (int i0 = 0; i0 < shape[0]; i0++)
2310 {
2311 fprintf(out, "[");
2312 for (int i1 = 0; i1 < shape[1]; i1++)
2313 {
2314 fprintf(out, fp_fmt, (*tensor)(i0, i1));
2315 }
2316 fprintf(out, "]\n");
2317 }
2318 fprintf(out, "]\n");
2319
2320 return 0;
2321}
2322
2323template <>
2324int TosaReference::Tensor3<float>::dumpTensor(FILE* out) const
2325{
Eric Kunze286f8342022-06-22 11:30:23 -07002326 char fp_fmt[32];
2327 snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -07002328
2329 if (tensor == nullptr)
2330 {
2331 fprintf(out, "<Not allocated>\n");
2332 return 0;
2333 }
2334
2335 fprintf(out, "[");
2336 for (int i0 = 0; i0 < shape[0]; i0++)
2337 {
2338 fprintf(out, "[");
2339 for (int i1 = 0; i1 < shape[1]; i1++)
2340 {
2341 fprintf(out, "[");
2342 for (int i2 = 0; i2 < shape[2]; i2++)
2343 {
2344 fprintf(out, fp_fmt, (*tensor)(i0, i1, i2));
2345 }
2346 fprintf(out, "]\n");
2347 }
2348 fprintf(out, "]\n");
2349 }
2350 fprintf(out, "]\n");
2351
2352 return 0;
2353}
2354
2355template <>
2356int TosaReference::Tensor4<float>::dumpTensor(FILE* out) const
2357{
Eric Kunze286f8342022-06-22 11:30:23 -07002358 char fp_fmt[32];
2359 snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -07002360
2361 if (tensor == nullptr)
2362 {
2363 fprintf(out, "<Not allocated>\n");
2364 return 0;
2365 }
2366
2367 fprintf(out, "[");
2368 for (int i0 = 0; i0 < shape[0]; i0++)
2369 {
2370 fprintf(out, "[");
2371 for (int i1 = 0; i1 < shape[1]; i1++)
2372 {
2373 fprintf(out, "[");
2374 for (int i2 = 0; i2 < shape[2]; i2++)
2375 {
2376 fprintf(out, "[");
2377 for (int i3 = 0; i3 < shape[3]; i3++)
2378 {
2379 fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3));
2380 }
2381 fprintf(out, "]\n");
2382 }
2383 fprintf(out, "]\n");
2384 }
2385 fprintf(out, "]\n");
2386 }
2387 fprintf(out, "]\n");
2388
2389 return 0;
2390}
2391
2392template <>
2393int TosaReference::Tensor5<float>::dumpTensor(FILE* out) const
2394{
Eric Kunze286f8342022-06-22 11:30:23 -07002395 char fp_fmt[32];
2396 snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -07002397
2398 if (tensor == nullptr)
2399 {
2400 fprintf(out, "<Not allocated>\n");
2401 return 0;
2402 }
2403
2404 fprintf(out, "[");
2405 for (int i0 = 0; i0 < shape[0]; i0++)
2406 {
2407 fprintf(out, "[");
2408 for (int i1 = 0; i1 < shape[1]; i1++)
2409 {
2410 fprintf(out, "[");
2411 for (int i2 = 0; i2 < shape[2]; i2++)
2412 {
2413 fprintf(out, "[");
2414 for (int i3 = 0; i3 < shape[3]; i3++)
2415 {
2416 fprintf(out, "[");
2417 for (int i4 = 0; i4 < shape[4]; i4++)
2418 {
2419 fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3, i4));
2420 }
2421 fprintf(out, "]\n");
2422 }
2423 fprintf(out, "]\n");
2424 }
2425 fprintf(out, "]\n");
2426 }
2427 fprintf(out, "]\n");
2428 }
2429 fprintf(out, "]\n");
2430
2431 return 0;
2432}
2433
2434template <>
2435int TosaReference::Tensor6<float>::dumpTensor(FILE* out) const
2436{
Eric Kunze286f8342022-06-22 11:30:23 -07002437 char fp_fmt[32];
2438 snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str());
Eric Kunzee5e26762020-10-13 16:11:07 -07002439
2440 if (tensor == nullptr)
2441 {
2442 fprintf(out, "<Not allocated>\n");
2443 return 0;
2444 }
2445
2446 fprintf(out, "[");
2447 for (int i0 = 0; i0 < shape[0]; i0++)
2448 {
2449 fprintf(out, "[");
2450 for (int i1 = 0; i1 < shape[1]; i1++)
2451 {
2452 fprintf(out, "[");
2453 for (int i2 = 0; i2 < shape[2]; i2++)
2454 {
2455 fprintf(out, "[");
2456 for (int i3 = 0; i3 < shape[3]; i3++)
2457 {
2458 fprintf(out, "[");
2459 for (int i4 = 0; i4 < shape[4]; i4++)
2460 {
2461 fprintf(out, "[");
2462 for (int i5 = 0; i5 < shape[5]; i5++)
2463 {
2464 fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3, i4, i5));
2465 }
2466 fprintf(out, "]\n");
2467 }
2468 fprintf(out, "]\n");
2469 }
2470 fprintf(out, "]\n");
2471 }
2472 fprintf(out, "]\n");
2473 }
2474 fprintf(out, "]\n");
2475 }
2476 fprintf(out, "]\n");
2477
2478 return 0;
2479}
2480
2481template <>
2482int TosaReference::Tensor0<int64_t>::dumpTensor(FILE* out) const
2483{
Eric Kunze286f8342022-06-22 11:30:23 -07002484 char i64_fmt[32];
2485 snprintf(i64_fmt, sizeof(i64_fmt), "[ %%ld ]\n");
Eric Kunzee5e26762020-10-13 16:11:07 -07002486
2487 if (tensor == nullptr)
2488 {
2489 fprintf(out, "<Not allocated>\n");
2490 return 0;
2491 }
2492
2493 fprintf(out, i64_fmt, (*tensor)(0));
2494
2495 return 0;
2496}
2497
2498template <>
2499int TosaReference::Tensor1<int64_t>::dumpTensor(FILE* out) const
2500{
Eric Kunze286f8342022-06-22 11:30:23 -07002501 char i64_fmt[32];
2502 snprintf(i64_fmt, sizeof(i64_fmt), " %%ld ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002503
2504 if (tensor == nullptr)
2505 {
2506 fprintf(out, "<Not allocated>\n");
2507 return 0;
2508 }
2509
2510 fprintf(out, "[");
2511 for (int i0 = 0; i0 < shape[0]; i0++)
2512 {
2513 fprintf(out, i64_fmt, (*tensor)(i0));
2514 }
2515 fprintf(out, "]\n");
2516
2517 return 0;
2518}
2519
2520template <>
2521int TosaReference::Tensor2<int64_t>::dumpTensor(FILE* out) const
2522{
Eric Kunze286f8342022-06-22 11:30:23 -07002523 char i64_fmt[32];
2524 snprintf(i64_fmt, sizeof(i64_fmt), " %%ld ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002525
2526 if (tensor == nullptr)
2527 {
2528 fprintf(out, "<Not allocated>\n");
2529 return 0;
2530 }
2531
2532 fprintf(out, "[");
2533 for (int i0 = 0; i0 < shape[0]; i0++)
2534 {
2535 fprintf(out, "[");
2536 for (int i1 = 0; i1 < shape[1]; i1++)
2537 {
2538 fprintf(out, i64_fmt, (*tensor)(i0, i1));
2539 }
2540 fprintf(out, "]\n");
2541 }
2542 fprintf(out, "]\n");
2543
2544 return 0;
2545}
2546
2547template <>
2548int TosaReference::Tensor3<int64_t>::dumpTensor(FILE* out) const
2549{
Eric Kunze286f8342022-06-22 11:30:23 -07002550 char i64_fmt[32];
2551 snprintf(i64_fmt, sizeof(i64_fmt), " %%ld ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002552
2553 if (tensor == nullptr)
2554 {
2555 fprintf(out, "<Not allocated>\n");
2556 return 0;
2557 }
2558
2559 fprintf(out, "[");
2560 for (int i0 = 0; i0 < shape[0]; i0++)
2561 {
2562 fprintf(out, "[");
2563 for (int i1 = 0; i1 < shape[1]; i1++)
2564 {
2565 fprintf(out, "[");
2566 for (int i2 = 0; i2 < shape[2]; i2++)
2567 {
2568 fprintf(out, i64_fmt, (*tensor)(i0, i1, i2));
2569 }
2570 fprintf(out, "]\n");
2571 }
2572 fprintf(out, "]\n");
2573 }
2574 fprintf(out, "]\n");
2575
2576 return 0;
2577}
2578
2579template <>
2580int TosaReference::Tensor4<int64_t>::dumpTensor(FILE* out) const
2581{
Eric Kunze286f8342022-06-22 11:30:23 -07002582 char i64_fmt[32];
2583 snprintf(i64_fmt, sizeof(i64_fmt), " %%ld ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002584
2585 if (tensor == nullptr)
2586 {
2587 fprintf(out, "<Not allocated>\n");
2588 return 0;
2589 }
2590
2591 fprintf(out, "[");
2592 for (int i0 = 0; i0 < shape[0]; i0++)
2593 {
2594 fprintf(out, "[");
2595 for (int i1 = 0; i1 < shape[1]; i1++)
2596 {
2597 fprintf(out, "[");
2598 for (int i2 = 0; i2 < shape[2]; i2++)
2599 {
2600 fprintf(out, "[");
2601 for (int i3 = 0; i3 < shape[3]; i3++)
2602 {
2603 fprintf(out, i64_fmt, (*tensor)(i0, i1, i2, i3));
2604 }
2605 fprintf(out, "]\n");
2606 }
2607 fprintf(out, "]\n");
2608 }
2609 fprintf(out, "]\n");
2610 }
2611 fprintf(out, "]\n");
2612
2613 return 0;
2614}
2615
2616template <>
2617int TosaReference::Tensor5<int64_t>::dumpTensor(FILE* out) const
2618{
Eric Kunze286f8342022-06-22 11:30:23 -07002619 char i64_fmt[32];
2620 snprintf(i64_fmt, sizeof(i64_fmt), " %%ld ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002621
2622 if (tensor == nullptr)
2623 {
2624 fprintf(out, "<Not allocated>\n");
2625 return 0;
2626 }
2627
2628 fprintf(out, "[");
2629 for (int i0 = 0; i0 < shape[0]; i0++)
2630 {
2631 fprintf(out, "[");
2632 for (int i1 = 0; i1 < shape[1]; i1++)
2633 {
2634 fprintf(out, "[");
2635 for (int i2 = 0; i2 < shape[2]; i2++)
2636 {
2637 fprintf(out, "[");
2638 for (int i3 = 0; i3 < shape[3]; i3++)
2639 {
2640 fprintf(out, "[");
2641 for (int i4 = 0; i4 < shape[4]; i4++)
2642 {
2643 fprintf(out, i64_fmt, (*tensor)(i0, i1, i2, i3, i4));
2644 }
2645 fprintf(out, "]\n");
2646 }
2647 fprintf(out, "]\n");
2648 }
2649 fprintf(out, "]\n");
2650 }
2651 fprintf(out, "]\n");
2652 }
2653 fprintf(out, "]\n");
2654
2655 return 0;
2656}
2657
2658template <>
2659int TosaReference::Tensor6<int64_t>::dumpTensor(FILE* out) const
2660{
Eric Kunze286f8342022-06-22 11:30:23 -07002661 char i64_fmt[32];
2662 snprintf(i64_fmt, sizeof(i64_fmt), " %%ld ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002663
2664 if (tensor == nullptr)
2665 {
2666 fprintf(out, "<Not allocated>\n");
2667 return 0;
2668 }
2669
2670 fprintf(out, "[");
2671 for (int i0 = 0; i0 < shape[0]; i0++)
2672 {
2673 fprintf(out, "[");
2674 for (int i1 = 0; i1 < shape[1]; i1++)
2675 {
2676 fprintf(out, "[");
2677 for (int i2 = 0; i2 < shape[2]; i2++)
2678 {
2679 fprintf(out, "[");
2680 for (int i3 = 0; i3 < shape[3]; i3++)
2681 {
2682 fprintf(out, "[");
2683 for (int i4 = 0; i4 < shape[4]; i4++)
2684 {
2685 fprintf(out, "[");
2686 for (int i5 = 0; i5 < shape[5]; i5++)
2687 {
2688 fprintf(out, i64_fmt, (*tensor)(i0, i1, i2, i3, i4, i5));
2689 }
2690 fprintf(out, "]\n");
2691 }
2692 fprintf(out, "]\n");
2693 }
2694 fprintf(out, "]\n");
2695 }
2696 fprintf(out, "]\n");
2697 }
2698 fprintf(out, "]\n");
2699 }
2700 fprintf(out, "]\n");
2701
2702 return 0;
2703}
2704
2705template <>
2706int TosaReference::Tensor0<int32_t>::dumpTensor(FILE* out) const
2707{
Eric Kunze286f8342022-06-22 11:30:23 -07002708 char i32_fmt[32];
2709 snprintf(i32_fmt, sizeof(i32_fmt), "[ %%d ]\n");
Eric Kunzee5e26762020-10-13 16:11:07 -07002710
2711 if (tensor == nullptr)
2712 {
2713 fprintf(out, "<Not allocated>\n");
2714 return 0;
2715 }
2716
2717 fprintf(out, i32_fmt, (*tensor)(0));
2718
2719 return 0;
2720}
2721
2722template <>
2723int TosaReference::Tensor1<int32_t>::dumpTensor(FILE* out) const
2724{
Eric Kunze286f8342022-06-22 11:30:23 -07002725 char i32_fmt[32];
2726 snprintf(i32_fmt, sizeof(i32_fmt), " %%d ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002727
2728 if (tensor == nullptr)
2729 {
2730 fprintf(out, "<Not allocated>\n");
2731 return 0;
2732 }
2733
2734 fprintf(out, "[");
2735 for (int i0 = 0; i0 < shape[0]; i0++)
2736 {
2737 fprintf(out, i32_fmt, (*tensor)(i0));
2738 }
2739 fprintf(out, "]\n");
2740
2741 return 0;
2742}
2743
2744template <>
2745int TosaReference::Tensor2<int32_t>::dumpTensor(FILE* out) const
2746{
Eric Kunze286f8342022-06-22 11:30:23 -07002747 char i32_fmt[32];
2748 snprintf(i32_fmt, sizeof(i32_fmt), " %%d ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002749
2750 if (tensor == nullptr)
2751 {
2752 fprintf(out, "<Not allocated>\n");
2753 return 0;
2754 }
2755
2756 if (tensor == nullptr)
2757 {
2758 fprintf(out, "<Not allocated>\n");
2759 return 0;
2760 }
2761
2762 fprintf(out, "[");
2763 for (int i0 = 0; i0 < shape[0]; i0++)
2764 {
2765 fprintf(out, "[");
2766 for (int i1 = 0; i1 < shape[1]; i1++)
2767 {
2768 fprintf(out, i32_fmt, (*tensor)(i0, i1));
2769 }
2770 fprintf(out, "]\n");
2771 }
2772 fprintf(out, "]\n");
2773
2774 return 0;
2775}
2776
2777template <>
2778int TosaReference::Tensor3<int32_t>::dumpTensor(FILE* out) const
2779{
Eric Kunze286f8342022-06-22 11:30:23 -07002780 char i32_fmt[32];
2781 snprintf(i32_fmt, sizeof(i32_fmt), " %%d ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002782
2783 if (tensor == nullptr)
2784 {
2785 fprintf(out, "<Not allocated>\n");
2786 return 0;
2787 }
2788
2789 if (tensor == nullptr)
2790 {
2791 fprintf(out, "<Not allocated>\n");
2792 return 0;
2793 }
2794
2795 fprintf(out, "[");
2796 for (int i0 = 0; i0 < shape[0]; i0++)
2797 {
2798 fprintf(out, "[");
2799 for (int i1 = 0; i1 < shape[1]; i1++)
2800 {
2801 fprintf(out, "[");
2802 for (int i2 = 0; i2 < shape[2]; i2++)
2803 {
2804 fprintf(out, i32_fmt, (*tensor)(i0, i1, i2));
2805 }
2806 fprintf(out, "]\n");
2807 }
2808 fprintf(out, "]\n");
2809 }
2810 fprintf(out, "]\n");
2811
2812 return 0;
2813}
2814
2815template <>
2816int TosaReference::Tensor4<int32_t>::dumpTensor(FILE* out) const
2817{
Eric Kunze286f8342022-06-22 11:30:23 -07002818 char i32_fmt[32];
2819 snprintf(i32_fmt, sizeof(i32_fmt), " %%d ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002820
2821 if (tensor == nullptr)
2822 {
2823 fprintf(out, "<Not allocated>\n");
2824 return 0;
2825 }
2826
2827 fprintf(out, "[");
2828 for (int i0 = 0; i0 < shape[0]; i0++)
2829 {
2830 fprintf(out, "[");
2831 for (int i1 = 0; i1 < shape[1]; i1++)
2832 {
2833 fprintf(out, "[");
2834 for (int i2 = 0; i2 < shape[2]; i2++)
2835 {
2836 fprintf(out, "[");
2837 for (int i3 = 0; i3 < shape[3]; i3++)
2838 {
2839 fprintf(out, i32_fmt, (*tensor)(i0, i1, i2, i3));
2840 }
2841 fprintf(out, "]\n");
2842 }
2843 fprintf(out, "]\n");
2844 }
2845 fprintf(out, "]\n");
2846 }
2847 fprintf(out, "]\n");
2848
2849 return 0;
2850}
2851
2852template <>
2853int TosaReference::Tensor5<int32_t>::dumpTensor(FILE* out) const
2854{
Eric Kunze286f8342022-06-22 11:30:23 -07002855 char i32_fmt[32];
2856 snprintf(i32_fmt, sizeof(i32_fmt), " %%d ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002857
2858 if (tensor == nullptr)
2859 {
2860 fprintf(out, "<Not allocated>\n");
2861 return 0;
2862 }
2863
2864 fprintf(out, "[");
2865 for (int i0 = 0; i0 < shape[0]; i0++)
2866 {
2867 fprintf(out, "[");
2868 for (int i1 = 0; i1 < shape[1]; i1++)
2869 {
2870 fprintf(out, "[");
2871 for (int i2 = 0; i2 < shape[2]; i2++)
2872 {
2873 fprintf(out, "[");
2874 for (int i3 = 0; i3 < shape[3]; i3++)
2875 {
2876 fprintf(out, "[");
2877 for (int i4 = 0; i4 < shape[4]; i4++)
2878 {
2879 fprintf(out, i32_fmt, (*tensor)(i0, i1, i2, i3, i4));
2880 }
2881 fprintf(out, "]\n");
2882 }
2883 fprintf(out, "]\n");
2884 }
2885 fprintf(out, "]\n");
2886 }
2887 fprintf(out, "]\n");
2888 }
2889 fprintf(out, "]\n");
2890
2891 return 0;
2892}
2893
2894template <>
2895int TosaReference::Tensor6<int32_t>::dumpTensor(FILE* out) const
2896{
Eric Kunze286f8342022-06-22 11:30:23 -07002897 char i32_fmt[32];
2898 snprintf(i32_fmt, sizeof(i32_fmt), " %%d ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002899
2900 if (tensor == nullptr)
2901 {
2902 fprintf(out, "<Not allocated>\n");
2903 return 0;
2904 }
2905
2906 fprintf(out, "[");
2907 for (int i0 = 0; i0 < shape[0]; i0++)
2908 {
2909 fprintf(out, "[");
2910 for (int i1 = 0; i1 < shape[1]; i1++)
2911 {
2912 fprintf(out, "[");
2913 for (int i2 = 0; i2 < shape[2]; i2++)
2914 {
2915 fprintf(out, "[");
2916 for (int i3 = 0; i3 < shape[3]; i3++)
2917 {
2918 fprintf(out, "[");
2919 for (int i4 = 0; i4 < shape[4]; i4++)
2920 {
2921 fprintf(out, "[");
2922 for (int i5 = 0; i5 < shape[5]; i5++)
2923 {
2924 fprintf(out, i32_fmt, (*tensor)(i0, i1, i2, i3, i4, i5));
2925 }
2926 fprintf(out, "]\n");
2927 }
2928 fprintf(out, "]\n");
2929 }
2930 fprintf(out, "]\n");
2931 }
2932 fprintf(out, "]\n");
2933 }
2934 fprintf(out, "]\n");
2935 }
2936 fprintf(out, "]\n");
2937
2938 return 0;
2939}
2940
2941template <>
2942int TosaReference::Tensor0<bool>::dumpTensor(FILE* out) const
2943{
Eric Kunze286f8342022-06-22 11:30:23 -07002944 char bool_fmt[32];
2945 snprintf(bool_fmt, sizeof(bool_fmt), "[ %%s ]\n");
Eric Kunzee5e26762020-10-13 16:11:07 -07002946
2947 if (tensor == nullptr)
2948 {
2949 fprintf(out, "<Not allocated>\n");
2950 return 0;
2951 }
2952
2953 fprintf(out, bool_fmt, bool_to_str((*tensor)(0)));
2954
2955 return 0;
2956}
2957
2958template <>
2959int TosaReference::Tensor1<bool>::dumpTensor(FILE* out) const
2960{
Eric Kunze286f8342022-06-22 11:30:23 -07002961 char bool_fmt[32];
2962 snprintf(bool_fmt, sizeof(bool_fmt), " %%s ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002963
2964 if (tensor == nullptr)
2965 {
2966 fprintf(out, "<Not allocated>\n");
2967 return 0;
2968 }
2969
2970 fprintf(out, "[");
2971 for (int i0 = 0; i0 < shape[0]; i0++)
2972 {
2973 fprintf(out, bool_fmt, bool_to_str((*tensor)(i0)));
2974 }
2975 fprintf(out, "]\n");
2976
2977 return 0;
2978}
2979
2980template <>
2981int TosaReference::Tensor2<bool>::dumpTensor(FILE* out) const
2982{
Eric Kunze286f8342022-06-22 11:30:23 -07002983 char bool_fmt[32];
2984 snprintf(bool_fmt, sizeof(bool_fmt), " %%s ");
Eric Kunzee5e26762020-10-13 16:11:07 -07002985
2986 if (tensor == nullptr)
2987 {
2988 fprintf(out, "<Not allocated>\n");
2989 return 0;
2990 }
2991
2992 fprintf(out, "[");
2993 for (int i0 = 0; i0 < shape[0]; i0++)
2994 {
2995 fprintf(out, "[");
2996 for (int i1 = 0; i1 < shape[1]; i1++)
2997 {
2998 fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1)));
2999 }
3000 fprintf(out, "]\n");
3001 }
3002 fprintf(out, "]\n");
3003
3004 return 0;
3005}
3006
3007template <>
3008int TosaReference::Tensor3<bool>::dumpTensor(FILE* out) const
3009{
Eric Kunze286f8342022-06-22 11:30:23 -07003010 char bool_fmt[32];
3011 snprintf(bool_fmt, sizeof(bool_fmt), " %%s ");
Eric Kunzee5e26762020-10-13 16:11:07 -07003012
3013 if (tensor == nullptr)
3014 {
3015 fprintf(out, "<Not allocated>\n");
3016 return 0;
3017 }
3018
3019 fprintf(out, "[");
3020 for (int i0 = 0; i0 < shape[0]; i0++)
3021 {
3022 fprintf(out, "[");
3023 for (int i1 = 0; i1 < shape[1]; i1++)
3024 {
3025 fprintf(out, "[");
3026 for (int i2 = 0; i2 < shape[2]; i2++)
3027 {
3028 fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2)));
3029 }
3030 fprintf(out, "]\n");
3031 }
3032 fprintf(out, "]\n");
3033 }
3034 fprintf(out, "]\n");
3035
3036 return 0;
3037}
3038
3039template <>
3040int TosaReference::Tensor4<bool>::dumpTensor(FILE* out) const
3041{
Eric Kunze286f8342022-06-22 11:30:23 -07003042 char bool_fmt[32];
3043 snprintf(bool_fmt, sizeof(bool_fmt), " %%s ");
Eric Kunzee5e26762020-10-13 16:11:07 -07003044
3045 if (tensor == nullptr)
3046 {
3047 fprintf(out, "<Not allocated>\n");
3048 return 0;
3049 }
3050
3051 fprintf(out, "[");
3052 for (int i0 = 0; i0 < shape[0]; i0++)
3053 {
3054 fprintf(out, "[");
3055 for (int i1 = 0; i1 < shape[1]; i1++)
3056 {
3057 fprintf(out, "[");
3058 for (int i2 = 0; i2 < shape[2]; i2++)
3059 {
3060 fprintf(out, "[");
3061 for (int i3 = 0; i3 < shape[3]; i3++)
3062 {
3063 fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2, i3)));
3064 }
3065 fprintf(out, "]\n");
3066 }
3067 fprintf(out, "]\n");
3068 }
3069 fprintf(out, "]\n");
3070 }
3071 fprintf(out, "]\n");
3072
3073 return 0;
3074}
3075
3076template <>
3077int TosaReference::Tensor5<bool>::dumpTensor(FILE* out) const
3078{
Eric Kunze286f8342022-06-22 11:30:23 -07003079 char bool_fmt[32];
3080 snprintf(bool_fmt, sizeof(bool_fmt), " %%s ");
Eric Kunzee5e26762020-10-13 16:11:07 -07003081
3082 if (tensor == nullptr)
3083 {
3084 fprintf(out, "<Not allocated>\n");
3085 return 0;
3086 }
3087
3088 fprintf(out, "[");
3089 for (int i0 = 0; i0 < shape[0]; i0++)
3090 {
3091 fprintf(out, "[");
3092 for (int i1 = 0; i1 < shape[1]; i1++)
3093 {
3094 fprintf(out, "[");
3095 for (int i2 = 0; i2 < shape[2]; i2++)
3096 {
3097 fprintf(out, "[");
3098 for (int i3 = 0; i3 < shape[3]; i3++)
3099 {
3100 fprintf(out, "[");
3101 for (int i4 = 0; i4 < shape[4]; i4++)
3102 {
3103 fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2, i3, i4)));
3104 }
3105 fprintf(out, "]\n");
3106 }
3107 fprintf(out, "]\n");
3108 }
3109 fprintf(out, "]\n");
3110 }
3111 fprintf(out, "]\n");
3112 }
3113 fprintf(out, "]\n");
3114
3115 return 0;
3116}
3117
3118template <>
3119int TosaReference::Tensor6<bool>::dumpTensor(FILE* out) const
3120{
Eric Kunze286f8342022-06-22 11:30:23 -07003121 char bool_fmt[32];
3122 snprintf(bool_fmt, sizeof(bool_fmt), " %%s ");
Eric Kunzee5e26762020-10-13 16:11:07 -07003123
3124 if (tensor == nullptr)
3125 {
3126 fprintf(out, "<Not allocated>\n");
3127 return 0;
3128 }
3129
3130 fprintf(out, "[");
3131 for (int i0 = 0; i0 < shape[0]; i0++)
3132 {
3133 fprintf(out, "[");
3134 for (int i1 = 0; i1 < shape[1]; i1++)
3135 {
3136 fprintf(out, "[");
3137 for (int i2 = 0; i2 < shape[2]; i2++)
3138 {
3139 fprintf(out, "[");
3140 for (int i3 = 0; i3 < shape[3]; i3++)
3141 {
3142 fprintf(out, "[");
3143 for (int i4 = 0; i4 < shape[4]; i4++)
3144 {
3145 fprintf(out, "[");
3146 for (int i5 = 0; i5 < shape[5]; i5++)
3147 {
3148 fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2, i3, i4, i5)));
3149 }
3150 fprintf(out, "]\n");
3151 }
3152 fprintf(out, "]\n");
3153 }
3154 fprintf(out, "]\n");
3155 }
3156 fprintf(out, "]\n");
3157 }
3158 fprintf(out, "]\n");
3159 }
3160 fprintf(out, "]\n");
3161
3162 return 0;
3163}
3164
3165template <class T>
3166int TosaReference::TensorTemplate<T>::dumpTensor(FILE* out) const
3167{
3168 return 0;
3169}
3170
3171// template explicit specialization
3172template class TosaReference::TensorTemplate<Eigen::Tensor<float, 0>>;
3173template class TosaReference::TensorTemplate<Eigen::Tensor<float, 1>>;
3174template class TosaReference::TensorTemplate<Eigen::Tensor<float, 2>>;
3175template class TosaReference::TensorTemplate<Eigen::Tensor<float, 3>>;
3176template class TosaReference::TensorTemplate<Eigen::Tensor<float, 4>>;
3177template class TosaReference::TensorTemplate<Eigen::Tensor<float, 5>>;
3178template class TosaReference::TensorTemplate<Eigen::Tensor<float, 6>>;
3179
3180template class TosaReference::TensorTemplate<Eigen::Tensor<int32_t, 0>>;
3181template class TosaReference::TensorTemplate<Eigen::Tensor<int32_t, 1>>;
3182template class TosaReference::TensorTemplate<Eigen::Tensor<int32_t, 2>>;
3183template class TosaReference::TensorTemplate<Eigen::Tensor<int32_t, 3>>;
3184template class TosaReference::TensorTemplate<Eigen::Tensor<int32_t, 4>>;
3185template class TosaReference::TensorTemplate<Eigen::Tensor<int32_t, 5>>;
3186template class TosaReference::TensorTemplate<Eigen::Tensor<int32_t, 6>>;
3187
3188template class TosaReference::TensorTemplate<Eigen::Tensor<int64_t, 0>>;
3189template class TosaReference::TensorTemplate<Eigen::Tensor<int64_t, 1>>;
3190template class TosaReference::TensorTemplate<Eigen::Tensor<int64_t, 2>>;
3191template class TosaReference::TensorTemplate<Eigen::Tensor<int64_t, 3>>;
3192template class TosaReference::TensorTemplate<Eigen::Tensor<int64_t, 4>>;
3193template class TosaReference::TensorTemplate<Eigen::Tensor<int64_t, 5>>;
3194template class TosaReference::TensorTemplate<Eigen::Tensor<int64_t, 6>>;
3195
3196template class TosaReference::TensorTemplate<Eigen::Tensor<bool, 0>>;
3197template class TosaReference::TensorTemplate<Eigen::Tensor<bool, 1>>;
3198template class TosaReference::TensorTemplate<Eigen::Tensor<bool, 2>>;
3199template class TosaReference::TensorTemplate<Eigen::Tensor<bool, 3>>;
3200template class TosaReference::TensorTemplate<Eigen::Tensor<bool, 4>>;
3201template class TosaReference::TensorTemplate<Eigen::Tensor<bool, 5>>;
3202template class TosaReference::TensorTemplate<Eigen::Tensor<bool, 6>>;