Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 1 | |
Tai Ly | 5d580fa | 2023-12-15 20:34:51 +0000 | [diff] [blame] | 2 | // Copyright (c) 2020-2024, ARM Limited. |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 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 | |
| 16 | namespace tosa; |
| 17 | |
| 18 | // This corresponds to the version. |
| 19 | file_identifier "TOSA"; |
| 20 | // File extension of any written files. |
| 21 | file_extension "tosa"; |
| 22 | |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 23 | // 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 Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 26 | enum DType:uint32 { |
| 27 | UNKNOWN = 0, |
| 28 | BOOL, |
| 29 | UINT8, |
| 30 | INT4, |
| 31 | INT8, |
| 32 | INT16, |
| 33 | INT32, |
| 34 | INT48, |
Jeremy Johnson | e1072a9 | 2022-09-27 12:44:11 +0100 | [diff] [blame] | 35 | FP32, |
Jeremy Johnson | 4102773 | 2022-05-25 17:52:29 +0100 | [diff] [blame] | 36 | UINT16, |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 37 | FP16, |
James Ward | 34a6279 | 2022-10-18 17:27:40 +0100 | [diff] [blame] | 38 | BF16, |
Won Jeon | cb4bbf4 | 2023-08-10 08:50:15 +0000 | [diff] [blame] | 39 | SHAPE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | enum ResizeMode:uint32 { |
| 43 | UNKNOWN = 0, |
| 44 | NEAREST, |
| 45 | BILINEAR, |
| 46 | } |
| 47 | |
| 48 | enum Op:uint32 { |
| 49 | UNKNOWN = 0, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 50 | ARGMAX, |
| 51 | AVG_POOL2D, |
| 52 | CONV2D, |
| 53 | CONV3D, |
| 54 | DEPTHWISE_CONV2D, |
| 55 | FULLY_CONNECTED, |
| 56 | MATMUL, |
| 57 | MAX_POOL2D, |
| 58 | TRANSPOSE_CONV2D, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 59 | CLAMP, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 60 | RESERVED, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 61 | SIGMOID, |
| 62 | TANH, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 63 | ADD, |
| 64 | ARITHMETIC_RIGHT_SHIFT, |
| 65 | BITWISE_AND, |
| 66 | BITWISE_OR, |
| 67 | BITWISE_XOR, |
Matthew Haddon | ab905ec | 2021-08-23 16:40:57 +0100 | [diff] [blame] | 68 | INTDIV, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 69 | LOGICAL_AND, |
| 70 | LOGICAL_LEFT_SHIFT, |
| 71 | LOGICAL_RIGHT_SHIFT, |
| 72 | LOGICAL_OR, |
| 73 | LOGICAL_XOR, |
| 74 | MAXIMUM, |
| 75 | MINIMUM, |
| 76 | MUL, |
| 77 | POW, |
| 78 | SUB, |
| 79 | TABLE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 80 | ABS, |
| 81 | BITWISE_NOT, |
| 82 | CEIL, |
| 83 | CLZ, |
| 84 | EXP, |
| 85 | FLOOR, |
| 86 | LOG, |
| 87 | LOGICAL_NOT, |
| 88 | NEGATE, |
| 89 | RECIPROCAL, |
| 90 | RSQRT, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 91 | SELECT, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 92 | EQUAL, |
| 93 | GREATER, |
| 94 | GREATER_EQUAL, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 95 | REDUCE_ANY, |
| 96 | REDUCE_ALL, |
| 97 | REDUCE_MAX, |
| 98 | REDUCE_MIN, |
| 99 | REDUCE_PRODUCT, |
| 100 | REDUCE_SUM, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 101 | CONCAT, |
| 102 | PAD, |
| 103 | RESHAPE, |
| 104 | REVERSE, |
| 105 | SLICE, |
| 106 | TILE, |
| 107 | TRANSPOSE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 108 | GATHER, |
| 109 | SCATTER, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 110 | RESIZE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 111 | CAST, |
| 112 | RESCALE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 113 | CONST, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 114 | IDENTITY, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 115 | CUSTOM, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 116 | COND_IF, |
| 117 | WHILE_LOOP, |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 118 | FFT2D, |
| 119 | RFFT2D, |
Won Jeon | 3acb1cb | 2023-06-07 23:26:32 +0000 | [diff] [blame] | 120 | ERF, |
Won Jeon | cb4bbf4 | 2023-08-10 08:50:15 +0000 | [diff] [blame] | 121 | DIM, |
Tai Ly | 5d580fa | 2023-12-15 20:34:51 +0000 | [diff] [blame] | 122 | CONST_SHAPE, |
| 123 | CONCAT_SHAPE, |
| 124 | ADD_SHAPE, |
| 125 | SUB_SHAPE, |
| 126 | MUL_SHAPE, |
| 127 | DIV_SHAPE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | union Attribute { |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 131 | PoolAttribute, |
| 132 | ConvAttribute, |
| 133 | TransposeConvAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 134 | PadAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 135 | AxisAttribute, |
| 136 | ReshapeAttribute, |
| 137 | SliceAttribute, |
| 138 | TileAttribute, |
| 139 | ResizeAttribute, |
| 140 | ClampAttribute, |
| 141 | RescaleAttribute, |
| 142 | MulAttribute, |
| 143 | ArithmeticRightShiftAttribute, |
| 144 | CondIfAttribute, |
| 145 | WhileLoopAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 146 | TransposeAttribute, |
| 147 | TableAttribute, |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 148 | MatMulAttribute, |
| 149 | FullyConnectedAttribute, |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 150 | NegateAttribute, |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 151 | CustomAttribute, |
| 152 | FFTAttribute, |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 153 | RFFTAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 156 | table PoolAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 157 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 158 | kernel: [int32]; |
| 159 | stride: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 160 | input_zp: int32; |
| 161 | output_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 162 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 165 | table ConvAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 166 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 167 | stride: [int32]; |
| 168 | dilation: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 169 | input_zp: int32; |
| 170 | weight_zp: int32; |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 171 | local_bound: bool; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 174 | table TransposeConvAttribute { |
Eric Kunze | 7ffa1ff | 2022-06-01 17:26:48 -0700 | [diff] [blame] | 175 | out_pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 176 | stride: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 177 | output_shape: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 178 | input_zp: int32; |
| 179 | weight_zp: int32; |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 180 | local_bound: bool; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 183 | table PadAttribute { |
| 184 | padding: [int32]; |
| 185 | pad_const_int: int32; |
James Ward | c15f7d5 | 2022-12-07 15:38:01 +0000 | [diff] [blame] | 186 | pad_const_fp: [ubyte] (force_align: 8); |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | table AxisAttribute { |
| 190 | axis: int32; |
| 191 | } |
| 192 | |
| 193 | table ReshapeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 194 | new_shape: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | table SliceAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 198 | start: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 199 | size: [int32]; |
| 200 | } |
| 201 | |
| 202 | table TileAttribute { |
| 203 | multiples: [int32]; |
| 204 | } |
| 205 | |
| 206 | table ResizeAttribute { |
TatWai Chong | 49b1ca6 | 2022-06-10 01:49:13 -0700 | [diff] [blame] | 207 | scale: [int16]; |
| 208 | offset: [int16]; |
| 209 | border: [int16]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 210 | mode: ResizeMode; |
| 211 | } |
| 212 | |
| 213 | table ClampAttribute { |
| 214 | min_int: int32; |
| 215 | max_int: int32; |
James Ward | c15f7d5 | 2022-12-07 15:38:01 +0000 | [diff] [blame] | 216 | min_fp: [ubyte] (force_align: 8); |
| 217 | max_fp: [ubyte] (force_align: 8); |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | table RescaleAttribute { |
| 221 | input_zp: int32; |
| 222 | output_zp: int32; |
| 223 | multiplier: [int32]; |
| 224 | shift: [int32]; |
| 225 | scale32: bool; |
| 226 | double_round: bool; |
| 227 | per_channel: bool; |
Eric Kunze | 9601cbd | 2023-08-17 20:44:39 +0000 | [diff] [blame] | 228 | input_unsigned: bool; |
| 229 | output_unsigned: bool; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | table MulAttribute { |
| 233 | shift: int32; |
| 234 | } |
| 235 | |
| 236 | table ArithmeticRightShiftAttribute { |
| 237 | round: bool; |
| 238 | } |
| 239 | |
| 240 | table CondIfAttribute { |
| 241 | then_branch: string; |
| 242 | else_branch: string; |
| 243 | } |
| 244 | |
| 245 | table WhileLoopAttribute { |
| 246 | cond_branch: string; |
| 247 | body_branch: string; |
| 248 | } |
| 249 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 250 | table TransposeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 251 | perms: [int32]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | table TableAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 255 | table: [int16]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 256 | } |
| 257 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 258 | table MatMulAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 259 | a_zp: int32; |
| 260 | b_zp: int32; |
| 261 | } |
| 262 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 263 | table FullyConnectedAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 264 | input_zp: int32; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 265 | weight_zp: int32; |
| 266 | } |
| 267 | |
| 268 | table NegateAttribute { |
| 269 | input1_zp: int32; |
| 270 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 273 | table CustomAttribute { |
Jerry Ge | cd914da | 2023-11-09 18:41:12 +0000 | [diff] [blame] | 274 | operator_name:string; |
| 275 | domain_name:string; |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 276 | implementation_attrs:[ubyte]; |
| 277 | } |
| 278 | |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 279 | table FFTAttribute { |
| 280 | inverse: bool; |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 281 | local_bound: bool; |
| 282 | } |
| 283 | |
| 284 | table RFFTAttribute { |
| 285 | local_bound: bool; |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 288 | table Version { |
Eric Kunze | f08956b | 2023-05-18 01:13:41 +0000 | [diff] [blame] | 289 | _major: int32 = -1; |
| 290 | _minor: int32 = -1; |
| 291 | _patch: int32 = -1; |
Eric Kunze | c3719ab | 2023-05-23 04:30:05 +0000 | [diff] [blame] | 292 | _draft: bool = true; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | table TosaTensor { |
Kevin Cheng | 3bb1bc1 | 2021-06-17 15:57:08 -0700 | [diff] [blame] | 296 | name:string; // name of the tensor, used for solving dependency |
| 297 | shape:[int32]; // shape of the tensor |
| 298 | type:DType; // data type of the tensor |
| 299 | data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor. |
Jerry Ge | 442261b | 2022-09-09 13:38:56 -0700 | [diff] [blame] | 300 | variable: bool; // is this a variable tensor |
Tai Ly | c6939a4 | 2023-08-21 17:00:29 +0000 | [diff] [blame] | 301 | is_unranked: bool; // whether this is an unranked tensor |
Tai Ly | d0520b9 | 2023-09-19 21:30:18 +0000 | [diff] [blame] | 302 | variable_name:string; // name for variable attribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | table TosaOperator { |
| 306 | op:Op; // operator enum |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 307 | attribute:Attribute; // union structure. operator attribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 308 | inputs:[string]; // list of input tensor names |
| 309 | outputs:[string]; // list of output tensor names |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | table 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 Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 320 | table TosaRegion { |
| 321 | name:string; // name of region |
| 322 | blocks:[TosaBasicBlock]; // basic blocks array |
| 323 | } |
| 324 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 325 | table TosaGraph { |
Eric Kunze | f08956b | 2023-05-18 01:13:41 +0000 | [diff] [blame] | 326 | version:Version (required); |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 327 | regions:[TosaRegion]; // regions array |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | root_type TosaGraph; |