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, |
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, |
| 164 | NegateAttribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 167 | table PoolAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 168 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 169 | kernel: [int32]; |
| 170 | stride: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 171 | input_zp: int32; |
| 172 | output_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 173 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 176 | table ConvAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 177 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 178 | stride: [int32]; |
| 179 | dilation: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 180 | input_zp: int32; |
| 181 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 182 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 185 | table TransposeConvAttribute { |
Eric Kunze | 7ffa1ff | 2022-06-01 17:26:48 -0700 | [diff] [blame] | 186 | out_pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 187 | stride: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 188 | output_shape: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 189 | input_zp: int32; |
| 190 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 191 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 194 | table PadAttribute { |
| 195 | padding: [int32]; |
| 196 | pad_const_int: int32; |
| 197 | pad_const_fp: float; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | table AxisAttribute { |
| 201 | axis: int32; |
| 202 | } |
| 203 | |
| 204 | table ReshapeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 205 | new_shape: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | table SliceAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 209 | start: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 210 | size: [int32]; |
| 211 | } |
| 212 | |
| 213 | table TileAttribute { |
| 214 | multiples: [int32]; |
| 215 | } |
| 216 | |
| 217 | table ResizeAttribute { |
TatWai Chong | 49b1ca6 | 2022-06-10 01:49:13 -0700 | [diff] [blame] | 218 | scale: [int16]; |
| 219 | offset: [int16]; |
| 220 | border: [int16]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 221 | mode: ResizeMode; |
| 222 | } |
| 223 | |
| 224 | table ClampAttribute { |
| 225 | min_int: int32; |
| 226 | max_int: int32; |
| 227 | min_fp: float; |
| 228 | max_fp: float; |
| 229 | } |
| 230 | |
| 231 | table 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 | |
| 241 | table MulAttribute { |
| 242 | shift: int32; |
| 243 | } |
| 244 | |
| 245 | table ArithmeticRightShiftAttribute { |
| 246 | round: bool; |
| 247 | } |
| 248 | |
| 249 | table CondIfAttribute { |
| 250 | then_branch: string; |
| 251 | else_branch: string; |
| 252 | } |
| 253 | |
| 254 | table WhileLoopAttribute { |
| 255 | cond_branch: string; |
| 256 | body_branch: string; |
| 257 | } |
| 258 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 259 | table TransposeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 260 | perms: [int32]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | table TableAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 264 | table: [int16]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 267 | table MatMulAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 268 | a_zp: int32; |
| 269 | b_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 270 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 271 | } |
| 272 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 273 | table FullyConnectedAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 274 | input_zp: int32; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 275 | weight_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 276 | accum_dtype: DType; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | table NegateAttribute { |
| 280 | input1_zp: int32; |
| 281 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | table Version { |
| 285 | _major: int32 = 0; |
Eric Kunze | 6388a09 | 2022-12-07 21:59:31 +0000 | [diff] [blame^] | 286 | _minor: int32 = 51; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 287 | _patch: int32 = 0; |
Eric Kunze | 6388a09 | 2022-12-07 21:59:31 +0000 | [diff] [blame^] | 288 | _draft: bool = true; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | table TosaTensor { |
Kevin Cheng | 3bb1bc1 | 2021-06-17 15:57:08 -0700 | [diff] [blame] | 292 | 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 Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | table 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 Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | table 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 | |
| 313 | table TosaGraph { |
| 314 | version: Version; |
| 315 | blocks:[TosaBasicBlock]; // basic blocks array |
| 316 | } |
| 317 | |
| 318 | root_type TosaGraph; |