blob: 093c235317530e4bd7d0544d02de476f05f27de9 [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
23enum DType:uint32 {
24 UNKNOWN = 0,
25 BOOL,
26 UINT8,
27 INT4,
28 INT8,
29 INT16,
30 INT32,
31 INT48,
Jeremy Johnsone1072a92022-09-27 12:44:11 +010032 FP32,
Jeremy Johnson41027732022-05-25 17:52:29 +010033 UINT16,
James Ward485a11d2022-08-05 13:48:37 +010034 FP16,
James Ward34a62792022-10-18 17:27:40 +010035 BF16,
Eric Kunze2364dcd2021-04-26 11:06:57 -070036}
37
38enum ResizeMode:uint32 {
39 UNKNOWN = 0,
40 NEAREST,
41 BILINEAR,
42}
43
44enum Op:uint32 {
45 UNKNOWN = 0,
46
47 // Tensor Operator
48 ARGMAX,
49 AVG_POOL2D,
50 CONV2D,
51 CONV3D,
52 DEPTHWISE_CONV2D,
53 FULLY_CONNECTED,
54 MATMUL,
55 MAX_POOL2D,
56 TRANSPOSE_CONV2D,
57
58 // Activation
59 CLAMP,
Kevin Cheng38d214c2021-10-15 15:49:19 -070060 RESERVED,
Eric Kunze2364dcd2021-04-26 11:06:57 -070061 SIGMOID,
62 TANH,
63
64 // Elementwise-Binary
65 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,
82
83 // Elementwise-Unary
84 ABS,
85 BITWISE_NOT,
86 CEIL,
87 CLZ,
88 EXP,
89 FLOOR,
90 LOG,
91 LOGICAL_NOT,
92 NEGATE,
93 RECIPROCAL,
94 RSQRT,
95
96 // Elementwise-Ternary
97 SELECT,
98
99 // Logical
100 EQUAL,
101 GREATER,
102 GREATER_EQUAL,
103
104 // Reduction
105 REDUCE_ANY,
106 REDUCE_ALL,
107 REDUCE_MAX,
108 REDUCE_MIN,
109 REDUCE_PRODUCT,
110 REDUCE_SUM,
111
112 // Data layout operation
113 CONCAT,
114 PAD,
115 RESHAPE,
116 REVERSE,
117 SLICE,
118 TILE,
119 TRANSPOSE,
120
121 // Gather/scatter operation
122 GATHER,
123 SCATTER,
124
125 // Image
126 RESIZE,
127
128 // Type conversion
129 CAST,
130 RESCALE,
131
132 // Data Nodes
133 CONST,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700134 IDENTITY,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700135
136 // Custom operations
137 CUSTOM,
138
139 // Control flow operators
140 COND_IF,
141 WHILE_LOOP,
142}
143
144union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700145 PoolAttribute,
146 ConvAttribute,
147 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700148 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700149 AxisAttribute,
150 ReshapeAttribute,
151 SliceAttribute,
152 TileAttribute,
153 ResizeAttribute,
154 ClampAttribute,
155 RescaleAttribute,
156 MulAttribute,
157 ArithmeticRightShiftAttribute,
158 CondIfAttribute,
159 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700160 TransposeAttribute,
161 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000162 MatMulAttribute,
163 FullyConnectedAttribute,
Eric Kunze497ab5d2022-10-21 16:39:01 -0700164 NegateAttribute,
165 CustomAttribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700166}
167
Kevin Cheng79a41992021-08-31 16:04:40 -0700168table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700169 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700170 kernel: [int32];
171 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000172 input_zp: int32;
173 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100174 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700175}
176
Kevin Cheng79a41992021-08-31 16:04:40 -0700177table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700178 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700179 stride: [int32];
180 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000181 input_zp: int32;
182 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100183 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700184}
185
Kevin Cheng79a41992021-08-31 16:04:40 -0700186table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700187 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700188 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700189 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000190 input_zp: int32;
191 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100192 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700193}
194
Kevin Cheng38d214c2021-10-15 15:49:19 -0700195table PadAttribute {
196 padding: [int32];
197 pad_const_int: int32;
198 pad_const_fp: float;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700199}
200
201table AxisAttribute {
202 axis: int32;
203}
204
205table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700206 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700207}
208
209table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700210 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700211 size: [int32];
212}
213
214table TileAttribute {
215 multiples: [int32];
216}
217
218table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700219 scale: [int16];
220 offset: [int16];
221 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700222 mode: ResizeMode;
223}
224
225table ClampAttribute {
226 min_int: int32;
227 max_int: int32;
228 min_fp: float;
229 max_fp: float;
230}
231
232table RescaleAttribute {
233 input_zp: int32;
234 output_zp: int32;
235 multiplier: [int32];
236 shift: [int32];
237 scale32: bool;
238 double_round: bool;
239 per_channel: bool;
240}
241
242table MulAttribute {
243 shift: int32;
244}
245
246table ArithmeticRightShiftAttribute {
247 round: bool;
248}
249
250table CondIfAttribute {
251 then_branch: string;
252 else_branch: string;
253}
254
255table WhileLoopAttribute {
256 cond_branch: string;
257 body_branch: string;
258}
259
Kevin Cheng38d214c2021-10-15 15:49:19 -0700260table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700261 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700262}
263
264table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700265 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700266}
267
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000268table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700269 a_zp: int32;
270 b_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100271 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700272}
273
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000274table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700275 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000276 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100277 accum_dtype: DType;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000278}
279
280table NegateAttribute {
281 input1_zp: int32;
282 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700283}
284
Eric Kunze497ab5d2022-10-21 16:39:01 -0700285table CustomAttribute {
286 identifier:string;
287 config:string;
288 implementation_attrs:[ubyte];
289}
290
Eric Kunze2364dcd2021-04-26 11:06:57 -0700291table Version {
292 _major: int32 = 0;
Eric Kunze6388a092022-12-07 21:59:31 +0000293 _minor: int32 = 51;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700294 _patch: int32 = 0;
Eric Kunze6388a092022-12-07 21:59:31 +0000295 _draft: bool = true;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700296}
297
298table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700299 name:string; // name of the tensor, used for solving dependency
300 shape:[int32]; // shape of the tensor
301 type:DType; // data type of the tensor
302 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700303}
304
305table TosaOperator {
306 op:Op; // operator enum
Jerry Ge13c78a62022-10-04 20:32:39 -0700307 attribute:Attribute; // union structure. operator attribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700308 inputs:[string]; // list of input tensor names
309 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700310}
311
312table TosaBasicBlock {
313 name:string; // basic block name
314 operators:[TosaOperator]; // operators array
315 tensors:[TosaTensor]; // tensors array
316 inputs:[string]; // name of graph inputs
317 outputs:[string]; // name of graph outputs
318}
319
Jerry Ge13c78a62022-10-04 20:32:39 -0700320table TosaRegion {
321 name:string; // name of region
322 blocks:[TosaBasicBlock]; // basic blocks array
323}
324
Eric Kunze2364dcd2021-04-26 11:06:57 -0700325table TosaGraph {
Jerry Ge13c78a62022-10-04 20:32:39 -0700326 version:Version;
327 regions:[TosaRegion]; // regions array
Eric Kunze2364dcd2021-04-26 11:06:57 -0700328}
329
330root_type TosaGraph;