blob: 841cf3df838703b7cd8704565354f1a019f8f1e9 [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001
2// Copyright (c) 2020, ARM Limited.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16namespace tosa;
17
18// This corresponds to the version.
19file_identifier "TOSA";
20// File extension of any written files.
21file_extension "tosa";
22
23enum DType:uint32 {
24 UNKNOWN = 0,
25 BOOL,
26 AINT8,
27 UINT8,
28 INT4,
29 INT8,
30 INT16,
31 INT32,
32 INT48,
33 FLOAT,
34}
35
36enum Format:uint32 {
37 UNKNOWN = 0,
38 NHWC,
39 NDHWC,
40 OHWI,
41 HWIM,
42 DOHWI,
43}
44
45enum Usage:uint32 {
46 UNKNOWN = 0,
47 ACTIVATION,
48 WEIGHT,
49 INDEX,
50}
51
52enum ResizeMode:uint32 {
53 UNKNOWN = 0,
54 NEAREST,
55 BILINEAR,
56}
57
58enum Op:uint32 {
59 UNKNOWN = 0,
60
61 // Tensor Operator
62 ARGMAX,
63 AVG_POOL2D,
64 CONV2D,
65 CONV3D,
66 DEPTHWISE_CONV2D,
67 FULLY_CONNECTED,
68 MATMUL,
69 MAX_POOL2D,
70 TRANSPOSE_CONV2D,
71
72 // Activation
73 CLAMP,
74 RELUN,
75 SIGMOID,
76 TANH,
77
78 // Elementwise-Binary
79 ADD,
80 ARITHMETIC_RIGHT_SHIFT,
81 BITWISE_AND,
82 BITWISE_OR,
83 BITWISE_XOR,
84 LOGICAL_AND,
85 LOGICAL_LEFT_SHIFT,
86 LOGICAL_RIGHT_SHIFT,
87 LOGICAL_OR,
88 LOGICAL_XOR,
89 MAXIMUM,
90 MINIMUM,
91 MUL,
92 POW,
93 SUB,
94 TABLE,
95
96 // Elementwise-Unary
97 ABS,
98 BITWISE_NOT,
99 CEIL,
100 CLZ,
101 EXP,
102 FLOOR,
103 LOG,
104 LOGICAL_NOT,
105 NEGATE,
106 RECIPROCAL,
107 RSQRT,
108
109 // Elementwise-Ternary
110 SELECT,
111
112 // Logical
113 EQUAL,
114 GREATER,
115 GREATER_EQUAL,
116
117 // Reduction
118 REDUCE_ANY,
119 REDUCE_ALL,
120 REDUCE_MAX,
121 REDUCE_MIN,
122 REDUCE_PRODUCT,
123 REDUCE_SUM,
124
125 // Data layout operation
126 CONCAT,
127 PAD,
128 RESHAPE,
129 REVERSE,
130 SLICE,
131 TILE,
132 TRANSPOSE,
133
134 // Gather/scatter operation
135 GATHER,
136
137 // Image
138 RESIZE,
139
140 // Type conversion
141 CAST,
142 RESCALE,
143
144 // Data Nodes
145 CONST,
146 PLACEHOLDER,
147 IDENTITY,
148 IDENTITYN,
149
150 // Custom operations
151 CUSTOM,
152
153 // Control flow operators
154 COND_IF,
155 WHILE_LOOP,
156}
157
158union Attribute {
159 Pool2dAttribute,
160 Conv2dAttribute,
161 TransposeConv2dAttribute,
162 ReluNAttribute,
163 AxisAttribute,
164 ReshapeAttribute,
165 SliceAttribute,
166 TileAttribute,
167 ResizeAttribute,
168 ClampAttribute,
169 RescaleAttribute,
170 CustomAttribute,
171 CondIfAttribute,
172 WhileLoopAttribute,
173}
174
175table Pool2dAttribute {
176 padding: [int32];
177 kernel: [int32];
178 stride: [int32];
179}
180
181table Conv2dAttribute {
182 padding: [int32];
183 stride: [int32];
184 dilation: [int32];
185}
186
187table TransposeConv2dAttribute {
188 outpad: [int32];
189 stride: [int32];
190 dilation: [int32];
191 output_shape: [int32];
192}
193
194table ReluNAttribute {
195 max_int: int32;
196 max_fp: float;
197}
198
199table AxisAttribute {
200 axis: int32;
201}
202
203table ReshapeAttribute {
204 shape: [int32];
205}
206
207table SliceAttribute {
208 begin: [int32];
209 size: [int32];
210}
211
212table TileAttribute {
213 multiples: [int32];
214}
215
216table ResizeAttribute {
217 output_size: [int32];
218 stride: [int32];
219 offset: [int32];
220 shift: int32;
221 mode: ResizeMode;
222}
223
224table ClampAttribute {
225 min_int: int32;
226 max_int: int32;
227 min_fp: float;
228 max_fp: float;
229}
230
231table RescaleAttribute {
232 input_zp: int32;
233 output_zp: int32;
234 multiplier: [int32];
235 shift: [int32];
236 scale32: bool;
237 double_round: bool;
238 per_channel: bool;
239}
240
241table CustomAttribute {
242 identifier: string;
243}
244
245table CondIfAttribute {
246 then_branch: string;
247 else_branch: string;
248}
249
250table WhileLoopAttribute {
251 cond_branch: string;
252 body_branch: string;
253}
254
255union QuantInfo {
256 UnaryQuantInfo,
257 ConvQuantInfo,
258 MatMulQuantInfo,
259 PadQuantInfo,
260}
261
262table UnaryQuantInfo {
263 input_zp: int32;
264 output_zp: int32;
265}
266
267table ConvQuantInfo {
268 input_zp: int32;
269 weight_zp: int32;
270}
271
272table MatMulQuantInfo {
273 a_zp: int32;
274 b_zp: int32;
275}
276
277table PadQuantInfo {
278 input_zp: int32;
279}
280
281table Version {
282 _major: int32 = 0;
283 _minor: int32 = 20;
284 _patch: int32 = 0;
285 _experimental: bool = false;
286}
287
288table TosaTensor {
289 name:string; // name of the tensor, used for solving dependency
290 shape:[int32]; // shape of the tensor
291 type:DType; // data type of the tensor
292 usage:[Usage]; // vector of possible usages. for the convenience of debugging only.
293 format:[Format]; // vector of possible formats. for the convenience of debugging only.
294 npy_filename: string; // numpy array filename
295}
296
297table TosaOperator {
298 op:Op; // operator enum
299 attribute: Attribute; // union structure. operator attribute
300 inputs:[string]; // list of input tensor names
301 outputs:[string]; // list of output tensor names
302 quant_info: QuantInfo; // op-based quantization information
303}
304
305table TosaBasicBlock {
306 name:string; // basic block name
307 operators:[TosaOperator]; // operators array
308 tensors:[TosaTensor]; // tensors array
309 inputs:[string]; // name of graph inputs
310 outputs:[string]; // name of graph outputs
311}
312
313table TosaGraph {
314 version: Version;
315 blocks:[TosaBasicBlock]; // basic blocks array
316}
317
318root_type TosaGraph;