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