blob: 171818dacf3795ba6a7a1b6edc327ce9f8ed6873 [file] [log] [blame]
Eric Kunze2364dcd2021-04-26 11:06:57 -07001
Tai Ly5d580fa2023-12-15 20:34:51 +00002// Copyright (c) 2020-2024, ARM Limited.
Eric Kunze2364dcd2021-04-26 11:06:57 -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
Luke Hutton5e268092023-01-12 22:20:53 +000023// NOTE: New values added to the schema should be placed
24// at the end of the list in order to keep schema stable.
25
Eric Kunze2364dcd2021-04-26 11:06:57 -070026enum DType:uint32 {
27 UNKNOWN = 0,
28 BOOL,
29 UINT8,
30 INT4,
31 INT8,
32 INT16,
33 INT32,
34 INT48,
Jeremy Johnsone1072a92022-09-27 12:44:11 +010035 FP32,
Jeremy Johnson41027732022-05-25 17:52:29 +010036 UINT16,
James Ward485a11d2022-08-05 13:48:37 +010037 FP16,
James Ward34a62792022-10-18 17:27:40 +010038 BF16,
Won Jeoncb4bbf42023-08-10 08:50:15 +000039 SHAPE,
Eric Kunze2364dcd2021-04-26 11:06:57 -070040}
41
42enum ResizeMode:uint32 {
43 UNKNOWN = 0,
44 NEAREST,
45 BILINEAR,
46}
47
48enum Op:uint32 {
49 UNKNOWN = 0,
Eric Kunze2364dcd2021-04-26 11:06:57 -070050 ARGMAX,
51 AVG_POOL2D,
52 CONV2D,
53 CONV3D,
54 DEPTHWISE_CONV2D,
55 FULLY_CONNECTED,
56 MATMUL,
57 MAX_POOL2D,
58 TRANSPOSE_CONV2D,
Eric Kunze2364dcd2021-04-26 11:06:57 -070059 CLAMP,
Kevin Cheng38d214c2021-10-15 15:49:19 -070060 RESERVED,
Eric Kunze2364dcd2021-04-26 11:06:57 -070061 SIGMOID,
62 TANH,
Eric Kunze2364dcd2021-04-26 11:06:57 -070063 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,
Eric Kunze2364dcd2021-04-26 11:06:57 -070080 ABS,
81 BITWISE_NOT,
82 CEIL,
83 CLZ,
84 EXP,
85 FLOOR,
86 LOG,
87 LOGICAL_NOT,
88 NEGATE,
89 RECIPROCAL,
90 RSQRT,
Eric Kunze2364dcd2021-04-26 11:06:57 -070091 SELECT,
Eric Kunze2364dcd2021-04-26 11:06:57 -070092 EQUAL,
93 GREATER,
94 GREATER_EQUAL,
Eric Kunze2364dcd2021-04-26 11:06:57 -070095 REDUCE_ANY,
96 REDUCE_ALL,
97 REDUCE_MAX,
98 REDUCE_MIN,
99 REDUCE_PRODUCT,
100 REDUCE_SUM,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700101 CONCAT,
102 PAD,
103 RESHAPE,
104 REVERSE,
105 SLICE,
106 TILE,
107 TRANSPOSE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700108 GATHER,
109 SCATTER,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700110 RESIZE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700111 CAST,
112 RESCALE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700113 CONST,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700114 IDENTITY,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700115 CUSTOM,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700116 COND_IF,
117 WHILE_LOOP,
Luke Hutton5e268092023-01-12 22:20:53 +0000118 FFT2D,
119 RFFT2D,
Won Jeon3acb1cb2023-06-07 23:26:32 +0000120 ERF,
Won Jeoncb4bbf42023-08-10 08:50:15 +0000121 DIM,
Tai Ly5d580fa2023-12-15 20:34:51 +0000122 CONST_SHAPE,
123 CONCAT_SHAPE,
124 ADD_SHAPE,
125 SUB_SHAPE,
126 MUL_SHAPE,
127 DIV_SHAPE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700128}
129
130union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700131 PoolAttribute,
132 ConvAttribute,
133 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700134 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700135 AxisAttribute,
136 ReshapeAttribute,
137 SliceAttribute,
138 TileAttribute,
139 ResizeAttribute,
140 ClampAttribute,
141 RescaleAttribute,
142 MulAttribute,
143 ArithmeticRightShiftAttribute,
144 CondIfAttribute,
145 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700146 TransposeAttribute,
147 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000148 MatMulAttribute,
149 FullyConnectedAttribute,
Eric Kunze497ab5d2022-10-21 16:39:01 -0700150 NegateAttribute,
Luke Hutton5e268092023-01-12 22:20:53 +0000151 CustomAttribute,
152 FFTAttribute,
Eric Kunze4881c292023-11-01 16:12:07 -0700153 RFFTAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700154}
155
Kevin Cheng79a41992021-08-31 16:04:40 -0700156table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700157 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700158 kernel: [int32];
159 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000160 input_zp: int32;
161 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100162 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700163}
164
Kevin Cheng79a41992021-08-31 16:04:40 -0700165table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700166 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700167 stride: [int32];
168 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000169 input_zp: int32;
170 weight_zp: int32;
Eric Kunze4881c292023-11-01 16:12:07 -0700171 local_bound: bool;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700172}
173
Kevin Cheng79a41992021-08-31 16:04:40 -0700174table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700175 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700176 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700177 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000178 input_zp: int32;
179 weight_zp: int32;
Eric Kunze4881c292023-11-01 16:12:07 -0700180 local_bound: bool;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700181}
182
Kevin Cheng38d214c2021-10-15 15:49:19 -0700183table PadAttribute {
184 padding: [int32];
185 pad_const_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000186 pad_const_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700187}
188
189table AxisAttribute {
190 axis: int32;
191}
192
193table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700194 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700195}
196
197table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700198 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700199 size: [int32];
200}
201
202table TileAttribute {
203 multiples: [int32];
204}
205
206table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700207 scale: [int16];
208 offset: [int16];
209 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700210 mode: ResizeMode;
211}
212
213table ClampAttribute {
214 min_int: int32;
215 max_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000216 min_fp: [ubyte] (force_align: 8);
217 max_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700218}
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;
Eric Kunze9601cbd2023-08-17 20:44:39 +0000228 input_unsigned: bool;
229 output_unsigned: bool;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700230}
231
232table MulAttribute {
233 shift: int32;
234}
235
236table ArithmeticRightShiftAttribute {
237 round: bool;
238}
239
240table CondIfAttribute {
241 then_branch: string;
242 else_branch: string;
243}
244
245table WhileLoopAttribute {
246 cond_branch: string;
247 body_branch: string;
248}
249
Kevin Cheng38d214c2021-10-15 15:49:19 -0700250table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700251 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700252}
253
254table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700255 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700256}
257
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000258table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700259 a_zp: int32;
260 b_zp: int32;
261}
262
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000263table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700264 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000265 weight_zp: int32;
266}
267
268table NegateAttribute {
269 input1_zp: int32;
270 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700271}
272
Eric Kunze497ab5d2022-10-21 16:39:01 -0700273table CustomAttribute {
Jerry Gecd914da2023-11-09 18:41:12 +0000274 operator_name:string;
275 domain_name:string;
Eric Kunze497ab5d2022-10-21 16:39:01 -0700276 implementation_attrs:[ubyte];
277}
278
Luke Hutton5e268092023-01-12 22:20:53 +0000279table FFTAttribute {
280 inverse: bool;
Eric Kunze4881c292023-11-01 16:12:07 -0700281 local_bound: bool;
282}
283
284table RFFTAttribute {
285 local_bound: bool;
Luke Hutton5e268092023-01-12 22:20:53 +0000286}
287
Eric Kunze2364dcd2021-04-26 11:06:57 -0700288table Version {
Eric Kunzef08956b2023-05-18 01:13:41 +0000289 _major: int32 = -1;
290 _minor: int32 = -1;
291 _patch: int32 = -1;
Eric Kunzec3719ab2023-05-23 04:30:05 +0000292 _draft: bool = true;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700293}
294
295table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700296 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 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Jerry Ge442261b2022-09-09 13:38:56 -0700300 variable: bool; // is this a variable tensor
Tai Lyc6939a42023-08-21 17:00:29 +0000301 is_unranked: bool; // whether this is an unranked tensor
Tai Lyd0520b92023-09-19 21:30:18 +0000302 variable_name:string; // name for variable attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700303}
304
305table TosaOperator {
306 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700307 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700308 inputs:[string]; // list of input tensor names
309 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700310}
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
Jerry Ge13c78a62022-10-04 20:32:39 -0700320table TosaRegion {
321 name:string; // name of region
322 blocks:[TosaBasicBlock]; // basic blocks array
323}
324
Eric Kunze2364dcd2021-04-26 11:06:57 -0700325table TosaGraph {
Eric Kunzef08956b2023-05-18 01:13:41 +0000326 version:Version (required);
Jerry Ge13c78a62022-10-04 20:32:39 -0700327 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700328}
329
330root_type TosaGraph;