Elffuss BraidHub

kikocis/kleidiai public

Branch: main
655592420abd fix: Improve SME2 F32 elastic GEMM kernel performance Viet-Hoa Do,
..
README.md6.8 KiB
kai_lhs_imatmul_pack_x16p2vlx2_x16p_sme.c3.0 KiB
kai_lhs_imatmul_pack_x16p2vlx2_x16p_sme.h2.3 KiB
kai_lhs_imatmul_pack_x16p2vlx2_x16p_sme_asm.S12.8 KiB
kai_lhs_imatmul_pack_x32p2vlx1_x32p_sme.c3.0 KiB
kai_lhs_imatmul_pack_x32p2vlx1_x32p_sme.h2.3 KiB
kai_lhs_imatmul_pack_x32p2vlx1_x32p_sme_asm.S12.5 KiB
kai_lhs_imatmul_pack_x8p2vlx4_x8p_sme.c3.0 KiB
kai_lhs_imatmul_pack_x8p2vlx4_x8p_sme.h2.3 KiB
kai_lhs_imatmul_pack_x8p2vlx4_x8p_sme_asm.S12.6 KiB
kai_lhs_pack_bf16p2vlx2_f32_sme.c2.9 KiB
kai_lhs_pack_bf16p2vlx2_f32_sme.h2.6 KiB
kai_lhs_pack_bf16p2vlx2_f32_sme2.c2.9 KiB
kai_lhs_pack_bf16p2vlx2_f32_sme2.h2.6 KiB
kai_lhs_pack_bf16p2vlx2_f32_sme2_asm.S7.5 KiB
kai_lhs_pack_bf16p2vlx2_f32_sme_asm.S20.3 KiB
kai_lhs_pack_bf16p8x4_f16_neon.c12.3 KiB
kai_lhs_pack_bf16p8x4_f16_neon.h2.9 KiB
kai_lhs_pack_f16pmrx2_f32_neon.c7.2 KiB
kai_lhs_pack_f16pmrx2_f32_neon.h2.9 KiB
kai_lhs_pack_f32p2vlx1_f32_sme.c3.1 KiB
kai_lhs_pack_f32p2vlx1_f32_sme.h2.8 KiB
kai_lhs_pack_f32p2vlx1_f32_sme_asm.S12.4 KiB
kai_lhs_pack_x16p2vlx2_x16_sme.c3.1 KiB
kai_lhs_pack_x16p2vlx2_x16_sme.h2.8 KiB
kai_lhs_pack_x16p2vlx2_x16_sme_asm.S12.7 KiB
kai_lhs_pack_x8p2vlx4_x8_sme.c3.1 KiB
kai_lhs_pack_x8p2vlx4_x8_sme.h2.8 KiB
kai_lhs_pack_x8p2vlx4_x8_sme_asm.S12.6 KiB
kai_lhs_quant_pack_bf16p1x4_f32_neon.c3.5 KiB
kai_lhs_quant_pack_bf16p1x4_f32_neon.h2.9 KiB
kai_lhs_quant_pack_bf16p8x4_f32_neon.c8.0 KiB
kai_lhs_quant_pack_bf16p8x4_f32_neon.h2.9 KiB
kai_lhs_quant_pack_qai8dxp_bf16_neon.c25.6 KiB
kai_lhs_quant_pack_qai8dxp_bf16_neon.h3.5 KiB
kai_lhs_quant_pack_qai8dxp_f16_neon.c23.6 KiB
kai_lhs_quant_pack_qai8dxp_f16_neon.h3.5 KiB
kai_lhs_quant_pack_qai8dxp_f32.c9.6 KiB
kai_lhs_quant_pack_qai8dxp_f32.h3.5 KiB
kai_lhs_quant_pack_qsi8d32p4x8sb_f32_neon.c16.9 KiB
kai_lhs_quant_pack_qsi8d32p4x8sb_f32_neon.h3.9 KiB
kai_lhs_quant_pack_qsi8d32p_f32.c4.1 KiB
kai_lhs_quant_pack_qsi8d32p_f32.h3.8 KiB
kai_lhs_quant_pack_qsi8d32p_f32_neon.c4.0 KiB
kai_lhs_quant_pack_qsi8d32p_f32_neon.h3.9 KiB
kai_lhs_quant_pack_qsi8d32pscalef32_f16_neon.c5.4 KiB
kai_lhs_quant_pack_qsi8d32pscalef32_f16_neon.h3.9 KiB
kai_lhs_quant_pack_qsi8d32pscalef32_f32_neon.c7.2 KiB
kai_lhs_quant_pack_qsi8d32pscalef32_f32_neon.h3.9 KiB
kai_matmul_pack_cols_x8p4vsx4_x8_sme_asm.S5.4 KiB
kai_matmul_pack_lhs_mxk_x32p4vsx1_x32_sme.c4.5 KiB
kai_matmul_pack_lhs_mxk_x32p4vsx1_x32_sme_asm.S8.3 KiB
kai_matmul_pack_lhs_mxk_x8p4vsx4_x8_sme.c4.5 KiB
kai_matmul_pack_rhs_kxn_qsi8cxp4vsx4bi32sf32_qsi8_i32_f32_sme.c5.4 KiB
kai_matmul_pack_rhs_kxn_qsi8cxp4vsx4bi32sf32_qsi8_i32_f32_sme_asm.S5.9 KiB
kai_matmul_pack_rhs_kxn_x32p4vsx1bx32_x32_x32_sme.c4.5 KiB
kai_matmul_pack_rhs_kxn_x32p4vsx1bx32_x32_x32_sme_asm.S3.9 KiB
kai_matmul_pack_rhs_kxn_x8p4vsx4_x8_sme.c4.7 KiB
kai_matmul_pack_rhs_nxk_x32p4vsx1bx32_x32_x32_sme.c4.9 KiB
kai_matmul_pack_rhs_nxk_x32p4vsx1bx32_x32_x32_sme_asm.S8.5 KiB
kai_matmul_pack_rhs_nxk_x8p4vsx4_x8_sme.c4.8 KiB
kai_matmul_pack_rows_x8p4vsx4_x8_sme_asm.S8.5 KiB
kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.c4.4 KiB
kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.h3.8 KiB
kai_rhs_imatmul_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme_asm.S6.7 KiB
kai_rhs_imatmul_pack_kxn_x16p2vlx2b_x16_x16_sme.c3.6 KiB
kai_rhs_imatmul_pack_kxn_x16p2vlx2b_x16_x16_sme.h3.2 KiB
kai_rhs_imatmul_pack_kxn_x16p2vlx2b_x16_x16_sme_asm.S5.1 KiB
kai_rhs_imatmul_pack_kxn_x32p2vlx1b_x32_x32_sme.c3.3 KiB
kai_rhs_imatmul_pack_kxn_x32p2vlx1b_x32_x32_sme.h3.2 KiB
kai_rhs_imatmul_pack_kxn_x32p2vlx1b_x32_x32_sme_asm.S4.8 KiB
kai_rhs_imatmul_pack_kxn_x32p4vlx1b_x32_x32_sve.c3.3 KiB
kai_rhs_imatmul_pack_kxn_x32p4vlx1b_x32_x32_sve.h3.2 KiB
kai_rhs_imatmul_pack_kxn_x32p4vlx1b_x32_x32_sve_asm.S5.8 KiB
kai_rhs_pack_kxn_bf16p12x4biasf16_f16_neon.c17.2 KiB
kai_rhs_pack_kxn_bf16p12x4biasf16_f16_neon.h3.3 KiB
kai_rhs_pack_kxn_bf16p12x4biasf32_f16_neon.c17.0 KiB
kai_rhs_pack_kxn_bf16p12x4biasf32_f16_neon.h3.0 KiB
kai_rhs_pack_kxn_bf16p2vlx2b_f32_x32_sme.c8.7 KiB
kai_rhs_pack_kxn_bf16p2vlx2b_f32_x32_sme.h3.3 KiB
kai_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon.c7.4 KiB
kai_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon.h3.0 KiB
kai_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme.c3.2 KiB
kai_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme.h3.2 KiB
kai_rhs_pack_kxn_f32p16vlx1b_f32_f32_sme_asm.S7.0 KiB
kai_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme.c3.3 KiB
kai_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme.h3.3 KiB
kai_rhs_pack_kxn_f32p2vlx1biasf32_f32_f32_sme_asm.S4.6 KiB
kai_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon.c7.4 KiB
kai_rhs_pack_kxn_f32p8x1biasf32_f32_f32_neon.h3.0 KiB
kai_rhs_pack_kxn_qsi4c32p_qsu4c32s1s0.c10.1 KiB
kai_rhs_pack_kxn_qsi4c32p_qsu4c32s1s0.h7.4 KiB
kai_rhs_pack_kxn_qsi4c32ps1s0nrx4_qsu4c32s1s0_neon.c15.6 KiB
kai_rhs_pack_kxn_qsi4c32ps1s0nrx4_qsu4c32s1s0_neon.h7.5 KiB
kai_rhs_pack_kxn_qsi4cxp_qs4cxs1s0.c7.7 KiB
kai_rhs_pack_kxn_qsi4cxp_qs4cxs1s0.h5.1 KiB
kai_rhs_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.c4.1 KiB
kai_rhs_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme.h3.7 KiB
kai_rhs_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme_asm.S6.6 KiB
kai_rhs_pack_kxn_qsi8cxp_qsi8cx_neon.c4.9 KiB
kai_rhs_pack_kxn_qsi8cxp_qsi8cx_neon.h4.5 KiB
kai_rhs_pack_kxn_x16p16vsx2bx16_x16_x16_sve.c4.9 KiB
kai_rhs_pack_kxn_x16p16vsx2bx16_x16_x16_sve_asm.S6.2 KiB
kai_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme.c3.5 KiB
kai_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme.h3.2 KiB
kai_rhs_pack_kxn_x16p2vlx2b_x16_x16_sme_asm.S4.9 KiB
kai_rhs_pack_kxn_x16p32x1b_x16_x16_neon.c3.1 KiB
kai_rhs_pack_kxn_x16p32x1b_x16_x16_neon.h3.2 KiB
kai_rhs_pack_kxn_x16p32x1b_x16_x16_neon_asm.S8.3 KiB
kai_rhs_pack_kxn_x32p16x1b_x32_x32_neon.c3.1 KiB
kai_rhs_pack_kxn_x32p16x1b_x32_x32_neon.h3.2 KiB
kai_rhs_pack_kxn_x32p16x1b_x32_x32_neon_asm.S7.3 KiB
kai_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve.c3.2 KiB
kai_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve.h3.2 KiB
kai_rhs_pack_kxn_x32p4vlx1b_x32_x32_sve_asm.S5.6 KiB
kai_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme.c3.4 KiB
kai_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme.h3.4 KiB
kai_rhs_pack_nxk_f32p2vlx1biasf32_f32_f32_sme_asm.S12.8 KiB
kai_rhs_pack_nxk_qai4c32p_qau4c32s0s1_f32_f32_f32_neon.c7.4 KiB
kai_rhs_pack_nxk_qai4c32p_qau4c32s0s1_f32_f32_f32_neon.h4.5 KiB
kai_rhs_pack_nxk_qai4c32ps1s0nrx4_qau4c32s0s1_f32_f32_f32_neon.c9.3 KiB
kai_rhs_pack_nxk_qai4c32ps1s0nrx4_qau4c32s0s1_f32_f32_f32_neon.h4.7 KiB
kai_rhs_pack_nxk_qai4c32ps1s0nrx4_qau4c32s1s0_f32_f32_f32_neon.c8.6 KiB
kai_rhs_pack_nxk_qai4c32ps1s0nrx4_qau4c32s1s0_f32_f32_f32_neon.h4.7 KiB
kai_rhs_pack_nxk_qsi4c32p_qsu4c32s1s0.c10.5 KiB
kai_rhs_pack_nxk_qsi4c32p_qsu4c32s1s0.h7.4 KiB
kai_rhs_pack_nxk_qsi4c32pnrx4_qsu4c32s1s0_neon.c16.3 KiB
kai_rhs_pack_nxk_qsi4c32pnrx4_qsu4c32s1s0_neon.h7.4 KiB
kai_rhs_pack_nxk_qsi4c32pnrx8_qsu4c32s1s0_neon.c14.7 KiB
kai_rhs_pack_nxk_qsi4c32pnrx8_qsu4c32s1s0_neon.h7.4 KiB
kai_rhs_pack_nxk_qsi4c32ps1s0nrx4_qsu4c32s1s0_neon.c15.2 KiB
kai_rhs_pack_nxk_qsi4c32ps1s0nrx4_qsu4c32s1s0_neon.h6.6 KiB
kai_rhs_pack_nxk_qsi4c32ps1s0scalef16_qsu4c32s16s0_neon.c20.3 KiB
kai_rhs_pack_nxk_qsi4c32ps1s0scalef16_qsu4c32s16s0_neon.h6.0 KiB
kai_rhs_pack_nxk_qsi4c32ps4s0sf16_qsu4c32s16s0_neon.c16.7 KiB
kai_rhs_pack_nxk_qsi4c32ps4s0sf16_qsu4c32s16s0_neon.h6.2 KiB
kai_rhs_pack_nxk_qsi4c32pscalef16_qsu4c32s16s0.c5.9 KiB
kai_rhs_pack_nxk_qsi4c32pscalef16_qsu4c32s16s0.h5.8 KiB
kai_rhs_pack_nxk_qsi4cxp_qs4cxs1s0.c7.7 KiB
kai_rhs_pack_nxk_qsi4cxp_qs4cxs1s0.h5.1 KiB
kai_rhs_pack_nxk_qsi4cxps1s0_qsu4cxs1s0_neon.c9.1 KiB
kai_rhs_pack_nxk_qsi4cxps1s0_qsu4cxs1s0_neon.h5.2 KiB
kai_rhs_pack_nxk_qsi8cxp_qsi8cx_neon.c4.9 KiB
kai_rhs_pack_nxk_qsi8cxp_qsi8cx_neon.h4.5 KiB
kai_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon.c18.1 KiB
kai_rhs_pack_nxk_qsu2cxp4vlx4_qsu2cx_neon.h5.4 KiB
kai_rhs_pack_nxk_qsu2cxp4x4bf32sf32_qsu2cx_neon.c22.3 KiB
kai_rhs_pack_nxk_qsu2cxp4x4bf32sf32_qsu2cx_neon.h5.4 KiB
kai_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme.c3.4 KiB
kai_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme.h3.4 KiB
kai_rhs_pack_nxk_x16p2vlx2b_x16_x16_sme_asm.S13.0 KiB
kai_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon.c3.2 KiB
kai_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon.h3.5 KiB
kai_rhs_pack_nxk_x16p32x1bx16_x16_x16_neon_asm.S37.1 KiB
kai_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon.c3.2 KiB
kai_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon.h3.5 KiB
kai_rhs_pack_nxk_x32p16x1bx32_x32_x32_neon_asm.S11.5 KiB
kai_rhs_quant_pack_kxn_bf16p12x4biasf32_f32_neon.c17.5 KiB
kai_rhs_quant_pack_kxn_bf16p12x4biasf32_f32_neon.h3.2 KiB

