blob: 79b83b1b0f66826652b38082ec11666b6d7ae263 [file] [log] [blame]
Eric Kunze2364dcd2021-04-26 11:06:57 -07001
Tai Ly5d580fa2023-12-15 20:34:51 +00002// Copyright (c) 2020-2024, 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,
Won Jeona029f1f2023-12-29 22:43:11 +000040 FP8E4M3,
41 FP8E5M2,
Eric Kunze2364dcd2021-04-26 11:06:57 -070042}
43
44enum ResizeMode:uint32 {
45 UNKNOWN = 0,
46 NEAREST,
47 BILINEAR,
48}
49
50enum Op:uint32 {
51 UNKNOWN = 0,
Eric Kunze2364dcd2021-04-26 11:06:57 -070052 ARGMAX,
53 AVG_POOL2D,
54 CONV2D,
55 CONV3D,
56 DEPTHWISE_CONV2D,
57 FULLY_CONNECTED,
58 MATMUL,
59 MAX_POOL2D,
60 TRANSPOSE_CONV2D,
Eric Kunze2364dcd2021-04-26 11:06:57 -070061 CLAMP,
Kevin Cheng38d214c2021-10-15 15:49:19 -070062 RESERVED,
Eric Kunze2364dcd2021-04-26 11:06:57 -070063 SIGMOID,
64 TANH,
Eric Kunze2364dcd2021-04-26 11:06:57 -070065 ADD,
66 ARITHMETIC_RIGHT_SHIFT,
67 BITWISE_AND,
68 BITWISE_OR,
69 BITWISE_XOR,
Matthew Haddonab905ec2021-08-23 16:40:57 +010070 INTDIV,
Eric Kunze2364dcd2021-04-26 11:06:57 -070071 LOGICAL_AND,
72 LOGICAL_LEFT_SHIFT,
73 LOGICAL_RIGHT_SHIFT,
74 LOGICAL_OR,
75 LOGICAL_XOR,
76 MAXIMUM,
77 MINIMUM,
78 MUL,
79 POW,
80 SUB,
81 TABLE,
Eric Kunze2364dcd2021-04-26 11:06:57 -070082 ABS,
83 BITWISE_NOT,
84 CEIL,
85 CLZ,
86 EXP,
87 FLOOR,
88 LOG,
89 LOGICAL_NOT,
90 NEGATE,
91 RECIPROCAL,
92 RSQRT,
Eric Kunze2364dcd2021-04-26 11:06:57 -070093 SELECT,
Eric Kunze2364dcd2021-04-26 11:06:57 -070094 EQUAL,
95 GREATER,
96 GREATER_EQUAL,
Eric Kunze2364dcd2021-04-26 11:06:57 -070097 REDUCE_ANY,
98 REDUCE_ALL,
99 REDUCE_MAX,
100 REDUCE_MIN,
101 REDUCE_PRODUCT,
102 REDUCE_SUM,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700103 CONCAT,
104 PAD,
105 RESHAPE,
106 REVERSE,
107 SLICE,
108 TILE,
109 TRANSPOSE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700110 GATHER,
111 SCATTER,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700112 RESIZE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700113 CAST,
114 RESCALE,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700115 CONST,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700116 IDENTITY,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700117 CUSTOM,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700118 COND_IF,
119 WHILE_LOOP,
Luke Hutton5e268092023-01-12 22:20:53 +0000120 FFT2D,
121 RFFT2D,
Won Jeon3acb1cb2023-06-07 23:26:32 +0000122 ERF,
Won Jeoncb4bbf42023-08-10 08:50:15 +0000123 DIM,
Tai Ly5d580fa2023-12-15 20:34:51 +0000124 CONST_SHAPE,
125 CONCAT_SHAPE,
126 ADD_SHAPE,
127 SUB_SHAPE,
128 MUL_SHAPE,
129 DIV_SHAPE,
Jerry Ge61a83132024-02-20 19:03:06 +0000130 COS,
131 SIN,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700132}
133
134union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700135 PoolAttribute,
136 ConvAttribute,
137 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700138 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700139 AxisAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700140 ResizeAttribute,
141 ClampAttribute,
142 RescaleAttribute,
143 MulAttribute,
144 ArithmeticRightShiftAttribute,
145 CondIfAttribute,
146 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700147 TransposeAttribute,
148 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000149 MatMulAttribute,
150 FullyConnectedAttribute,
Eric Kunze497ab5d2022-10-21 16:39:01 -0700151 NegateAttribute,
Luke Hutton5e268092023-01-12 22:20:53 +0000152 CustomAttribute,
153 FFTAttribute,
Eric Kunze4881c292023-11-01 16:12:07 -0700154 RFFTAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700155}
156
Kevin Cheng79a41992021-08-31 16:04:40 -0700157table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700158 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700159 kernel: [int32];
160 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000161 input_zp: int32;
162 output_zp: int32;
Tai Ly81db8ee2024-02-14 19:57:38 +0000163 acc_type: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700164}
165
Kevin Cheng79a41992021-08-31 16:04:40 -0700166table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700167 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700168 stride: [int32];
169 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000170 input_zp: int32;
171 weight_zp: int32;
Eric Kunze4881c292023-11-01 16:12:07 -0700172 local_bound: bool;
Tai Lyad78daa2024-03-13 18:52:45 +0000173 acc_type: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700174}
175
Kevin Cheng79a41992021-08-31 16:04:40 -0700176table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700177 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700178 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700179 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000180 input_zp: int32;
181 weight_zp: int32;
Eric Kunze4881c292023-11-01 16:12:07 -0700182 local_bound: bool;
Tai Lyad78daa2024-03-13 18:52:45 +0000183 acc_type: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700184}
185
Kevin Cheng38d214c2021-10-15 15:49:19 -0700186table PadAttribute {
Tai Ly0b6d7c22024-03-08 17:03:25 +0000187 pad_const: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700188}
189
190table AxisAttribute {
191 axis: int32;
192}
193
Eric Kunze2364dcd2021-04-26 11:06:57 -0700194table 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 {
Tai Ly0b6d7c22024-03-08 17:03:25 +0000202 min_val: [ubyte] (force_align: 8);
203 max_val: [ubyte] (force_align: 8);
Eric Kunze2364dcd2021-04-26 11:06:57 -0700204}
205
206table RescaleAttribute {
207 input_zp: int32;
208 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700209 scale32: bool;
210 double_round: bool;
211 per_channel: bool;
Eric Kunze9601cbd2023-08-17 20:44:39 +0000212 input_unsigned: bool;
213 output_unsigned: bool;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700214}
215
216table MulAttribute {
217 shift: int32;
218}
219
220table ArithmeticRightShiftAttribute {
221 round: bool;
222}
223
224table CondIfAttribute {
Tai Ly81db8ee2024-02-14 19:57:38 +0000225 then_graph: string;
226 else_graph: string;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700227}
228
229table WhileLoopAttribute {
Tai Ly81db8ee2024-02-14 19:57:38 +0000230 cond_graph: string;
231 body_graph: string;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700232}
233
Kevin Cheng38d214c2021-10-15 15:49:19 -0700234table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700235 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700236}
237
238table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700239 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700240}
241
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000242table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700243 a_zp: int32;
244 b_zp: int32;
245}
246
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000247table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700248 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000249 weight_zp: int32;
250}
251
252table NegateAttribute {
253 input1_zp: int32;
254 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700255}
256
Eric Kunze497ab5d2022-10-21 16:39:01 -0700257table CustomAttribute {
Jerry Gecd914da2023-11-09 18:41:12 +0000258 operator_name:string;
259 domain_name:string;
Eric Kunze497ab5d2022-10-21 16:39:01 -0700260 implementation_attrs:[ubyte];
261}
262
Luke Hutton5e268092023-01-12 22:20:53 +0000263table FFTAttribute {
264 inverse: bool;
Eric Kunze4881c292023-11-01 16:12:07 -0700265 local_bound: bool;
266}
267
268table RFFTAttribute {
269 local_bound: bool;
Luke Hutton5e268092023-01-12 22:20:53 +0000270}
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.
Jerry Ge442261b2022-09-09 13:38:56 -0700284 variable: bool; // is this a variable tensor
Tai Lyc6939a42023-08-21 17:00:29 +0000285 is_unranked: bool; // whether this is an unranked tensor
Tai Lyd0520b92023-09-19 21:30:18 +0000286 variable_name:string; // name for variable attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700287}
288
289table TosaOperator {
290 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700291 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700292 inputs:[string]; // list of input tensor names
293 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700294}
295
296table TosaBasicBlock {
297 name:string; // basic block name
298 operators:[TosaOperator]; // operators array
299 tensors:[TosaTensor]; // tensors array
300 inputs:[string]; // name of graph inputs
301 outputs:[string]; // name of graph outputs
302}
303
Jerry Ge13c78a62022-10-04 20:32:39 -0700304table TosaRegion {
305 name:string; // name of region
306 blocks:[TosaBasicBlock]; // basic blocks array
307}
308
Eric Kunze2364dcd2021-04-26 11:06:57 -0700309table TosaGraph {
Eric Kunzef08956b2023-05-18 01:13:41 +0000310 version:Version (required);
Jerry Ge13c78a62022-10-04 20:32:39 -0700311 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700312}
313
314root_type TosaGraph;