Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 1 | |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame^] | 2 | // Copyright (c) 2020-2023, 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 | |
| 23 | enum DType:uint32 { |
| 24 | UNKNOWN = 0, |
| 25 | BOOL, |
| 26 | UINT8, |
| 27 | INT4, |
| 28 | INT8, |
| 29 | INT16, |
| 30 | INT32, |
| 31 | INT48, |
Jeremy Johnson | e1072a9 | 2022-09-27 12:44:11 +0100 | [diff] [blame] | 32 | FP32, |
Jeremy Johnson | 4102773 | 2022-05-25 17:52:29 +0100 | [diff] [blame] | 33 | UINT16, |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 34 | FP16, |
James Ward | 34a6279 | 2022-10-18 17:27:40 +0100 | [diff] [blame] | 35 | BF16, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | enum ResizeMode:uint32 { |
| 39 | UNKNOWN = 0, |
| 40 | NEAREST, |
| 41 | BILINEAR, |
| 42 | } |
| 43 | |
| 44 | enum 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 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, |
| 63 | |
| 64 | // Elementwise-Binary |
| 65 | ADD, |
| 66 | ARITHMETIC_RIGHT_SHIFT, |
| 67 | BITWISE_AND, |
| 68 | BITWISE_OR, |
| 69 | BITWISE_XOR, |
Matthew Haddon | ab905ec | 2021-08-23 16:40:57 +0100 | [diff] [blame] | 70 | INTDIV, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 71 | 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 Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 134 | IDENTITY, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 135 | |
| 136 | // Custom operations |
| 137 | CUSTOM, |
| 138 | |
| 139 | // Control flow operators |
| 140 | COND_IF, |
| 141 | WHILE_LOOP, |
| 142 | } |
| 143 | |
| 144 | union Attribute { |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 145 | PoolAttribute, |
| 146 | ConvAttribute, |
| 147 | TransposeConvAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 148 | PadAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 149 | AxisAttribute, |
| 150 | ReshapeAttribute, |
| 151 | SliceAttribute, |
| 152 | TileAttribute, |
| 153 | ResizeAttribute, |
| 154 | ClampAttribute, |
| 155 | RescaleAttribute, |
| 156 | MulAttribute, |
| 157 | ArithmeticRightShiftAttribute, |
| 158 | CondIfAttribute, |
| 159 | WhileLoopAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 160 | TransposeAttribute, |
| 161 | TableAttribute, |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 162 | MatMulAttribute, |
| 163 | FullyConnectedAttribute, |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame^] | 164 | NegateAttribute, |
| 165 | CustomAttribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 168 | table PoolAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 169 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 170 | kernel: [int32]; |
| 171 | stride: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 172 | input_zp: int32; |
| 173 | output_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 174 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 177 | table ConvAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 178 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 179 | stride: [int32]; |
| 180 | dilation: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 181 | input_zp: int32; |
| 182 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 183 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 186 | table TransposeConvAttribute { |
Eric Kunze | 7ffa1ff | 2022-06-01 17:26:48 -0700 | [diff] [blame] | 187 | out_pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 188 | stride: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 189 | output_shape: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 190 | input_zp: int32; |
| 191 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 192 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 195 | table PadAttribute { |
| 196 | padding: [int32]; |
| 197 | pad_const_int: int32; |
| 198 | pad_const_fp: float; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | table AxisAttribute { |
| 202 | axis: int32; |
| 203 | } |
| 204 | |
| 205 | table ReshapeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 206 | new_shape: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | table SliceAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 210 | start: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 211 | size: [int32]; |
| 212 | } |
| 213 | |
| 214 | table TileAttribute { |
| 215 | multiples: [int32]; |
| 216 | } |
| 217 | |
| 218 | table ResizeAttribute { |
TatWai Chong | 49b1ca6 | 2022-06-10 01:49:13 -0700 | [diff] [blame] | 219 | scale: [int16]; |
| 220 | offset: [int16]; |
| 221 | border: [int16]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 222 | mode: ResizeMode; |
| 223 | } |
| 224 | |
| 225 | table ClampAttribute { |
| 226 | min_int: int32; |
| 227 | max_int: int32; |
| 228 | min_fp: float; |
| 229 | max_fp: float; |
| 230 | } |
| 231 | |
| 232 | table 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 | |
| 242 | table MulAttribute { |
| 243 | shift: int32; |
| 244 | } |
| 245 | |
| 246 | table ArithmeticRightShiftAttribute { |
| 247 | round: bool; |
| 248 | } |
| 249 | |
| 250 | table CondIfAttribute { |
| 251 | then_branch: string; |
| 252 | else_branch: string; |
| 253 | } |
| 254 | |
| 255 | table WhileLoopAttribute { |
| 256 | cond_branch: string; |
| 257 | body_branch: string; |
| 258 | } |
| 259 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 260 | table TransposeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 261 | perms: [int32]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | table TableAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 265 | table: [int16]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 268 | table MatMulAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 269 | a_zp: int32; |
| 270 | b_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 271 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 274 | table FullyConnectedAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 275 | input_zp: int32; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 276 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 277 | accum_dtype: DType; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | table NegateAttribute { |
| 281 | input1_zp: int32; |
| 282 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame^] | 285 | table CustomAttribute { |
| 286 | identifier:string; |
| 287 | config:string; |
| 288 | implementation_attrs:[ubyte]; |
| 289 | } |
| 290 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 291 | table Version { |
| 292 | _major: int32 = 0; |
Eric Kunze | 6388a09 | 2022-12-07 21:59:31 +0000 | [diff] [blame] | 293 | _minor: int32 = 51; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 294 | _patch: int32 = 0; |
Eric Kunze | 6388a09 | 2022-12-07 21:59:31 +0000 | [diff] [blame] | 295 | _draft: bool = true; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | table TosaTensor { |
Kevin Cheng | 3bb1bc1 | 2021-06-17 15:57:08 -0700 | [diff] [blame] | 299 | 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 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 { |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 326 | version:Version; |
| 327 | regions:[TosaRegion]; // regions array |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | root_type TosaGraph; |