Skip to content

Commit 0621336

Browse files
Refine documentation for building and testing KleidiCV on macOS, including updates to prerequisites, environment setup, and test instructions.
1 parent 7c8797f commit 0621336

File tree

3 files changed

+53
-36
lines changed

3 files changed

+53
-36
lines changed

content/learning-paths/laptops-and-desktops/kleidicv-on-mac/_index.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
---
22
title: Build and test KleidiCV on macOS
33

4-
draft: true
5-
cascade:
6-
draft: true
7-
84
minutes_to_complete: 30
95

106
who_is_this_for: This is an introductory topic for software developers who want to build and test KleidiCV on macOS.
@@ -16,8 +12,8 @@ learning_objectives:
1612

1713
prerequisites:
1814
- A Mac with Apple Silicon (M4 generation or newer)
19-
- Basic familiarity with command-line tools
2015
- Xcode command line tools installed
16+
- Basic familiarity with using the Terminal and command-line tools
2117

2218
author: Jett Zhou
2319

content/learning-paths/laptops-and-desktops/kleidicv-on-mac/build-1.md

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,19 @@ layout: learningpathall
77

88
## Introduction
99

10-
Arm KleidiCV is an open-source library of optimized, performance-critical routines for Arm CPUs. You can integrate it into any Computer Vision (CV) framework to get the best performance for CV workloads on Arm, with no action needed by application developers.
10+
Arm KleidiCV is an open-source library that provides fast, optimized routines for Arm CPUs. You can use KleidiCV with any computer vision (CV) framework to boost performance for CV workloads on Arm systems.
1111

12-
Each KleidiCV function has different implementations targeting Neon, SVE2 (Scalable Vector Extension), or Streaming SVE and SME2 (Scalable Matrix Extension). KleidiCV automatically detects the hardware it is running on and selects the best implementation. You can use KleidiCV as a lightweight standalone image processing library or as part of the OpenCV library.
12+
KleidiCV includes multiple optimized implementations for each function, targeting Arm Neon, SVE2 (Scalable Vector Extension 2), and SME2 (Scalable Matrix Extension 2) instruction sets. The library automatically detects your hardware and chooses the fastest available code path, so you don't need to adjust your code for different Arm CPUs.
1313

14-
Since the Apple M4 family is based on the Armv9.2‑A architecture, it supports the Scalable Matrix Extension (SME) for accelerating matrix computations. In this Learning Path, you will build and test KleidiCV to understand how the backend implementation is called for the KleidiCV functions.
14+
You can use KleidiCV as a standalone image processing library or integrate it with OpenCV for broader computer vision support. On Apple M4 processors, which use the Armv9.2‑A architecture and support SME, you'll see improved performance for matrix operations. In this Learning Path, you'll build and test KleidiCV to observe how it selects the best backend for your hardware.
1515

16-
## Host environment
16+
## Set up your environment
1717

18-
The host machine is a MacBook Pro (Apple Silicon M4), and the operating system version is detailed below.
19-
20-
You can find this information on your Mac by selecting the **Apple menu ()** in the top-left corner of your screen, then selecting **About This Mac**. Alternatively, run the following command in a terminal:
18+
To follow this example you'll need a MacBook Pro with an Apple Silicon M4 processor. To check your operating system version, select the **Apple menu ()** in the top-left corner of your screen and choose **About This Mac**. Alternatively, open a terminal and run:
2119

2220
```console
2321
sw_vers
2422
```
25-
2623
The output is similar to:
2724

2825
```output
@@ -31,18 +28,19 @@ ProductVersion: 15.5
3128
BuildVersion: 24F74
3229
```
3330

34-
If CMake is not already installed on your host machine, you can install it using Homebrew.
31+
You also need CMake. If CMake is not already installed on your host machine, you can install it using Homebrew:
3532

3633
```bash
3734
brew install cmake
3835
```
39-
40-
You can verify the host architecture features as outlined below, confirming that `FEAT_SME` is supported:
36+
To check which Arm architecture features your Mac supports, run the following command in your terminal:
4137

4238
```bash
4339
sysctl -a | grep hw.optional.arm.FEAT
4440
```
4541

