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, |
| 32 | FLOAT, |
Jeremy Johnson | 4102773 | 2022-05-25 17:52:29 +0100 | [diff] [blame] | 33 | UINT16, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | enum ResizeMode:uint32 { |
| 37 | UNKNOWN = 0, |
| 38 | NEAREST, |
| 39 | BILINEAR, |
| 40 | } |
| 41 | |
| 42 | enum Op:uint32 { |
| 43 | UNKNOWN = 0, |
| 44 | |
| 45 | // Tensor Operator |
| 46 | ARGMAX, |
| 47 | AVG_POOL2D, |
| 48 | CONV2D, |
| 49 | CONV3D, |
| 50 | DEPTHWISE_CONV2D, |
| 51 | FULLY_CONNECTED, |
| 52 | MATMUL, |
| 53 | MAX_POOL2D, |
| 54 | TRANSPOSE_CONV2D, |
| 55 | |
| 56 | // Activation |
| 57 | CLAMP, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 58 | RESERVED, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 59 | SIGMOID, |
| 60 | TANH, |
| 61 | |
| 62 | // Elementwise-Binary |
| 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, |
| 80 | |
| 81 | // Elementwise-Unary |
| 82 | ABS, |
| 83 | BITWISE_NOT, |
| 84 | CEIL, |
| 85 | CLZ, |
| 86 | EXP, |
| 87 | FLOOR, |
| 88 | LOG, |
| 89 | LOGICAL_NOT, |
| 90 | NEGATE, |
| 91 | RECIPROCAL, |
| 92 | RSQRT, |
| 93 | |
| 94 | // Elementwise-Ternary |
| 95 | SELECT, |
| 96 | |
| 97 | // Logical |
| 98 | EQUAL, |
| 99 | GREATER, |
| 100 | GREATER_EQUAL, |
| 101 | |
| 102 | // Reduction |
| 103 | REDUCE_ANY, |
| 104 | REDUCE_ALL, |
| 105 | REDUCE_MAX, |
| 106 | REDUCE_MIN, |
| 107 | REDUCE_PRODUCT, |
| 108 | REDUCE_SUM, |
| 109 | |
| 110 | // Data layout operation |
| 111 | CONCAT, |
| 112 | PAD, |
| 113 | RESHAPE, |
| 114 | REVERSE, |
| 115 | SLICE, |
| 116 | TILE, |
| 117 | TRANSPOSE, |
| 118 | |
| 119 | // Gather/scatter operation |
| 120 | GATHER, |
| 121 | SCATTER, |
| 122 | |
| 123 | // Image |
| 124 | RESIZE, |
| 125 | |
| 126 | // Type conversion |
| 127 | CAST, |
| 128 | RESCALE, |
| 129 | |
| 130 | // Data Nodes |
| 131 | CONST, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 132 | IDENTITY, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 133 | |
| 134 | // Custom operations |
| 135 | CUSTOM, |
| 136 | |
| 137 | // Control flow operators |
| 138 | COND_IF, |
| 139 | WHILE_LOOP, |
| 140 | } |
| 141 | |
| 142 | union Attribute { |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 143 | PoolAttribute, |
| 144 | ConvAttribute, |
| 145 | TransposeConvAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 146 | PadAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 147 | AxisAttribute, |
| 148 | ReshapeAttribute, |
| 149 | SliceAttribute, |
| 150 | TileAttribute, |
| 151 | ResizeAttribute, |
| 152 | ClampAttribute, |
| 153 | RescaleAttribute, |
| 154 | MulAttribute, |
| 155 | ArithmeticRightShiftAttribute, |
| 156 | CondIfAttribute, |
| 157 | WhileLoopAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 158 | TransposeAttribute, |
| 159 | TableAttribute, |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 160 | MatMulAttribute, |
| 161 | FullyConnectedAttribute, |
| 162 | NegateAttribute |
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 PoolAttribute { |
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 | kernel: [int32]; |
| 168 | stride: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 169 | input_zp: int32; |
| 170 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 173 | table ConvAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 174 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 175 | stride: [int32]; |
| 176 | dilation: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 177 | input_zp: int32; |
| 178 | weight_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 179 | } |
| 180 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 181 | table TransposeConvAttribute { |
Eric Kunze | 7ffa1ff | 2022-06-01 17:26:48 -0700 | [diff] [blame] | 182 | out_pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 183 | stride: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 184 | output_shape: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 185 | input_zp: int32; |
| 186 | weight_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 189 | table PadAttribute { |
| 190 | padding: [int32]; |
| 191 | pad_const_int: int32; |
| 192 | pad_const_fp: float; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | table AxisAttribute { |
| 196 | axis: int32; |
| 197 | } |
| 198 | |
| 199 | table ReshapeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 200 | new_shape: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | table SliceAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 204 | start: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 205 | size: [int32]; |
| 206 | } |
| 207 | |
| 208 | table TileAttribute { |
| 209 | multiples: [int32]; |
| 210 | } |
| 211 | |
| 212 | table ResizeAttribute { |
TatWai Chong | 49b1ca6 | 2022-06-10 01:49:13 -0700 | [diff] [blame] | 213 | scale: [int16]; |
| 214 | offset: [int16]; |
| 215 | border: [int16]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 216 | mode: ResizeMode; |
| 217 | } |
| 218 | |
| 219 | table ClampAttribute { |
| 220 | min_int: int32; |
| 221 | max_int: int32; |
| 222 | min_fp: float; |
| 223 | max_fp: float; |
| 224 | } |
| 225 | |
| 226 | table RescaleAttribute { |
| 227 | input_zp: int32; |
| 228 | output_zp: int32; |
| 229 | multiplier: [int32]; |
| 230 | shift: [int32]; |
| 231 | scale32: bool; |
| 232 | double_round: bool; |
| 233 | per_channel: bool; |
| 234 | } |
| 235 | |
| 236 | table MulAttribute { |
| 237 | shift: int32; |
| 238 | } |
| 239 | |
| 240 | table ArithmeticRightShiftAttribute { |
| 241 | round: bool; |
| 242 | } |
| 243 | |
| 244 | table CondIfAttribute { |
| 245 | then_branch: string; |
| 246 | else_branch: string; |
| 247 | } |
| 248 | |
| 249 | table WhileLoopAttribute { |
| 250 | cond_branch: string; |
| 251 | body_branch: string; |
| 252 | } |
| 253 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 254 | table TransposeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 255 | perms: [int32]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | table TableAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 259 | table: [int16]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 262 | table MatMulAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 263 | a_zp: int32; |
| 264 | b_zp: int32; |
| 265 | } |
| 266 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 267 | table FullyConnectedAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 268 | input_zp: int32; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 269 | weight_zp: int32; |
| 270 | } |
| 271 | |
| 272 | table NegateAttribute { |
| 273 | input1_zp: int32; |
| 274 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | table Version { |
| 278 | _major: int32 = 0; |
Eric Kunze | b2fdef2 | 2022-08-29 11:53:18 -0700 | [diff] [blame] | 279 | _minor: int32 = 40; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 280 | _patch: int32 = 0; |
Eric Kunze | 011a333 | 2022-08-30 21:12:01 +0000 | [diff] [blame] | 281 | _draft: bool = false; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | table TosaTensor { |
Kevin Cheng | 3bb1bc1 | 2021-06-17 15:57:08 -0700 | [diff] [blame] | 285 | name:string; // name of the tensor, used for solving dependency |
| 286 | shape:[int32]; // shape of the tensor |
| 287 | type:DType; // data type of the tensor |
| 288 | 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] | 289 | } |
| 290 | |
| 291 | table TosaOperator { |
| 292 | op:Op; // operator enum |
| 293 | attribute: Attribute; // union structure. operator attribute |
| 294 | inputs:[string]; // list of input tensor names |
| 295 | outputs:[string]; // list of output tensor names |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | table TosaBasicBlock { |
| 299 | name:string; // basic block name |
| 300 | operators:[TosaOperator]; // operators array |
| 301 | tensors:[TosaTensor]; // tensors array |
| 302 | inputs:[string]; // name of graph inputs |
| 303 | outputs:[string]; // name of graph outputs |
| 304 | } |
| 305 | |
| 306 | table TosaGraph { |
| 307 | version: Version; |
| 308 | blocks:[TosaBasicBlock]; // basic blocks array |
| 309 | } |
| 310 | |
| 311 | root_type TosaGraph; |