blob: e30c3cfbb6e9a73d4cef444b5b5c88f56592ac83 [file] [log] [blame]
Eric Kunzee5e26762020-10-13 16:11:07 -07001
Kevin Cheng3a478572021-01-22 17:21:02 -08002// Copyright (c) 2020-2021, ARM Limited.
Eric Kunzee5e26762020-10-13 16:11:07 -07003//
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,
Eric Kunzee5e26762020-10-13 16:11:07 -070026 UINT8,
27 INT4,
28 INT8,
29 INT16,
30 INT32,
31 INT48,
32 FLOAT,
33}
34
35enum Format:uint32 {
36 UNKNOWN = 0,
37 NHWC,
38 NDHWC,
39 OHWI,
40 HWIM,
41 DOHWI,
42}
43
44enum Usage:uint32 {
45 UNKNOWN = 0,
46 ACTIVATION,
47 WEIGHT,
48 INDEX,
49}
50
51enum ResizeMode:uint32 {
52 UNKNOWN = 0,
53 NEAREST,
54 BILINEAR,
55}
56
57enum Op:uint32 {
58 UNKNOWN = 0,
59
60 // Tensor Operator
61 ARGMAX,
62 AVG_POOL2D,
63 CONV2D,
64 CONV3D,
65 DEPTHWISE_CONV2D,
66 FULLY_CONNECTED,
67 MATMUL,
68 MAX_POOL2D,
69 TRANSPOSE_CONV2D,
70
71 // Activation
72 CLAMP,
73 RELUN,
74 SIGMOID,
75 TANH,
76
77 // Elementwise-Binary
78 ADD,
79 ARITHMETIC_RIGHT_SHIFT,
80 BITWISE_AND,
81 BITWISE_OR,
82 BITWISE_XOR,
83 LOGICAL_AND,
84 LOGICAL_LEFT_SHIFT,
85 LOGICAL_RIGHT_SHIFT,
86 LOGICAL_OR,
87 LOGICAL_XOR,
88 MAXIMUM,
89 MINIMUM,
90 MUL,
91 POW,
92 SUB,
93 TABLE,
94
95 // Elementwise-Unary
96 ABS,
97 BITWISE_NOT,
98 CEIL,
99 CLZ,
100 EXP,
101 FLOOR,
102 LOG,
103 LOGICAL_NOT,
104 NEGATE,
105 RECIPROCAL,
106 RSQRT,
107
108 // Elementwise-Ternary
109 SELECT,
110
111 // Logical
112 EQUAL,
113 GREATER,
114 GREATER_EQUAL,
115
116 // Reduction
117 REDUCE_ANY,
118 REDUCE_ALL,
119 REDUCE_MAX,
120 REDUCE_MIN,
121 REDUCE_PRODUCT,
122 REDUCE_SUM,
123
124 // Data layout operation
125 CONCAT,
126 PAD,
127 RESHAPE,
128 REVERSE,
129 SLICE,
130 TILE,
131 TRANSPOSE,
132
133 // Gather/scatter operation
134 GATHER,
Kevin Cheng77d0f762020-11-24 10:26:32 -0800135 SCATTER,
Eric Kunzee5e26762020-10-13 16:11:07 -0700136
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,
Kevin Chengaee1fac2020-11-11 13:54:06 -0800170 MulAttribute,
171 ArithmeticRightShiftAttribute,
Eric Kunzee5e26762020-10-13 16:11:07 -0700172 CondIfAttribute,
173 WhileLoopAttribute,
174}
175
176table Pool2dAttribute {
177 padding: [int32];
178 kernel: [int32];
179 stride: [int32];
180}
181
182table Conv2dAttribute {
183 padding: [int32];
184 stride: [int32];
185 dilation: [int32];
186}
187
188table TransposeConv2dAttribute {
189 outpad: [int32];
190 stride: [int32];
191 dilation: [int32];
192 output_shape: [int32];
193}
194
195table ReluNAttribute {
196 max_int: int32;
197 max_fp: float;
198}
199
200table AxisAttribute {
201 axis: int32;
202}
203
204table ReshapeAttribute {
205 shape: [int32];
206}
207
208table SliceAttribute {
209 begin: [int32];
210 size: [int32];
211}
212
213table TileAttribute {
214 multiples: [int32];
215}
216
217table ResizeAttribute {
218 output_size: [int32];
219 stride: [int32];
220 offset: [int32];
221 shift: int32;
Kevin Cheng77d0f762020-11-24 10:26:32 -0800222 stride_fp: [float];
223 offset_fp: [float];
Eric Kunzee5e26762020-10-13 16:11:07 -0700224 mode: ResizeMode;
225}
226
227table ClampAttribute {
228 min_int: int32;
229 max_int: int32;
230 min_fp: float;
231 max_fp: float;
232}
233
234table RescaleAttribute {
235 input_zp: int32;
236 output_zp: int32;
237 multiplier: [int32];
238 shift: [int32];
239 scale32: bool;
240 double_round: bool;
241 per_channel: bool;
242}
243
Kevin Chengaee1fac2020-11-11 13:54:06 -0800244table MulAttribute {
245 shift: int32;
246}
247
248table ArithmeticRightShiftAttribute {
249 round: bool;
Eric Kunzee5e26762020-10-13 16:11:07 -0700250}
251
252table CondIfAttribute {
253 then_branch: string;
254 else_branch: string;
255}
256
257table WhileLoopAttribute {
258 cond_branch: string;
259 body_branch: string;
260}
261
262union QuantInfo {
263 UnaryQuantInfo,
264 ConvQuantInfo,
265 MatMulQuantInfo,
266 PadQuantInfo,
267}
268
269table UnaryQuantInfo {
270 input_zp: int32;
271 output_zp: int32;
272}
273
274table ConvQuantInfo {
275 input_zp: int32;
276 weight_zp: int32;
277}
278
279table MatMulQuantInfo {
280 a_zp: int32;
281 b_zp: int32;
282}
283
284table PadQuantInfo {
285 input_zp: int32;
286}
287
288table Version {
289 _major: int32 = 0;
Kevin Cheng77d0f762020-11-24 10:26:32 -0800290 _minor: int32 = 21;
Eric Kunzee5e26762020-10-13 16:11:07 -0700291 _patch: int32 = 0;
292 _experimental: bool = false;
293}
294
295table TosaTensor {
296 name:string; // name of the tensor, used for solving dependency
297 shape:[int32]; // shape of the tensor
298 type:DType; // data type of the tensor
299 usage:[Usage]; // vector of possible usages. for the convenience of debugging only.
300 format:[Format]; // vector of possible formats. for the convenience of debugging only.
301 npy_filename: string; // numpy array filename
302}
303
304table TosaOperator {
305 op:Op; // operator enum
306 attribute: Attribute; // union structure. operator attribute
307 inputs:[string]; // list of input tensor names
308 outputs:[string]; // list of output tensor names
309 quant_info: QuantInfo; // op-based quantization information
310}
311
312table TosaBasicBlock {
313 name:string; // basic block name
314 operators:[TosaOperator]; // operators array
315 tensors:[TosaTensor]; // tensors array
316 inputs:[string]; // name of graph inputs
317 outputs:[string]; // name of graph outputs
318}
319
320table TosaGraph {
321 version: Version;
322 blocks:[TosaBasicBlock]; // basic blocks array
323}
324
325root_type TosaGraph;