blob: d022a9be7c52ed9e6ff6cc7cac058cc1bdf7afcb [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;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700161}
162
Kevin Cheng79a41992021-08-31 16:04:40 -0700163table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700164 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700165 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700166 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000167 input_zp: int32;
168 weight_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700169}
170
Kevin Cheng38d214c2021-10-15 15:49:19 -0700171table PadAttribute {
172 padding: [int32];
173 pad_const_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000174 pad_const_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700175}
176
177table AxisAttribute {
178 axis: int32;
179}
180
181table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700182 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700183}
184
185table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700186 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700187 size: [int32];
188}
189
190table TileAttribute {
191 multiples: [int32];
192}
193
194table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700195 scale: [int16];
196 offset: [int16];
197 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700198 mode: ResizeMode;
199}
200
201table ClampAttribute {
202 min_int: int32;
203 max_int: int32;
James Wardc15f7d52022-12-07 15:38:01 +0000204 min_fp: [ubyte] (force_align: 8);
205 max_fp: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700206}
207
208table RescaleAttribute {
209 input_zp: int32;
210 output_zp: int32;
211 multiplier: [int32];
212 shift: [int32];
213 scale32: bool;
214 double_round: bool;
215 per_channel: bool;
216}
217
218table MulAttribute {
219 shift: int32;
220}
221
222table ArithmeticRightShiftAttribute {
223 round: bool;
224}
225
226table CondIfAttribute {
227 then_branch: string;
228 else_branch: string;
229}
230
231table WhileLoopAttribute {
232 cond_branch: string;
233 body_branch: string;
234}
235
Kevin Cheng38d214c2021-10-15 15:49:19 -0700236table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700237 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700238}
239
240table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700241 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700242}
243
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000244table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700245 a_zp: int32;
246 b_zp: int32;
247}
248
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000249table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700250 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000251 weight_zp: int32;
252}
253
254table NegateAttribute {
255 input1_zp: int32;
256 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700257}
258
Eric Kunze497ab5d2022-10-21 16:39:01 -0700259table CustomAttribute {
260 identifier:string;
261 config:string;
262 implementation_attrs:[ubyte];
263}
264
Luke Hutton5e268092023-01-12 22:20:53 +0000265table FFTAttribute {
266 inverse: bool;
267}
268
Eric Kunze2364dcd2021-04-26 11:06:57 -0700269table Version {
270 _major: int32 = 0;
Eric Kunzefb90dd42023-03-08 13:07:07 -0800271 _minor: int32 = 60;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700272 _patch: int32 = 0;
Eric Kunzefb90dd42023-03-08 13:07:07 -0800273 _draft: bool = false;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700274}
275
276table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700277 name:string; // name of the tensor, used for solving dependency
278 shape:[int32]; // shape of the tensor
279 type:DType; // data type of the tensor
280 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700281}
282
283table TosaOperator {
284 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700285 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700286 inputs:[string]; // list of input tensor names
287 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700288}
289
290table TosaBasicBlock {
291 name:string; // basic block name
292 operators:[TosaOperator]; // operators array
293 tensors:[TosaTensor]; // tensors array
294 inputs:[string]; // name of graph inputs
295 outputs:[string]; // name of graph outputs
296}
297
Jerry Ge13c78a62022-10-04 20:32:39 -0700298table TosaRegion {
299 name:string; // name of region
300 blocks:[TosaBasicBlock]; // basic blocks array
301}
302
Eric Kunze2364dcd2021-04-26 11:06:57 -0700303table TosaGraph {
Jerry Ge13c78a62022-10-04 20:32:39 -0700304 version:Version;
305 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700306}
307
308root_type TosaGraph;