Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 1 | |
| 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 | |
| 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, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | enum ResizeMode:uint32 { |
| 38 | UNKNOWN = 0, |
| 39 | NEAREST, |
| 40 | BILINEAR, |
| 41 | } |
| 42 | |
| 43 | enum 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 Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 59 | RESERVED, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 60 | SIGMOID, |
| 61 | TANH, |
| 62 | |
| 63 | // Elementwise-Binary |
| 64 | ADD, |
| 65 | ARITHMETIC_RIGHT_SHIFT, |
| 66 | BITWISE_AND, |
| 67 | BITWISE_OR, |
| 68 | BITWISE_XOR, |
Matthew Haddon | ab905ec | 2021-08-23 16:40:57 +0100 | [diff] [blame] | 69 | INTDIV, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 70 | 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 Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 133 | IDENTITY, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 134 | |
| 135 | // Custom operations |
| 136 | CUSTOM, |
| 137 | |
| 138 | // Control flow operators |
| 139 | COND_IF, |
| 140 | WHILE_LOOP, |
| 141 | } |
| 142 | |
| 143 | union Attribute { |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 144 | PoolAttribute, |
| 145 | ConvAttribute, |
| 146 | TransposeConvAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 147 | PadAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 148 | AxisAttribute, |
| 149 | ReshapeAttribute, |
| 150 | SliceAttribute, |
| 151 | TileAttribute, |
| 152 | ResizeAttribute, |
| 153 | ClampAttribute, |
| 154 | RescaleAttribute, |
| 155 | MulAttribute, |
| 156 | ArithmeticRightShiftAttribute, |
| 157 | CondIfAttribute, |
| 158 | WhileLoopAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 159 | TransposeAttribute, |
| 160 | TableAttribute, |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 161 | MatMulAttribute, |
| 162 | FullyConnectedAttribute, |
| 163 | NegateAttribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 166 | table PoolAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 167 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 168 | kernel: [int32]; |
| 169 | stride: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 170 | input_zp: int32; |
| 171 | output_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 172 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 175 | table ConvAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 176 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 177 | stride: [int32]; |
| 178 | dilation: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 179 | input_zp: int32; |
| 180 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 181 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 184 | table TransposeConvAttribute { |
Eric Kunze | 7ffa1ff | 2022-06-01 17:26:48 -0700 | [diff] [blame] | 185 | out_pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 186 | stride: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 187 | output_shape: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 188 | input_zp: int32; |
| 189 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 190 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 193 | table PadAttribute { |
| 194 | padding: [int32]; |
| 195 | pad_const_int: int32; |
| 196 | pad_const_fp: float; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | table AxisAttribute { |
| 200 | axis: int32; |
| 201 | } |
| 202 | |
| 203 | table ReshapeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 204 | new_shape: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | table SliceAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 208 | start: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 209 | size: [int32]; |
| 210 | } |
| 211 | |
| 212 | table TileAttribute { |
| 213 | multiples: [int32]; |
| 214 | } |
| 215 | |
| 216 | table ResizeAttribute { |
TatWai Chong | 49b1ca6 | 2022-06-10 01:49:13 -0700 | [diff] [blame] | 217 | scale: [int16]; |
| 218 | offset: [int16]; |
| 219 | border: [int16]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 220 | mode: ResizeMode; |
| 221 | } |
| 222 | |
| 223 | table ClampAttribute { |
| 224 | min_int: int32; |
| 225 | max_int: int32; |
| 226 | min_fp: float; |
| 227 | max_fp: float; |
| 228 | } |
| 229 | |
| 230 | table 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 | |
| 240 | table MulAttribute { |
| 241 | shift: int32; |
| 242 | } |
| 243 | |
| 244 | table ArithmeticRightShiftAttribute { |
| 245 | round: bool; |
| 246 | } |
| 247 | |
| 248 | table CondIfAttribute { |
| 249 | then_branch: string; |
| 250 | else_branch: string; |
| 251 | } |
| 252 | |
| 253 | table WhileLoopAttribute { |
| 254 | cond_branch: string; |
| 255 | body_branch: string; |
| 256 | } |
| 257 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 258 | table TransposeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 259 | perms: [int32]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | table TableAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 263 | table: [int16]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 266 | table MatMulAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 267 | a_zp: int32; |
| 268 | b_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 269 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 272 | table FullyConnectedAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 273 | input_zp: int32; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 274 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 275 | accum_dtype: DType; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | table NegateAttribute { |
| 279 | input1_zp: int32; |
| 280 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | table Version { |
| 284 | _major: int32 = 0; |
Eric Kunze | 24a68bb | 2022-09-08 23:54:21 +0000 | [diff] [blame] | 285 | _minor: int32 = 41; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 286 | _patch: int32 = 0; |
Eric Kunze | 24a68bb | 2022-09-08 23:54:21 +0000 | [diff] [blame] | 287 | _draft: bool = true; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | table TosaTensor { |
Kevin Cheng | 3bb1bc1 | 2021-06-17 15:57:08 -0700 | [diff] [blame] | 291 | 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 Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | table 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 Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | table 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 | |
| 312 | table TosaGraph { |
| 313 | version: Version; |
| 314 | blocks:[TosaBasicBlock]; // basic blocks array |
| 315 | } |
| 316 | |
| 317 | root_type TosaGraph; |