Skip to content

Commit cfcdc9d

Browse files
author
Zenon Xiu
committed
new learning path: Unleashing leading On-Device AI performance with llama.cpp, SME2 and KleidiAI
1 parent 92cce15 commit cfcdc9d

12 files changed

Lines changed: 335 additions & 0 deletions
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: Unleashing leading On-Device AI performance with llama.cpp, SME2 and KleidiAI
3+
4+
minutes_to_complete: 40
5+
6+
who_is_this_for: This is an advanced topic for software developers, performance engineers, and AI practitioners
7+
8+
learning_objectives:
9+
- Build llama.cpp library with KleidiAI and SME2 support
10+
- Profile performance of LLMs running on llama-cli
11+
- Learn how KleidiAI and SME2 accelerates LLM operators
12+
13+
prerequisites:
14+
- Knowledge of KleidiAI and SME2
15+
- An Linux or Android device with Arm SME2 support
16+
17+
author: Zenon Zhilong Xiu
18+
19+
### Tags
20+
skilllevels: Advanced
21+
subjects: ML
22+
armips:
23+
- Arm C1 CPU
24+
- Arm SME2 unit
25+
tools_software_languages:
26+
- C++
27+
- llama.cpp
28+
operatingsystems:
29+
- Android
30+
- Linux
31+
32+
33+
34+
further_reading:
35+
- resource:
36+
title: part 1 Arm Scalable Matrix Extension Introduction
37+
link: https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-scalable-matrix-extension-introduction
38+
type: blog
39+
- resource:
40+
title: part 2 Arm Scalable Matrix Extension Instructions
41+
link: https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-scalable-matrix-extension-introduction-p2
42+
type: blog
43+
- resource:
44+
title: part4 Arm SME2 Introduction
45+
link: https://developer.arm.com/community/arm-community-blogs/b/architectures-and-processors-blog/posts/part4-arm-sme2-introduction
46+
type: blog
47+
- resource:
48+
title: Profile llama.cpp performance with Arm Streamline and KleidiAI LLM kernels
49+
link: https://learn.arm.com/learning-paths/servers-and-cloud-computing/llama_cpp_streamline/
50+
type: blog
51+
52+
53+
54+
### FIXED, DO NOT MODIFY
55+
# ================================================================================
56+
weight: 1 # _index.md always has weight of 1 to order correctly
57+
layout: "learningpathall" # All files under learning paths have this same wrapper
58+
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
59+
---
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
# ================================================================================
3+
# FIXED, DO NOT MODIFY THIS FILE
4+
# ================================================================================
5+
weight: 21 # The weight controls the order of the pages. _index.md always has weight 1.
6+
title: "Next Steps" # Always the same, html page title.
7+
layout: "learningpathall" # All files under learning paths have this same wrapper for Hugo processing.
8+
---
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Build llama.cpp with KleidiAI and SME2 enabled
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Build llama.cpp with KleidiAI and SME2 enabled
10+
For convenience, llama.cpp is statically linked. We use aarch64 GCC cross compile toolchain, *aarch64-none-linux-gnu-* to build the project. To support SME2, GCC compiler version 14.2 and onwards is required. The toolchain can be downloaded [here](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads) .
11+
12+
The llama.cpp with Tag b7611 is used in this tutorial, newer versions should also work but they are not tested.
13+
14+
After downloading the llama.cpp source code [here](https://github.com/ggml-org/llama.cpp/releases/tag/b7610), create a new directory *build* under the llama.cpp root directory and change to the new directory,
15+
16+
```bash
17+
cd ~/llama.cpp
18+
mkdir build && cd build
19+
```
20+
Next, configure the project,
21+
22+
```bash
23+
cmake .. \
24+
-DCMAKE_SYSTEM_NAME=Linux \
25+
-DCMAKE_SYSTEM_PROCESSOR=arm \
26+
-DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \
27+
-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
28+
-DLLAMA_NATIVE=OFF \
29+
-DLLAMA_F16C=OFF \
30+
-DLLAMA_GEMM_ARM=ON \
31+
-DBUILD_SHARED_LIBS=OFF \
32+
-DCMAKE_EXE_LINKER_FLAGS="-static -g" \
33+
-DGGML_OPENMP=OFF \
34+
-DCMAKE_C_FLAGS=" -march=armv8.7-a+sve+i8mm+dotprod+sme2 -g" \
35+
-DCMAKE_CXX_FLAGS=" -march=armv8.7-a+sve+i8mm+dotprod+sme2 -g" \
36+
-DLLAMA_BUILD_TESTS=OFF \
37+
-DLLAMA_BUILD_EXAMPLES=ON \
38+
-DLLAMA_CURL=OFF \
39+
-DGGML_CPU_KLEIDIAI=ON
40+
```
41+
Set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER to your cross compiler path. Make sure that *-march* in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS includes "+sme2".
42+
43+
The *-static* and *-g* options are specified to produce a statically linked executable, in oder to run on different Arm64 Linux/Android environments and include debug information.
44+
45+
Next, build the project,
46+
47+
```bash
48+
cd ~/llama.cpp/build
49+
cmake --build ./ --config Release -j $(nproc)
50+
```
51+
After the building process completes, you can find the application,*llama-cli*,in the ~/llama.cpp/build/bin/ directory.
52+
53+
To enable SME2 microkernels, you must set following environment variable before running the application.
54+
55+
```bash
56+
GGML_KLEIDIAI_SME="1"
57+
```
33.2 KB
Loading
66 KB
Loading
41.5 KB
Loading
482 KB
Loading
584 KB
Loading
997 KB
Loading
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: Overview
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: Overview
7+
---
8+
9+
## Introduction
10+
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.
11+
12+
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+
14+
By default llama.cpp integrates with Arm KleidiAI, a suite of optimized microkernels for Arm CPUs. KleidiAI includes SME2 optimized microkernels to get more performance benefits.
15+
16+
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+
18+
19+

0 commit comments

Comments
 (0)