Elffuss BraidHub

kikocis/kleidiai public

main · 10.6 KiBSourceRawPermalink

The micro-kernel naming scheme

This document describes the KleidiAI micro-kernel naming scheme.

Naming Structure

The high level view of micro-kernel naming is generated from the documented grammar rules:

Common Name Shapes

For matmul-family compute micro-kernels, buffer descriptors appear in the order destination, LHS input, then RHS input. The output descriptors of LHS and RHS packing micro-kernels match the corresponding packed input descriptors of the matmul micro-kernel.

Packed Buffer Layouts

Packed buffers include a p<width>x<height> layout in full micro-kernel names. For matmul-family names, the LHS packed width is normally the row blocking dimension (MR), and the RHS packed width is normally the column blocking dimension (NR). The packed height is the block depth (BD), which is derived from the KR and SR values used by the micro-kernel as KR / SR.

Packed buffers can also encode data order, packed scale type, and packed bias type. Scale values are encoded as s<type> and bias values as b<type>. Legacy scalef* and biasf* spellings are not valid in the grammar.

How to Read the Grammar

Naming Rules

The documented naming rules are listed below.

Micro-kernel directory name

Describes every micro-kernel directory name accepted by the naming rules.

directory_name = "pack" | matmul_fused_ops "_" simplified_buffer ("_" simplified_buffer)+ | "dwconv" "_" simplified_buffer ("_" simplified_buffer)+

Micro-kernel name

Describes every micro-kernel name accepted by the naming rules.

kernel_name = matmul_ukernel_name | dwconv_ukernel_name

Matmul micro-kernel name

Describes names for matmul-family compute and packing micro-kernels.

matmul_ukernel_name = "kai_" matmul_fused_ops ("_" buffer) ("_" buffer)+ ["_" tile_size] ["_" tech] ["_" feature] ["_" instruction] ["_" uarch]

where:

Depthwise micro-kernel name

Describes names for depthwise convolution and depthwise RHS packing micro-kernels.

dwconv_ukernel_name = "kai_" ("dwconv_clamp" ("_" buffer)+ ("_" filter_size) ("_" dw_stride) ("_" dwconv_output_block_size) ("_" tech) ["_" instruction] | "rhs_dwconv_pack" ("_" buffer)+ ("_" tech))

Target microarchitecture

Describes a target microarchitecture for which a micro-kernel is optimized.

uarch = "cortexa55"

SIMD engine

Describes the SIMD engine targeted by the implementation.

tech = "neon" | "sve" | "sve2" | "sve2p1" | "sme" | "sme2" | "sme2p1"

Primary feature

Describes the predominant FEAT_<feature> used by the implementation.

feature = "i8mm" | "dotprod"

Primary instruction family

Describes the predominant SIMD instruction family used by the implementation.

instruction = "dot" | "i8mm" | "mla" | "mmla" | "mopa" | "sdot"

Convolution stride

Describes the stride used by a depthwise convolution micro-kernel.

dw_stride = "s" @natural_int

Convolution filter size

Describes the height-by-width filter shape used by a depthwise convolution micro-kernel.

filter_size = @natural_int "x" @natural_int

Fused operation descriptor

Describes the primary matmul-family operation and any encoded fused operation.

matmul_fused_ops = ["i"] "matmul" ["_clamp"] | "lhs_pack" | "rhs_pack_kxn" | "rhs_pack_nxk"

Directory buffer descriptor

Describes an input or output buffer in a micro-kernel directory name. Directory names use abbreviated descriptors and omit concrete packed layout details.

simplified_buffer = [quantization] @operand_type [quantization_axis] ["p"]

Buffer descriptor

Describes an input or output buffer in a full micro-kernel name. Packed buffers include their concrete packed layout.

buffer = [quantization] @operand_type [quantization_axis] [pack_description]

where:

Packed buffer layout description

Describes the packed-buffer suffix of a full buffer descriptor.

