blob: f51b2109b48dd465381049d8496a3df809f850ea [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.
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010017inline DType ArmNNToDType(const DataType& type)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +010018{
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.
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010046inline std::vector<int32_t> GetTosaTensorShape(const TensorShape& shape)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +010047{
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;
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010058inline std::string GetUniqueTosaMappingID()
Cathal Corbett9c9d5b92022-08-17 17:30:16 +010059{
60 return std::to_string(++uniqueTosaMappingID);
61}
Cathal Corbettbd18eab2022-11-15 12:56:16 +000062
63// Function to return Tosa Op as string.
64inline std::string TosaOpToString(Op tosaOp)
65{
66 switch (tosaOp)
67 {
68 case Op_ADD:
69 return "Op_ADD";
70 case Op_AVG_POOL2D:
71 return "Op_AVG_POOL2D";
72 case Op_MAX_POOL2D:
73 return "Op_MAX_POOL2D";
74 case Op_PAD:
75 return "Op_PAD";
76 case Op_UNKNOWN:
77 return "Op_UNKNOWN";
78 case Op_ARGMAX:
79 return "Op_ARGMAX";
80 case Op_CONV2D:
81 return "Op_CONV2D";
82 case Op_CONV3D:
83 return "Op_CONV3D";
84 case Op_DEPTHWISE_CONV2D:
85 return "Op_DEPTHWISE_CONV2D";
86 case Op_FULLY_CONNECTED:
87 return "Op_FULLY_CONNECTED";
88 case Op_MATMUL:
89 return "Op_MATMUL";
90 case Op_TRANSPOSE_CONV2D:
91 return "Op_TRANSPOSE_CONV2D";
92 case Op_CLAMP:
93 return "Op_CLAMP";
94 case Op_RESERVED:
95 return "Op_RESERVED";
96 case Op_SIGMOID:
97 return "Op_SIGMOID";
98 case Op_TANH:
99 return "Op_TANH";
100 case Op_ARITHMETIC_RIGHT_SHIFT:
101 return "Op_ARITHMETIC_RIGHT_SHIFT";
102 case Op_BITWISE_AND:
103 return "Op_BITWISE_AND";
104 case Op_BITWISE_OR:
105 return "Op_BITWISE_OR";
106 case Op_BITWISE_XOR:
107 return "Op_BITWISE_XOR";
108 case Op_INTDIV:
109 return "Op_INTDIV";
110 case Op_LOGICAL_AND:
111 return "Op_LOGICAL_AND";
112 case Op_LOGICAL_LEFT_SHIFT:
113 return "Op_LOGICAL_LEFT_SHIFT";
114 case Op_LOGICAL_RIGHT_SHIFT:
115 return "Op_LOGICAL_RIGHT_SHIFT";
116 case Op_LOGICAL_OR:
117 return "Op_LOGICAL_OR";
118 case Op_LOGICAL_XOR:
119 return "Op_LOGICAL_XOR";
120 case Op_MAXIMUM:
121 return "Op_MAXIMUM";
122 case Op_MINIMUM:
123 return "Op_MINIMUM";
124 case Op_MUL:
125 return "Op_MUL";
126 case Op_POW:
127 return "Op_POW";
128 case Op_SUB:
129 return "Op_SUB";
130 case Op_TABLE:
131 return "Op_TABLE";
132 case Op_ABS:
133 return "Op_ABS";
134 case Op_BITWISE_NOT:
135 return "Op_BITWISE_NOT";
136 case Op_CEIL:
137 return "Op_CEIL";
138 case Op_CLZ:
139 return "Op_CLZ";
140 case Op_EXP:
141 return "Op_EXP";
142 case Op_FLOOR:
143 return "Op_FLOOR";
144 case Op_LOG:
145 return "Op_LOG";
146 case Op_LOGICAL_NOT:
147 return "Op_LOGICAL_NOT";
148 case Op_NEGATE:
149 return "Op_NEGATE";
150 case Op_RECIPROCAL:
151 return "Op_RECIPROCAL";
152 case Op_RSQRT:
153 return "Op_RSQRT";
154 case Op_SELECT:
155 return "Op_SELECT";
156 case Op_EQUAL:
157 return "Op_EQUAL";
158 case Op_GREATER:
159 return "Op_GREATER";
160 case Op_GREATER_EQUAL:
161 return "Op_GREATER_EQUAL";
162 case Op_REDUCE_ANY:
163 return "Op_REDUCE_ANY";
164 case Op_REDUCE_ALL:
165 return "Op_REDUCE_ALL";
166 case Op_REDUCE_MAX:
167 return "Op_REDUCE_MAX";
168 case Op_REDUCE_MIN:
169 return "Op_REDUCE_MIN";
170 case Op_REDUCE_PRODUCT:
171 return "Op_REDUCE_PRODUCT";
172 case Op_REDUCE_SUM:
173 return "Op_REDUCE_SUM";
174 case Op_CONCAT:
175 return "Op_CONCAT";
176 case Op_RESHAPE:
177 return "Op_RESHAPE";
178 case Op_REVERSE:
179 return "Op_REVERSE";
180 case Op_SLICE:
181 return "Op_SLICE";
182 case Op_TILE:
183 return "Op_TILE";
184 case Op_TRANSPOSE:
185 return "Op_TRANSPOSE";
186 case Op_GATHER:
187 return "Op_GATHER";
188 case Op_SCATTER:
189 return "Op_SCATTER";
190 case Op_RESIZE:
191 return "Op_RESIZE";
192 case Op_CAST:
193 return "Op_CAST";
194 case Op_RESCALE:
195 return "Op_RESCALE";
196 case Op_CONST:
197 return "Op_CONST";
198 case Op_IDENTITY:
199 return "Op_IDENTITY";
200 case Op_CUSTOM:
201 return "Op_CUSTOM";
202 case Op_COND_IF:
203 return "Op_COND_IF";
204 case Op_WHILE_LOOP:
205 return "Op_WHILE_LOOP";
206 }
207 return "";
208}