Skip to content

Commit f140768

Browse files
Merge pull request #2700 from zenonxiu81/main
New learn path: Unleashing SME2 Performance - Profile ONNX models with KleidiAI-Optimized ONNX Runtime
2 parents f5c52b4 + 6b567cc commit f140768

15 files changed

Lines changed: 373 additions & 0 deletions
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: Unleashing SME2 Performance - Profile ONNX models with KleidiAI-Optimized ONNX Runtime
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 ONNX runtime library with KleidiAI and SME2 support
10+
- Profile performance of ONNX models
11+
- Learn how KleidiAI and SME2 accelerates ONNX operators
12+
13+
prerequisites:
14+
- Knowledge of KleidiAI and SME2
15+
- An 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+
- ONNX runtime
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+
48+
49+
50+
### FIXED, DO NOT MODIFY
51+
# ================================================================================
52+
weight: 1 # _index.md always has weight of 1 to order correctly
53+
layout: "learningpathall" # All files under learning paths have this same wrapper
54+
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
55+
---
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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Build ONNX Runtime with KleidiAI and SME2 for Android
3+
weight: 4
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Build ONNX Runtime and benchmark application with KleidiAI and SME2 support for Android
10+
11+
To run this on an Android device, you must cross-compile ORT using the Android NDK.
12+
Prerequisites
13+
- Android NDK: Version r26b or newer (r27+ recommended for latest SME2 toolchain support).
14+
- CMake & Ninja: Ensure these are in your system PATH.
15+
16+
### Build Command
17+
Run the following from the root of the ONNX Runtime repository:
18+
```bash
19+
./build.sh --android --android_sdk_path $ANDROID_NDK_HOME --android_ndk_path $ANDROID_NDK_HOME --android_abi arm64-v8a --android_api 27 --config RelWithDebInfo --build_shared_lib --cmake_extra_defines onnxruntime_USE_KLEIDIAI=ON --cmake_generator Ninja --parallel
20+
```
21+
22+
Note: The flag “onnxruntime_USE_KLEIDIAI=ON” triggers the inclusion of Arm KleidiAI kernels into the MLAS library.
23+
24+
## Profiling Performance with onnxruntime_perf_test
25+
Once the build is complete, you will find the libonnxruntime.so shared library and onnxruntime_perf_test binary in your build directory. The onnxruntime_perf_test is essential for measuring latency and identifying bottlenecks.
26+
### Step 1: Push files to Android Device
27+
```bash
28+
adb push <build_dir>/Android/RelWithDebInfo/onnxruntime_perf_test /data/local/tmp/
29+
adb push <build_dir>/Android/RelWithDebInfo/libonnxruntime.so /data/local/tmp/
30+
adb push your_model.onnx /data/local/tmp/
31+
```
32+
### Step 2: Run the Performance Test
33+
The perf_test tool allows you to simulate inference and gather statistics. For example,
34+
```bash
35+
# Execute on the device
36+
adb shell "/data/local/tmp/onnxruntime_perf_test -e cpu -m times -r 20 -s -Z -x 1 /data/local/tmp/your_model.onnx"
37+
```
38+
The command example set the arguments of the application as,
39+
- “-e cpu” specifies the provider as cpu provider
40+
- “-m times” specifies the test mode as “times”
41+
- “-r 20” specifies the repeated times as 20
42+
- “-Z” disallows thread from spinning during runs to reduce cpu usage
43+
- “-s” shows statistics result
44+
- “-x 1” sets the number of threads used to parallelize the execution within nodes as 1
45+
46+
You can try other arguments setting if you would like to.
47+
48+
### Step 3: Deep Dive into Operator Profiling
49+
To see exactly how many milliseconds are spent on each operator, use the profiling flag -p.
50+
```bash
51+
adb shell "/data/local/tmp/onnxruntime_perf_test -p profile.json -e cpu -m times -r 5 -s -Z -x 1 /data/local/tmp/your_model.onnx"
52+
adb pull /data/local/tmp/profile.json
53+
```
54+
The argument “-p” enables performance profiling during the benchmark run. When you provide this flag followed by a filename, ONNX Runtime will generate a JSON file containing a detailed trace of the model execution.
55+
You can view the results by opening [prefetto tool]( https://ui.perfetto.dev/), and loading the generated JSON file. This allows you to see a visual timeline of which operations took the most time.
56+
You also can convert the JSON file to a CSV sheet by creating a python script.
21.4 KB
Loading
20.7 KB
Loading
831 KB
Loading
18 KB
Loading
898 KB
Loading
204 KB
Loading
Loading

0 commit comments

Comments
 (0)