README.md

About

Almost all matrix multiplication (matmul) micro-kernels have some kind of packing involved with Right Hand Side (RHS) and/or Left Hand Side (LHS). They are done for performance reasons. Here is a list of different packing micro-kernels that are used for matmul.

Packing

For information about terminologies like mr, nr used here, please refer to the README in the main directory of the micro-kernel.

kai_run_rhs_pack_kxn_f16p16x1biasf16_f16_f16_neon()

Packs RHS(weights) and bias into X blocks that are a combination of RHS and bias. Details of the input are as below.

  1. Bias for N elements
  2. Non-transposed RHS of dimension KxN

The pattern of the packed output is shown below

rhs_pack_pattern_1

Each block has bias and weights arranged as expected by the micro-kernel to produce a mr x nr output matrix. There can be padding involved in the blocks depending on the combination of underlying instruction used for the optimization in the micro-kernel, the chosen values of mr and nr and input dimensions, M, N and K.

kai_run_rhs_pack_kxn_qsi8cxp2vlx4sb_qs8cx_f32_i32_sme()

Pack RHS(weights), bias and scaling factor together into X number of blocks that are a combination of scale, bias and RHS. Details of the input are below.

  1. Values calculated using the bias, reduce_sum and lhs_zero point such that; Value[n] = Bias[n] - (lhs_zero_point * reduce_sum[n]). Each block has nr elements, including padding.
  2. Non-transposed RHS of dimension KxN. Each block contains nr*kr elements, including any padding.
  3. Scale values calculated as Scale[n] = (rhs_scale[n] * lhs_scale) / dst_scale. Each block has nr elements, including any padding.

