blob: fef1f5e57cf9d8c29abb487314f63b102b40eab7 [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,
Jeremy Johnson41027732022-05-25 17:52:29 +010033 UINT16,
Eric Kunze2364dcd2021-04-26 11:06:57 -070034}
35
36enum ResizeMode:uint32 {
37 UNKNOWN = 0,
38 NEAREST,
39 BILINEAR,
40}
41
42enum Op:uint32 {
43 UNKNOWN = 0,
44
45 // Tensor Operator
46 ARGMAX,
47 AVG_POOL2D,
48 CONV2D,
49 CONV3D,
50 DEPTHWISE_CONV2D,
51 FULLY_CONNECTED,
52 MATMUL,
53 MAX_POOL2D,
54 TRANSPOSE_CONV2D,
55
56 // Activation
57 CLAMP,
Kevin Cheng38d214c2021-10-15 15:49:19 -070058 RESERVED,
Eric Kunze2364dcd2021-04-26 11:06:57 -070059 SIGMOID,
60 TANH,
61
62 // Elementwise-Binary
63 ADD,
64 ARITHMETIC_RIGHT_SHIFT,
65 BITWISE_AND,
66 BITWISE_OR,
67 BITWISE_XOR,
Matthew Haddonab905ec2021-08-23 16:40:57 +010068 INTDIV,
Eric Kunze2364dcd2021-04-26 11:06:57 -070069 LOGICAL_AND,
70 LOGICAL_LEFT_SHIFT,
71 LOGICAL_RIGHT_SHIFT,
72 LOGICAL_OR,
73 LOGICAL_XOR,
74 MAXIMUM,
75 MINIMUM,
76 MUL,
77 POW,
78 SUB,
79 TABLE,
80
81 // Elementwise-Unary
82 ABS,
83 BITWISE_NOT,
84 CEIL,
85 CLZ,
86 EXP,
87 FLOOR,
88 LOG,
89 LOGICAL_NOT,
90 NEGATE,
91 RECIPROCAL,
92 RSQRT,
93
94 // Elementwise-Ternary
95 SELECT,
96
97 // Logical
98 EQUAL,
99 GREATER,
100 GREATER_EQUAL,
101
102 // Reduction
103 REDUCE_ANY,
104 REDUCE_ALL,
105 REDUCE_MAX,
106 REDUCE_MIN,
107 REDUCE_PRODUCT,
108 REDUCE_SUM,
109
110 // Data layout operation
111 CONCAT,
112 PAD,
113 RESHAPE,
114 REVERSE,
115 SLICE,
116 TILE,
117 TRANSPOSE,
118
119 // Gather/scatter operation
120 GATHER,
121 SCATTER,
122
123 // Image
124 RESIZE,
125
126 // Type conversion
127 CAST,
128 RESCALE,
129
130 // Data Nodes
131 CONST,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700132 IDENTITY,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700133
134 // Custom operations
135 CUSTOM,
136
137 // Control flow operators
138 COND_IF,
139 WHILE_LOOP,
140}
141
142union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700143 PoolAttribute,
144 ConvAttribute,
145 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700146 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700147 AxisAttribute,
148 ReshapeAttribute,
149 SliceAttribute,
150 TileAttribute,
151 ResizeAttribute,
152 ClampAttribute,
153 RescaleAttribute,
154 MulAttribute,
155 ArithmeticRightShiftAttribute,
156 CondIfAttribute,
157 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700158 TransposeAttribute,
159 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000160 MatMulAttribute,
161 FullyConnectedAttribute,
162 NegateAttribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700163}
164
Kevin Cheng79a41992021-08-31 16:04:40 -0700165table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700166 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700167 kernel: [int32];
168 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000169 input_zp: int32;
170 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700171}
172
Kevin Cheng79a41992021-08-31 16:04:40 -0700173table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700174 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700175 stride: [int32];
176 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000177 input_zp: int32;
178 weight_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700179}
180
Kevin Cheng79a41992021-08-31 16:04:40 -0700181table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700182 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700183 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700184 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000185 input_zp: int32;
186 weight_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700187}
188
Kevin Cheng38d214c2021-10-15 15:49:19 -0700189table PadAttribute {
190 padding: [int32];
191 pad_const_int: int32;
192 pad_const_fp: float;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700193}
194
195table AxisAttribute {
196 axis: int32;
197}
198
199table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700200 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700201}
202
203table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700204 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700205 size: [int32];
206}
207
208table TileAttribute {
209 multiples: [int32];
210}
211
212table ResizeAttribute {
213 output_size: [int32];
214 stride: [int32];
215 offset: [int32];
216 shift: int32;
217 stride_fp: [float];
218 offset_fp: [float];
219 mode: ResizeMode;
220}
221
222table ClampAttribute {
223 min_int: int32;
224 max_int: int32;
225 min_fp: float;
226 max_fp: float;
227}
228
229table RescaleAttribute {
230 input_zp: int32;
231 output_zp: int32;
232 multiplier: [int32];
233 shift: [int32];
234 scale32: bool;
235 double_round: bool;
236 per_channel: bool;
237}
238
239table MulAttribute {
240 shift: int32;
241}
242
243table ArithmeticRightShiftAttribute {
244 round: bool;
245}
246
247table CondIfAttribute {
248 then_branch: string;
249 else_branch: string;
250}
251
252table WhileLoopAttribute {
253 cond_branch: string;
254 body_branch: string;
255}
256
Kevin Cheng38d214c2021-10-15 15:49:19 -0700257table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700258 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700259}
260
261table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700262 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700263}
264
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000265table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700266 a_zp: int32;
267 b_zp: int32;
268}
269
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000270table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700271 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000272 weight_zp: int32;
273}
274
275table NegateAttribute {
276 input1_zp: int32;
277 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700278}
279
280table Version {
281 _major: int32 = 0;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000282 _minor: int32 = 30;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700283 _patch: int32 = 0;
Eric Kunze8fcef212022-06-16 15:45:39 -0700284 _draft: bool = false;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700285}
286
287table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700288 name:string; // name of the tensor, used for solving dependency
289 shape:[int32]; // shape of the tensor
290 type:DType; // data type of the tensor
291 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700292}
293
294table TosaOperator {
295 op:Op; // operator enum
296 attribute: Attribute; // union structure. operator attribute
297 inputs:[string]; // list of input tensor names
298 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700299}
300
301table TosaBasicBlock {
302 name:string; // basic block name
303 operators:[TosaOperator]; // operators array
304 tensors:[TosaTensor]; // tensors array
305 inputs:[string]; // name of graph inputs
306 outputs:[string]; // name of graph outputs
307}
308
309table TosaGraph {
310 version: Version;
311 blocks:[TosaBasicBlock]; // basic blocks array
312}
313
314root_type TosaGraph;