blob: e11f293b12e7ac88170063029c82c8671802ac03 [file] [log] [blame]
Cathal Corbett9c9d5b92022-08-17 17:30:16 +01001//
2// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include <armnn/Tensor.hpp>
9#include <armnn/Types.hpp>
10
11#include <tosa_generated.h>
12
13using namespace armnn;
14using namespace tosa;
15
16// Function to return Tosa datatype from input ArmNN datatype.
17DType ArmNNToDType(const DataType& type)
18{
19 switch (type)
20 {
21 case DataType::Float16:
Cathal Corbett9c9d5b92022-08-17 17:30:16 +010022 case DataType::BFloat16:
Matthew Sloyanda824cc2022-10-10 12:43:20 +010023 return DType_FP16;
24 case DataType::Float32:
25 return DType_FP32;
Cathal Corbett9c9d5b92022-08-17 17:30:16 +010026 case DataType::QAsymmU8:
27 return DType_UINT8;
28 case DataType::QSymmS8:
29 case DataType::QAsymmS8:
30 return DType_INT8;
31 case DataType::QSymmS16:
32 return DType_INT16;
33 case DataType::Signed32:
34 return DType_INT32;
35 case DataType::Signed64:
36 // No signed 64, only DType_INT48.
37 return DType_UNKNOWN;
38 case DataType::Boolean:
39 return DType_BOOL;
40 default:
41 return DType_UNKNOWN;
42 }
43}
44
45// Function to return Tosa tensor shape from input ArmNN tensor shape.
46std::vector<int32_t> GetTosaTensorShape(const TensorShape& shape)
47{
48 std::vector<int32_t> returnShape;
49 for (u_int32_t i = 0; i < shape.GetNumDimensions(); i++)
50 {
51 returnShape.push_back(static_cast<int32_t>(shape[i]));
52 }
53 return returnShape;
54}
55
56// Function to return unique int as a string to ensure uniqueness between all input, output and block names.
57static int uniqueTosaMappingID = 0;
58std::string GetUniqueTosaMappingID()
59{
60 return std::to_string(++uniqueTosaMappingID);
61}