42+
Look for `hw.optional.arm.FEAT_SME: 1` in the output. If you see this line, your system supports SME (Scalable Matrix Extension). If the value is `0`, SME is not available on your hardware.
43+
4644
The output is:
4745

4846
```output
@@ -96,11 +94,11 @@ hw.optional.arm.FEAT_SME_F64F64: 1
9694
hw.optional.arm.FEAT_SME_I16I64: 1
9795
```
9896

99-
If you don't have an M4 Mac you will not see the `FEAT_SME` flags set to 1.
97+
If your Mac does not have an M4 processor, you won't see the `FEAT_SME` flags set to `1`. In that case, SME (Scalable Matrix Extension) features are not available on your hardware, and KleidiCV will use other optimized code paths instead.
10098

101-
## Create a workspace.
99+
## Create a workspace
102100

103-
You can use an environment variable to define your workspace.
101+
You can use an environment variable to define your workspace:
104102

105103
```bash
106104
export WORKSPACE=<your-workspace-directdory>
@@ -113,7 +111,7 @@ mkdir $HOME/kleidi
113111
export WORKSPACE=$HOME/kleidi
114112
```
115113

116-
## Download the Software
114+
## Download the software
117115

118116
To set up KleidiCV and OpenCV, first download the source code from GitLab.
119117

@@ -124,7 +122,7 @@ cd $WORKSPACE
124122
git clone -b 0.6.0 https://git.gitlab.arm.com/kleidi/kleidicv.git
125123
```
126124

127-
Clone the OpenCV repository into $WORKSPACE using the v4.12.0 release tag.
125+
Clone the OpenCV repository into $WORKSPACE using the v4.12.0 release tag:
128126

129127
```bash
130128
cd $WORKSPACE
@@ -133,24 +131,37 @@ cd opencv
133131
git checkout 4.12.0
134132
```
135133

136-
Apply the patch for OpenCV version 4.12.
134+
Apply the patch for OpenCV version 4.12:
137135

138136
```bash
139137
patch -p1 < ../kleidicv/adapters/opencv/opencv-4.12.patch
140138
patch -p1 < ../kleidicv/adapters/opencv/extra_benchmarks/opencv-4.12.patch
141139
```
142140

143141

144-
## Build Options
142+
## Build options
143+
144+
KleidiCV provides several CMake options to control which instruction sets and features are enabled during the build. Here are the most important options for Arm systems:
145+
146+
- **KLEIDICV_ENABLE_SVE2**
147+
Enables Scalable Vector Extension 2 (SVE2) code paths. This is on by default for popular compilers that support SVE2, but off otherwise.
145148

146-
* 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.
147-
- 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.
148-
* KLEIDICV_BENCHMARK - Enable building KleidiCV benchmarks. The benchmarks use Google Benchmark which will be downloaded automatically. Off by default.
149-
* 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.
150-
- 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.
149+
- **KLEIDICV_LIMIT_SVE2_TO_SELECTED_ALGORITHMS**
150+
Limits SVE2 code paths to algorithms where SVE2 is expected to outperform other options. This is on by default. It has no effect if SVE2 is disabled.
151+
152+
- **KLEIDICV_BENCHMARK**
153+
Enables building KleidiCV benchmarks. The benchmarks use Google Benchmark, which is downloaded automatically. This is off by default.
154+
155+
- **KLEIDICV_ENABLE_SME2**
156+
Enables Scalable Matrix Extension 2 (SME2) and Streaming SVE code paths. This is off by default while the ACLE SME specification is in beta.
157+
158+
- **KLEIDICV_LIMIT_SME2_TO_SELECTED_ALGORITHMS**
159+
Limits SME2 code paths to cases where SME2 is expected to provide a benefit. This is on by default. It has no effect if SME2 is disabled.
160+
161+
You can set these options when running `cmake` to customize your build for your hardware and use case.
151162

152163
{{% notice Note %}}
153-
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).
164+
KleidiCV automatically selects the fastest available code path for your hardware. If the library detects that SVE2 (Scalable Vector Extension 2) or SME2 (Scalable Matrix Extension 2) is slower than NEON for a specific function, it defaults to NEONunless you explicitly turn off this behavior by setting `-DKLEIDICV_LIMIT_SVE2_TO_SELECTED_ALGORITHMS=OFF` or `-DKLEIDICV_LIMIT_SME2_TO_SELECTED_ALGORITHMS=OFF`.
154165
{{% /notice %}}
155166

156167
## Build the KleidiCV standalone
@@ -203,4 +214,8 @@ ls build-opencv-kleidicv-sme/bin/opencv_perf_core
203214
ls build-opencv-kleidicv-sme/bin/opencv_perf_imgproc
204215
```
205216

