blob: 8977f59591ad8c6241ce86aa6ed005ff6c8b1f99 [file] [log] [blame]
Eric Kunze2364dcd2021-04-26 11:06:57 -07001
2// Copyright (c) 2020-2021, 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 UINT8,
27 INT4,
28 INT8,
29 INT16,
30 INT32,
31 INT48,
32 FLOAT,
33}
34
35enum ResizeMode:uint32 {
36 UNKNOWN = 0,
37 NEAREST,
38 BILINEAR,
39}
40
41enum Op:uint32 {
42 UNKNOWN = 0,
43
44 // Tensor Operator
45 ARGMAX,
46 AVG_POOL2D,
47 CONV2D,
48 CONV3D,
49 DEPTHWISE_CONV2D,
50 FULLY_CONNECTED,
51 MATMUL,
52 MAX_POOL2D,
53 TRANSPOSE_CONV2D,
54
55 // Activation
56 CLAMP,
Kevin Cheng38d214c2021-10-15 15:49:19 -070057 RESERVED,
Eric Kunze2364dcd2021-04-26 11:06:57 -070058 SIGMOID,
59 TANH,
60
61 // Elementwise-Binary
62 ADD,
63 ARITHMETIC_RIGHT_SHIFT,
64 BITWISE_AND,
65 BITWISE_OR,
66 BITWISE_XOR,
Matthew Haddonab905ec2021-08-23 16:40:57 +010067 INTDIV,
Eric Kunze2364dcd2021-04-26 11:06:57 -070068 LOGICAL_AND,
69 LOGICAL_LEFT_SHIFT,
70 LOGICAL_RIGHT_SHIFT,
71 LOGICAL_OR,
72 LOGICAL_XOR,
73 MAXIMUM,
74 MINIMUM,
75 MUL,
76 POW,
77 SUB,
78 TABLE,
79
80 // Elementwise-Unary
81 ABS,
82 BITWISE_NOT,
83 CEIL,
84 CLZ,
85 EXP,
86 FLOOR,
87 LOG,
88 LOGICAL_NOT,
89 NEGATE,
90 RECIPROCAL,
91 RSQRT,
92
93 // Elementwise-Ternary
94 SELECT,
95
96 // Logical
97 EQUAL,
98 GREATER,
99 GREATER_EQUAL,
100
101 // Reduction
102 REDUCE_ANY,
103 REDUCE_ALL,
104 REDUCE_MAX,
105 REDUCE_MIN,
106 REDUCE_PRODUCT,
107 REDUCE_SUM,
108
109 // Data layout operation
110 CONCAT,
111 PAD,
112 RESHAPE,
113 REVERSE,
114 SLICE,
115 TILE,
116 TRANSPOSE,
117
118 // Gather/scatter operation
119 GATHER,
120 SCATTER,
121
122 // Image
123 RESIZE,
124
125 // Type conversion
126 CAST,
127 RESCALE,
128
129 // Data Nodes
130 CONST,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700131 IDENTITY,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700132
133 // Custom operations
134 CUSTOM,
135
136 // Control flow operators
137 COND_IF,
138 WHILE_LOOP,
139}
140
141union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700142 PoolAttribute,
143 ConvAttribute,
144 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700145 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700146 AxisAttribute,
147 ReshapeAttribute,
148 SliceAttribute,
149 TileAttribute,
150 ResizeAttribute,
151 ClampAttribute,
152 RescaleAttribute,
153 MulAttribute,
154 ArithmeticRightShiftAttribute,
155 CondIfAttribute,
156 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700157 TransposeAttribute,
158 TableAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700159}
160
Kevin Cheng79a41992021-08-31 16:04:40 -0700161table PoolAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700162 padding: [int32];
163 kernel: [int32];
164 stride: [int32];
165}
166
Kevin Cheng79a41992021-08-31 16:04:40 -0700167table ConvAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700168 padding: [int32];
169 stride: [int32];
170 dilation: [int32];
171}
172
Kevin Cheng79a41992021-08-31 16:04:40 -0700173table TransposeConvAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700174 outpad: [int32];
175 stride: [int32];
176 dilation: [int32];
177 output_shape: [int32];
178}
179
Kevin Cheng38d214c2021-10-15 15:49:19 -0700180table PadAttribute {
181 padding: [int32];
182 pad_const_int: int32;
183 pad_const_fp: float;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700184}
185
186table AxisAttribute {
187 axis: int32;
188}
189
190table ReshapeAttribute {
191 shape: [int32];
192}
193
194table SliceAttribute {
195 begin: [int32];
196 size: [int32];
197}
198
199table TileAttribute {
200 multiples: [int32];
201}
202
203table ResizeAttribute {
204 output_size: [int32];
205 stride: [int32];
206 offset: [int32];
207 shift: int32;
208 stride_fp: [float];
209 offset_fp: [float];
210 mode: ResizeMode;
211}
212
213table ClampAttribute {
214 min_int: int32;
215 max_int: int32;
216 min_fp: float;
217 max_fp: float;
218}
219
220table RescaleAttribute {
221 input_zp: int32;
222 output_zp: int32;
223 multiplier: [int32];
224 shift: [int32];
225 scale32: bool;
226 double_round: bool;
227 per_channel: bool;
228}
229
230table MulAttribute {
231 shift: int32;
232}
233
234table ArithmeticRightShiftAttribute {
235 round: bool;
236}
237
238table CondIfAttribute {
239 then_branch: string;
240 else_branch: string;
241}
242
243table WhileLoopAttribute {
244 cond_branch: string;
245 body_branch: string;
246}
247
Kevin Cheng38d214c2021-10-15 15:49:19 -0700248table TransposeAttribute {
249 perm: [int32];
250}
251
252table TableAttribute {
253 table: [int32];
254}
255
Eric Kunze2364dcd2021-04-26 11:06:57 -0700256union QuantInfo {
257 UnaryQuantInfo,
258 ConvQuantInfo,
259 MatMulQuantInfo,
260 PadQuantInfo,
261}
262
263table UnaryQuantInfo {
264 input_zp: int32;
265 output_zp: int32;
266}
267
268table ConvQuantInfo {
269 input_zp: int32;
270 weight_zp: int32;
271}
272
273table MatMulQuantInfo {
274 a_zp: int32;
275 b_zp: int32;
276}
277
278table PadQuantInfo {
279 input_zp: int32;
280}
281
282table Version {
283 _major: int32 = 0;
Kevin Chengb97cb1d2021-10-14 11:53:39 -0700284 _minor: int32 = 23;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700285 _patch: int32 = 0;
Kevin Chengb97cb1d2021-10-14 11:53:39 -0700286 _draft: bool = true;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700287}
288
289table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700290 name:string; // name of the tensor, used for solving dependency
291 shape:[int32]; // shape of the tensor
292 type:DType; // data type of the tensor
293 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700294}
295
296table TosaOperator {
297 op:Op; // operator enum
298 attribute: Attribute; // union structure. operator attribute
299 inputs:[string]; // list of input tensor names
300 outputs:[string]; // list of output tensor names
301 quant_info: QuantInfo; // op-based quantization information
302}
303
304table TosaBasicBlock {
305 name:string; // basic block name
306 operators:[TosaOperator]; // operators array
307 tensors:[TosaTensor]; // tensors array
308 inputs:[string]; // name of graph inputs
309 outputs:[string]; // name of graph outputs
310}
311
312table TosaGraph {
313 version: Version;
314 blocks:[TosaBasicBlock]; // basic blocks array
315}
316
317root_type TosaGraph;