blob: f57d9dc085d6d94d89a59fa8cf87bc2ddb7c415b [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,
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;
222 mode: ResizeMode;
223}
224
225table ClampAttribute {
226 min_int: int32;
227 max_int: int32;
228 min_fp: float;
229 max_fp: float;
230}
231
232table RescaleAttribute {
233 input_zp: int32;
234 output_zp: int32;
235 multiplier: [int32];
236 shift: [int32];
237 scale32: bool;
238 double_round: bool;
239 per_channel: bool;
240}
241
Kevin Chengaee1fac2020-11-11 13:54:06 -0800242table MulAttribute {
243 shift: int32;
244}
245
246table ArithmeticRightShiftAttribute {
247 round: bool;
Eric Kunzee5e26762020-10-13 16:11:07 -0700248}
249
250table CondIfAttribute {
251 then_branch: string;
252 else_branch: string;
253}
254
255table WhileLoopAttribute {
256 cond_branch: string;
257 body_branch: string;
258}
259
260union QuantInfo {
261 UnaryQuantInfo,
262 ConvQuantInfo,
263 MatMulQuantInfo,
264 PadQuantInfo,
265}
266
267table UnaryQuantInfo {
268 input_zp: int32;
269 output_zp: int32;
270}
271
272table ConvQuantInfo {
273 input_zp: int32;
274 weight_zp: int32;
275}
276
277table MatMulQuantInfo {
278 a_zp: int32;
279 b_zp: int32;
280}
281
282table PadQuantInfo {
283 input_zp: int32;
284}
285
286table Version {
287 _major: int32 = 0;
288 _minor: int32 = 20;
289 _patch: int32 = 0;
290 _experimental: bool = false;
291}
292
293table TosaTensor {
294 name:string; // name of the tensor, used for solving dependency
295 shape:[int32]; // shape of the tensor
296 type:DType; // data type of the tensor
297 usage:[Usage]; // vector of possible usages. for the convenience of debugging only.
298 format:[Format]; // vector of possible formats. for the convenience of debugging only.
299 npy_filename: string; // numpy array filename
300}
301
302table TosaOperator {
303 op:Op; // operator enum
304 attribute: Attribute; // union structure. operator attribute
305 inputs:[string]; // list of input tensor names
306 outputs:[string]; // list of output tensor names
307 quant_info: QuantInfo; // op-based quantization information
308}
309
310table TosaBasicBlock {
311 name:string; // basic block name
312 operators:[TosaOperator]; // operators array
313 tensors:[TosaTensor]; // tensors array
314 inputs:[string]; // name of graph inputs
315 outputs:[string]; // name of graph outputs
316}
317
318table TosaGraph {
319 version: Version;
320 blocks:[TosaBasicBlock]; // basic blocks array
321}
322
323root_type TosaGraph;