blob: e4a24981a1f04f9fd95d3d5f896b4fed9bd9bea7 [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,
Eric Kunze2364dcd2021-04-26 11:06:57 -070039}
40
41enum ResizeMode:uint32 {
42 UNKNOWN = 0,
43 NEAREST,
44 BILINEAR,
45}
46
47enum Op:uint32 {
48 UNKNOWN = 0,
Eric Kunze2364dcd2021-04-26 11:06:57 -070049 ARGMAX,
50 AVG_POOL2D,
51 CONV2D,
52 CONV3D,
53 DEPTHWISE_CONV2D,
54 FULLY_CONNECTED,
55 MATMUL,
56 MAX_POOL2D,
57 TRANSPOSE_CONV2D,
Eric Kunze2364dcd2021-04-26 11:06:57 -070058 CLAMP,
Kevin Cheng38d214c2021-10-15 15:49:19 -070059 RESERVED,
Eric Kunze2364dcd2021-04-26 11:06:57 -070060 SIGMOID,
61 TANH,
Eric Kunze2364dcd2021-04-26 11:06:57 -070062 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,
Eric Kunze2364dcd2021-04-26 11:06:57 -070079 ABS,
80 BITWISE_NOT,
81 CEIL,
82 CLZ,
83 EXP,
84 FLOOR,
85 LOG,
86 LOGICAL_NOT,
87 NEGATE,
88 RECIPROCAL,
89 RSQRT,
Eric Kunze2364dcd2021-04-26 11:06:57 -070090 SELECT,
Eric Kunze2364dcd2021-04-26 11:06:57 -070091 EQUAL,
92 GREATER,
93 GREATER_EQUAL,
Eric Kunze2364dcd2021-04-26 11:06:57 -070094 REDUCE_ANY,
95 REDUCE_ALL,
96 REDUCE_MAX,
97 REDUCE_MIN,
98 REDUCE_PRODUCT,
99 REDUCE_SUM,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700100 CONCAT,
101 PAD,
102 RESHAPE,
103 REVERSE,
104 SLICE,
105 TILE,
106 TRANSPOSE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700107 GATHER,
108 SCATTER,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700109 RESIZE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700110 CAST,
111 RESCALE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700112 CONST,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700113 IDENTITY,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700114 CUSTOM,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700115 COND_IF,
116 WHILE_LOOP,
Luke Hutton5e268092023-01-12 22:20:53 +0000117 FFT2D,
118 RFFT2D,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700119}
120
121union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700122 PoolAttribute,
123 ConvAttribute,
124 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700125 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700126 AxisAttribute,
127 ReshapeAttribute,
128 SliceAttribute,
129 TileAttribute,
130 ResizeAttribute,
131 ClampAttribute,
132 RescaleAttribute,
133 MulAttribute,
134 ArithmeticRightShiftAttribute,
135 CondIfAttribute,
136 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700137 TransposeAttribute,
138 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000139 MatMulAttribute,
140 FullyConnectedAttribute,
Eric Kunze497ab5d2022-10-21 16:39:01 -0700141 NegateAttribute,
Luke Hutton5e268092023-01-12 22:20:53 +0000142 CustomAttribute,
143 FFTAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700144}
145
Kevin Cheng79a41992021-08-31 16:04:40 -0700146table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700147 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700148 kernel: [int32];
149 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000150 input_zp: int32;
151 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100152 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700153}
154
Kevin Cheng79a41992021-08-31 16:04:40 -0700155table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700156 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700157 stride: [int32];
158 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000159 input_zp: int32;
160 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100161 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700162}
163
Kevin Cheng79a41992021-08-31 16:04:40 -0700164table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700165 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700166 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700167 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000168 input_zp: int32;
169 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100170 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700171}
172
Kevin Cheng38d214c2021-10-15 15:49:19 -0700173table PadAttribute {
174 padding: [int32];
175 pad_const_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000176 pad_const_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700177}
178
179table AxisAttribute {
180 axis: int32;
181}
182
183table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700184 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700185}
186
187table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700188 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700189 size: [int32];
190}
191
192table TileAttribute {
193 multiples: [int32];
194}
195
196table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700197 scale: [int16];
198 offset: [int16];
199 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700200 mode: ResizeMode;
201}
202
203table ClampAttribute {
204 min_int: int32;
205 max_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000206 min_fp: [ubyte] (force_align: 8);
207 max_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700208}
209
210table RescaleAttribute {
211 input_zp: int32;
212 output_zp: int32;
213 multiplier: [int32];
214 shift: [int32];
215 scale32: bool;
216 double_round: bool;
217 per_channel: bool;
218}
219
220table MulAttribute {
221 shift: int32;
222}
223
224table ArithmeticRightShiftAttribute {
225 round: bool;
226}
227
228table CondIfAttribute {
229 then_branch: string;
230 else_branch: string;
231}
232
233table WhileLoopAttribute {
234 cond_branch: string;
235 body_branch: string;
236}
237
Kevin Cheng38d214c2021-10-15 15:49:19 -0700238table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700239 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700240}
241
242table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700243 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700244}
245
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000246table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700247 a_zp: int32;
248 b_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100249 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700250}
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;
James Ward485a11d2022-08-05 13:48:37 +0100255 accum_dtype: DType;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000256}
257
258table NegateAttribute {
259 input1_zp: int32;
260 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700261}
262
Eric Kunze497ab5d2022-10-21 16:39:01 -0700263table CustomAttribute {
264 identifier:string;
265 config:string;
266 implementation_attrs:[ubyte];
267}
268
Luke Hutton5e268092023-01-12 22:20:53 +0000269table FFTAttribute {
270 inverse: bool;
271}
272
Eric Kunze2364dcd2021-04-26 11:06:57 -0700273table Version {
274 _major: int32 = 0;
Eric Kunze6388a092022-12-07 21:59:31 +0000275 _minor: int32 = 51;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700276 _patch: int32 = 0;
Eric Kunze6388a092022-12-07 21:59:31 +0000277 _draft: bool = true;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700278}
279
280table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700281 name:string; // name of the tensor, used for solving dependency
282 shape:[int32]; // shape of the tensor
283 type:DType; // data type of the tensor
284 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700285}
286
287table TosaOperator {
288 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700289 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700290 inputs:[string]; // list of input tensor names
291 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700292}
293
294table TosaBasicBlock {
295 name:string; // basic block name
296 operators:[TosaOperator]; // operators array
297 tensors:[TosaTensor]; // tensors array
298 inputs:[string]; // name of graph inputs
299 outputs:[string]; // name of graph outputs
300}
301
Jerry Ge13c78a62022-10-04 20:32:39 -0700302table TosaRegion {
303 name:string; // name of region
304 blocks:[TosaBasicBlock]; // basic blocks array
305}
306
Eric Kunze2364dcd2021-04-26 11:06:57 -0700307table TosaGraph {
Jerry Ge13c78a62022-10-04 20:32:39 -0700308 version:Version;
309 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700310}
311
312root_type TosaGraph;