pack_description = packing_layout [pack_order] [scale_type] [bias_type]

Packed bias type

Describes the operand type used for bias values stored in a packed buffer.

bias_type = "b" @operand_type

Packed scale type

Describes the operand type used for scale values stored in a packed buffer.

scale_type = "s" @operand_type

Packing layout

Describes the dimensions used when data is packed into a buffer.

packing_layout = "p" size "x" size

where:

Packed data order

Describes the ordering of values inside a packed buffer.

pack_order = "s1s0" | "s4s0" | "s16s0"

where:

Depthwise output block size

Describes the output block shape produced by a depthwise convolution micro-kernel. The c column size means all channels.

dwconv_output_block_size = @natural_int "x" (@natural_int | "c")

Primary tile size

Describes the primary row-by-column tile computed by a micro-kernel.

tile_size = size "x" size

Dimension size

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.

size = @natural_int | @natural_int "vl" | @natural_int "vs" | "mr" | "nr"

where:

Quantization axis or block shape

Describes how quantization parameters are associated with data dimensions or blocks.

quantization_axis = "cx" | "dx" | "d32" | "c32"

where:

Quantization mode

Describes whether quantized data uses symmetric or asymmetric quantization.

quantization = "qa" | "qs"

where:

Rule Enforcement

The naming scheme is implemented in tools/naming/rules.py. Micro-kernel and directory names are checked by tools/check_microkernel_names.py, and CI uses the same checker to enforce the rules.

This document is generated from the naming rules. Regenerate it with tools/check_microkernel_names.py --generate-documentation after updating the naming scheme.

Known naming issues

Some legacy micro-kernel and directory names do not match the current grammar, but are retained to preserve the existing API. The known exceptions are listed in tools/naming/issues.py. To include them in checker output, run tools/check_microkernel_names.py --report-known-issues.

Full naming grammar

The grammar below is generated from the naming rules.

directory_name = "pack" | matmul_fused_ops "_" simplified_buffer ("_" simplified_buffer)+ | "dwconv" "_" simplified_buffer ("_" simplified_buffer)+
kernel_name = matmul_ukernel_name | dwconv_ukernel_name
matmul_ukernel_name = "kai_" matmul_fused_ops ("_" buffer) ("_" buffer)+ ["_" tile_size] ["_" tech] ["_" feature] ["_" instruction] ["_" uarch]
dwconv_ukernel_name = "kai_" ("dwconv_clamp" ("_" buffer)+ ("_" filter_size) ("_" dw_stride) ("_" dwconv_output_block_size) ("_" tech) ["_" instruction] | "rhs_dwconv_pack" ("_" buffer)+ ("_" tech))
uarch = "cortexa55"
tech = "neon" | "sve" | "sve2" | "sve2p1" | "sme" | "sme2" | "sme2p1"
feature = "i8mm" | "dotprod"
instruction = "dot" | "i8mm" | "mla" | "mmla" | "mopa" | "sdot"
dw_stride = "s" @natural_int
filter_size = @natural_int "x" @natural_int
matmul_fused_ops = ["i"] "matmul" ["_clamp"] | "lhs_pack" | "rhs_pack_kxn" | "rhs_pack_nxk"
simplified_buffer = [quantization] @operand_type [quantization_axis] ["p"]
buffer = [quantization] @operand_type [quantization_axis] [pack_description]
pack_description = packing_layout [pack_order] [scale_type] [bias_type]
bias_type = "b" @operand_type
scale_type = "s" @operand_type
packing_layout = "p" size "x" size
pack_order = "s1s0" | "s4s0" | "s16s0"
dwconv_output_block_size = @natural_int "x" (@natural_int | "c")
tile_size = size "x" size
size = @natural_int | @natural_int "vl" | @natural_int "vs" | "mr" | "nr"
quantization_axis = "cx" | "dx" | "d32" | "c32"
quantization = "qa" | "qs"