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