blob: f101fa33189d660314dbc8092d5e586dff39e92a [file] [log] [blame]
Eric Kunze2364dcd2021-04-26 11:06:57 -07001
Eric Kunze497ab5d2022-10-21 16:39:01 -07002// Copyright (c) 2020-2023, 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,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700122}
123
124union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700125 PoolAttribute,
126 ConvAttribute,
127 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700128 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700129 AxisAttribute,
130 ReshapeAttribute,
131 SliceAttribute,
132 TileAttribute,
133 ResizeAttribute,
134 ClampAttribute,
135 RescaleAttribute,
136 MulAttribute,
137 ArithmeticRightShiftAttribute,
138 CondIfAttribute,
139 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700140 TransposeAttribute,
141 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000142 MatMulAttribute,
143 FullyConnectedAttribute,
Eric Kunze497ab5d2022-10-21 16:39:01 -0700144 NegateAttribute,
Luke Hutton5e268092023-01-12 22:20:53 +0000145 CustomAttribute,
146 FFTAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700147}
148
Kevin Cheng79a41992021-08-31 16:04:40 -0700149table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700150 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700151 kernel: [int32];
152 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000153 input_zp: int32;
154 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100155 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700156}
157
Kevin Cheng79a41992021-08-31 16:04:40 -0700158table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700159 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700160 stride: [int32];
161 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000162 input_zp: int32;
163 weight_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700164}
165
Kevin Cheng79a41992021-08-31 16:04:40 -0700166table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700167 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700168 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700169 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000170 input_zp: int32;
171 weight_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700172}
173
Kevin Cheng38d214c2021-10-15 15:49:19 -0700174table PadAttribute {
175 padding: [int32];
176 pad_const_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000177 pad_const_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700178}
179
180table AxisAttribute {
181 axis: int32;
182}
183
184table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700185 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700186}
187
188table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700189 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700190 size: [int32];
191}
192
193table TileAttribute {
194 multiples: [int32];
195}
196
197table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700198 scale: [int16];
199 offset: [int16];
200 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700201 mode: ResizeMode;
202}
203
204table ClampAttribute {
205 min_int: int32;
206 max_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000207 min_fp: [ubyte] (force_align: 8);
208 max_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700209}
210
211table RescaleAttribute {
212 input_zp: int32;
213 output_zp: int32;
214 multiplier: [int32];
215 shift: [int32];
216 scale32: bool;
217 double_round: bool;
218 per_channel: bool;
219}
220
221table MulAttribute {
222 shift: int32;
223}
224
225table ArithmeticRightShiftAttribute {
226 round: bool;
227}
228
229table CondIfAttribute {
230 then_branch: string;
231 else_branch: string;
232}
233
234table WhileLoopAttribute {
235 cond_branch: string;
236 body_branch: string;
237}
238
Kevin Cheng38d214c2021-10-15 15:49:19 -0700239table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700240 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700241}
242
243table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700244 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700245}
246
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000247table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700248 a_zp: int32;
249 b_zp: int32;
250}
251
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000252table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700253 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000254 weight_zp: int32;
255}
256
257table NegateAttribute {
258 input1_zp: int32;
259 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700260}
261
Eric Kunze497ab5d2022-10-21 16:39:01 -0700262table CustomAttribute {
263 identifier:string;
264 config:string;
265 implementation_attrs:[ubyte];
266}
267
Luke Hutton5e268092023-01-12 22:20:53 +0000268table FFTAttribute {
269 inverse: bool;
270}
271
Eric Kunze2364dcd2021-04-26 11:06:57 -0700272table Version {
Eric Kunzef08956b2023-05-18 01:13:41 +0000273 _major: int32 = -1;
274 _minor: int32 = -1;
275 _patch: int32 = -1;
Eric Kunzec3719ab2023-05-23 04:30:05 +0000276 _draft: bool = true;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700277}
278
279table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700280 name:string; // name of the tensor, used for solving dependency
281 shape:[int32]; // shape of the tensor
282 type:DType; // data type of the tensor
283 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700284}
285
286table TosaOperator {
287 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700288 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700289 inputs:[string]; // list of input tensor names
290 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700291}
292
293table TosaBasicBlock {
294 name:string; // basic block name
295 operators:[TosaOperator]; // operators array
296 tensors:[TosaTensor]; // tensors array
297 inputs:[string]; // name of graph inputs
298 outputs:[string]; // name of graph outputs
299}
300
Jerry Ge13c78a62022-10-04 20:32:39 -0700301table TosaRegion {
302 name:string; // name of region
303 blocks:[TosaBasicBlock]; // basic blocks array
304}
305
Eric Kunze2364dcd2021-04-26 11:06:57 -0700306table TosaGraph {
Eric Kunzef08956b2023-05-18 01:13:41 +0000307 version:Version (required);
Jerry Ge13c78a62022-10-04 20:32:39 -0700308 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700309}
310
311root_type TosaGraph;