// Copyright (c) 2020-2024, ARM Limited. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "tensor.h" #include "arith_util.h" #include "array_proxy.h" #include "half.hpp" using namespace TosaReference; using namespace Eigen; using namespace tosa; TosaReference::Tensor::Tensor(const std::string tensorName_, const DType serializationDtype_, const std::vector shape_) : tensorName(tensorName_) , serializationDtype(serializationDtype_) , shape(shape_) , tensorDtype(ConvertDType(serializationDtype_)) { producer = nullptr; isValid = false; consumers.clear(); isSubgraphInput = false; isSubgraphOutput = false; isParentGraphOutput = false; isVariable = false; } TosaReference::Tensor::~Tensor() {} int TosaReference::Tensor::setIsParentGraphOutput() { isParentGraphOutput = true; return 0; } int TosaReference::Tensor::setIsSubgraphInput() { isSubgraphInput = true; return 0; } int TosaReference::Tensor::setIsSubgraphOutput() { isSubgraphOutput = true; return 0; } int TosaReference::Tensor::setIsVariable() { isVariable = true; return 0; } int TosaReference::Tensor::setProducer(GraphNode* node) { ASSERT_MSG(node, "Tensor::setProducer: no node passed in"); ASSERT_MSG(!producer, "Tensor::setProducer: producer node already set, tensor %s", tensorName.c_str()); producer = node; return 0; } int TosaReference::Tensor::addConsumer(GraphNode* node) { ASSERT_MSG(node, "Tensor::addConsumer: no node passed in"); consumers.push_back(node); return 0; } int TosaReference::Tensor::dumpTensorParams(FILE* out) const { fprintf(out, "Name: %s DType=%s isValid=%d Rank=%d Shape=%s\n", tensorName.c_str(), EnumNameTOSAREFTYPE(getDtype()), getIsValid(), getRank(), getShapeAsString().c_str()); return 0; } int TosaReference::Tensor::dumpTensorParams(std::ostream& out) const { out << "Name: " << getName() << " DType=" << EnumNameTOSAREFTYPE(getDtype()) << " isValid=" << getIsValid() << " Rank=" << getRank() << " Shape=" << getShapeAsString() << "\n"; return 0; } int TosaReference::Tensor::readFromNpyFile(const char* filename) { uint32_t elements = getElementCount(); double* f64databuf = nullptr; float* f32databuf = nullptr; half_float::half* f16databuf = nullptr; int32_t* i32databuf = nullptr; int64_t* i64databuf = nullptr; bool* bdatabuf = nullptr; NumpyUtilities::NPError nperror; TOSA_REF_TYPE dtype = getDtype(); DType serialization_dtype = getSerializationDtype(); assert(dtype == ConvertDType(serialization_dtype)); // if dtype is FP64, serialization_dtype must be one of FP32, FP16, BF16 assert(dtype != TOSA_REF_TYPE_FP64 || serialization_dtype == DType_FP32 || serialization_dtype == DType_FP16 || serialization_dtype == DType_BF16 || serialization_dtype == DType_FP8E4M3 || serialization_dtype == DType_FP8E5M2); switch (serialization_dtype) { case DType_FP32: case DType_BF16: case DType_FP8E4M3: case DType_FP8E5M2: f32databuf = (float*)calloc(sizeof(float), elements); ASSERT_MEM(f32databuf); nperror = NumpyUtilities::readFromNpyFile(filename, elements, f32databuf); break; case DType_FP16: f16databuf = (half_float::half*)calloc(sizeof(half_float::half), elements); ASSERT_MEM(f16databuf); nperror = NumpyUtilities::readFromNpyFile(filename, elements, f16databuf); break; case DType_INT32: case DType_UINT8: case DType_INT4: case DType_INT8: case DType_INT16: case DType_UINT16: i32databuf = (int32_t*)calloc(sizeof(int32_t), elements); ASSERT_MEM(i32databuf); nperror = NumpyUtilities::readFromNpyFile(filename, elements, i32databuf); break; case DType_INT48: case DType_SHAPE: i64databuf = (int64_t*)calloc(sizeof(int64_t), elements); ASSERT_MEM(i64databuf); nperror = NumpyUtilities::readFromNpyFile(filename, elements, i64databuf); break; case DType_BOOL: bdatabuf = (bool*)calloc(sizeof(bool), elements); ASSERT_MEM(bdatabuf); nperror = NumpyUtilities::readFromNpyFile(filename, elements, bdatabuf); break; default: FATAL_ERROR("unknown tensor type=%s", EnumNameDType(serialization_dtype)); } switch (nperror) { case NumpyUtilities::NO_ERROR: break; case NumpyUtilities::FILE_NOT_FOUND: FATAL_ERROR("readFromNpyFile: Cannot open file %s", filename); case NumpyUtilities::FILE_IO_ERROR: FATAL_ERROR("readFromNpyFile: IO error reading file: %s", filename); case NumpyUtilities::FILE_TYPE_MISMATCH: FATAL_ERROR("readFromNpyFile: Tensor type %s and Numpy file type mismatch for tensor %s filename %s", EnumNameTOSAREFTYPE(getDtype()), getName().c_str(), filename); case NumpyUtilities::HEADER_PARSE_ERROR: FATAL_ERROR("Numpy header parsing error for file: %s", filename); case NumpyUtilities::BUFFER_SIZE_MISMATCH: FATAL_ERROR("Buffer size does not match numpy file size for tensor %s filename %s", getName().c_str(), filename); default: FATAL_ERROR("Unknown error parsing Numpy file: %s", filename); } switch (dtype) { case TOSA_REF_TYPE_FP16: // Convert from fp16 to fp32 so that fp16 values can be manipulated as float f32databuf = (float*)calloc(sizeof(float), elements); ASSERT_MEM(f32databuf); for (uint32_t i = 0; i < elements; i++) { f32databuf[i] = half_float::half_cast(f16databuf[i]); } if (setTensorValueFloat(elements, f32databuf)) { free(f16databuf); free(f32databuf); return 1; } break; case TOSA_REF_TYPE_BF16: for (uint32_t i = 0; i < elements; i++) { ASSERT_MSG(checkValidBFloat(f32databuf[i]), "Input float value not a valid bfloat16 value."); } if (setTensorValueFloat(elements, f32databuf)) { free(f32databuf); return 1; } break; case TOSA_REF_TYPE_FP8E4M3: case TOSA_REF_TYPE_FP8E5M2: if (setTensorValueFloat(elements, f32databuf)) { free(f32databuf); return 1; } break; case TOSA_REF_TYPE_FP32: if (setTensorValueFloat(elements, f32databuf)) { free(f32databuf); return 1; } break; case TOSA_REF_TYPE_INT32: case TOSA_REF_TYPE_UINT8: case TOSA_REF_TYPE_INT4: case TOSA_REF_TYPE_INT8: case TOSA_REF_TYPE_INT16: case TOSA_REF_TYPE_UINT16: if (setTensorValueInt32(elements, i32databuf)) { free(i32databuf); return 1; } break; case TOSA_REF_TYPE_INT48: case TOSA_REF_TYPE_SHAPE: if (setTensorValueInt64(elements, i64databuf)) { free(i64databuf); return 1; } break; case TOSA_REF_TYPE_BOOL: if (setTensorValueBool(elements, bdatabuf)) { free(i32databuf); return 1; } break; case TOSA_REF_TYPE_FP64: switch (serialization_dtype) { case DType_FP16: // FP16 -> FP64 f64databuf = (double*)calloc(sizeof(double), elements); ASSERT_MEM(f64databuf); for (uint32_t i = 0; i < elements; i++) { f64databuf[i] = half_float::half_cast(f16databuf[i]); } if (setTensorValueDouble(elements, f64databuf)) { free(f16databuf); free(f64databuf); return 1; } break; case DType_BF16: // BF16 -> FP64 f64databuf = (double*)calloc(sizeof(double), elements); ASSERT_MEM(f64databuf); for (uint32_t i = 0; i < elements; i++) { ASSERT_MSG(checkValidBFloat(f32databuf[i]), "Input float value not a valid bfloat16 value."); f64databuf[i] = static_cast(f32databuf[i]); } if (setTensorValueDouble(elements, f64databuf)) { free(f32databuf); free(f64databuf); return 1; } break; case DType_FP8E4M3: case DType_FP8E5M2: f64databuf = (double*)calloc(sizeof(double), elements); ASSERT_MEM(f64databuf); for (uint32_t i = 0; i < elements; i++) { f64databuf[i] = static_cast(f32databuf[i]); } if (setTensorValueDouble(elements, f64databuf)) { free(f32databuf); free(f64databuf); return 1; } break; case DType_FP32: // FP32 -> FP64 f64databuf = (double*)calloc(sizeof(double), elements); ASSERT_MEM(f64databuf); for (uint32_t i = 0; i < elements; i++) { f64databuf[i] = static_cast(f32databuf[i]); } if (setTensorValueDouble(elements, f64databuf)) { free(f32databuf); free(f64databuf); return 1; } break; default: FATAL_ERROR("unexpected tensor type=%s and original tensor type=%s", EnumNameTOSAREFTYPE(dtype), EnumNameDType(serialization_dtype)); } break; default: FATAL_ERROR("unsupported tensor type=%s", EnumNameTOSAREFTYPE(dtype)); } setIsValid(); if (f32databuf) free(f32databuf); if (f16databuf) free(f16databuf); if (f64databuf) free(f64databuf); if (i32databuf) free(i32databuf); if (i64databuf) free(i64databuf); if (bdatabuf) free(bdatabuf); return 0; } int TosaReference::Tensor::writeToNpyFile(const char* filename) const { float* f32databuf = nullptr; double* f64databuf = nullptr; half_float::half* f16databuf = nullptr; uint8_t* ui8databuf = nullptr; int8_t* i8databuf = nullptr; int16_t* i16databuf = nullptr; uint16_t* ui16databuf = nullptr; int32_t* i32databuf = nullptr; int64_t* i64databuf = nullptr; bool* bdatabuf = nullptr; NumpyUtilities::NPError nperror = NumpyUtilities::NO_ERROR; uint32_t elements = getElementCount(); const TOSA_REF_TYPE dtype = getDtype(); switch (dtype) { case TOSA_REF_TYPE_FP32: case TOSA_REF_TYPE_BF16: case TOSA_REF_TYPE_FP8E4M3: case TOSA_REF_TYPE_FP8E5M2: f32databuf = (float*)calloc(sizeof(float), elements); ASSERT_MEM(f32databuf); if (getTensorValueFloat(elements, f32databuf)) { free(f32databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, f32databuf); free(f32databuf); break; case TOSA_REF_TYPE_FP16: f32databuf = (float*)calloc(sizeof(float), elements); ASSERT_MEM(f32databuf); f16databuf = (half_float::half*)calloc(sizeof(half_float::half), elements); ASSERT_MEM(f16databuf); if (getTensorValueFloat(elements, f32databuf)) { free(f32databuf); free(f16databuf); return 1; } // Convert fp32 to fp16 so that output file contains valid fp16 data for (uint32_t i = 0; i < elements; i++) { f16databuf[i] = half_float::half_cast(f32databuf[i]); } nperror = NumpyUtilities::writeToNpyFile(filename, shape, f16databuf); free(f32databuf); free(f16databuf); break; case TOSA_REF_TYPE_INT32: i32databuf = (int32_t*)calloc(sizeof(int32_t), elements); ASSERT_MEM(i32databuf); if (getTensorValueInt32(elements, i32databuf)) { free(i32databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, i32databuf); free(i32databuf); break; case TOSA_REF_TYPE_UINT8: ui8databuf = (uint8_t*)calloc(sizeof(uint8_t), elements); ASSERT_MEM(ui8databuf); if (getTensorValueUInt8(elements, ui8databuf)) { free(ui8databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, ui8databuf); free(ui8databuf); break; case TOSA_REF_TYPE_INT4: case TOSA_REF_TYPE_INT8: i8databuf = (int8_t*)calloc(sizeof(int8_t), elements); ASSERT_MEM(i8databuf); if (getTensorValueInt8(elements, i8databuf)) { free(i8databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, i8databuf); free(i8databuf); break; case TOSA_REF_TYPE_INT16: i16databuf = (int16_t*)calloc(sizeof(int16_t), elements); ASSERT_MEM(i16databuf); if (getTensorValueInt16(elements, i16databuf)) { free(i16databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, i16databuf); free(i16databuf); break; case TOSA_REF_TYPE_UINT16: ui16databuf = (uint16_t*)calloc(sizeof(uint16_t), elements); ASSERT_MEM(ui16databuf); if (getTensorValueUInt16(elements, ui16databuf)) { free(ui16databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, ui16databuf); free(ui16databuf); break; case TOSA_REF_TYPE_INT48: case TOSA_REF_TYPE_SHAPE: i64databuf = (int64_t*)calloc(sizeof(int64_t), elements); ASSERT_MEM(i64databuf); if (getTensorValueInt64(elements, i64databuf)) { free(i64databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, i64databuf); free(i64databuf); break; case TOSA_REF_TYPE_BOOL: bdatabuf = (bool*)calloc(sizeof(bool), elements); ASSERT_MEM(bdatabuf); if (getTensorValueBool(elements, bdatabuf)) { free(bdatabuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, bdatabuf); free(bdatabuf); break; case TOSA_REF_TYPE_FP64: // @todo : support FP64 dtype f64databuf = (double*)calloc(sizeof(double), elements); ASSERT_MEM(f64databuf); if (getTensorValueDouble(elements, f64databuf)) { free(f64databuf); return 1; } nperror = NumpyUtilities::writeToNpyFile(filename, shape, f64databuf); free(f64databuf); break; case TOSA_REF_TYPE_UNKNOWN: FATAL_ERROR("unsupported tensor type=%s", EnumNameTOSAREFTYPE(getDtype())); } switch (nperror) { case NumpyUtilities::NO_ERROR: break; case NumpyUtilities::FILE_NOT_FOUND: FATAL_ERROR("writeToNpyFile: Cannot open output file %s", filename); case NumpyUtilities::FILE_IO_ERROR: FATAL_ERROR("writeToNpyFile: IO error writing file: %s", filename); case NumpyUtilities::FILE_TYPE_MISMATCH: FATAL_ERROR("writeToNpyFile: Tensor type and Numpy file type mismatch for tensor %s filename %s", getName().c_str(), filename); case NumpyUtilities::HEADER_PARSE_ERROR: FATAL_ERROR("Numpy header parsing error for file: %s", filename); case NumpyUtilities::BUFFER_SIZE_MISMATCH: FATAL_ERROR("Buffer size does not match numpy file size for tensor %s filename %s", getName().c_str(), filename); default: FATAL_ERROR("Unknown error writing Numpy file: %s", filename); } return 0; } template int TosaReference::TensorTemplate::copyValueFrom(TosaReference::Tensor* src) { FATAL_ERROR("TensorTemplate::copyValueFrom should not be called. " "Implement template specialization version."); return 0; } #define DEF_CTENSOR_COPY_VALUE_FROM(RANK, TYPE) \ template <> \ int TosaReference::Tensor##RANK::copyValueFrom(TosaReference::Tensor* src) \ { \ TosaReference::Tensor##RANK* t = dynamic_cast*>(src); \ if (!t) \ { \ WARNING("tensor %s templated class does not match %s", src->getName().c_str(), this->getName().c_str()); \ return 1; \ } \ \ const uint32_t src_rank = src->getRank(); \ const uint32_t dst_rank = this->getRank(); \ const TOSA_REF_TYPE src_dtype = src->getDtype(); \ const TOSA_REF_TYPE dst_dtype = this->getDtype(); \ bool tensor_match = true; \ \ if ((src_rank != dst_rank) || (src_dtype != dst_dtype)) \ { \ tensor_match = false; \ } \ else \ { \ for (uint32_t i = 0; i < src_rank; i++) \ { \ int src_dim = src->getShape()[i]; \ int dst_dim = this->getShape()[i]; \ if (src_dim != dst_dim) \ { \ tensor_match = false; \ } \ } \ } \ \ if (!tensor_match) \ { \ WARNING("source tensor %s (rank=%u, dtype=%s, shape=%s) doesn't match destination tensor %s (rank=%u, " \ "dtype=%s, shape=%s)", \ src->getName().c_str(), src_rank, EnumNameTOSAREFTYPE(src_dtype), src->getShapeAsString().c_str(), \ this->getName().c_str(), dst_rank, EnumNameTOSAREFTYPE(dst_dtype), \ this->getShapeAsString().c_str()); \ return 1; \ } \ \ this->getTensor() = t->getTensor(); \ return 0; \ } DEF_CTENSOR_COPY_VALUE_FROM(0, float) DEF_CTENSOR_COPY_VALUE_FROM(1, float) DEF_CTENSOR_COPY_VALUE_FROM(2, float) DEF_CTENSOR_COPY_VALUE_FROM(3, float) DEF_CTENSOR_COPY_VALUE_FROM(4, float) DEF_CTENSOR_COPY_VALUE_FROM(5, float) DEF_CTENSOR_COPY_VALUE_FROM(6, float) DEF_CTENSOR_COPY_VALUE_FROM(0, double) DEF_CTENSOR_COPY_VALUE_FROM(1, double) DEF_CTENSOR_COPY_VALUE_FROM(2, double) DEF_CTENSOR_COPY_VALUE_FROM(3, double) DEF_CTENSOR_COPY_VALUE_FROM(4, double) DEF_CTENSOR_COPY_VALUE_FROM(5, double) DEF_CTENSOR_COPY_VALUE_FROM(6, double) DEF_CTENSOR_COPY_VALUE_FROM(0, int32_t) DEF_CTENSOR_COPY_VALUE_FROM(1, int32_t) DEF_CTENSOR_COPY_VALUE_FROM(2, int32_t) DEF_CTENSOR_COPY_VALUE_FROM(3, int32_t) DEF_CTENSOR_COPY_VALUE_FROM(4, int32_t) DEF_CTENSOR_COPY_VALUE_FROM(5, int32_t) DEF_CTENSOR_COPY_VALUE_FROM(6, int32_t) DEF_CTENSOR_COPY_VALUE_FROM(0, int64_t) DEF_CTENSOR_COPY_VALUE_FROM(1, int64_t) DEF_CTENSOR_COPY_VALUE_FROM(2, int64_t) DEF_CTENSOR_COPY_VALUE_FROM(3, int64_t) DEF_CTENSOR_COPY_VALUE_FROM(4, int64_t) DEF_CTENSOR_COPY_VALUE_FROM(5, int64_t) DEF_CTENSOR_COPY_VALUE_FROM(6, int64_t) DEF_CTENSOR_COPY_VALUE_FROM(0, bool) DEF_CTENSOR_COPY_VALUE_FROM(1, bool) DEF_CTENSOR_COPY_VALUE_FROM(2, bool) DEF_CTENSOR_COPY_VALUE_FROM(3, bool) DEF_CTENSOR_COPY_VALUE_FROM(4, bool) DEF_CTENSOR_COPY_VALUE_FROM(5, bool) DEF_CTENSOR_COPY_VALUE_FROM(6, bool) #undef DEF_CTENSOR_COPY_VALUE_FROM int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_FP64: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueDouble(elements, vals.data()); break; default: WARNING("The input type (float) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_FP64: if (!g_func_config.precise_mode) { WARNING("The input type (float) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } // continue with setting float vals in the tensor case TOSA_REF_TYPE_FP16: case TOSA_REF_TYPE_FP32: case TOSA_REF_TYPE_FP8E4M3: case TOSA_REF_TYPE_FP8E5M2: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueFloat(elements, vals.data()); break; case TOSA_REF_TYPE_BF16: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } for (auto v : vals) { ASSERT_MSG(checkValidBFloat(v), "Input float value not a valid bfloat16 value."); } setTensorValueFloat(elements, vals.data()); break; default: WARNING("The input type (float) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); std::vector tensor(elements); switch (getDtype()) { case TOSA_REF_TYPE_FP64: if (!g_func_config.precise_mode) { WARNING("The input type (float) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } // continue with setting float vals in the tensor case TOSA_REF_TYPE_FP16: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } // Convert from fp16 to fp32 for (uint32_t i = 0; i < elements; i++) { tensor[i] = half_float::half_cast(vals[i]); } setTensorValueFloat(elements, tensor.data()); break; default: WARNING("The input type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT8: case TOSA_REF_TYPE_UINT8: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueInt8(elements, vals.data()); break; default: WARNING("The input type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT16: case TOSA_REF_TYPE_UINT16: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueUInt16(elements, vals.data()); break; default: WARNING("The input type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT16: case TOSA_REF_TYPE_UINT16: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueInt16(elements, vals.data()); break; default: WARNING("The input type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT32: case TOSA_REF_TYPE_UINT8: case TOSA_REF_TYPE_INT4: case TOSA_REF_TYPE_INT8: case TOSA_REF_TYPE_INT16: case TOSA_REF_TYPE_UINT16: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueInt32(elements, vals.data()); break; default: WARNING("The input type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT48: case TOSA_REF_TYPE_SHAPE: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueInt64(elements, vals.data()); break; default: WARNING("The input type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::readfromVector(const ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_BOOL: if (vals.size() != elements) { WARNING("The input size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } setTensorValueBool(elements, reinterpret_cast(vals.data())); break; default: WARNING("The input type (bool) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } setIsValid(); return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_FP64: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueDouble(elements, vals.data()); break; default: WARNING("The output type (float) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_FP16: case TOSA_REF_TYPE_FP32: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueFloat(elements, vals.data()); break; case TOSA_REF_TYPE_BF16: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueFloat(elements, vals.data()); for (auto v : vals) { ASSERT_MSG(checkValidBFloat(v), "Float value not a valid bfloat16 value."); } break; default: WARNING("The output type (float) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); std::vector tensor(elements); switch (getDtype()) { case TOSA_REF_TYPE_FP16: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueFloat(elements, tensor.data()); // Convert fp32 to fp16 for (uint32_t i = 0; i < elements; i++) { vals[i] = half_float::half_cast(tensor[i]); } break; default: WARNING("The output type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT8: case TOSA_REF_TYPE_UINT8: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueInt8(elements, vals.data()); break; default: WARNING("The output type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT16: case TOSA_REF_TYPE_UINT16: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueUInt16(elements, vals.data()); break; default: WARNING("The output type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT16: case TOSA_REF_TYPE_UINT16: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueInt16(elements, vals.data()); break; default: WARNING("The output type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT32: case TOSA_REF_TYPE_UINT8: case TOSA_REF_TYPE_INT4: case TOSA_REF_TYPE_INT8: case TOSA_REF_TYPE_INT16: case TOSA_REF_TYPE_UINT16: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueInt32(elements, vals.data()); break; default: WARNING("The output type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_INT48: case TOSA_REF_TYPE_SHAPE: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueInt64(elements, vals.data()); break; default: WARNING("The output type doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } int TosaReference::Tensor::writeToVector(ArrayProxy vals) { uint32_t elements = getElementCount(); switch (getDtype()) { case TOSA_REF_TYPE_BOOL: if (vals.size() != elements) { WARNING("The output size (%ld) doesn't match the number of elements (%d) assigned to the tensor.", vals.size(), elements); return -1; } getTensorValueBool(elements, reinterpret_cast(vals.data())); break; default: WARNING("The output type (bool) doesn't match the data type assigned to the tensor (%s).", EnumNameTOSAREFTYPE(getDtype())); return -2; } return 0; } template int TosaReference::TensorTemplate::setTensorValueDouble(const size_t buflen, const double* vals) { FATAL_ERROR("TensorTemplate::setTensorValueDouble should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueDouble(const size_t bufLen, const double* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = vals[0]; return 0; } template <> int TosaReference::Tensor1::setTensorValueDouble(const size_t bufLen, const double* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = vals[idx++]; } return 0; } template <> int TosaReference::Tensor2::setTensorValueDouble(const size_t bufLen, const double* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = vals[idx++]; } } return 0; } template <> int TosaReference::Tensor3::setTensorValueDouble(const size_t bufLen, const double* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = vals[idx++]; } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueDouble(const size_t bufLen, const double* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = vals[idx++]; } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueDouble(const size_t bufLen, const double* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = vals[idx++]; } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueDouble(const size_t bufLen, const double* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++]; } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueFloat(const size_t buflen, const float* vals) { FATAL_ERROR("TensorTemplate::setTensorValueFloat should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueFloat(const size_t bufLen, const float* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = vals[0]; return 0; } template <> int TosaReference::Tensor1::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = vals[idx++]; } return 0; } template <> int TosaReference::Tensor2::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = vals[idx++]; } } return 0; } template <> int TosaReference::Tensor3::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = vals[idx++]; } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = vals[idx++]; } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = vals[idx++]; } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++]; } } } } } } return 0; } template <> int TosaReference::Tensor0::setTensorValueFloat(const size_t bufLen, const float* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = vals[0]; return 0; } template <> int TosaReference::Tensor1::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = vals[idx++]; } return 0; } template <> int TosaReference::Tensor2::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = vals[idx++]; } } return 0; } template <> int TosaReference::Tensor3::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = vals[idx++]; } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = vals[idx++]; } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = vals[idx++]; } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueFloat(const size_t bufLen, const float* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++]; } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { FATAL_ERROR("TensorTemplate::setTensorValueUInt8 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = static_cast(vals[0]); return 0; } template <> int TosaReference::Tensor1::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = static_cast(vals[idx++]); } return 0; } template <> int TosaReference::Tensor2::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = static_cast(vals[idx++]); } } return 0; } template <> int TosaReference::Tensor3::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = static_cast(vals[idx++]); } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = static_cast(vals[idx++]); } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = static_cast(vals[idx++]); } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueUInt8(const size_t bufLen, const uint8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = static_cast(vals[idx++]); } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { FATAL_ERROR("TensorTemplate::setTensorValueInt8 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = static_cast(vals[0]); return 0; } template <> int TosaReference::Tensor1::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = static_cast(vals[idx++]); } return 0; } template <> int TosaReference::Tensor2::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = static_cast(vals[idx++]); } } return 0; } template <> int TosaReference::Tensor3::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = static_cast(vals[idx++]); } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = static_cast(vals[idx++]); } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = static_cast(vals[idx++]); } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueInt8(const size_t bufLen, const int8_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = static_cast(vals[idx++]); } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { FATAL_ERROR("TensorTemplate::setTensorValueUInt16 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = static_cast(vals[0]); return 0; } template <> int TosaReference::Tensor1::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = static_cast(vals[idx++]); } return 0; } template <> int TosaReference::Tensor2::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = static_cast(vals[idx++]); } } return 0; } template <> int TosaReference::Tensor3::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = static_cast(vals[idx++]); } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = static_cast(vals[idx++]); } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = static_cast(vals[idx++]); } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueUInt16(const size_t bufLen, const uint16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = static_cast(vals[idx++]); } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { FATAL_ERROR("TensorTemplate::setTensorValueInt16 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = static_cast(vals[0]); return 0; } template <> int TosaReference::Tensor1::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = static_cast(vals[idx++]); } return 0; } template <> int TosaReference::Tensor2::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = static_cast(vals[idx++]); } } return 0; } template <> int TosaReference::Tensor3::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = static_cast(vals[idx++]); } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = static_cast(vals[idx++]); } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = static_cast(vals[idx++]); } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueInt16(const size_t bufLen, const int16_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = static_cast(vals[idx++]); } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { FATAL_ERROR("TensorTemplate::setTensorValueInt32 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = vals[0]; return 0; } template <> int TosaReference::Tensor1::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = vals[idx++]; } return 0; } template <> int TosaReference::Tensor2::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = vals[idx++]; } } return 0; } template <> int TosaReference::Tensor3::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = vals[idx++]; } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = vals[idx++]; } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = vals[idx++]; } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueInt32(const size_t bufLen, const int32_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++]; } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { FATAL_ERROR("TensorTemplate::setTensorValueInt64 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = vals[0]; return 0; } template <> int TosaReference::Tensor1::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = vals[idx++]; } return 0; } template <> int TosaReference::Tensor2::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = vals[idx++]; } } return 0; } template <> int TosaReference::Tensor3::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = vals[idx++]; } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = vals[idx++]; } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = vals[idx++]; } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueInt64(const size_t bufLen, const int64_t* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++]; } } } } } } return 0; } template int TosaReference::TensorTemplate::setTensorValueBool(const size_t buflen, const bool* vals) { FATAL_ERROR("TensorTemplate::setTensorValueBool should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::setTensorValueBool(const size_t bufLen, const bool* vals) { ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); (*tensor)(0) = vals[0]; return 0; } template <> int TosaReference::Tensor1::setTensorValueBool(const size_t bufLen, const bool* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { (*tensor)(i0) = vals[idx++]; } return 0; } template <> int TosaReference::Tensor2::setTensorValueBool(const size_t bufLen, const bool* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { (*tensor)(i0, i1) = vals[idx++]; } } return 0; } template <> int TosaReference::Tensor3::setTensorValueBool(const size_t bufLen, const bool* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { (*tensor)(i0, i1, i2) = vals[idx++]; } } } return 0; } template <> int TosaReference::Tensor4::setTensorValueBool(const size_t bufLen, const bool* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { (*tensor)(i0, i1, i2, i3) = vals[idx++]; } } } } return 0; } template <> int TosaReference::Tensor5::setTensorValueBool(const size_t bufLen, const bool* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { (*tensor)(i0, i1, i2, i3, i4) = vals[idx++]; } } } } } return 0; } template <> int TosaReference::Tensor6::setTensorValueBool(const size_t bufLen, const bool* vals) { uint32_t idx = 0; ASSERT_MSG(bufLen == getElementCount(), "Total elements must match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { (*tensor)(i0, i1, i2, i3, i4, i5) = vals[idx++]; } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueDouble(const size_t bufLen, double* vals) const { FATAL_ERROR("TensorTemplate::getTensorValueDouble should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueDouble(const size_t bufLen, double* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueDouble(const size_t bufLen, double* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueDouble(const size_t bufLen, double* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueDouble(const size_t bufLen, double* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueDouble(const size_t bufLen, double* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueDouble(const size_t bufLen, double* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueDouble(const size_t bufLen, double* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueFloat(const size_t bufLen, float* vals) const { FATAL_ERROR("TensorTemplate::getTensorValueFloat should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueFloat(const size_t bufLen, float* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueFloat(const size_t bufLen, float* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueFloat(const size_t bufLen, float* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueFloat(const size_t bufLen, float* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueFloat(const size_t bufLen, float* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueFloat(const size_t bufLen, float* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueFloat(const size_t bufLen, float* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { std::cout << "T is: " << typeid(T).name() << std::endl; FATAL_ERROR("TensorTemplate::getTensorValueUInt8 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueUInt8(const size_t bufLen, uint8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { std::cout << "T is: " << typeid(T).name() << std::endl; FATAL_ERROR("TensorTemplate::getTensorValueInt8 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueInt8(const size_t bufLen, int8_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { FATAL_ERROR("TensorTemplate::getTensorValueUInt16 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueUInt16(const size_t bufLen, uint16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { FATAL_ERROR("TensorTemplate::getTensorValueInt16 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueInt16(const size_t bufLen, int16_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { FATAL_ERROR("TensorTemplate::getTensorValueInt32 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueInt32(const size_t bufLen, int32_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { FATAL_ERROR("TensorTemplate::getTensorValueInt64 should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueInt64(const size_t bufLen, int64_t* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } template int TosaReference::TensorTemplate::getTensorValueBool(const size_t bufLen, bool* vals) const { FATAL_ERROR("TensorTemplate::getTensorValueBool should not be called. " "Implement template specialization version."); return 0; } template <> int TosaReference::Tensor0::getTensorValueBool(const size_t bufLen, bool* vals) const { int totalVals = 1; ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); vals[0] = (*tensor)(0); return 0; } template <> int TosaReference::Tensor1::getTensorValueBool(const size_t bufLen, bool* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { vals[idx++] = (*tensor)(i0); } return 0; } template <> int TosaReference::Tensor2::getTensorValueBool(const size_t bufLen, bool* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { vals[idx++] = (*tensor)(i0, i1); } } return 0; } template <> int TosaReference::Tensor3::getTensorValueBool(const size_t bufLen, bool* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { vals[idx++] = (*tensor)(i0, i1, i2); } } } return 0; } template <> int TosaReference::Tensor4::getTensorValueBool(const size_t bufLen, bool* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { vals[idx++] = (*tensor)(i0, i1, i2, i3); } } } } return 0; } template <> int TosaReference::Tensor5::getTensorValueBool(const size_t bufLen, bool* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4); } } } } } return 0; } template <> int TosaReference::Tensor6::getTensorValueBool(const size_t bufLen, bool* vals) const { uint32_t idx = 0; int totalVals = 1; for (size_t i = 0; i < shape.size(); i++) { totalVals *= shape[i]; } ASSERT_MSG((size_t)totalVals == bufLen, "Output buffer and tensor size do not match"); for (int i0 = 0; i0 < shape[0]; i0++) { for (int i1 = 0; i1 < shape[1]; i1++) { for (int i2 = 0; i2 < shape[2]; i2++) { for (int i3 = 0; i3 < shape[3]; i3++) { for (int i4 = 0; i4 < shape[4]; i4++) { for (int i5 = 0; i5 < shape[5]; i5++) { vals[idx++] = (*tensor)(i0, i1, i2, i3, i4, i5); } } } } } } return 0; } #define TOSAREF_ZERORANK_TENSOR_ALLOCATE(dtype) \ template <> \ int TosaReference::Tensor0::allocate() \ { \ ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor"); \ tensor = new ETensor0(); \ \ if (tensor) \ return 0; \ else \ return 1; \ } #define TOSAREF_TENSOR_ALLOCATE(rank, dtype) \ template <> \ int TosaReference::Tensor##rank::allocate() \ { \ ASSERT_MSG(tensor == nullptr, "Error: double allocate Eigen tensor"); \ std::array arrshape; \ std::copy_n(shape.begin(), rank, arrshape.begin()); \ tensor = new ETensor##rank(arrshape); \ \ if (tensor) \ return 0; \ else \ return 1; \ } TOSAREF_ZERORANK_TENSOR_ALLOCATE(double) TOSAREF_TENSOR_ALLOCATE(1, double) TOSAREF_TENSOR_ALLOCATE(2, double) TOSAREF_TENSOR_ALLOCATE(3, double) TOSAREF_TENSOR_ALLOCATE(4, double) TOSAREF_TENSOR_ALLOCATE(5, double) TOSAREF_TENSOR_ALLOCATE(6, double) TOSAREF_ZERORANK_TENSOR_ALLOCATE(float) TOSAREF_TENSOR_ALLOCATE(1, float) TOSAREF_TENSOR_ALLOCATE(2, float) TOSAREF_TENSOR_ALLOCATE(3, float) TOSAREF_TENSOR_ALLOCATE(4, float) TOSAREF_TENSOR_ALLOCATE(5, float) TOSAREF_TENSOR_ALLOCATE(6, float) TOSAREF_ZERORANK_TENSOR_ALLOCATE(int32_t) TOSAREF_TENSOR_ALLOCATE(1, int32_t) TOSAREF_TENSOR_ALLOCATE(2, int32_t) TOSAREF_TENSOR_ALLOCATE(3, int32_t) TOSAREF_TENSOR_ALLOCATE(4, int32_t) TOSAREF_TENSOR_ALLOCATE(5, int32_t) TOSAREF_TENSOR_ALLOCATE(6, int32_t) TOSAREF_ZERORANK_TENSOR_ALLOCATE(int64_t) TOSAREF_TENSOR_ALLOCATE(1, int64_t) TOSAREF_TENSOR_ALLOCATE(2, int64_t) TOSAREF_TENSOR_ALLOCATE(3, int64_t) TOSAREF_TENSOR_ALLOCATE(4, int64_t) TOSAREF_TENSOR_ALLOCATE(5, int64_t) TOSAREF_TENSOR_ALLOCATE(6, int64_t) TOSAREF_ZERORANK_TENSOR_ALLOCATE(bool) TOSAREF_TENSOR_ALLOCATE(1, bool) TOSAREF_TENSOR_ALLOCATE(2, bool) TOSAREF_TENSOR_ALLOCATE(3, bool) TOSAREF_TENSOR_ALLOCATE(4, bool) TOSAREF_TENSOR_ALLOCATE(5, bool) TOSAREF_TENSOR_ALLOCATE(6, bool) template <> int TosaReference::Tensor0::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), "[ %%%sf ]\n", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, fp_fmt, (*tensor)(0)); return 0; } template <> int TosaReference::Tensor1::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, fp_fmt, (*tensor)(i0)); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor2::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, fp_fmt, (*tensor)(i0, i1)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor3::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor4::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor5::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3, i4)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor6::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, "["); for (int i5 = 0; i5 < shape[5]; i5++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3, i4, i5)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor0::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), "[ %%%sf ]\n", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, fp_fmt, (*tensor)(0)); return 0; } template <> int TosaReference::Tensor1::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, fp_fmt, (*tensor)(i0)); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor2::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, fp_fmt, (*tensor)(i0, i1)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor3::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor4::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor5::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3, i4)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor6::dumpTensor(FILE* out) const { char fp_fmt[32]; snprintf(fp_fmt, sizeof(fp_fmt), " %%%sf ", g_func_config.fp_format.c_str()); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, "["); for (int i5 = 0; i5 < shape[5]; i5++) { fprintf(out, fp_fmt, (*tensor)(i0, i1, i2, i3, i4, i5)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor0::dumpTensor(FILE* out) const { char i64_fmt[32]; snprintf(i64_fmt, sizeof(i64_fmt), "[ %%ld ]\n"); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, i64_fmt, (*tensor)(0)); return 0; } template <> int TosaReference::Tensor1::dumpTensor(FILE* out) const { char i64_fmt[32]; snprintf(i64_fmt, sizeof(i64_fmt), " %%ld "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, i64_fmt, (*tensor)(i0)); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor2::dumpTensor(FILE* out) const { char i64_fmt[32]; snprintf(i64_fmt, sizeof(i64_fmt), " %%ld "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, i64_fmt, (*tensor)(i0, i1)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor3::dumpTensor(FILE* out) const { char i64_fmt[32]; snprintf(i64_fmt, sizeof(i64_fmt), " %%ld "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, i64_fmt, (*tensor)(i0, i1, i2)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor4::dumpTensor(FILE* out) const { char i64_fmt[32]; snprintf(i64_fmt, sizeof(i64_fmt), " %%ld "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, i64_fmt, (*tensor)(i0, i1, i2, i3)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor5::dumpTensor(FILE* out) const { char i64_fmt[32]; snprintf(i64_fmt, sizeof(i64_fmt), " %%ld "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, i64_fmt, (*tensor)(i0, i1, i2, i3, i4)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor6::dumpTensor(FILE* out) const { char i64_fmt[32]; snprintf(i64_fmt, sizeof(i64_fmt), " %%ld "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, "["); for (int i5 = 0; i5 < shape[5]; i5++) { fprintf(out, i64_fmt, (*tensor)(i0, i1, i2, i3, i4, i5)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor0::dumpTensor(FILE* out) const { char i32_fmt[32]; snprintf(i32_fmt, sizeof(i32_fmt), "[ %%d ]\n"); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, i32_fmt, (*tensor)(0)); return 0; } template <> int TosaReference::Tensor1::dumpTensor(FILE* out) const { char i32_fmt[32]; snprintf(i32_fmt, sizeof(i32_fmt), " %%d "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, i32_fmt, (*tensor)(i0)); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor2::dumpTensor(FILE* out) const { char i32_fmt[32]; snprintf(i32_fmt, sizeof(i32_fmt), " %%d "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, i32_fmt, (*tensor)(i0, i1)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor3::dumpTensor(FILE* out) const { char i32_fmt[32]; snprintf(i32_fmt, sizeof(i32_fmt), " %%d "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, i32_fmt, (*tensor)(i0, i1, i2)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor4::dumpTensor(FILE* out) const { char i32_fmt[32]; snprintf(i32_fmt, sizeof(i32_fmt), " %%d "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, i32_fmt, (*tensor)(i0, i1, i2, i3)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor5::dumpTensor(FILE* out) const { char i32_fmt[32]; snprintf(i32_fmt, sizeof(i32_fmt), " %%d "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, i32_fmt, (*tensor)(i0, i1, i2, i3, i4)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor6::dumpTensor(FILE* out) const { char i32_fmt[32]; snprintf(i32_fmt, sizeof(i32_fmt), " %%d "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, "["); for (int i5 = 0; i5 < shape[5]; i5++) { fprintf(out, i32_fmt, (*tensor)(i0, i1, i2, i3, i4, i5)); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor0::dumpTensor(FILE* out) const { char bool_fmt[32]; snprintf(bool_fmt, sizeof(bool_fmt), "[ %%s ]\n"); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, bool_fmt, bool_to_str((*tensor)(0))); return 0; } template <> int TosaReference::Tensor1::dumpTensor(FILE* out) const { char bool_fmt[32]; snprintf(bool_fmt, sizeof(bool_fmt), " %%s "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, bool_fmt, bool_to_str((*tensor)(i0))); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor2::dumpTensor(FILE* out) const { char bool_fmt[32]; snprintf(bool_fmt, sizeof(bool_fmt), " %%s "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1))); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor3::dumpTensor(FILE* out) const { char bool_fmt[32]; snprintf(bool_fmt, sizeof(bool_fmt), " %%s "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2))); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor4::dumpTensor(FILE* out) const { char bool_fmt[32]; snprintf(bool_fmt, sizeof(bool_fmt), " %%s "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2, i3))); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor5::dumpTensor(FILE* out) const { char bool_fmt[32]; snprintf(bool_fmt, sizeof(bool_fmt), " %%s "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2, i3, i4))); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template <> int TosaReference::Tensor6::dumpTensor(FILE* out) const { char bool_fmt[32]; snprintf(bool_fmt, sizeof(bool_fmt), " %%s "); if (tensor == nullptr) { fprintf(out, "\n"); return 0; } fprintf(out, "["); for (int i0 = 0; i0 < shape[0]; i0++) { fprintf(out, "["); for (int i1 = 0; i1 < shape[1]; i1++) { fprintf(out, "["); for (int i2 = 0; i2 < shape[2]; i2++) { fprintf(out, "["); for (int i3 = 0; i3 < shape[3]; i3++) { fprintf(out, "["); for (int i4 = 0; i4 < shape[4]; i4++) { fprintf(out, "["); for (int i5 = 0; i5 < shape[5]; i5++) { fprintf(out, bool_fmt, bool_to_str((*tensor)(i0, i1, i2, i3, i4, i5))); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); } fprintf(out, "]\n"); return 0; } template int TosaReference::TensorTemplate::dumpTensor(FILE* out) const { return 0; } // template explicit specialization template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>; template class TosaReference::TensorTemplate>;