The pattern of the packed output is shown below.

rhs_pack_pattern_2

Padding may be involved in the blocks depending on the values of mr, nr and kr and the input dimensions, M, N and K.

Packing for int4 matmul micro-kernels

For optimal cache utilization, the operands are packed for the matmul operations. There are 2 types of packing micro-kernels used in int4 matmul micro-kernels:

1. Quantize and pack:

These packing micro-kernels are used with LHS operand of the matmul. It quantizes the input to int8 and packs them along with their scale (and offset values in asymmetric quantization) in the destination matrix.

kai_run_lhs_quant_pack_qsi8d32p_f32()

Quantize and pack LHS matrix with per-block quantization parameters.

Inputs

  1. LHS matrix(M x K) with float (f32) input values and dimensions
  2. Block length, mr, kr, sr and other parameters defines how to interleave multiple rows and split the rows in packing implementation.

Output

LHS packed matrix containing quantized (q) symmertric (s) signed int8 (i8) values, with block-wise quantization (d32p) parameters, i.e. the quantized elements are stored in blocks and each block has a scale factor.

kai_run_lhs_quant_pack_qsi8d32p4x8sb_f32_neon()

This micro-kernel follows the same format as kai_run_lhs_quant_pack_qsi8d32p_f32() above.

However, it differs in the following way:

  1. Functionality is implemented using vectorized Advanced SIMD to improve performance
  2. The packing micro-kernel targets a specific shape with mr 4, kr 16, sr 2 & bl 32