206-
Continue to the next section to run the benchmarks and learn about SME.
217+
## What you've accomplished and what's next
218+
219+
You've successfully set up your development environment, downloaded the KleidiCV and OpenCV source code, and built both libraries with SME2 support on your Apple Silicon Mac. At this point, you have all the tools you need to explore how KleidiCV optimizes for Arm architectures.
220+
221+
In the next section, you'll run benchmarks to see SME in action and learn how KleidiCV automatically selects the best code paths for your hardware. This will help you understand the performance benefits of Arm's advanced instruction sets for computer vision workloads.

content/learning-paths/laptops-and-desktops/kleidicv-on-mac/run-test-2.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ layout: learningpathall
99
## Run the Test
1010

1111
Once the build steps are complete, you can run the KleidiCV and OpenCV tests.
12+
The KleidiCV API test checks the public C++ API and confirms that the build is working as expected. To run the test, use the following command:
1213

13-
The KleidiCV API test verifies the public C++ API. You can run it as shown below. The full test log is not included for brevity:
14+
```bash
15+
./build-kleidicv-benchmark-SME/test/api/kleidicv-api-test
16+
```
17+
18+
You will see output showing the number of tests run and their results. The full test log is omitted here for clarity.
1419

1520
```bash
1621
./build-kleidicv-benchmark-SME/test/api/kleidicv-api-test
@@ -60,16 +65,17 @@ Currently, Apple Xcode is built on Clang 17. Version clang-1700.3.19.1 has an SM
6065
{{% /notice %}}
6166

6267

63-
### Run the OpenCV test
68+
## Run the OpenCV test
69+
70+
After building OpenCV with KleidiCV, you will find the test binaries in the `build-opencv-kleidicv-sme/bin/` directory. The main tool for benchmarking image processing performance is `opencv_perf_imgproc`. This utility measures both execution speed and throughput for the OpenCV `imgproc` module, including KleidiCV-accelerated operations.
6471

65-
Upon completing the build steps for OpenCV with KleidiCV, the test binaries are located in the `build-opencv-kleidicv-sme/bin/` directory. For example, `opencv_perf_imgproc` is OpenCV’s performance benchmark suite for the image processing (`imgproc`) module, which evaluates both execution speed and throughput.
72+
To focus your testing, use the `--gtest_filter` option to select specific tests and `--gtest_param_filter` to set test parameters. For example, you can run the Gaussian blur 5×5 performance test three times on a 1920x1080 grayscale image with replicated borders:
6673

67-
You can customize testing by selecting specific test filters and parameters using the `--gtest_filter` and `--gtest_param_filter` options, respectively. For instance, to run the Gaussian blur 5×5 performance tests three times with the following parameter settings:
6874
- Image size: 1920x1080 (Full HD)
69-
- Image type: 8UC1 (8-bit unsigned, single channel, grayscale)
75+
- Image type: 8UC1 (8-bit unsigned, single channel)
7076
- Border type: BORDER_REPLICATE
7177

72-
Additional test cases are available in [benchmarks.txt](https://gitlab.arm.com/kleidi/kleidicv/-/blob/0.6.0/scripts/benchmark/benchmarks.txt?ref_type=tags).
78+
You can explore additional test cases and parameter combinations in the [benchmarks.txt](https://gitlab.arm.com/kleidi/kleidicv/-/blob/0.6.0/scripts/benchmark/benchmarks.txt?ref_type=tags) file in the KleidiCV repository.
7379

7480
The command for running the test is as follows:
7581

0 commit comments

Comments
 (0)