You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update learning path content for SME2 and KleidiAI integration on Android
- Revised titles and descriptions for clarity and consistency
- Enhanced learning objectives to reflect performance measurement focus
- Improved prerequisite details for building and running llama.cpp
- Updated figures and alt-text for better accessibility and understanding
- Added summaries and next steps to guide users through the learning path
Copy file name to clipboardExpand all lines: content/learning-paths/mobile-graphics-and-gaming/performance_llama_cpp_sme2/introduction.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,13 @@ layout: learningpathall
10
10
In this section, you get a quick mental model of SME2, KleidiAI, and what llama.cpp is doing when it runs LLM inference on an Arm CPU.
11
11
Arm’s latest Client CPU processors such as Arm C1 include Scalable Matrix Extension 2 (SME2). SME2 accelerates the matrix-heavy AI operations behind large language models (LLMs), media processing, speech recognition, computer vision, real-time apps and multimodal apps.
12
12
13
-
llama.cpp provides extensive support for many LLMs, including Phi, Llama, DeepSeek, Gemma and Qwen. Llama.cpp is designed for efficient CPU-based inference. It enables on-device LLM execution, reducing latency and enhancing privacy.
13
+
llama.cpp provides extensive support for many LLMs, including Phi, Llama, DeepSeek, Gemma and Qwen. It's designed for efficient CPU-based inference, enabling on-device LLM execution that reduces latency and enhances privacy.
14
14
15
-
By default llama.cpp integrates with Arm KleidiAI, a suite of optimized microkernels for Arm CPUs. KleidiAI includes SME2optimized microkernels to get more performance benefits.
15
+
By default, llama.cpp integrates with Arm KleidiAI, a suite of optimized microkernels for Arm CPUs. KleidiAI includes SME2-optimized microkernels to deliver additional performance benefits.
16
16
17
-
In this learning path, llama.cpp and Llama-3.2-3B-Instruct-Q4_0.gguf model with 3 Billion parameters is used for the tutorial.
17
+
This Learning Path uses the `Llama-3.2-3B-Instruct-Q4_0.gguf` model with 3 billion parameters.
18
+
19
+
Move on to the next section to see how KleidiAI microkernels integrate into llama.cpp's CPU backend.
Copy file name to clipboardExpand all lines: content/learning-paths/mobile-graphics-and-gaming/performance_llama_cpp_sme2/kleidiai_integration.md
+9-3Lines changed: 9 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ In this section, you look at how SME2 connects into the Arm software ecosystem b
13
13
14
14
The KleidiAI library provides optimized matrix multiplication (matmul) kernels tailored for hardware features such as SME, I8MM, and Dot Product (DotProd) acceleration. In llama.cpp this feature is enabled with the build option `GGML_CPU_KLEIDIAI`.
15
15
16
-

16
+

17
17
18
18
KleidiAI is integrated as a trait of `ggml-cpu` in the llama.cpp CPU backend.
19
19
The integration source code is located in the following directory of llama.cpp:
@@ -43,7 +43,7 @@ More operators and data types are being supported by KleidiAI microkernels.
43
43
44
44
The figure below shows how KleidiAI microkernels are used for `matmul` with `GGML_TYPE_Q4_0` or `GGML_TYPE_Q8_0` RHS(weight).
45
45
46
-

46
+

