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
Note: The flag “onnxruntime_USE_KLEIDIAI=ON” triggers the inclusion of Arm KleidiAI kernels into the MLAS library.
26
+
Note: The flag `onnxruntime_USE_KLEIDIAI=ON` triggers the inclusion of Arm KleidiAI kernels into the MLAS library.
23
27
24
28
## 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.
29
+
Once the build is complete, you will find the `libonnxruntime.so` shared library and `onnxruntime_perf_test` binary in your build directory.
30
+
31
+
`onnxruntime_perf_test` is essential for measuring latency and identifying bottlenecks of an ONNX model (named `<your_model>.onnx` hereafter).
The perf_test tool allows you to simulate inference and gather statistics. For example,
41
+
The `onnxruntime_perf_test` tool allows you to simulate inference and gather statistics. For example,
34
42
```bash
35
43
# 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"
44
+
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
45
```
46
+
38
47
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
48
+
-`-e cpu` specifies the provider as cpu provider
49
+
-`-m times` specifies the test mode as “times”
50
+
-`-r 20` specifies the repeated times as 20
51
+
-`-Z` disallows thread from spinning during runs to reduce cpu usage
52
+
-`-s` shows statistics result
53
+
-`-x 1` sets the number of threads used to parallelize the execution within nodes as 1
45
54
46
55
You can try other arguments setting if you would like to.
47
56
48
57
### Step 3: Deep Dive into Operator Profiling
49
-
To see exactly how many milliseconds are spent on each operator, use the profiling flag -p.
58
+
To see exactly how many milliseconds are spent on each operator, use the profiling flag `-p`.
50
59
```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"
60
+
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
61
adb pull /data/local/tmp/profile.json
53
62
```
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.
63
+
64
+
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.
65
+
You can view the results by opening [perfetto 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.
66
+
You also can convert the JSON file to a CSV sheet by creating a python script.
Copy file name to clipboardExpand all lines: content/learning-paths/mobile-graphics-and-gaming/performance_onnxruntime_kleidiai_sme2/kleidiai_integration.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,10 +11,10 @@ ONNX runtime is built with KleidiAI support:
11
11
1. Detection: At runtime, MLAS checks the CPU capabilities for SME2 support.
12
12
2. Dispatch: If SME2 is detected, MLAS overrides its default kernels. For example, a Gemm (General Matrix Multiplication) operation that would normally use standard vector instructions (such as NEON) is dispatched to a KleidiAI SME2 micro-kernel.
13
13
14
-
Currently, KleidiAI in MLAS provides ArmKleidiAI::MlasConv, ArmKleidiAI::MlasGemmBatch and ArmKleidiAI::MlasDynamicQGemmBatch kernels.
14
+
Currently, KleidiAI in MLAS provides `ArmKleidiAI::MlasConv`, `ArmKleidiAI::MlasGemmBatch` and `ArmKleidiAI::MlasDynamicQGemmBatch` kernels.
15
15
16
16
### The ArmKleidiAI::MlasConv kernel
17
-
Usually, 2D fp32 convolution operators with batch_size=1 and multiple filters (filter kernel is equal or greater than (3,3)) are dispatched to the ArmKleidiAI::MlasConv kernel.
17
+
Usually, 2D fp32 convolution operators with batch_size=1 and multiple filters (filter kernel is equal or greater than (3,3)) are dispatched to the `ArmKleidiAI::MlasConv` kernel.
18
18
19
19
For example, the figure below shows a (7,7) Conv node.
It performs a batched fp32 matrix multiplication (GEMM or GemV) operation using KleidiAI matmul micro kernels. fp32 Conv operators with (1,1) filter kernels also use this kernel.
49
+
It performs a batched fp32 matrix multiplication (GEMM or GemV) operation using KleidiAI matmul micro kernels. fp32 Conv operators with (1,1) filter kernels also uses this kernel.
50
50
51
51
For example, the figure below shows a (1,1) Conv node.
Copy file name to clipboardExpand all lines: content/learning-paths/mobile-graphics-and-gaming/performance_onnxruntime_kleidiai_sme2/profiling_example.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,22 +6,22 @@ weight: 5
6
6
layout: learningpathall
7
7
---
8
8
9
-
## Profile an ONNX model – Use Resnet50v2 as an example
9
+
## Profile an ONNX model – Using Resnet50v2 as an example
10
10
The Resnet50v2 fp32 ONNX model can be downloaded from Hugging Face or Modescope.
11
11
12
-
The Android device that we used is a VIVO X300 phone with MTK D9500 processor, which has Arm C1-Ultra, C1-Premium and C1-Pro CPU cores with SME2 support on it. We chose a C1-Pro CPU core running at 2.0GHz to run the onnxruntime_perf_test benchmark application. You can use any other Android device with SME2 support.
12
+
The Android device that we used is a VIVO X300 phone with MTK D9500 processor, which has Arm C1-Ultra, C1-Premium and C1-Pro CPU cores with SME2 support on it. We chose a C1-Pro CPU core running at 2.0GHz to run the `onnxruntime_perf_test` benchmark application. You can use any other Android device with SME2 support.
13
13
14
-
To compare the performance of running Resnet50v2 on ORT with SME2 and without SME2 support, we built two versions of ORT, one with SME2 support (set *onnxruntime_USE_KLEIDIAI=ON* when building ORT), the other without SME2 support(*onnxruntime_USE_KLEIDIAI=OFF* when building ORT).
14
+
To compare the performance of running Resnet50v2 on ORT with SME2 and without SME2 support, we built two versions of ORT, one with SME2 support (set `onnxruntime_USE_KLEIDIAI=ON` when building ORT), the other without SME2 support(`onnxruntime_USE_KLEIDIAI=OFF` when building ORT).
15
15
16
16
Run following command on the device,
17
17
```bash
18
-
taskset 1 ./onnxruntime_perf_test -e cpu -r 5 -m times -s -Z -x 1 ./resnet50v2.onnx -p "resnet50v2.onnx_1xC1-Pro_profile
18
+
taskset 1 ./onnxruntime_perf_test -e cpu -r 5 -m times -s -Z -x 1 ./resnet50v2.onnx -p resnet50v2.onnx_1xC1-Pro_profile
19
19
```
20
20
21
-
The *taskset 1*in the command sets the CPU affinity of *onnxruntime_perf_test* benchmark to CPU core 0, which is a C1-Pro CPU core.
22
-
*-x 1*in the command sets the number of threads used to parallelize the execution within nodes as 1 (single thread).
21
+
The `taskset 1` in the command sets the CPU affinity of `onnxruntime_perf_test` benchmark to CPU core 0, which is a C1-Pro CPU core.
22
+
`-x 1` in the command sets the number of threads used to parallelize the execution within nodes as 1 (single thread).
23
23
24
-
Here is output from running onnxruntime_perf_test with ORT with SME2 support as below.
24
+
Here is output from running `onnxruntime_perf_test` with ORT with SME2 support as below.
25
25
```text
26
26
Setting intra_op_num_threads to 1
27
27
Disabling intra-op thread spinning between runs
@@ -46,7 +46,7 @@ P99 Latency: 0.101519 s
46
46
P999 Latency: 0.101519 s
47
47
```
48
48
49
-
Here is output from running onnxruntime_perf_test with ORT without SME2 support as below.
49
+
Here is output from running `onnxruntime_perf_test` with ORT without SME2 support as below.
50
50
```text
51
51
Setting intra_op_num_threads to 1
52
52
Disabling intra-op thread spinning between runs
@@ -70,12 +70,14 @@ P95 Latency: 0.34682 s
70
70
P99 Latency: 0.34682 s
71
71
P999 Latency: 0.34682 s
72
72
```
73
-
### Performance
73
+
## Performance analysis
74
74
75
-
We can use [prefetto tool](https://ui.perfetto.dev/), to view the two JSON profile files.
75
+
### Using [perfetto tool](https://ui.perfetto.dev/)
76
+
77
+
We can use [perfetto tool](https://ui.perfetto.dev/) to view the two JSON profile files.
76
78
77
79
The figure below is a screenshot of the view of the Non-KleidiAI version of JSON profile file.
78
-
The selected part(one model_run/SequentialExecutor) in the figure includes information of one inference execution.
80
+
The selected part(one `model_run/SequentialExecutor`) in the figure includes information of one inference execution.
79
81
80
82

81
83
@@ -88,6 +90,8 @@ We also convert the two JSON profile files to CSV sheets, then we combine the in
88
90
89
91
It shows that ORT with KleidiAI (with SME2) kernels uplifts the performance significantly, especially for convolution operators.
90
92
93
+
### Using Arm Streamline
94
+
91
95
If we use Arm Streamline tools and PMU counters for further investigation, in the timeline view of Streamline, we can see SME2 floating point Outer Product and Accumulate (MOPA) instruction is used intensively during the inference.
92
96
93
97

@@ -96,7 +100,7 @@ Then we combine the function call view of ORT without KleidiAI and with KleidiAI
96
100
97
101

98
102
99
-
It shows that KleidiAI kernels provide a significant performance uplift for convolution operators compared to the default MLSA kernels (*MlasSgemmKernelAdd* and *MlasSgemmKernelZero*).
103
+
It shows that KleidiAI kernels provide a significant performance uplift for convolution operators compared to the default MLSA kernels (`MlasSgemmKernelAdd` and `MlasSgemmKernelZero`).
100
104
101
105
## Summary
102
-
By integrating KleidiAI (SME2) into ONNX Runtime, you unlock the massive parallel processing power of Arm SME2. This turns the Arm CPU from a "fallback" into a high-performance AI engine capable of running LLMs and complex vision models locally on devices.
106
+
By enabling KleidiAI (SME2) into ONNX Runtime, you unlock the massive parallel processing power of Arm SME2. This turns the Arm CPU from a "fallback" into a high-performance AI engine capable of running LLMs and complex vision models locally on devices.
0 commit comments