blob: 54b907931b7d60067387e17c3f28bef113cbfd7d [file] [log] [blame]
Eric Kunze2364dcd2021-04-26 11:06:57 -07001
2// Copyright (c) 2020-2021, ARM Limited.
3//
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,
164 NegateAttribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700165}
166
Kevin Cheng79a41992021-08-31 16:04:40 -0700167table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700168 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700169 kernel: [int32];
170 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000171 input_zp: int32;
172 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100173 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700174}
175
Kevin Cheng79a41992021-08-31 16:04:40 -0700176table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700177 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700178 stride: [int32];
179 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000180 input_zp: int32;
181 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100182 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700183}
184
Kevin Cheng79a41992021-08-31 16:04:40 -0700185table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700186 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700187 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700188 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000189 input_zp: int32;
190 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100191 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700192}
193
Kevin Cheng38d214c2021-10-15 15:49:19 -0700194table PadAttribute {
195 padding: [int32];
196 pad_const_int: int32;
197 pad_const_fp: float;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700198}
199
200table AxisAttribute {
201 axis: int32;
202}
203
204table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700205 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700206}
207
208table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700209 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700210 size: [int32];
211}
212
213table TileAttribute {
214 multiples: [int32];
215}
216
217table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700218 scale: [int16];
219 offset: [int16];
220 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700221 mode: ResizeMode;
222}
223
224table ClampAttribute {
225 min_int: int32;
226 max_int: int32;
227 min_fp: float;
228 max_fp: float;
229}
230
231table RescaleAttribute {
232 input_zp: int32;
233 output_zp: int32;
234 multiplier: [int32];
235 shift: [int32];
236 scale32: bool;
237 double_round: bool;
238 per_channel: bool;
239}
240
241table MulAttribute {
242 shift: int32;
243}
244
245table ArithmeticRightShiftAttribute {
246 round: bool;
247}
248
249table CondIfAttribute {
250 then_branch: string;
251 else_branch: string;
252}
253
254table WhileLoopAttribute {
255 cond_branch: string;
256 body_branch: string;
257}
258
Kevin Cheng38d214c2021-10-15 15:49:19 -0700259table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700260 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700261}
262
263table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700264 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700265}
266
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000267table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700268 a_zp: int32;
269 b_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100270 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700271}
272
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000273table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700274 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000275 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100276 accum_dtype: DType;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000277}
278
279table NegateAttribute {
280 input1_zp: int32;
281 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700282}
283
284table Version {
285 _major: int32 = 0;
Eric Kunze9e2e0bb2022-12-05 23:23:54 +0000286 _minor: int32 = 50;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700287 _patch: int32 = 0;
Eric Kunze9e2e0bb2022-12-05 23:23:54 +0000288 _draft: bool = false;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700289}
290
291table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700292 name:string; // name of the tensor, used for solving dependency
293 shape:[int32]; // shape of the tensor
294 type:DType; // data type of the tensor
295 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700296}
297
298table TosaOperator {
299 op:Op; // operator enum
300 attribute: Attribute; // union structure. operator attribute
301 inputs:[string]; // list of input tensor names
302 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700303}
304
305table TosaBasicBlock {
306 name:string; // basic block name
307 operators:[TosaOperator]; // operators array
308 tensors:[TosaTensor]; // tensors array
309 inputs:[string]; // name of graph inputs
310 outputs:[string]; // name of graph outputs
311}
312
313table TosaGraph {
314 version: Version;
315 blocks:[TosaBasicBlock]; // basic blocks array
316}
317
318root_type TosaGraph;