blob: 19756672cfb3a5fc2aa2b0d3844cbc8eb5fc646c [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 Kunze4881c292023-11-01 16:12:07 -0700147 RFFTAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700148}
149
Kevin Cheng79a41992021-08-31 16:04:40 -0700150table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700151 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700152 kernel: [int32];
153 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000154 input_zp: int32;
155 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100156 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700157}
158
Kevin Cheng79a41992021-08-31 16:04:40 -0700159table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700160 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700161 stride: [int32];
162 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000163 input_zp: int32;
164 weight_zp: int32;
Eric Kunze4881c292023-11-01 16:12:07 -0700165 local_bound: bool;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700166}
167
Kevin Cheng79a41992021-08-31 16:04:40 -0700168table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700169 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700170 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700171 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000172 input_zp: int32;
173 weight_zp: int32;
Eric Kunze4881c292023-11-01 16:12:07 -0700174 local_bound: bool;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700175}
176
Kevin Cheng38d214c2021-10-15 15:49:19 -0700177table PadAttribute {
178 padding: [int32];
179 pad_const_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000180 pad_const_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700181}
182
183table AxisAttribute {
184 axis: int32;
185}
186
187table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700188 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700189}
190
191table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700192 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700193 size: [int32];
194}
195
196table TileAttribute {
197 multiples: [int32];
198}
199
200table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700201 scale: [int16];
202 offset: [int16];
203 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700204 mode: ResizeMode;
205}
206
207table ClampAttribute {
208 min_int: int32;
209 max_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000210 min_fp: [ubyte] (force_align: 8);
211 max_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700212}
213
214table RescaleAttribute {
215 input_zp: int32;
216 output_zp: int32;
217 multiplier: [int32];
218 shift: [int32];
219 scale32: bool;
220 double_round: bool;
221 per_channel: bool;
Eric Kunze9601cbd2023-08-17 20:44:39 +0000222 input_unsigned: bool;
223 output_unsigned: bool;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700224}
225
226table MulAttribute {
227 shift: int32;
228}
229
230table ArithmeticRightShiftAttribute {
231 round: bool;
232}
233
234table CondIfAttribute {
235 then_branch: string;
236 else_branch: string;
237}
238
239table WhileLoopAttribute {
240 cond_branch: string;
241 body_branch: string;
242}
243
Kevin Cheng38d214c2021-10-15 15:49:19 -0700244table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700245 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700246}
247
248table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700249 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700250}
251
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000252table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700253 a_zp: int32;
254 b_zp: int32;
255}
256
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000257table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700258 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000259 weight_zp: int32;
260}
261
262table NegateAttribute {
263 input1_zp: int32;
264 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700265}
266
Eric Kunze497ab5d2022-10-21 16:39:01 -0700267table CustomAttribute {
Jerry Gecd914da2023-11-09 18:41:12 +0000268 operator_name:string;
269 domain_name:string;
Eric Kunze497ab5d2022-10-21 16:39:01 -0700270 implementation_attrs:[ubyte];
271}
272
Luke Hutton5e268092023-01-12 22:20:53 +0000273table FFTAttribute {
274 inverse: bool;
Eric Kunze4881c292023-11-01 16:12:07 -0700275 local_bound: bool;
276}
277
278table RFFTAttribute {
279 local_bound: bool;
Luke Hutton5e268092023-01-12 22:20:53 +0000280}
281
Eric Kunze2364dcd2021-04-26 11:06:57 -0700282table Version {
Eric Kunzef08956b2023-05-18 01:13:41 +0000283 _major: int32 = -1;
284 _minor: int32 = -1;
285 _patch: int32 = -1;
Eric Kunzec3719ab2023-05-23 04:30:05 +0000286 _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.
Jerry Ge442261b2022-09-09 13:38:56 -0700294 variable: bool; // is this a variable tensor
Tai Lyc6939a42023-08-21 17:00:29 +0000295 is_unranked: bool; // whether this is an unranked tensor
Tai Lyd0520b92023-09-19 21:30:18 +0000296 variable_name:string; // name for variable attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700297}
298
299table TosaOperator {
300 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700301 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700302 inputs:[string]; // list of input tensor names
303 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700304}
305
306table TosaBasicBlock {
307 name:string; // basic block name
308 operators:[TosaOperator]; // operators array
309 tensors:[TosaTensor]; // tensors array
310 inputs:[string]; // name of graph inputs
311 outputs:[string]; // name of graph outputs
312}
313
Jerry Ge13c78a62022-10-04 20:32:39 -0700314table TosaRegion {
315 name:string; // name of region
316 blocks:[TosaBasicBlock]; // basic blocks array
317}
318
Eric Kunze2364dcd2021-04-26 11:06:57 -0700319table TosaGraph {
Eric Kunzef08956b2023-05-18 01:13:41 +0000320 version:Version (required);
Jerry Ge13c78a62022-10-04 20:32:39 -0700321 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700322}
323
324root_type TosaGraph;