blob: 057933cc6354178f675faa34ac839320a7b6bcab [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,
Won Jeon3acb1cb2023-06-07 23:26:32 +0000119 ERF,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700120}
121
122union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700123 PoolAttribute,
124 ConvAttribute,
125 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700126 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700127 AxisAttribute,
128 ReshapeAttribute,
129 SliceAttribute,
130 TileAttribute,
131 ResizeAttribute,
132 ClampAttribute,
133 RescaleAttribute,
134 MulAttribute,
135 ArithmeticRightShiftAttribute,
136 CondIfAttribute,
137 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700138 TransposeAttribute,
139 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000140 MatMulAttribute,
141 FullyConnectedAttribute,
Eric Kunze497ab5d2022-10-21 16:39:01 -0700142 NegateAttribute,
Luke Hutton5e268092023-01-12 22:20:53 +0000143 CustomAttribute,
144 FFTAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700145}
146
Kevin Cheng79a41992021-08-31 16:04:40 -0700147table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700148 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700149 kernel: [int32];
150 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000151 input_zp: int32;
152 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100153 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700154}
155
Kevin Cheng79a41992021-08-31 16:04:40 -0700156table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700157 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700158 stride: [int32];
159 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000160 input_zp: int32;
161 weight_zp: int32;
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;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700170}
171
Kevin Cheng38d214c2021-10-15 15:49:19 -0700172table PadAttribute {
173 padding: [int32];
174 pad_const_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000175 pad_const_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700176}
177
178table AxisAttribute {
179 axis: int32;
180}
181
182table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700183 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700184}
185
186table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700187 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700188 size: [int32];
189}
190
191table TileAttribute {
192 multiples: [int32];
193}
194
195table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700196 scale: [int16];
197 offset: [int16];
198 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700199 mode: ResizeMode;
200}
201
202table ClampAttribute {
203 min_int: int32;
204 max_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000205 min_fp: [ubyte] (force_align: 8);
206 max_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700207}
208
209table RescaleAttribute {
210 input_zp: int32;
211 output_zp: int32;
212 multiplier: [int32];
213 shift: [int32];
214 scale32: bool;
215 double_round: bool;
216 per_channel: bool;
217}
218
219table MulAttribute {
220 shift: int32;
221}
222
223table ArithmeticRightShiftAttribute {
224 round: bool;
225}
226
227table CondIfAttribute {
228 then_branch: string;
229 else_branch: string;
230}
231
232table WhileLoopAttribute {
233 cond_branch: string;
234 body_branch: string;
235}
236
Kevin Cheng38d214c2021-10-15 15:49:19 -0700237table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700238 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700239}
240
241table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700242 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700243}
244
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000245table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700246 a_zp: int32;
247 b_zp: int32;
248}
249
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000250table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700251 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000252 weight_zp: int32;
253}
254
255table NegateAttribute {
256 input1_zp: int32;
257 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700258}
259
Eric Kunze497ab5d2022-10-21 16:39:01 -0700260table CustomAttribute {
261 identifier:string;
262 config:string;
263 implementation_attrs:[ubyte];
264}
265
Luke Hutton5e268092023-01-12 22:20:53 +0000266table FFTAttribute {
267 inverse: bool;
268}
269
Eric Kunze2364dcd2021-04-26 11:06:57 -0700270table Version {
Eric Kunzef08956b2023-05-18 01:13:41 +0000271 _major: int32 = -1;
272 _minor: int32 = -1;
273 _patch: int32 = -1;
Eric Kunzec3719ab2023-05-23 04:30:05 +0000274 _draft: bool = true;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700275}
276
277table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700278 name:string; // name of the tensor, used for solving dependency
279 shape:[int32]; // shape of the tensor
280 type:DType; // data type of the tensor
281 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700282}
283
284table TosaOperator {
285 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700286 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700287 inputs:[string]; // list of input tensor names
288 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700289}
290
291table TosaBasicBlock {
292 name:string; // basic block name
293 operators:[TosaOperator]; // operators array
294 tensors:[TosaTensor]; // tensors array
295 inputs:[string]; // name of graph inputs
296 outputs:[string]; // name of graph outputs
297}
298
Jerry Ge13c78a62022-10-04 20:32:39 -0700299table TosaRegion {
300 name:string; // name of region
301 blocks:[TosaBasicBlock]; // basic blocks array
302}
303
Eric Kunze2364dcd2021-04-26 11:06:57 -0700304table TosaGraph {
Eric Kunzef08956b2023-05-18 01:13:41 +0000305 version:Version (required);
Jerry Ge13c78a62022-10-04 20:32:39 -0700306 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700307}
308
309root_type TosaGraph;