Skip to content

Commit c59f9e3

Browse files
Merge pull request #2494 from jtzhou-001/kleidicv-mac-os
laptops-and-desktops: add the article about KleidiCV
2 parents 54d3a9f + cfce145 commit c59f9e3

File tree

4 files changed

+748
-0
lines changed

4 files changed

+748
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: Learn how to build and test Kleidicv on Mac OS
3+
4+
minutes_to_complete: 30
5+
6+
who_is_this_for: This is an introductory topic for software developers to learn how
7+
to to build and test kleidicv on Mac OS.
8+
9+
learning_objectives:
10+
- Install and compile kleidiCV on macOS
11+
- Run KleidiCV example tests
12+
- Enable SME build and verify SME backend
13+
14+
prerequisites:
15+
- An M4 Mac OS computer.
16+
17+
author: Jett Zhou
18+
19+
### Tags
20+
skilllevels: Introductory
21+
subjects: SME
22+
armips:
23+
- ARMv9-A
24+
tools_software_languages:
25+
- kleidiCV and C/C++
26+
operatingsystems:
27+
- Mac OS
28+
29+
30+
31+
further_reading:
32+
- resource:
33+
title: kleidicv doc
34+
link: https://gitlab.arm.com/kleidi/kleidicv/-/tree/0.6.0/doc?ref_type=tags
35+
type: documentation
36+
- resource:
37+
title: Announcing Arm KleidiCV 0.1
38+
link: https://developer.arm.com/community/arm-community-blogs/b/ai-blog/posts/kleidicv
39+
type: blog
40+
41+
42+
43+
### FIXED, DO NOT MODIFY
44+
# ================================================================================
45+
weight: 1 # _index.md always has weight of 1 to order correctly
46+
layout: "learningpathall" # All files under learning paths have this same wrapper
47+
learning_path_main_page: "yes" # This should be surfaced when looking for related content. Only set for _index.md of learning path content.
48+
---
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 # Set to always be larger than the content in this path to be at the end of the navigation.
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: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
title: Download and Build for the Kleidicv Software
3+
weight: 2
4+
5+
### FIXED, DO NOT MODIFY
6+
layout: learningpathall
7+
---
8+
9+
## Introduction
10+
11+
Arm KleidiCV is an open-source library of optimized performance-critical routines for Arm CPUs. It is designed for integrating into any CV framework to enable best performance for CV workloads on Arm, with no action needed by application developers.
12+
13+
Each KleidiCV function has three different implementations targeting Neon, SVE2 (Scalable Vector Extension) or Streaming SVE & SME2 (Scalable Matrix Extension). KleidiCV will automatically detect what hardware it's running on and select the best implementation accordingly.KleidiCV can be used as a lightweight standalone image processing library. Alternatively KleidiCV can be used seamlessly as part of the extremely popular OpenCV library.
14+
15+
Since the Apple M4 family is based on the ARMv9.2‑A architecture, it supports the Scalable Matrix Extension (SME) (or a variant thereof) for matrix-compute acceleration. we will demostrate the build and do run test of the kleidicv, understand how the backend implementation is called for the KleidiCV functions.
16+
17+
## Host Environment
18+
19+
The host machine utilized is a MacBook Pro (Apple M4 Pro), and the operating system version is detailed below:
20+
21+
```bash
22+
ProductName: macOS
23+
ProductVersion: 15.5
24+
BuildVersion: 24F74
25+
```
26+
27+
CMake is available for installation through Homebrew if it is not already installed on the host machine.
28+
29+
```bash
30+
brew install cmake
31+
```
32+
33+
The host architecture feature can be verified as outlined below, confirming that FEAT_SME is supported:
34+
35+
```bash
36+
sysctl -a | grep hw.optional.arm.FEAT
37+
hw.optional.arm.FEAT_CRC32: 1
38+
hw.optional.arm.FEAT_FlagM: 1
39+
hw.optional.arm.FEAT_FlagM2: 1
40+
hw.optional.arm.FEAT_FHM: 1
41+
hw.optional.arm.FEAT_DotProd: 1
42+
hw.optional.arm.FEAT_SHA3: 1
43+
hw.optional.arm.FEAT_RDM: 1
44+
hw.optional.arm.FEAT_LSE: 1
45+
hw.optional.arm.FEAT_SHA256: 1
46+
hw.optional.arm.FEAT_SHA512: 1
47+
hw.optional.arm.FEAT_SHA1: 1
48+
hw.optional.arm.FEAT_AES: 1
49+
hw.optional.arm.FEAT_PMULL: 1
50+
hw.optional.arm.FEAT_SPECRES: 0
51+
hw.optional.arm.FEAT_SPECRES2: 0
52+
hw.optional.arm.FEAT_SB: 1
53+
hw.optional.arm.FEAT_FRINTTS: 1
54+
hw.optional.arm.FEAT_PACIMP: 1
55+
hw.optional.arm.FEAT_LRCPC: 1
56+
hw.optional.arm.FEAT_LRCPC2: 1
57+
hw.optional.arm.FEAT_FCMA: 1
58+
hw.optional.arm.FEAT_JSCVT: 1
59+
hw.optional.arm.FEAT_PAuth: 1
60+
hw.optional.arm.FEAT_PAuth2: 1
61+
hw.optional.arm.FEAT_FPAC: 1
62+
hw.optional.arm.FEAT_FPACCOMBINE: 1
63+
hw.optional.arm.FEAT_DPB: 1
64+
hw.optional.arm.FEAT_DPB2: 1
65+
hw.optional.arm.FEAT_BF16: 1
66+
hw.optional.arm.FEAT_EBF16: 0
67+
hw.optional.arm.FEAT_I8MM: 1
68+
hw.optional.arm.FEAT_WFxT: 1
69+
hw.optional.arm.FEAT_RPRES: 1
70+
hw.optional.arm.FEAT_CSSC: 0
71+
hw.optional.arm.FEAT_HBC: 0
72+
hw.optional.arm.FEAT_ECV: 1
73+
hw.optional.arm.FEAT_AFP: 1
74+
hw.optional.arm.FEAT_LSE2: 1
75+
hw.optional.arm.FEAT_CSV2: 1
76+
hw.optional.arm.FEAT_CSV3: 1
77+
hw.optional.arm.FEAT_DIT: 1
78+
hw.optional.arm.FEAT_FP16: 1
79+
hw.optional.arm.FEAT_SSBS: 0
80+
hw.optional.arm.FEAT_BTI: 1
81+
hw.optional.arm.FEAT_SME: 1
82+
hw.optional.arm.FEAT_SME2: 1
83+
hw.optional.arm.FEAT_SME_F64F64: 1
84+
hw.optional.arm.FEAT_SME_I16I64: 1
85+
```
86+
87+
## Download the Software
88+
89+
To set up KleidiCV and OpenCV, first download the source code from GitLab. In your $WORKSPACE directory, clone KleidiCV using the v0.6.0 release tag.
90+
91+
```bash
92+
cd $WORKSPACE
93+
git clone -b 0.6.0 https://git.gitlab.arm.com/kleidi/kleidicv.git
94+
```
95+
96+
Clone the OpenCV repository into $WORKSPACE using the v4.12.0 release tag.
97+
98+
```bash
99+
cd $WORKSPACE
100+
git clone https://github.com/opencv/opencv.git
101+
git checkout 4.12.0
102+
```
103+
104+
Apply the patch for OpenCV version 4.12.
105+
106+
```bash
107+
patch -p1 < ../kleidicv/adapters/opencv/opencv-4.12.patch
108+
patch -p1 < ../kleidicv/adapters/opencv/extra_benchmarks/opencv-4.12.patch
109+
```
110+
111+
112+
## Build Options
113+
114+
* KLEIDICV_ENABLE_SVE2 - Enable Scalable Vector Extension 2 code paths. This is on by default for some popular compilers known to support SVE2 but otherwise off by default.
115+
- KLEIDICV_LIMIT_SVE2_TO_SELECTED_ALGORITHMS - Limit Scalable Vector Extension 2 code paths to cases where it is expected to provide a benefit over other code paths. On by default. Has no effect if KLEIDICV_ENABLE_SVE2 is off.
116+
* KLEIDICV_BENCHMARK - Enable building KleidiCV benchmarks. The benchmarks use Google Benchmark which will be downloaded automatically. Off by default.
117+
* KLEIDICV_ENABLE_SME2 - Enable Scalable Matrix Extension 2 and Streaming Scalable Vector Extension code paths. Off by default while the ACLE SME specification is in beta.
118+
- KLEIDICV_LIMIT_SME2_TO_SELECTED_ALGORITHMS - Limit Scalable Matrix Extension 2 code paths to cases where it is expected to provide a benefit over other code paths. On by default. Has no effect if KLEIDICV_ENABLE_SME2 is off.
119+
120+
{{% notice Note %}}
121+
Normally, if our tests show SVE2 or SME2 are slower than NEON, we default to NEON (unless overridden with -DKLEIDICV_LIMIT_SVE2_TO_SELECTED_ALGORITHMS=OFF or -DKLEIDICV_LIMIT_SME2_TO_SELECTED_ALGORITHMS=OFF).
122+
{{% /notice %}}
123+
124+
## Build the KleidiCV standalone
125+
126+
Use the following command to build kleidicv natively:
127+
128+
```bash
129+
cmake -S $WORKSPCE/kleidicv \
130+
-B build-kleidicv-benchmark-SME \
131+
-DKLEIDICV_ENABLE_SME2=ON \
132+
-DKLEIDICV_LIMIT_SME2_TO_SELECTED_ALGORITHMS=OFF \
133+
-DKLEIDICV_BENCHMARK=ON \
134+
-DCMAKE_BUILD_TYPE=Release
135+
136+
cmake --build build-kleidicv-benchmark-SME --parallel
137+
```
138+
Once the build completes, the kleidicv API and framework tests appear below:
139+
140+
```bash
141+
./build-kleidicv-benchmark-SME/test/framework/kleidicv-framework-test
142+
./build-kleidicv-benchmark-SME/test/api/kleidicv-api-test
143+
```
144+
145+
The Kleidicv benchmark test is available as follows:
146+
147+
```bash
148+
./build-kleidicv-benchmark-SME/benchmark/kleidicv-benchmark
149+
```
150+
## Build the OpenCV with KleidiCV
151+
152+
The following command can be used to build OpenCV with kleidicv:
153+
154+
```bash
155+
cmake -S $workspace/opencv /
156+
-B build-opencv-kleidicv-sme /
157+
-DWITH_KLEIDICV=ON /
158+
-DKLEIDICV_ENABLE_SME2=ON /
159+
-DKLEIDICV_SOURCE_PATH=$workspace/kleidicv /
160+
-DBUILD_LIST=imgproc,core,ts /
161+
-DBUILD_SHARED_LIBS=OFF /
162+
-DBUILD_TESTS=ON /
163+
-DBUILD_PERF_TEST=ON /
164+
-DWITH_PNG=OFF
165+
166+
cmake --build build-opencv-kleidicv-sme --parallel --target opencv_perf_imgproc opencv_perf_core
167+
```
168+
169+
Upon completion of the build process, the OpenCV test binary will be available at the following location:
170+
171+
```bash
172+
build-opencv-kleidicv-sme/bin/opencv_perf_core
173+
build-opencv-kleidicv-sme/bin/opencv_perf_imgproc
174+
```
175+

0 commit comments

Comments
 (0)