Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 1 | |
Tai Ly | 5d580fa | 2023-12-15 20:34:51 +0000 | [diff] [blame] | 2 | // Copyright (c) 2020-2024, 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, |
Won Jeon | cb4bbf4 | 2023-08-10 08:50:15 +0000 | [diff] [blame] | 39 | SHAPE, |
Won Jeon | a029f1f | 2023-12-29 22:43:11 +0000 | [diff] [blame] | 40 | FP8E4M3, |
| 41 | FP8E5M2, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | enum ResizeMode:uint32 { |
| 45 | UNKNOWN = 0, |
| 46 | NEAREST, |
| 47 | BILINEAR, |
| 48 | } |
| 49 | |
| 50 | enum Op:uint32 { |
| 51 | UNKNOWN = 0, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 52 | ARGMAX, |
| 53 | AVG_POOL2D, |
| 54 | CONV2D, |
| 55 | CONV3D, |
| 56 | DEPTHWISE_CONV2D, |
| 57 | FULLY_CONNECTED, |
| 58 | MATMUL, |
| 59 | MAX_POOL2D, |
| 60 | TRANSPOSE_CONV2D, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 61 | CLAMP, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 62 | RESERVED, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 63 | SIGMOID, |
| 64 | TANH, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 65 | ADD, |
| 66 | ARITHMETIC_RIGHT_SHIFT, |
| 67 | BITWISE_AND, |
| 68 | BITWISE_OR, |
| 69 | BITWISE_XOR, |
Matthew Haddon | ab905ec | 2021-08-23 16:40:57 +0100 | [diff] [blame] | 70 | INTDIV, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 71 | LOGICAL_AND, |
| 72 | LOGICAL_LEFT_SHIFT, |
| 73 | LOGICAL_RIGHT_SHIFT, |
| 74 | LOGICAL_OR, |
| 75 | LOGICAL_XOR, |
| 76 | MAXIMUM, |
| 77 | MINIMUM, |
| 78 | MUL, |
| 79 | POW, |
| 80 | SUB, |
| 81 | TABLE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 82 | ABS, |
| 83 | BITWISE_NOT, |
| 84 | CEIL, |
| 85 | CLZ, |
| 86 | EXP, |
| 87 | FLOOR, |
| 88 | LOG, |
| 89 | LOGICAL_NOT, |
| 90 | NEGATE, |
| 91 | RECIPROCAL, |
| 92 | RSQRT, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 93 | SELECT, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 94 | EQUAL, |
| 95 | GREATER, |
| 96 | GREATER_EQUAL, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 97 | REDUCE_ANY, |
| 98 | REDUCE_ALL, |
| 99 | REDUCE_MAX, |
| 100 | REDUCE_MIN, |
| 101 | REDUCE_PRODUCT, |
| 102 | REDUCE_SUM, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 103 | CONCAT, |
| 104 | PAD, |
| 105 | RESHAPE, |
| 106 | REVERSE, |
| 107 | SLICE, |
| 108 | TILE, |
| 109 | TRANSPOSE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 110 | GATHER, |
| 111 | SCATTER, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 112 | RESIZE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 113 | CAST, |
| 114 | RESCALE, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 115 | CONST, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 116 | IDENTITY, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 117 | CUSTOM, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 118 | COND_IF, |
| 119 | WHILE_LOOP, |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 120 | FFT2D, |
| 121 | RFFT2D, |
Won Jeon | 3acb1cb | 2023-06-07 23:26:32 +0000 | [diff] [blame] | 122 | ERF, |
Won Jeon | cb4bbf4 | 2023-08-10 08:50:15 +0000 | [diff] [blame] | 123 | DIM, |
Tai Ly | 5d580fa | 2023-12-15 20:34:51 +0000 | [diff] [blame] | 124 | CONST_SHAPE, |
| 125 | CONCAT_SHAPE, |
| 126 | ADD_SHAPE, |
| 127 | SUB_SHAPE, |
| 128 | MUL_SHAPE, |
| 129 | DIV_SHAPE, |
Jerry Ge | 61a8313 | 2024-02-20 19:03:06 +0000 | [diff] [blame] | 130 | COS, |
| 131 | SIN, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | union Attribute { |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 135 | PoolAttribute, |
| 136 | ConvAttribute, |
| 137 | TransposeConvAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 138 | PadAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 139 | AxisAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 140 | ResizeAttribute, |
| 141 | ClampAttribute, |
| 142 | RescaleAttribute, |
| 143 | MulAttribute, |
| 144 | ArithmeticRightShiftAttribute, |
| 145 | CondIfAttribute, |
| 146 | WhileLoopAttribute, |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 147 | TransposeAttribute, |
| 148 | TableAttribute, |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 149 | MatMulAttribute, |
| 150 | FullyConnectedAttribute, |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 151 | NegateAttribute, |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 152 | CustomAttribute, |
| 153 | FFTAttribute, |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 154 | RFFTAttribute, |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 157 | table PoolAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 158 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 159 | kernel: [int32]; |
| 160 | stride: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 161 | input_zp: int32; |
| 162 | output_zp: int32; |
Tai Ly | 81db8ee | 2024-02-14 19:57:38 +0000 | [diff] [blame] | 163 | acc_type: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 166 | table ConvAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 167 | pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 168 | stride: [int32]; |
| 169 | dilation: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 170 | input_zp: int32; |
| 171 | weight_zp: int32; |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 172 | local_bound: bool; |
Tai Ly | ad78daa | 2024-03-13 18:52:45 +0000 | [diff] [blame] | 173 | acc_type: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Kevin Cheng | 79a4199 | 2021-08-31 16:04:40 -0700 | [diff] [blame] | 176 | table TransposeConvAttribute { |
Eric Kunze | 7ffa1ff | 2022-06-01 17:26:48 -0700 | [diff] [blame] | 177 | out_pad: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 178 | stride: [int32]; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 179 | output_shape: [int32]; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 180 | input_zp: int32; |
| 181 | weight_zp: int32; |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 182 | local_bound: bool; |
Tai Ly | ad78daa | 2024-03-13 18:52:45 +0000 | [diff] [blame] | 183 | acc_type: DType; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 186 | table PadAttribute { |
Tai Ly | 0b6d7c2 | 2024-03-08 17:03:25 +0000 | [diff] [blame] | 187 | pad_const: [ubyte] (force_align: 8); |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | table AxisAttribute { |
| 191 | axis: int32; |
| 192 | } |
| 193 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 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 { |
Tai Ly | 0b6d7c2 | 2024-03-08 17:03:25 +0000 | [diff] [blame] | 202 | min_val: [ubyte] (force_align: 8); |
| 203 | max_val: [ubyte] (force_align: 8); |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | table RescaleAttribute { |
| 207 | input_zp: int32; |
| 208 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 209 | scale32: bool; |
| 210 | double_round: bool; |
| 211 | per_channel: bool; |
Eric Kunze | 9601cbd | 2023-08-17 20:44:39 +0000 | [diff] [blame] | 212 | input_unsigned: bool; |
| 213 | output_unsigned: bool; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | table MulAttribute { |
| 217 | shift: int32; |
| 218 | } |
| 219 | |
| 220 | table ArithmeticRightShiftAttribute { |
| 221 | round: bool; |
| 222 | } |
| 223 | |
| 224 | table CondIfAttribute { |
Tai Ly | 81db8ee | 2024-02-14 19:57:38 +0000 | [diff] [blame] | 225 | then_graph: string; |
| 226 | else_graph: string; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | table WhileLoopAttribute { |
Tai Ly | 81db8ee | 2024-02-14 19:57:38 +0000 | [diff] [blame] | 230 | cond_graph: string; |
| 231 | body_graph: string; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 234 | table TransposeAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 235 | perms: [int32]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | table TableAttribute { |
TatWai Chong | 7be7165 | 2022-05-10 17:26:20 -0700 | [diff] [blame] | 239 | table: [int16]; |
Kevin Cheng | 38d214c | 2021-10-15 15:49:19 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 242 | table MatMulAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 243 | a_zp: int32; |
| 244 | b_zp: int32; |
| 245 | } |
| 246 | |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 247 | table FullyConnectedAttribute { |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 248 | input_zp: int32; |
Eric Kunze | bdcc3fe | 2022-06-07 05:17:37 +0000 | [diff] [blame] | 249 | weight_zp: int32; |
| 250 | } |
| 251 | |
| 252 | table NegateAttribute { |
| 253 | input1_zp: int32; |
| 254 | output_zp: int32; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 257 | table CustomAttribute { |
Jerry Ge | cd914da | 2023-11-09 18:41:12 +0000 | [diff] [blame] | 258 | operator_name:string; |
| 259 | domain_name:string; |
Eric Kunze | 497ab5d | 2022-10-21 16:39:01 -0700 | [diff] [blame] | 260 | implementation_attrs:[ubyte]; |
| 261 | } |
| 262 | |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 263 | table FFTAttribute { |
| 264 | inverse: bool; |
Eric Kunze | 4881c29 | 2023-11-01 16:12:07 -0700 | [diff] [blame] | 265 | local_bound: bool; |
| 266 | } |
| 267 | |
| 268 | table RFFTAttribute { |
| 269 | local_bound: bool; |
Luke Hutton | 5e26809 | 2023-01-12 22:20:53 +0000 | [diff] [blame] | 270 | } |
| 271 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 272 | table Version { |
Eric Kunze | f08956b | 2023-05-18 01:13:41 +0000 | [diff] [blame] | 273 | _major: int32 = -1; |
| 274 | _minor: int32 = -1; |
| 275 | _patch: int32 = -1; |
Eric Kunze | c3719ab | 2023-05-23 04:30:05 +0000 | [diff] [blame] | 276 | _draft: bool = true; |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | table TosaTensor { |
Kevin Cheng | 3bb1bc1 | 2021-06-17 15:57:08 -0700 | [diff] [blame] | 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 | data: [ubyte] (force_align: 8); // raw data array if it's a constant tensor. |
Jerry Ge | 442261b | 2022-09-09 13:38:56 -0700 | [diff] [blame] | 284 | variable: bool; // is this a variable tensor |
Tai Ly | c6939a4 | 2023-08-21 17:00:29 +0000 | [diff] [blame] | 285 | is_unranked: bool; // whether this is an unranked tensor |
Tai Ly | d0520b9 | 2023-09-19 21:30:18 +0000 | [diff] [blame] | 286 | variable_name:string; // name for variable attribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | table TosaOperator { |
| 290 | op:Op; // operator enum |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 291 | attribute:Attribute; // union structure. operator attribute |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 292 | inputs:[string]; // list of input tensor names |
| 293 | outputs:[string]; // list of output tensor names |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | table TosaBasicBlock { |
| 297 | name:string; // basic block name |
| 298 | operators:[TosaOperator]; // operators array |
| 299 | tensors:[TosaTensor]; // tensors array |
| 300 | inputs:[string]; // name of graph inputs |
| 301 | outputs:[string]; // name of graph outputs |
| 302 | } |
| 303 | |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 304 | table TosaRegion { |
| 305 | name:string; // name of region |
| 306 | blocks:[TosaBasicBlock]; // basic blocks array |
| 307 | } |
| 308 | |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 309 | table TosaGraph { |
Eric Kunze | f08956b | 2023-05-18 01:13:41 +0000 | [diff] [blame] | 310 | version:Version (required); |
Jerry Ge | 13c78a6 | 2022-10-04 20:32:39 -0700 | [diff] [blame] | 311 | regions:[TosaRegion]; // regions array |
Eric Kunze | 2364dcd | 2021-04-26 11:06:57 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | root_type TosaGraph; |