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, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | union Attribute { |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 122 | PoolAttribute, |
| 123 | ConvAttribute, |
| 124 | TransposeConvAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 125 | PadAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 126 | AxisAttribute, |
| 127 | ReshapeAttribute, |
| 128 | SliceAttribute, |
| 129 | TileAttribute, |
| 130 | ResizeAttribute, |
| 131 | ClampAttribute, |
| 132 | RescaleAttribute, |
| 133 | MulAttribute, |
| 134 | ArithmeticRightShiftAttribute, |
| 135 | CondIfAttribute, |
| 136 | WhileLoopAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 137 | TransposeAttribute, |
| 138 | TableAttribute, |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 139 | MatMulAttribute, |
| 140 | FullyConnectedAttribute, |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 141 | NegateAttribute, |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 142 | CustomAttribute, |
| 143 | FFTAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 146 | table PoolAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 147 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 148 | kernel: [int32]; |
| 149 | stride: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 150 | input_zp: int32; |
| 151 | output_zp: int32; |
James Ward | 485a11d | 2022-08-05 13:48:37 +0100 | [diff] [blame] | 152 | accum_dtype: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 155 | table ConvAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 156 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 157 | stride: [int32]; |
| 158 | dilation: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 159 | input_zp: int32; |
| 160 | weight_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 163 | table TransposeConvAttribute { |
Eric Kunze | 7ffa1ff | 2022-06-01 17:26:48 -0700 | [diff] [blame] | 164 | out_pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 165 | stride: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 166 | output_shape: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 167 | input_zp: int32; |
| 168 | weight_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 169 | } |
| 170 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 171 | table PadAttribute { |
| 172 | padding: [int32]; |
| 173 | pad_const_int: int32; |
James Ward | c15f7d5 | 2022-12-07 15:38:01 +0000 | [diff] [blame] | 174 | pad_const_fp: [ubyte] (force_align: 8); |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | table AxisAttribute { |
| 178 | axis: int32; |
| 179 | } |
| 180 | |
| 181 | table ReshapeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 182 | new_shape: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | table SliceAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 186 | start: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 187 | size: [int32]; |
| 188 | } |
| 189 | |
| 190 | table TileAttribute { |
| 191 | multiples: [int32]; |
| 192 | } |
| 193 | |
| 194 | table ResizeAttribute { |
TatWai Chong | 49b1ca6 | 2022-06-10 01:49:13 -0700 | [diff] [blame] | 195 | scale: [int16]; |
| 196 | offset: [int16]; |
| 197 | border: [int16]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 198 | mode: ResizeMode; |
| 199 | } |
| 200 | |
| 201 | table ClampAttribute { |
| 202 | min_int: int32; |
| 203 | max_int: int32; |
James Ward | c15f7d5 | 2022-12-07 15:38:01 +0000 | [diff] [blame] | 204 | min_fp: [ubyte] (force_align: 8); |
| 205 | max_fp: [ubyte] (force_align: 8); |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | table RescaleAttribute { |
| 209 | input_zp: int32; |
| 210 | output_zp: int32; |
| 211 | multiplier: [int32]; |
| 212 | shift: [int32]; |
| 213 | scale32: bool; |
| 214 | double_round: bool; |
| 215 | per_channel: bool; |
| 216 | } |
| 217 | |
| 218 | table MulAttribute { |
| 219 | shift: int32; |
| 220 | } |
| 221 | |
| 222 | table ArithmeticRightShiftAttribute { |
| 223 | round: bool; |
| 224 | } |
| 225 | |
| 226 | table CondIfAttribute { |
| 227 | then_branch: string; |
| 228 | else_branch: string; |
| 229 | } |
| 230 | |
| 231 | table WhileLoopAttribute { |
| 232 | cond_branch: string; |
| 233 | body_branch: string; |
| 234 | } |
| 235 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 236 | table TransposeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 237 | perms: [int32]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | table TableAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 241 | table: [int16]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 244 | table MatMulAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 245 | a_zp: int32; |
| 246 | b_zp: int32; |
| 247 | } |
| 248 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 249 | table FullyConnectedAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 250 | input_zp: int32; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 251 | weight_zp: int32; |
| 252 | } |
| 253 | |
| 254 | table NegateAttribute { |
| 255 | input1_zp: int32; |
| 256 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 259 | table CustomAttribute { |
| 260 | identifier:string; |
| 261 | config:string; |
| 262 | implementation_attrs:[ubyte]; |
| 263 | } |
| 264 | |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 265 | table FFTAttribute { |
| 266 | inverse: bool; |
| 267 | } |
| 268 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 269 | table Version { |
| 270 | _major: int32 = 0; |
Eric Kunze | fb90dd4 | 2023-03-08 13:07:07 -0800 | [diff] [blame^] | 271 | _minor: int32 = 60; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 272 | _patch: int32 = 0; |
Eric Kunze | fb90dd4 | 2023-03-08 13:07:07 -0800 | [diff] [blame^] | 273 | _draft: bool = false; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | table TosaTensor { |
Kevin Cheng | 3bb1bc1 | 2021-06-17 15:57:08 -0700 | [diff] [blame] | 277 | name:string; // name of the tensor, used for solving dependency |
| 278 | shape:[int32]; // shape of the tensor |
| 279 | type:DType; // data type of the tensor |
| 280 | 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] | 281 | } |
| 282 | |
| 283 | table TosaOperator { |
| 284 | op:Op; // operator enum |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 285 | attribute:Attribute; // union structure. operator attribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 286 | inputs:[string]; // list of input tensor names |
| 287 | outputs:[string]; // list of output tensor names |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | table TosaBasicBlock { |
| 291 | name:string; // basic block name |
| 292 | operators:[TosaOperator]; // operators array |
| 293 | tensors:[TosaTensor]; // tensors array |
| 294 | inputs:[string]; // name of graph inputs |
| 295 | outputs:[string]; // name of graph outputs |
| 296 | } |
| 297 | |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 298 | table TosaRegion { |
| 299 | name:string; // name of region |
| 300 | blocks:[TosaBasicBlock]; // basic blocks array |
| 301 | } |
| 302 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 303 | table TosaGraph { |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 304 | version:Version; |
| 305 | regions:[TosaRegion]; // regions array |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | root_type TosaGraph; |