|
| 1 | +--- |
| 2 | +title: Cross-Compile ExecuTorch for the Aarch64 platform |
| 3 | +weight: 3 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | + |
| 10 | +This section describes how to cross-compile ExecuTorch for an AArch64 target platform with XNNPACK and KleidiAI support enabled. |
| 11 | +All commands below are intended to be executed on an x86-64 Linux host with an appropriate cross-compilation toolchain installed (e.g., aarch64-linux-gnu-gcc). |
| 12 | + |
| 13 | + |
| 14 | +### Run CMake Configuration |
| 15 | + |
| 16 | +Use CMake to configure the ExecuTorch build for Aarch64. The example below enables key extensions, developer tools, and XNNPACK with KleidiAI acceleration: |
| 17 | + |
| 18 | +```bash |
| 19 | + |
| 20 | +cd $WORKSPACE |
| 21 | +mkdir -p build-arm64 |
| 22 | +cd build-arm64 |
| 23 | + |
| 24 | +cmake -GNinja \ |
| 25 | + -DCMAKE_BUILD_TYPE=Debug \ |
| 26 | + -DCMAKE_SYSTEM_NAME=Linux \ |
| 27 | + -DCMAKE_SYSTEM_PROCESSOR=aarch64 \ |
| 28 | + -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc \ |
| 29 | + -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \ |
| 30 | + -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \ |
| 31 | + -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH \ |
| 32 | + -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \ |
| 33 | + -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \ |
| 34 | + -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \ |
| 35 | + -DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \ |
| 36 | + -DEXECUTORCH_BUILD_EXTENSION_NAMED_DATA_MAP=ON \ |
| 37 | + -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \ |
| 38 | + -DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \ |
| 39 | + -DEXECUTORCH_BUILD_XNNPACK=ON \ |
| 40 | + -DEXECUTORCH_BUILD_DEVTOOLS=ON \ |
| 41 | + -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ |
| 42 | + -DEXECUTORCH_ENABLE_LOGGING=ON \ |
| 43 | + -DEXECUTORCH_LOG_LEVEL=debug \ |
| 44 | + -DEXECUTORCH_XNNPACK_ENABLE_KLEIDI=ON \ |
| 45 | + ../executorch |
| 46 | + |
| 47 | +``` |
| 48 | + |
| 49 | +#### Key Build Options |
| 50 | + |
| 51 | +| **CMake Option** | **Description** | |
| 52 | +| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| 53 | +| `EXECUTORCH_BUILD_XNNPACK` | Builds the **XNNPACK backend**, which provides highly optimized CPU operators (GEMM, convolution, etc.) for Arm64 platforms. | |
| 54 | +| `EXECUTORCH_XNNPACK_ENABLE_KLEIDI` | Enables **Arm KleidiAI** acceleration for XNNPACK kernels, providing further performance improvements on Armv8.2+ CPUs. | |
| 55 | +| `EXECUTORCH_BUILD_DEVTOOLS` | Builds **developer tools** such as the ExecuTorch Inspector and diagnostic utilities for profiling and debugging. | |
| 56 | +| `EXECUTORCH_BUILD_EXTENSION_MODULE` | Builds the **Module API** extension, which provides a high-level abstraction for model loading and execution using `Module` objects. | |
| 57 | +| `EXECUTORCH_BUILD_EXTENSION_TENSOR` | Builds the **Tensor API** extension, providing convenience functions for creating, manipulating, and managing tensors in C++ runtime. | |
| 58 | +| `EXECUTORCH_BUILD_KERNELS_OPTIMIZED` | Enables building **optimized kernel implementations** for better performance on supported architectures. | |
| 59 | +| `EXECUTORCH_ENABLE_EVENT_TRACER` | Enables the **event tracing** feature, which records performance and operator timing information for runtime analysis. | |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +### Build ExecuTorch |
| 64 | + |
| 65 | +```bash |
| 66 | +cmake --build . -j$(nproc) |
| 67 | + |
| 68 | +``` |
| 69 | + |
| 70 | +If the build completes successfully, you should find the executor_runner binary under the directory: |
| 71 | + |
| 72 | +```bash |
| 73 | +build-arm64/executor_runner |
| 74 | + |
| 75 | +``` |
| 76 | + |
| 77 | +This binary can be used to run ExecuTorch models on the ARM64 target device using the XNNPACK backend with KleidiAI acceleration. |
| 78 | + |
0 commit comments