kai_run_lhs_quant_pack_qai8dxp_f32()

Quantize and pack LHS matrix with per-dimension(row) quantization parameters.

Inputs

  1. LHS matrix(M x K) with float(f32) input values and dimensions
  2. mr, kr, sr and other parameters defines how to interleave multiple rows and split the rows in packing implementation.

Output

LHS packed matrix containing quantized (q) asymmertric (a) signed int8 (i8) values, with per-row (dx) quantization parameters, i.e. the scale factor is stored at the end of each row.

2. Pack:

These packing micro-kernels are used with RHS values. It takes 4-bit quantized unsigned int values, with their scales (and offset values in asymmetric quantization) and bias as inputs and packs them in the destination matrix. Optionally, reduction sums are also calculated and packed for each row/block as well.

kai_run_rhs_pack_nxk_qsi4c32pscalef16_qsu4c32s16s0()

Packs RHS matrix and bias with per-block quantization parameters.

Inputs

  1. RHS matrix and dimensions. The input RHS matrix (N x K) has quantized (q) symmetric (s) 4-bit unsigned int (u4) values with per-block quantization (c32) parameters. The two int4 elements are packed in interleaved order (s16s0) i.e. two int4 values stored in one byte, where the lower order part of the byte (low) holds the low nibble (K-index + 0) and the higher order of the byte holds the high nibble (K-index + 16). Fp16 scale factors are stored at the beginning of each block.
  2. Block length, mr, kr sr and other parameters defines how to interleave multiple rows and split the rows in packing implementation.
  3. Bias for N elements

