blob: b8877216483960957ed5e9613ea01d0480980916 [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:
22 case DataType::Float32:
23 case DataType::BFloat16:
24 return DType_FLOAT;
25 case DataType::QAsymmU8:
26 return DType_UINT8;
27 case DataType::QSymmS8:
28 case DataType::QAsymmS8:
29 return DType_INT8;
30 case DataType::QSymmS16:
31 return DType_INT16;
32 case DataType::Signed32:
33 return DType_INT32;
34 case DataType::Signed64:
35 // No signed 64, only DType_INT48.
36 return DType_UNKNOWN;
37 case DataType::Boolean:
38 return DType_BOOL;
39 default:
40 return DType_UNKNOWN;
41 }
42}
43
44// Function to return Tosa tensor shape from input ArmNN tensor shape.
45std::vector<int32_t> GetTosaTensorShape(const TensorShape& shape)
46{
47 std::vector<int32_t> returnShape;
48 for (u_int32_t i = 0; i < shape.GetNumDimensions(); i++)
49 {
50 returnShape.push_back(static_cast<int32_t>(shape[i]));
51 }
52 return returnShape;
53}
54
55// Function to return unique int as a string to ensure uniqueness between all input, output and block names.
56static int uniqueTosaMappingID = 0;
57std::string GetUniqueTosaMappingID()
58{
59 return std::to_string(++uniqueTosaMappingID);
60}