12 #include "common/include/ProfilingGuid.hpp"
14 #include <tosa_serialization_handler.h>
16 using namespace armnn;
54 std::vector<int32_t> returnShape;
57 returnShape.push_back(
static_cast<int32_t
>(shape[i]));
65 std::string guid = std::to_string(layer.
GetGuid());
66 std::string slotAndGuid = std::to_string(layerSlot) +
"_" + guid;
71 return "input" + slotAndGuid;
73 return "output" + slotAndGuid;
75 return "constant_" + guid;
77 return "intermediate" + slotAndGuid;
99 static int uniqueTosaMappingID = 0;
102 return std::to_string(++uniqueTosaMappingID);
111 return "DType_UNKNOWN";
115 return "DType_UINT8";
121 return "DType_INT16";
123 return "DType_INT32";
125 return "DType_INT48";
129 return "DType_UINT16";
146 return "Op_AVG_POOL2D";
148 return "Op_MAX_POOL2D";
159 case Op_DEPTHWISE_CONV2D:
160 return "Op_DEPTHWISE_CONV2D";
161 case Op_FULLY_CONNECTED:
162 return "Op_FULLY_CONNECTED";
165 case Op_TRANSPOSE_CONV2D:
166 return "Op_TRANSPOSE_CONV2D";
170 return "Op_RESERVED";
175 case Op_ARITHMETIC_RIGHT_SHIFT:
176 return "Op_ARITHMETIC_RIGHT_SHIFT";
178 return "Op_BITWISE_AND";
180 return "Op_BITWISE_OR";
182 return "Op_BITWISE_XOR";
186 return "Op_LOGICAL_AND";
187 case Op_LOGICAL_LEFT_SHIFT:
188 return "Op_LOGICAL_LEFT_SHIFT";
189 case Op_LOGICAL_RIGHT_SHIFT:
190 return "Op_LOGICAL_RIGHT_SHIFT";
192 return "Op_LOGICAL_OR";
194 return "Op_LOGICAL_XOR";
210 return "Op_BITWISE_NOT";
222 return "Op_LOGICAL_NOT";
226 return "Op_RECIPROCAL";
235 case Op_GREATER_EQUAL:
236 return "Op_GREATER_EQUAL";
238 return "Op_REDUCE_ANY";
240 return "Op_REDUCE_ALL";
242 return "Op_REDUCE_MAX";
244 return "Op_REDUCE_MIN";
245 case Op_REDUCE_PRODUCT:
246 return "Op_REDUCE_PRODUCT";
248 return "Op_REDUCE_SUM";
260 return "Op_TRANSPOSE";
274 return "Op_IDENTITY";
280 return "Op_WHILE_LOOP";
291 tosa_err_t
error = tosa_err_t::TOSA_OK;
292 std::vector<uint8_t> uint8Data;
293 auto tensorInfo = tensorHandle->GetTensorInfo();
295 switch (tensorInfo.GetDataType())
299 std::vector<float> data(tensorInfo.GetNumElements());
300 memcpy(data.data(), tensorHandle->Map(
true), tensorInfo.GetNumBytes());
302 error = TosaSerializationHandler::ConvertF32toU8(data, uint8Data);
307 std::vector<float> data(tensorInfo.GetNumElements());
308 memcpy(data.data(), tensorHandle->Map(
true), tensorInfo.GetNumBytes());
310 error = TosaSerializationHandler::ConvertF16toU8(data, uint8Data);
316 std::vector<int8_t> data(tensorInfo.GetNumElements());
317 memcpy(data.data(), tensorHandle->Map(
true), tensorInfo.GetNumBytes());
319 error = TosaSerializationHandler::ConvertI8toU8(data, uint8Data);
324 memcpy(uint8Data.data(), tensorHandle->Map(
true), tensorInfo.GetNumBytes());
329 std::vector<int16_t> data(tensorInfo.GetNumElements());
330 memcpy(data.data(), tensorHandle->Map(
true), tensorInfo.GetNumBytes());
332 error = TosaSerializationHandler::ConvertI16toU8(data, uint8Data);
337 std::vector<int32_t> data(tensorInfo.GetNumElements());
338 memcpy(data.data(), tensorHandle->Map(
true), tensorInfo.GetNumBytes());
340 error = TosaSerializationHandler::ConvertI32toU8(data, uint8Data);
345 throw armnn::Exception(
"SetConstantTensorData: An unsupported data type was encountered.");
349 if(
error != tosa_err_t::TOSA_OK)
351 throw armnn::Exception(
"SetConstantTensorData: An error occurred when converting constant data");
354 tensorHandle->Unmap();
360 const std::vector<int32_t>& shape)
362 std::vector<uint8_t> uint8Data;
363 tosa_err_t
error = tosa_err_t::TOSA_OK;
365 unsigned int numElements = 1;
370 throw armnn::Exception(
"CreateConstTosaData: negative shape elements unhandled.");
372 numElements = numElements *
static_cast<unsigned int>(s);
377 case DType::DType_FP32:
379 std::vector<float> data(numElements, *
static_cast<const float*
>(value));
380 error = TosaSerializationHandler::ConvertF32toU8(data, uint8Data);
383 case DType::DType_FP16:
385 std::vector<float> data(numElements, *
static_cast<const float*
>(value));
386 error = TosaSerializationHandler::ConvertF16toU8(data, uint8Data);
389 case DType::DType_INT48:
391 std::vector<int64_t> data(numElements, *
static_cast<const int64_t*
>(value));
392 error = TosaSerializationHandler::ConvertI48toU8(data, uint8Data);
395 case DType::DType_INT32:
397 std::vector<int32_t> data(numElements, *
static_cast<const int32_t*
>(value));
398 error = TosaSerializationHandler::ConvertI32toU8(data, uint8Data);
401 case DType::DType_INT16:
403 std::vector<int16_t> data(numElements, *
static_cast<const int16_t*
>(value));
404 error = TosaSerializationHandler::ConvertI16toU8(data, uint8Data);
407 case DType::DType_INT8:
409 std::vector<int8_t> data(numElements, *
static_cast<const int8_t*
>(value));
410 error = TosaSerializationHandler::ConvertI8toU8(data, uint8Data);
413 case DType::DType_INT4:
415 std::vector<int8_t> data(numElements, *
static_cast<const int8_t*
>(value));
416 error = TosaSerializationHandler::ConvertI4toU8(data, uint8Data);
419 case DType::DType_BOOL:
421 std::vector<bool> data(numElements, *
static_cast<const bool*
>(value));
422 error = TosaSerializationHandler::ConvertBooltoU8(data, uint8Data);
427 throw armnn::Exception(
"CreateConstTosaData: An unsupported data type was encountered.");
431 if(
error != tosa_err_t::TOSA_OK)
433 throw armnn::Exception(
"CreateConstTosaData: An error occurred when converting constant data");
443 const std::vector<int32_t>& shape,
444 TosaSerializationOperator*& op,
445 TosaSerializationTensor*& tensor)
447 std::vector<uint8_t> uint8Data =
CreateConstTosaData(
static_cast<const void *
>(&value), dtype, shape);
449 op =
new TosaSerializationOperator(Op_CONST, Attribute_NONE,
nullptr, {}, {outputName});
452 tensor =
new TosaSerializationTensor(outputName, shape, dtype, uint8Data);
458 #define TOSA_COMPAT_VERSION(_major, _minor, _patch) \
459 (TOSA_VERSION_MAJOR >= _major) || \
460 (TOSA_VERSION_MINOR >= _minor) || \
461 (TOSA_VERSION_PATCH >= _patch)