Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
| 2 | // Copyright (c) 2020, 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 | AINT8, |
| 27 | UINT8, |
| 28 | INT4, |
| 29 | INT8, |
| 30 | INT16, |
| 31 | INT32, |
| 32 | INT48, |
| 33 | FLOAT, |
| 34 | } |
| 35 | |
| 36 | enum Format:uint32 { |
| 37 | UNKNOWN = 0, |
| 38 | NHWC, |
| 39 | NDHWC, |
| 40 | OHWI, |
| 41 | HWIM, |
| 42 | DOHWI, |
| 43 | } |
| 44 | |
| 45 | enum Usage:uint32 { |
| 46 | UNKNOWN = 0, |
| 47 | ACTIVATION, |
| 48 | WEIGHT, |
| 49 | INDEX, |
| 50 | } |
| 51 | |
| 52 | enum ResizeMode:uint32 { |
| 53 | UNKNOWN = 0, |
| 54 | NEAREST, |
| 55 | BILINEAR, |
| 56 | } |
| 57 | |
| 58 | enum Op:uint32 { |
| 59 | UNKNOWN = 0, |
| 60 | |
| 61 | // Tensor Operator |
| 62 | ARGMAX, |
| 63 | AVG_POOL2D, |
| 64 | CONV2D, |
| 65 | CONV3D, |
| 66 | DEPTHWISE_CONV2D, |
| 67 | FULLY_CONNECTED, |
| 68 | MATMUL, |
| 69 | MAX_POOL2D, |
| 70 | TRANSPOSE_CONV2D, |
| 71 | |
| 72 | // Activation |
| 73 | CLAMP, |
| 74 | RELUN, |
| 75 | SIGMOID, |
| 76 | TANH, |
| 77 | |
| 78 | // Elementwise-Binary |
| 79 | ADD, |
| 80 | ARITHMETIC_RIGHT_SHIFT, |
| 81 | BITWISE_AND, |
| 82 | BITWISE_OR, |
| 83 | BITWISE_XOR, |
| 84 | LOGICAL_AND, |
| 85 | LOGICAL_LEFT_SHIFT, |
| 86 | LOGICAL_RIGHT_SHIFT, |
| 87 | LOGICAL_OR, |
| 88 | LOGICAL_XOR, |
| 89 | MAXIMUM, |
| 90 | MINIMUM, |
| 91 | MUL, |
| 92 | POW, |
| 93 | SUB, |
| 94 | TABLE, |
| 95 | |
| 96 | // Elementwise-Unary |
| 97 | ABS, |
| 98 | BITWISE_NOT, |
| 99 | CEIL, |
| 100 | CLZ, |
| 101 | EXP, |
| 102 | FLOOR, |
| 103 | LOG, |
| 104 | LOGICAL_NOT, |
| 105 | NEGATE, |
| 106 | RECIPROCAL, |
| 107 | RSQRT, |
| 108 | |
| 109 | // Elementwise-Ternary |
| 110 | SELECT, |
| 111 | |
| 112 | // Logical |
| 113 | EQUAL, |
| 114 | GREATER, |
| 115 | GREATER_EQUAL, |
| 116 | |
| 117 | // Reduction |
| 118 | REDUCE_ANY, |
| 119 | REDUCE_ALL, |
| 120 | REDUCE_MAX, |
| 121 | REDUCE_MIN, |
| 122 | REDUCE_PRODUCT, |
| 123 | REDUCE_SUM, |
| 124 | |
| 125 | // Data layout operation |
| 126 | CONCAT, |
| 127 | PAD, |
| 128 | RESHAPE, |
| 129 | REVERSE, |
| 130 | SLICE, |
| 131 | TILE, |
| 132 | TRANSPOSE, |
| 133 | |
| 134 | // Gather/scatter operation |
| 135 | GATHER, |
Kevin Cheng | 77d0f76 | 2020-11-24 10:26:32 -0800 | [diff] [blame] | 136 | SCATTER, |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 137 | |
| 138 | // Image |
| 139 | RESIZE, |
| 140 | |
| 141 | // Type conversion |
| 142 | CAST, |
| 143 | RESCALE, |
| 144 | |
| 145 | // Data Nodes |
| 146 | CONST, |
| 147 | PLACEHOLDER, |
| 148 | IDENTITY, |
| 149 | IDENTITYN, |
| 150 | |
| 151 | // Custom operations |
| 152 | CUSTOM, |
| 153 | |
| 154 | // Control flow operators |
| 155 | COND_IF, |
| 156 | WHILE_LOOP, |
| 157 | } |
| 158 | |
| 159 | union Attribute { |
| 160 | Pool2dAttribute, |
| 161 | Conv2dAttribute, |
| 162 | TransposeConv2dAttribute, |
| 163 | ReluNAttribute, |
| 164 | AxisAttribute, |
| 165 | ReshapeAttribute, |
| 166 | SliceAttribute, |
| 167 | TileAttribute, |
| 168 | ResizeAttribute, |
| 169 | ClampAttribute, |
| 170 | RescaleAttribute, |
Kevin Cheng | aee1fac | 2020-11-11 13:54:06 -0800 | [diff] [blame] | 171 | MulAttribute, |
| 172 | ArithmeticRightShiftAttribute, |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 173 | CondIfAttribute, |
| 174 | WhileLoopAttribute, |
| 175 | } |
| 176 | |
| 177 | table Pool2dAttribute { |
| 178 | padding: [int32]; |
| 179 | kernel: [int32]; |
| 180 | stride: [int32]; |
| 181 | } |
| 182 | |
| 183 | table Conv2dAttribute { |
| 184 | padding: [int32]; |
| 185 | stride: [int32]; |
| 186 | dilation: [int32]; |
| 187 | } |
| 188 | |
| 189 | table TransposeConv2dAttribute { |
| 190 | outpad: [int32]; |
| 191 | stride: [int32]; |
| 192 | dilation: [int32]; |
| 193 | output_shape: [int32]; |
| 194 | } |
| 195 | |
| 196 | table ReluNAttribute { |
| 197 | max_int: int32; |
| 198 | max_fp: float; |
| 199 | } |
| 200 | |
| 201 | table AxisAttribute { |
| 202 | axis: int32; |
| 203 | } |
| 204 | |
| 205 | table ReshapeAttribute { |
| 206 | shape: [int32]; |
| 207 | } |
| 208 | |
| 209 | table SliceAttribute { |
| 210 | begin: [int32]; |
| 211 | size: [int32]; |
| 212 | } |
| 213 | |
| 214 | table TileAttribute { |
| 215 | multiples: [int32]; |
| 216 | } |
| 217 | |
| 218 | table ResizeAttribute { |
| 219 | output_size: [int32]; |
| 220 | stride: [int32]; |
| 221 | offset: [int32]; |
| 222 | shift: int32; |
Kevin Cheng | 77d0f76 | 2020-11-24 10:26:32 -0800 | [diff] [blame] | 223 | stride_fp: [float]; |
| 224 | offset_fp: [float]; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 225 | mode: ResizeMode; |
| 226 | } |
| 227 | |
| 228 | table ClampAttribute { |
| 229 | min_int: int32; |
| 230 | max_int: int32; |
| 231 | min_fp: float; |
| 232 | max_fp: float; |
| 233 | } |
| 234 | |
| 235 | table RescaleAttribute { |
| 236 | input_zp: int32; |
| 237 | output_zp: int32; |
| 238 | multiplier: [int32]; |
| 239 | shift: [int32]; |
| 240 | scale32: bool; |
| 241 | double_round: bool; |
| 242 | per_channel: bool; |
| 243 | } |
| 244 | |
Kevin Cheng | aee1fac | 2020-11-11 13:54:06 -0800 | [diff] [blame] | 245 | table MulAttribute { |
| 246 | shift: int32; |
| 247 | } |
| 248 | |
| 249 | table ArithmeticRightShiftAttribute { |
| 250 | round: bool; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | table CondIfAttribute { |
| 254 | then_branch: string; |
| 255 | else_branch: string; |
| 256 | } |
| 257 | |
| 258 | table WhileLoopAttribute { |
| 259 | cond_branch: string; |
| 260 | body_branch: string; |
| 261 | } |
| 262 | |
| 263 | union QuantInfo { |
| 264 | UnaryQuantInfo, |
| 265 | ConvQuantInfo, |
| 266 | MatMulQuantInfo, |
| 267 | PadQuantInfo, |
| 268 | } |
| 269 | |
| 270 | table UnaryQuantInfo { |
| 271 | input_zp: int32; |
| 272 | output_zp: int32; |
| 273 | } |
| 274 | |
| 275 | table ConvQuantInfo { |
| 276 | input_zp: int32; |
| 277 | weight_zp: int32; |
| 278 | } |
| 279 | |
| 280 | table MatMulQuantInfo { |
| 281 | a_zp: int32; |
| 282 | b_zp: int32; |
| 283 | } |
| 284 | |
| 285 | table PadQuantInfo { |
| 286 | input_zp: int32; |
| 287 | } |
| 288 | |
| 289 | table Version { |
| 290 | _major: int32 = 0; |
Kevin Cheng | 77d0f76 | 2020-11-24 10:26:32 -0800 | [diff] [blame] | 291 | _minor: int32 = 21; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 292 | _patch: int32 = 0; |
| 293 | _experimental: bool = false; |
| 294 | } |
| 295 | |
| 296 | table TosaTensor { |
| 297 | name:string; // name of the tensor, used for solving dependency |
| 298 | shape:[int32]; // shape of the tensor |
| 299 | type:DType; // data type of the tensor |
| 300 | usage:[Usage]; // vector of possible usages. for the convenience of debugging only. |
| 301 | format:[Format]; // vector of possible formats. for the convenience of debugging only. |
| 302 | npy_filename: string; // numpy array filename |
| 303 | } |
| 304 | |
| 305 | table TosaOperator { |
| 306 | op:Op; // operator enum |
| 307 | attribute: Attribute; // union structure. operator attribute |
| 308 | inputs:[string]; // list of input tensor names |
| 309 | outputs:[string]; // list of output tensor names |
| 310 | quant_info: QuantInfo; // op-based quantization information |
| 311 | } |
| 312 | |
| 313 | table TosaBasicBlock { |
| 314 | name:string; // basic block name |
| 315 | operators:[TosaOperator]; // operators array |
| 316 | tensors:[TosaTensor]; // tensors array |
| 317 | inputs:[string]; // name of graph inputs |
| 318 | outputs:[string]; // name of graph outputs |
| 319 | } |
| 320 | |
| 321 | table TosaGraph { |
| 322 | version: Version; |
| 323 | blocks:[TosaBasicBlock]; // basic blocks array |
| 324 | } |
| 325 | |
| 326 | root_type TosaGraph; |