Output

RHS packed matrix (N x K) contains quantized (q) symmetric (s) 4-bit signed int (i4) values with per-block quantization (c32). Two int4 values are stored in one byte. Fp16 scale factors (scalef16) are stored at the end of each block.

kai_run_rhs_pack_nxk_qsi4cxp_qs4cxs1s0()

Packs RHS matrix and bias with per-channel quantization parameters.

Inputs

  1. RHS matrix and dimensions. The input RHS matrix (N x K) has quantized (q) symmetric (s) 4-bit signed or unsigned int (4) values with per-channel quantization (cx) parameters. The two int4 elements are packed in sequential order (s1s0) i.e. two int4 values stored in one byte, where the lower order part of the byte (low) holds the low nibble (K-index + 0) and the higher order of the byte holds the high nibble (K-index + 1).
  2. Block length, mr, kr sr and other parameters defines how to interleave multiple rows and split the rows.
  3. Bias for N elements
  4. Scale factors

Output

RHS packed matrix (N x K) contains quantized (q) symmetric (s) 4-bit signed int (i4) values with per-channel quantization (cx). Two int4 values are stored in one byte.

kai_run_rhs_pack_kxn_qsi4cxp_qs4cxs1s0()

Same as kai_run_rhs_pack_nxk_qsi4cxp_qs4cxs1s0() with the input RHS matrix dimensions as K x N.

Vectorized packing micro-kernels with predefined block depth

Alternative versions of certain packing micro-kernels are provided using Advanced SIMD, specialized for a predefined block depth (equal to kr / sr).

kai_run_rhs_pack_nxk_qsi4c32pnrx8_qsu4c32s1s0_neon()

This takes the same input and provides the same output as kai_run_rhs_pack_nxk_qsi4c32p_qsu4c32s1s0(), with faster execution time where Advanced SIMD instructions are supported. The nrx8 included within the name indicates that this routine works only where kr / sr = 8, and for any value of nr that fits within the wider constraints.