47
47
48
48
The packing of `GGML_TYPE_Q4_0` or `GGML_TYPE_Q8_0` weight (RHS) only needs to be performed one time when llama.cpp loads the model and weight tensor data, because the weight never changes during inference. For performance, it repacks the original GGUF weights into a layout optimized for cache-friendly access and DotProd, I8MM, and SME2 operations with the KleidiAI microkernels.
Now that you know where the KleidiAI SME2 path lives in llama.cpp and what it accelerates, move on to the next section to build the binary for inference.
134
+
## What you've accomplished and what's next
135
+
136
+
In this section:
137
+
- You traced the KleidiAI SME2 path through the llama.cpp CPU backend, from model load through prefill and token decode
138
+
- You identified the specific microkernels that handle each stage and the priority order (SME2 → I8MM → DotProd) used for microkernel selection
139
+
140
+
In the next section, you'll set up the cross-compile toolchain and build a statically linked `llama-cli` binary with SME2 and KleidiAI enabled.
Copy file name to clipboardExpand all lines: content/learning-paths/mobile-graphics-and-gaming/performance_llama_cpp_sme2/run_llm.md
+17-15Lines changed: 17 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ layout: learningpathall
8
8
9
9
## Run the Llama-3.2-3B-Instruct-Q4_0.gguf model with llama-cli
10
10
11
-
In this section, you run the model on an SME2-capable Android device. You will compare performance with SME2 enabled and disabled.
11
+
In this section, you run the model on an SME2-capable Android device and compare performance with SME2 enabled and disabled.
12
12
13
13
Put the built `llama-cli` executable and the `Llama-3.2-3B-Instruct-Q4_0.gguf` model file on your Android target that supports SME2. Using Android Debug Bridge (ADB) is usually the easiest way to transfer files and open a shell on the device.
14
14
@@ -44,17 +44,17 @@ adb shell
44
44
cd /data/local/tmp/llama_sme2
45
45
```
46
46
47
-
The figure below shows the architecture of Llama-3.2-3B model,
48
-

47
+
The figure below shows the architecture of the Llama-3.2-3B model:
48
+

49
49
50
50
## Inference with SME2 enabled
51
51
52
-
You run the model by binding it to a single Arm C1-Pro core with CPU affinity. To enable SME2 microkernels, you must set the `GGML_KLEIDIAI_SME` environment variable before running the application.
52
+
To enable SME2 microkernels, set the `GGML_KLEIDIAI_SME` environment variable before running the application. The flags used here are: `taskset 2` pins the process to CPU core 2 (the Arm C1-Pro core), `-st` enables single-token generation mode to report per-token performance stats, `-C 0x2 -Cb 0x2` sets CPU affinity for operator execution, and `-t 1` limits inference to one thread. If `taskset` is not available on your device, run the command without it.
env GGML_KLEIDIAI_SME="1" taskset 2 ./llama-cli -m ./Llama-3.2-3B-Instruct-Q4_0.gguf -st -C 0x2 -Cb 0x2 -t 1 -p "What is Arm SME2 and how does it accelerate AI workloads?"
58
58
```
59
59
60
60
Here `env GGML_KLEIDIAI_SME="1"` enables SME2 microkernels, `taskset 2` binds the `llama-cli` process to CPU core 2 (the Arm C1-Pro core in our case), `-C 0x2 -Cb 0x2` sets the CPU affinity for operator execution, and `-t 1` sets the number of threads to one. If `taskset` is not available on your target device, run the same command without it.
@@ -65,15 +65,17 @@ With the SME2 kernels enabled, you'll notice the following performance output:
65
65
[ Prompt: 12.3 t/s | Generation: 9.1 t/s ]
66
66
```
67
67
68
-
## Inference without SME2 enabled
68
+
Your results will vary depending on the device and the SME2 streaming vector length available.
69
69
70
-
For a performance comparison, you can run the model with SME2 microkernels disabled. In this scenario, I8MM and Dotprod microkernels are used instead.
70
+
## Baseline performance without SME2
71
+
72
+
For a performance comparison, run the model with SME2 microkernels disabled. In this scenario, I8MM and DotProd microkernels are used instead.
env GGML_KLEIDIAI_SME="0" taskset 2 ./llama-cli -m ./Llama-3.2-3B-Instruct-Q4_0.gguf -st -C 0x2 -Cb 0x2 -t 1 -p "What is Arm SME2 and how does it accelerate AI workloads?"
74
76
```
75
77
76
-
With the resulting performance:
78
+
The output is similar to:
77
79
78
80
```output
79
81
[ Prompt: 7.9 t/s | Generation: 5.9 t/s ]
@@ -85,15 +87,15 @@ You can profile the model execution with the approach introduced in [Profile lla
85
87
86
88
The Streamline Timeline view and Annotate Markers in the figure below show that the token generation speeds up significantly at both Prefill and Decode stage. The PMU event counters show that many SME2 instructions, especially SME2 Integer Outer Product Accumulate instructions at the Prefill stage and SME2 Integer Outer Product instructions at the Decode stage, are used for acceleration.
87
89
88
-

90
+

89
91
90
92
The Streamline Call Paths view below indicates similar speedup, it also shows that DotProd and I8MM KleidiAI microkernels are used instead when SME2 is not enabled.
91
93
92
-

94
+

93
95
94
96
## Optional: Print the kernel names at runtime
95
97
96
-
To investigate which operators in the model graph are delegated to KleidiAI microkernels, you can add some code as below to *./ggml/src/ggml-cpu/kleidiai/kleidiai.cpp* and recompile the binary. When you run the inference, the names of operators that make use of KleidiAI microkernels will be printed. This is only for debugging purposes.
98
+
To investigate which operators in the model graph are delegated to KleidiAI microkernels, you can add some code as below to `./ggml/src/ggml-cpu/kleidiai/kleidiai.cpp` and recompile the binary. When you run the inference, the names of operators that make use of KleidiAI microkernels will be printed. This is only for debugging purposes.
KleidiAI support in llama.cpp is still evolving, more operators will be accelerated by KleidiAI microkernels, unleashing greater potential of SME2.
132
+
You've run a quantized LLM on an SME2-capable Android device and measured the throughput difference with KleidiAI SME2 microkernels enabled and disabled. The results demonstrate meaningful gains at both the Prefill and Decode stages, making on-device LLM inference faster and more power-efficient on Arm hardware.
131
133
132
-
With out-of-box KleidiAI and SME2 support in llama.cpp, you can get significant performance uplift at both Prefill and Decode stage, which enhances the experience of running LLM locally on device.
134
+
With out-of-the-box KleidiAI and SME2 support in llama.cpp, you can achieve significant performance improvements without any changes to the model or application code.
133
135
134
-
Now that you have validated the runtime behavior with SME2 on your target device, move on to the Next Steps section to explore profiling and related Arm on-device AI performance resources.
136
+
Move on to the Next Steps section to explore profiling and related Arm on-device AI performance resources.
0 commit comments