| 1 | <!-- |
| 2 | SPDX-FileCopyrightText: Copyright 2026 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | |
| 4 | SPDX-License-Identifier: Apache-2.0 |
| 5 | --> |
| 6 | |
| 7 | # The micro-kernel naming scheme |
| 8 | |
| 9 | This document describes the KleidiAI micro-kernel naming scheme. |
| 10 | |
| 11 | ## Naming Structure |
| 12 | |
| 13 | The high level view of micro-kernel naming is generated from the documented |
| 14 | grammar rules: |
| 15 | |
| 16 | - Micro-kernel source files use names beginning with `kai_`. |
| 17 | - Matmul micro-kernels use the `matmul_ukernel_name` grammar. |
| 18 | - Depthwise convolution micro-kernels describe the operation, buffers, filter, stride, output block, SIMD engine, and optional instruction through the `dwconv_ukernel_name` grammar. |
| 19 | - Micro-kernel directories use the `directory_name` grammar. |
| 20 | |
| 21 | ### Common Name Shapes |
| 22 | |
| 23 | - LHS packing micro-kernels are named `kai_lhs_pack_<output>_<input>_<description>`. |
| 24 | - RHS packing micro-kernels are named `kai_rhs_pack_<orientation>_<output>_<inputs>_<description>`. |
| 25 | - Matmul compute micro-kernels are named `kai_<operation>_<output>_<LHS input>_<RHS input>_<description>`. |
| 26 | - Depthwise convolution micro-kernels are named with the depthwise operation, buffers, filter, stride, output block, SIMD engine, and optional instruction. |
| 27 | |
| 28 | For matmul-family compute micro-kernels, buffer descriptors appear in the order |
| 29 | destination, LHS input, then RHS input. The output descriptors of LHS and RHS |
| 30 | packing micro-kernels match the corresponding packed input descriptors of the |
| 31 | matmul micro-kernel. |
| 32 | |
| 33 | ### Packed Buffer Layouts |
| 34 | |
| 35 | Packed buffers include a `p<width>x<height>` layout in full micro-kernel names. |
| 36 | For matmul-family names, the LHS packed width is normally the row blocking |
| 37 | dimension (`MR`), and the RHS packed width is normally the column blocking |
| 38 | dimension (`NR`). The packed height is the block depth (`BD`), which is derived |
| 39 | from the `KR` and `SR` values used by the micro-kernel as `KR / SR`. |
| 40 | |
| 41 | Packed buffers can also encode data order, packed scale type, and packed bias |
| 42 | type. Scale values are encoded as `s<type>` and bias values as `b<type>`. |
| 43 | Legacy `scalef*` and `biasf*` spellings are not valid in the grammar. |
| 44 | |
| 45 | ### How to Read the Grammar |
| 46 | |
| 47 | - **`rule_name`**: Reference to another grammar rule. |
| 48 | - **`"text"`**: Literal text that appears in the name. |
| 49 | - **`a b`**: Sequence: `a` followed by `b`. |
| 50 | - **`a | b`**: Choice: either `a` or `b`. |
| 51 | - **`[a]`**: Optional expression. |
| 52 | - **`a+`**: One or more repetitions of `a`. |
| 53 | - **`(a b)`**: Grouped expression. |
| 54 | - **`@natural_int`**: Positive integer literal. |
| 55 | - **`@pow2_int`**: Power-of-two integer literal. |
| 56 | - **`@operand_type`**: Data type descriptor. |
| 57 | |
| 58 | ## Naming Rules |
| 59 | |
| 60 | The documented naming rules are listed below. |
| 61 | |
| 62 | ### Micro-kernel directory name |
| 63 | |
| 64 | Describes every micro-kernel directory name accepted by the naming rules. |
| 65 | |
| 66 | **`directory_name`** = `"pack" | matmul_fused_ops "_" simplified_buffer ("_" simplified_buffer)+ | "dwconv" "_" simplified_buffer ("_" simplified_buffer)+` |
| 67 | |
| 68 | ### Micro-kernel name |
| 69 | |
| 70 | Describes every micro-kernel name accepted by the naming rules. |
| 71 | |
| 72 | **`kernel_name`** = `matmul_ukernel_name | dwconv_ukernel_name` |
| 73 | |
| 74 | ### Matmul micro-kernel name |
| 75 | |
| 76 | Describes names for matmul-family compute and packing micro-kernels. |
| 77 | |
| 78 | **`matmul_ukernel_name`** = `"kai_" matmul_fused_ops ("_" buffer) ("_" buffer)+ ["_" tile_size] ["_" tech] ["_" feature] ["_" instruction] ["_" uarch]` |
| 79 | |
| 80 | where: |
| 81 | |
| 82 | - **`"_" buffer`**: Destination buffer |
| 83 | - **`("_" buffer)+`**: Input buffer(s) |
| 84 | - **`["_" tile_size]`**: Tile size |
| 85 | - **`["_" tech]`**: SIMD engine |
| 86 | - **`["_" feature]`**: Primary feature |
| 87 | - **`["_" instruction]`**: Primary instruction |
| 88 | - **`["_" uarch]`**: Target micro-architecture |
| 89 | |
| 90 | ### Depthwise micro-kernel name |
| 91 | |
| 92 | Describes names for depthwise convolution and depthwise RHS packing micro-kernels. |
| 93 | |
| 94 | **`dwconv_ukernel_name`** = `"kai_" ("dwconv_clamp" ("_" buffer)+ ("_" filter_size) ("_" dw_stride) ("_" dwconv_output_block_size) ("_" tech) ["_" instruction] | "rhs_dwconv_pack" ("_" buffer)+ ("_" tech))` |
| 95 | |
| 96 | ### Target microarchitecture |
| 97 | |
| 98 | Describes a target microarchitecture for which a micro-kernel is optimized. |
| 99 | |
| 100 | **`uarch`** = `"cortexa55"` |
| 101 | |
| 102 | ### SIMD engine |
| 103 | |
| 104 | Describes the SIMD engine targeted by the implementation. |
| 105 | |
| 106 | **`tech`** = `"neon" | "sve" | "sve2" | "sve2p1" | "sme" | "sme2" | "sme2p1"` |
| 107 | |
| 108 | ### Primary feature |
| 109 | |
| 110 | Describes the predominant `FEAT_<feature>` used by the implementation. |
| 111 | |
| 112 | **`feature`** = `"i8mm" | "dotprod"` |
| 113 | |
| 114 | ### Primary instruction family |
| 115 | |
| 116 | Describes the predominant SIMD instruction family used by the implementation. |
| 117 | |
| 118 | **`instruction`** = `"dot" | "i8mm" | "mla" | "mmla" | "mopa" | "sdot"` |
| 119 | |
| 120 | ### Convolution stride |
| 121 | |
| 122 | Describes the stride used by a depthwise convolution micro-kernel. |
| 123 | |
| 124 | **`dw_stride`** = `"s" @natural_int` |
| 125 | |
| 126 | ### Convolution filter size |
| 127 | |
| 128 | Describes the height-by-width filter shape used by a depthwise convolution micro-kernel. |
| 129 | |
| 130 | **`filter_size`** = `@natural_int "x" @natural_int` |
| 131 | |
| 132 | ### Fused operation descriptor |
| 133 | |
| 134 | Describes the primary matmul-family operation and any encoded fused operation. |
| 135 | |
| 136 | **`matmul_fused_ops`** = `["i"] "matmul" ["_clamp"] | "lhs_pack" | "rhs_pack_kxn" | "rhs_pack_nxk"` |
| 137 | |
| 138 | ### Directory buffer descriptor |
| 139 | |
| 140 | Describes an input or output buffer in a micro-kernel directory name. Directory names use abbreviated descriptors and omit concrete packed layout details. |
| 141 | |
| 142 | **`simplified_buffer`** = `[quantization] @operand_type [quantization_axis] ["p"]` |
| 143 | |
| 144 | ### Buffer descriptor |
| 145 | |
| 146 | Describes an input or output buffer in a full micro-kernel name. Packed buffers include their concrete packed layout. |
| 147 | |
| 148 | **`buffer`** = `[quantization] @operand_type [quantization_axis] [pack_description]` |
| 149 | |
| 150 | where: |
| 151 | |
| 152 | - **`[quantization]`**: Quantization indication |
| 153 | - **`@operand_type`**: The main data-type stored in buffer |
| 154 | - **`[quantization_axis]`**: If quantized, indicates quantization granularity |
| 155 | - **`[pack_description]`**: If packed, indicates packing properties |
| 156 | |
| 157 | ### Packed buffer layout description |
| 158 | |
| 159 | Describes the packed-buffer suffix of a full buffer descriptor. |
| 160 | |
| 161 | **`pack_description`** = `packing_layout [pack_order] [scale_type] [bias_type]` |
| 162 | |
| 163 | ### Packed bias type |
| 164 | |
| 165 | Describes the operand type used for bias values stored in a packed buffer. |
| 166 | |
| 167 | **`bias_type`** = `"b" @operand_type` |
| 168 | |
| 169 | ### Packed scale type |
| 170 | |
| 171 | Describes the operand type used for scale values stored in a packed buffer. |
| 172 | |
| 173 | **`scale_type`** = `"s" @operand_type` |
| 174 | |
| 175 | ### Packing layout |
| 176 | |
| 177 | Describes the dimensions used when data is packed into a buffer. |
| 178 | |
| 179 | **`packing_layout`** = `"p" size "x" size` |
| 180 | |
| 181 | where: |
| 182 | |
| 183 | - **`size`**: Width component of a packed buffer layout |
| 184 | - **`size`**: Height component of a packed buffer layout |
| 185 | |
| 186 | ### Packed data order |
| 187 | |
| 188 | Describes the ordering of values inside a packed buffer. |
| 189 | |
| 190 | **`pack_order`** = `"s1s0" | "s4s0" | "s16s0"` |
| 191 | |
| 192 | where: |
| 193 | |
| 194 | - **`"s1s0"`**: Packing order of data is sequential |
| 195 | - **`"s4s0"`**: Packing order of data is interleaved with nibble distance of 4 |
| 196 | - **`"s16s0"`**: Packing order of data is interleaved |
| 197 | |
| 198 | ### Depthwise output block size |
| 199 | |
| 200 | Describes the output block shape produced by a depthwise convolution micro-kernel. The `c` column size means all channels. |
| 201 | |
| 202 | **`dwconv_output_block_size`** = `@natural_int "x" (@natural_int | "c")` |
| 203 | |
| 204 | ### Primary tile size |
| 205 | |
| 206 | Describes the primary row-by-column tile computed by a micro-kernel. |
| 207 | |
| 208 | **`tile_size`** = `size "x" size` |
| 209 | |
| 210 | ### Dimension size |
| 211 | |
| 212 | Describes a dimension size, which can be a positive integer, a vector-length multiple using `vl`, a vector-scale multiple using `vs`, or a parametric `mr` or `nr` value. |
| 213 | |
| 214 | **`size`** = `@natural_int | @natural_int "vl" | @natural_int "vs" | "mr" | "nr"` |
| 215 | |
| 216 | where: |
| 217 | |
| 218 | - **`@natural_int`**: Constant value |
| 219 | - **`@natural_int "vl"`**: Accumulator vector length multiple. Assuming 32-bit accumulation on a 512-bit configuration, `4vl` means 64 elements |
| 220 | - **`@natural_int "vs"`**: Vector scale multiplier, assuming a vector length of 128 bits. For a 512-bit configuration, `4vs` means 16 elements |
| 221 | - **`"mr"`**: Parametric size, given as argument to micro-kernel |
| 222 | - **`"nr"`**: Parametric size, given as argument to micro-kernel |
| 223 | |
| 224 | ### Quantization axis or block shape |
| 225 | |
| 226 | Describes how quantization parameters are associated with data dimensions or blocks. |
| 227 | |
| 228 | **`quantization_axis`** = `"cx" | "dx" | "d32" | "c32"` |
| 229 | |
| 230 | where: |
| 231 | |
| 232 | - **`"cx"`**: Per channel quantized |
| 233 | - **`"dx"`**: Per dimension quantized |
| 234 | - **`"d32"`**: Per-dimension block quantization, with block length multiple of 32 |
| 235 | - **`"c32"`**: Per block quantization, with block length multiple of 32 |
| 236 | |
| 237 | ### Quantization mode |
| 238 | |
| 239 | Describes whether quantized data uses symmetric or asymmetric quantization. |
| 240 | |
| 241 | **`quantization`** = `"qa" | "qs"` |
| 242 | |
| 243 | where: |
| 244 | |
| 245 | - **`"qa"`**: Asymmetrical quantization |
| 246 | - **`"qs"`**: Symmetrical quantization |
| 247 | |
| 248 | ## Rule Enforcement |
| 249 | |
| 250 | The naming scheme is implemented in `tools/naming/rules.py`. Micro-kernel and |
| 251 | directory names are checked by `tools/check_microkernel_names.py`, and CI uses |
| 252 | the same checker to enforce the rules. |
| 253 | |
| 254 | This document is generated from the naming rules. Regenerate it with |
| 255 | `tools/check_microkernel_names.py --generate-documentation` after updating the |
| 256 | naming scheme. |
| 257 | |
| 258 | ## Known naming issues |
| 259 | |
| 260 | Some legacy micro-kernel and directory names do not match the current grammar, |
| 261 | but are retained to preserve the existing API. The known exceptions are listed |
| 262 | in `tools/naming/issues.py`. To include them in checker output, run |
| 263 | `tools/check_microkernel_names.py --report-known-issues`. |
| 264 | |
| 265 | ## Full naming grammar |
| 266 | |
| 267 | The grammar below is generated from the naming rules. |
| 268 | |
| 269 | ```text |
| 270 | directory_name = "pack" | matmul_fused_ops "_" simplified_buffer ("_" simplified_buffer)+ | "dwconv" "_" simplified_buffer ("_" simplified_buffer)+ |
| 271 | kernel_name = matmul_ukernel_name | dwconv_ukernel_name |
| 272 | matmul_ukernel_name = "kai_" matmul_fused_ops ("_" buffer) ("_" buffer)+ ["_" tile_size] ["_" tech] ["_" feature] ["_" instruction] ["_" uarch] |
| 273 | dwconv_ukernel_name = "kai_" ("dwconv_clamp" ("_" buffer)+ ("_" filter_size) ("_" dw_stride) ("_" dwconv_output_block_size) ("_" tech) ["_" instruction] | "rhs_dwconv_pack" ("_" buffer)+ ("_" tech)) |
| 274 | uarch = "cortexa55" |
| 275 | tech = "neon" | "sve" | "sve2" | "sve2p1" | "sme" | "sme2" | "sme2p1" |
| 276 | feature = "i8mm" | "dotprod" |
| 277 | instruction = "dot" | "i8mm" | "mla" | "mmla" | "mopa" | "sdot" |
| 278 | dw_stride = "s" @natural_int |
| 279 | filter_size = @natural_int "x" @natural_int |
| 280 | matmul_fused_ops = ["i"] "matmul" ["_clamp"] | "lhs_pack" | "rhs_pack_kxn" | "rhs_pack_nxk" |
| 281 | simplified_buffer = [quantization] @operand_type [quantization_axis] ["p"] |
| 282 | buffer = [quantization] @operand_type [quantization_axis] [pack_description] |
| 283 | pack_description = packing_layout [pack_order] [scale_type] [bias_type] |
| 284 | bias_type = "b" @operand_type |
| 285 | scale_type = "s" @operand_type |
| 286 | packing_layout = "p" size "x" size |
| 287 | pack_order = "s1s0" | "s4s0" | "s16s0" |
| 288 | dwconv_output_block_size = @natural_int "x" (@natural_int | "c") |
| 289 | tile_size = size "x" size |
| 290 | size = @natural_int | @natural_int "vl" | @natural_int "vs" | "mr" | "nr" |
| 291 | quantization_axis = "cx" | "dx" | "d32" | "c32" |
| 292 | quantization = "qa" | "qs" |
| 293 | ``` |