|
| 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