ArmNN
 22.11
TosaOperatorUtils.hpp
Go to the documentation of this file.
1 //
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 
13 using namespace armnn;
14 using namespace tosa;
15 
16 // Function to return Tosa datatype from input ArmNN datatype.
17 inline DType ArmNNToDType(const DataType& type)
18 {
19  switch (type)
20  {
21  case DataType::Float16:
22  case DataType::BFloat16:
23  return DType_FP16;
24  case DataType::Float32:
25  return DType_FP32;
26  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.
46 inline std::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.
57 static int uniqueTosaMappingID = 0;
58 inline std::string GetUniqueTosaMappingID()
59 {
60  return std::to_string(++uniqueTosaMappingID);
61 }
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
DType ArmNNToDType(const DataType &type)
Copyright (c) 2021 ARM Limited and Contributors.
std::string GetUniqueTosaMappingID()
DataType
Definition: Types.hpp:48
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174