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