blob: eb76f756e82839eb6fc25db1e0f241ea2427fbc3 [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,
Eric Kunze2364dcd2021-04-26 11:06:57 -070035}
36
37enum ResizeMode:uint32 {
38 UNKNOWN = 0,
39 NEAREST,
40 BILINEAR,
41}
42
43enum Op:uint32 {
44 UNKNOWN = 0,
45
46 // Tensor Operator
47 ARGMAX,
48 AVG_POOL2D,
49 CONV2D,
50 CONV3D,
51 DEPTHWISE_CONV2D,
52 FULLY_CONNECTED,
53 MATMUL,
54 MAX_POOL2D,
55 TRANSPOSE_CONV2D,
56
57 // Activation
58 CLAMP,
Kevin Cheng38d214c2021-10-15 15:49:19 -070059 RESERVED,
Eric Kunze2364dcd2021-04-26 11:06:57 -070060 SIGMOID,
61 TANH,
62
63 // Elementwise-Binary
64 ADD,
65 ARITHMETIC_RIGHT_SHIFT,
66 BITWISE_AND,
67 BITWISE_OR,
68 BITWISE_XOR,
Matthew Haddonab905ec2021-08-23 16:40:57 +010069 INTDIV,
Eric Kunze2364dcd2021-04-26 11:06:57 -070070 LOGICAL_AND,
71 LOGICAL_LEFT_SHIFT,
72 LOGICAL_RIGHT_SHIFT,
73 LOGICAL_OR,
74 LOGICAL_XOR,
75 MAXIMUM,
76 MINIMUM,
77 MUL,
78 POW,
79 SUB,
80 TABLE,
81
82 // Elementwise-Unary
83 ABS,
84 BITWISE_NOT,
85 CEIL,
86 CLZ,
87 EXP,
88 FLOOR,
89 LOG,
90 LOGICAL_NOT,
91 NEGATE,
92 RECIPROCAL,
93 RSQRT,
94
95 // Elementwise-Ternary
96 SELECT,
97
98 // Logical
99 EQUAL,
100 GREATER,
101 GREATER_EQUAL,
102
103 // Reduction
104 REDUCE_ANY,
105 REDUCE_ALL,
106 REDUCE_MAX,
107 REDUCE_MIN,
108 REDUCE_PRODUCT,
109 REDUCE_SUM,
110
111 // Data layout operation
112 CONCAT,
113 PAD,
114 RESHAPE,
115 REVERSE,
116 SLICE,
117 TILE,
118 TRANSPOSE,
119
120 // Gather/scatter operation
121 GATHER,
122 SCATTER,
123
124 // Image
125 RESIZE,
126
127 // Type conversion
128 CAST,
129 RESCALE,
130
131 // Data Nodes
132 CONST,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700133 IDENTITY,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700134
135 // Custom operations
136 CUSTOM,
137
138 // Control flow operators
139 COND_IF,
140 WHILE_LOOP,
141}
142
143union Attribute {
Kevin Cheng79a41992021-08-31 16:04:40 -0700144 PoolAttribute,
145 ConvAttribute,
146 TransposeConvAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700147 PadAttribute,
Eric Kunze2364dcd2021-04-26 11:06:57 -0700148 AxisAttribute,
149 ReshapeAttribute,
150 SliceAttribute,
151 TileAttribute,
152 ResizeAttribute,
153 ClampAttribute,
154 RescaleAttribute,
155 MulAttribute,
156 ArithmeticRightShiftAttribute,
157 CondIfAttribute,
158 WhileLoopAttribute,
Kevin Cheng38d214c2021-10-15 15:49:19 -0700159 TransposeAttribute,
160 TableAttribute,
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000161 MatMulAttribute,
162 FullyConnectedAttribute,
163 NegateAttribute
Eric Kunze2364dcd2021-04-26 11:06:57 -0700164}
165
Kevin Cheng79a41992021-08-31 16:04:40 -0700166table PoolAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700167 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700168 kernel: [int32];
169 stride: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000170 input_zp: int32;
171 output_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100172 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700173}
174
Kevin Cheng79a41992021-08-31 16:04:40 -0700175table ConvAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700176 pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700177 stride: [int32];
178 dilation: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000179 input_zp: int32;
180 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100181 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700182}
183
Kevin Cheng79a41992021-08-31 16:04:40 -0700184table TransposeConvAttribute {
Eric Kunze7ffa1ff2022-06-01 17:26:48 -0700185 out_pad: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700186 stride: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700187 output_shape: [int32];
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000188 input_zp: int32;
189 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100190 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700191}
192
Kevin Cheng38d214c2021-10-15 15:49:19 -0700193table PadAttribute {
194 padding: [int32];
195 pad_const_int: int32;
196 pad_const_fp: float;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700197}
198
199table AxisAttribute {
200 axis: int32;
201}
202
203table ReshapeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700204 new_shape: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700205}
206
207table SliceAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700208 start: [int32];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700209 size: [int32];
210}
211
212table TileAttribute {
213 multiples: [int32];
214}
215
216table ResizeAttribute {
TatWai Chong49b1ca62022-06-10 01:49:13 -0700217 scale: [int16];
218 offset: [int16];
219 border: [int16];
Eric Kunze2364dcd2021-04-26 11:06:57 -0700220 mode: ResizeMode;
221}
222
223table ClampAttribute {
224 min_int: int32;
225 max_int: int32;
226 min_fp: float;
227 max_fp: float;
228}
229
230table RescaleAttribute {
231 input_zp: int32;
232 output_zp: int32;
233 multiplier: [int32];
234 shift: [int32];
235 scale32: bool;
236 double_round: bool;
237 per_channel: bool;
238}
239
240table MulAttribute {
241 shift: int32;
242}
243
244table ArithmeticRightShiftAttribute {
245 round: bool;
246}
247
248table CondIfAttribute {
249 then_branch: string;
250 else_branch: string;
251}
252
253table WhileLoopAttribute {
254 cond_branch: string;
255 body_branch: string;
256}
257
Kevin Cheng38d214c2021-10-15 15:49:19 -0700258table TransposeAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700259 perms: [int32];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700260}
261
262table TableAttribute {
TatWai Chong7be71652022-05-10 17:26:20 -0700263 table: [int16];
Kevin Cheng38d214c2021-10-15 15:49:19 -0700264}
265
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000266table MatMulAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700267 a_zp: int32;
268 b_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100269 accum_dtype: DType;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700270}
271
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000272table FullyConnectedAttribute {
Eric Kunze2364dcd2021-04-26 11:06:57 -0700273 input_zp: int32;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000274 weight_zp: int32;
James Ward485a11d2022-08-05 13:48:37 +0100275 accum_dtype: DType;
Eric Kunzebdcc3fe2022-06-07 05:17:37 +0000276}
277
278table NegateAttribute {
279 input1_zp: int32;
280 output_zp: int32;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700281}
282
283table Version {
284 _major: int32 = 0;
Eric Kunze24a68bb2022-09-08 23:54:21 +0000285 _minor: int32 = 41;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700286 _patch: int32 = 0;
Eric Kunze24a68bb2022-09-08 23:54:21 +0000287 _draft: bool = true;
Eric Kunze2364dcd2021-04-26 11:06:57 -0700288}
289
290table TosaTensor {
Kevin Cheng3bb1bc12021-06-17 15:57:08 -0700291 name:string; // name of the tensor, used for solving dependency
292 shape:[int32]; // shape of the tensor
293 type:DType; // data type of the tensor
294 data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor.
Eric Kunze2364dcd2021-04-26 11:06:57 -0700295}
296
297table TosaOperator {
298 op:Op; // operator enum
299 attribute: Attribute; // union structure. operator attribute
300 inputs:[string]; // list of input tensor names
301 outputs:[string]; // list of output tensor names
Eric Kunze2364dcd2021-04-26 11:06:57 -0700302}
303
304table TosaBasicBlock {
305 name:string; // basic block name
306 operators:[TosaOperator]; // operators array
307 tensors:[TosaTensor]; // tensors array
308 inputs:[string]; // name of graph inputs
309 outputs:[string]; // name of graph outputs
310}
311
312table TosaGraph {
313 version: Version;
314 blocks:[TosaBasicBlock]; // basic blocks array
315}
316
317root_type TosaGraph;