Elffuss BraidHub

kikocis/kleidiai public

main · 8.6 KiBRenderedRawPermalink
1<!--
2 SPDX-FileCopyrightText: Copyright 2024-2026 Arm Limited and/or its affiliates <open-source-office@arm.com>
3
4 SPDX-License-Identifier: Apache-2.0
5-->
6
7# KleidiAI Benchmark Tool
8
9KleidiAI provides a single benchmarking binary that runs multiple variants via subcommands:
10
11- `kleidiai_benchmark matmul` for standard matrix multiplication (matmul)
12- `kleidiai_benchmark pack_matmul` for LHS packing followed by matrix multiplication
13- `kleidiai_benchmark imatmul` for indirect matrix multiplication (imatmul, chunked K)
14- `kleidiai_benchmark dwconv` for depthwise convolution (dwconv)
15
16The tool supports flexible argument parsing and Benchmark Framework options.
17If no operator is specified, `matmul` will be used by default.
18
19## Building
20
21From the KleidiAI root directory:
22
23### Build instructions
24
25```
26mkdir -p build && cd build
27cmake -DKLEIDIAI_BUILD_BENCHMARK=ON -DCMAKE_BUILD_TYPE=Release ../
28make -j
29```
30
31### Linux®-target
32
33```
34$ mkdir -p build && cd build
35$ cmake -DCMAKE_C_COMPILER=/path/to/aarch64-none-linux-gnu-gcc -DCMAKE_CXX_COMPILER=/path/to/aarch64-none-linux-gnu-g++ -DKLEIDIAI_BUILD_BENCHMARK=ON -DCMAKE_BUILD_TYPE=Release ../
36```
37
38### Android™-target
39
40```
41$ mkdir -p build && cd build
42$ cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/android-ndk/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=30 -DKLEIDIAI_BUILD_BENCHMARK=ON -DCMAKE_BUILD_TYPE=Release ../
43```
44
45## Usage
46
47### Quick Examples
48
49Run matmul, pack_matmul, imatmul and dwconv with example dimensions:
50
51```sh
52./kleidiai_benchmark matmul -m 32 -n 32 -k 32
53./kleidiai_benchmark pack_matmul -m 32 -n 32 -k 32
54./kleidiai_benchmark imatmul -m 32 -n 32 -c 4 -l 8
55./kleidiai_benchmark dwconv --input_height 32 --input_width 32 --channels 64 --padding 1,1,1,1
56```
57
58### Matmul Benchmark
59
60The dimensions of the LHS- and RHS-matrices needs to be specified with the `-m`, `-n` and `-k` options.
61The shape of the LHS-matrix is MxK, and the shape of the RHS-matrix is KxN.
62Run the matmul benchmark with matrix dimensions:
63
64```
65./kleidiai_benchmark matmul -m <M> -n <N> -k <K> [-b <BLOCK_SIZE>]
66```
67
68Use `--benchmark_filter` to run an individual matrix multiplication micro-kernel:
69
70```
71./kleidiai_benchmark matmul -m <M> -n <N> -k <K> --benchmark_filter=^<name>
72```
73
74`-b` sets the block size for blockwise quantization and defaults to `32` if omitted.
75
76### PackMatmul Benchmark
77
78Some matrix multiplication micro-kernels have benchmark metadata for LHS preparation. Use `pack_matmul` to run
79registered LHS packing and matrix multiplication micro-kernel pairs:
80
81```
82./kleidiai_benchmark pack_matmul -m <M> -n <N> -k <K> [-b <BLOCK_SIZE>]
83```
84
85Example:
86
87```
88$ ./kleidiai_benchmark matmul -m 13 -n 17 -k 18
89Run on (8 X 1800 MHz CPU s)
90Load Average: 10.01, 10.06, 10.06
91-----------------------------------------------------------------------------------------------------
92Benchmark Time CPU Iterations
93-----------------------------------------------------------------------------------------------------
94matmul_clamp_f32_qai8dxp1x8_qsi4cxp4x8_1x4x32_neon_dotprod 123 ns 123 ns 1234567
95matmul_clamp_f32_qai8dxp1x8_qsi4cxp8x8_1x8x32_neon_dotprod 123 ns 123 ns 1234567
96matmul_clamp_f32_qai8dxp4x8_qsi4cxp4x8_4x4x32_neon_i8mm 123 ns 123 ns 1234567
97matmul_clamp_f32_qai8dxp4x8_qsi4cxp4x8_8x4x32_neon_i8mm 123 ns 123 ns 1234567
98matmul_clamp_f32_qai8dxp4x8_qsi4cxp8x8_4x8x32_neon_i8mm 123 ns 123 ns 1234567
99matmul_clamp_f32_qai8dxp4x8_qsi4cxp8x8_8x8x32_neon_i8mm 123 ns 123 ns 1234567
100```
101
102### iMatmul Benchmark (chunked K)
103
104Run the imatmul benchmark with matrix dimensions and chunking:
105
106```
107./kleidiai_benchmark imatmul -m <M> -n <N> -c <CHUNK_COUNT> -l <CHUNK_LENGTH>
108```
109
110Where:
111
112- `-m`, `-n` are matrix dimensions (LHS: MxK, RHS: KxN)
113- `-c` is the number of K chunks
114- `-l` is the length of each K chunk
115
116Example:
117
118```
119./kleidiai_benchmark imatmul -m 32 -n 32 -c 4 -l 16
120Run on (12 X 24 MHz CPU s)
121Load Average: 4.59, 3.95, 3.95
122---------------------------------------------------------------------------------------------------------
123Benchmark Time CPU Iterations
124---------------------------------------------------------------------------------------------------------
125imatmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa 123 ns 123 ns 1234567
126imatmul_clamp_f16_f16p2vlx2_f16p2vlx2b_2vlx2vl_sme_mopa 123 ns 123 ns 1234567
127imatmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme2_mopa 123 ns 123 ns 1234567
128imatmul_clamp_f32_f32p2vlx1_f32p2vlx1b_2vlx2vl_sme_mopa 123 ns 123 ns 1234567
129imatmul_clamp_qai8_qai8p2vlx4_qsi8cxp2vlx4sb_2vlx2vl_sme_mopa 123 ns 123 ns 1234567
130imatmul_clamp_qai8_qai8p2vlx4_qsi8cxpsb2vlx4_2vlx2vl_sme2_mopa 123 ns 123 ns 1234567
131```
132
133### DWConv Benchmark (depthwise convolution)
134
135Run the dwconv benchmark specifying the input shape, number of channels, and optional stride/padding/dilation.
136The output dimensions are inferred automatically.
137
138```
139./kleidiai_benchmark dwconv --input_height <H> --input_width <W> --channels <C>
140 [--stride <S_h>,<S_w>] [--padding <P_top>,<P_bottom>,<P_left>,<P_right>]
141 [--dilation <D_h>,<D_w>]
142```
143
144- `--stride` takes two positive comma-separated integers `(stride_rows,stride_cols)` supplied as a single argument
145 (for example, `--stride 1,1` or `--stride=1,2`).
146- `--padding` takes four non-negative comma-separated integers `(top,bottom,left,right)` so you can control padding on
147 both sides of each dimension.
148- `--dilation` takes two positive comma-separated integers `(dilation_rows,dilation_cols)`.
149 Defaults for stride and dilation are `1,1`, and padding defaults to `0,0,0,0`.
150- **Note:** The currently registered DWConv micro-kernels only support `stride=1` and `dilation=1`.
151 The benchmark driver will reject other values to avoid advertising unsupported functionality.
152
153Example:
154
155```
156./kleidiai_benchmark dwconv --input_height 32 --input_width 32 --channels 64 --stride 1,1 --padding 1,1,1,1
157Run on (12 X 24 MHz CPU s)
158Load Average: 4.59, 3.95, 3.95
159---------------------------------------------------------------------------------------------------------
160Benchmark Time CPU Iterations
161---------------------------------------------------------------------------------------------------------
162kai_dwconv_clamp_f32_f32_f32p1vlx1b_3x3_s1_4xc_sme2_mla 123 ns 123 ns 1234567
163```
164
165### Filtering
166
167Benchmarks can be filtered using the --benchmark_filter option, which accepts a regex. For example, to only run the sme2 micro-kernels:
168(Note: The measurement results are placeholders)
169
170```
171./kleidiai_benchmark matmul --benchmark_filter=sme2 -m 13 -n 17 -k 18
172./kleidiai_benchmark pack_matmul --benchmark_filter=sme2 -m 13 -n 17 -k 18
173./kleidiai_benchmark imatmul --benchmark_filter=sme2 -m 13 -n 17 -c 1 -l 18
174./kleidiai_benchmark dwconv --benchmark_filter=sme2 --input_height 32 --input_width 32 --channels 64 --padding 1,1,1,1
175Run on (8 X 1800 MHz CPU s)
176Load Average: 10.09, 10.13, 10.09
177-----------------------------------------------------------------------------------------------------
178Benchmark Time CPU Iterations
179-----------------------------------------------------------------------------------------------------
180matmul_clamp_f32_qsi8d32p1x4_qsi4c32p4vlx4_1x4vl_sme2_sdot 123 ns 123 ns 1234567
181imatmul_clamp_f16_f16p2vlx2_f16p2vlx2_2vlx2vl_sme2_mopa 123 ns 123 ns 1234567
182kai_dwconv_clamp_f32_f32_f32p1vlx1b_3x3_s1_4xc_sme2_mla 123 ns 123 ns 1234567
183```
184
185### Listing Available Benchmarks
186
187To list all available benchmarks:
188
189```
190./kleidiai_benchmark --benchmark_list_tests
191
192```
193
194Specify the micro-kernel operator to list all the benchmarks of a certain type.
195
196```
197./kleidiai_benchmark matmul --benchmark_list_tests
198./kleidiai_benchmark pack_matmul --benchmark_list_tests
199./kleidiai_benchmark imatmul --benchmark_list_tests
200./kleidiai_benchmark dwconv --benchmark_list_tests
201```
202
203### Notes
204
205This application uses [Google Benchmark](https://github.com/google/benchmark), so all options that Google Benchmark provides can be used.
206To list the options provided use the `--help` flag or refer to the [user guide](https://github.com/google/benchmark/blob/main/docs/user_guide.md).