From 9a346eba7ed4fcc9ff15c3ed8a8c7eac6f13c53e Mon Sep 17 00:00:00 2001 From: Yunus Kalkan Date: Fri, 27 Jun 2025 10:52:25 +0100 Subject: [PATCH] MLECO-6042: Adding CMake user profiles Presets for Android added which reduce required user flags. Build now warns at configuration stage if common, incompatible or sub-optimal settings are requested e.g. Kleidi enabled without suitable sub-feature flag being passed. Co-authored-by: Yunus Kalkan Co-authored-by: Liam Barry Signed-off-by: Liam Barry Change-Id: Ifcfe9e09b289d7b474f629c26d00c700f6f2bf8b Signed-off-by: Kshitij Sisodia --- CMakeLists.txt | 11 ++++ CMakePresets.json | 76 ++++++++++++++++++++++++ README.md | 2 +- scripts/cmake/configuration-presets.json | 22 +++++++ 4 files changed, 110 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 729649e..64fb05a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,17 @@ project(arm-llm-wrapper DESCRIPTION "An LLM interface library" LANGUAGES C CXX ASM) +if (USE_KLEIDIAI) + # Ensure target or host is Arm + if (NOT CMAKE_CROSSCOMPILING) + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" SYSTEM_PROC_LOWER) + if (NOT SYSTEM_PROC_LOWER MATCHES "^(aarch64|arm64)$") + message(WARNING + "KleidiAI=ON but not on an Arm host (${CMAKE_SYSTEM_PROCESSOR}).") + endif() + endif() +endif() + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake") # Set the runtime and lib directories diff --git a/CMakePresets.json b/CMakePresets.json index c53e598..02fde46 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -81,6 +81,82 @@ "unit-tests-disabled", "build-shared-disabled" ] + }, + { + "name": "linux-x86_64-default", + "displayName": "Linux x86_64 (no KleidiAI)", + "description": "Native Linux build on x86_64, KleidiAI=OFF", + "generator": "Ninja", + "inherits": [ + "build-type-rel", + "kleidi-off" + ] + }, + { + "name": "linux-arm64-kleidi", + "displayName": "Linux ARM64 (KleidiAI=ON)", + "description": "Native ARM64 build on Linux (auto defaults to v8.2a+dotprod+i8mm)", + "generator": "Ninja", + "inherits": [ + "build-type-rel", + "kleidi-on" + ] + }, + { + "name": "android-arm64-release-kleidi-off", + "description": "Android ARM64 Release (KleidiAI=OFF)", + "generator": "Ninja", + "inherits": [ + "build-type-rel", + "kleidi-off" + ], + "cacheVariables": { + "ANDROID_ABI": { "type": "STRING", "value": "arm64-v8a" }, + "ANDROID_PLATFORM": { "type": "STRING", "value": "android-33" } + } + }, + { + "name": "android-arm64-release-kleidi-on-v82a-dotprod-i8mm", + "description": "Android ARM64 Release (KleidiAI=ON, march=v8.2a+dotprod+i8mm)", + "generator": "Ninja", + "inherits": [ + "build-type-rel", + "kleidi-on" + ], + "cacheVariables": { + "ANDROID_ABI": { "type": "STRING", "value": "arm64-v8a" }, + "ANDROID_PLATFORM": { "type": "STRING", "value": "android-33" }, + "CMAKE_C_FLAGS": { "type": "STRING", "value": "-march=armv8.2a+dotprod+i8mm" }, + "CMAKE_CXX_FLAGS": { "type": "STRING", "value": "-march=armv8.2a+dotprod+i8mm" } + } + }, + { + "name": "android-arm64-debug-kleidi-off", + "description": "Android ARM64 Debug (KleidiAI=OFF)", + "generator": "Ninja", + "inherits": [ + "build-type-dbg", + "kleidi-off" + ], + "cacheVariables": { + "ANDROID_ABI": { "type": "STRING", "value": "arm64-v8a" }, + "ANDROID_PLATFORM": { "type": "STRING", "value": "android-33" } + } + }, + { + "name": "android-arm64-debug-kleidi-on-v82a-dotprod-i8mm", + "description": "Android ARM64 Debug (KleidiAI=ON, march=v8.2a+dotprod+i8mm)", + "generator": "Ninja", + "inherits": [ + "build-type-dbg", + "kleidi-on" + ], + "cacheVariables": { + "ANDROID_ABI": { "type": "STRING", "value": "arm64-v8a" }, + "ANDROID_PLATFORM": { "type": "STRING", "value": "android-33" }, + "CMAKE_C_FLAGS": { "type": "STRING", "value": "-march=armv8.2a+dotprod+i8mm" }, + "CMAKE_CXX_FLAGS": { "type": "STRING", "value": "-march=armv8.2a+dotprod+i8mm" } + } } ] } diff --git a/README.md b/README.md index adb5745..5bafd25 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ These files are essential for loading and running ONNX models effectively. > **NOTE**: Currently only int4 and block size 32 models are accelerated by Arm® KleidiAI™ kernels in `onnxruntime-genai`. ### To build for Android -For Android™ build, ensure the `NDK_PATH` is set to installed Android™ NDK, specify Android™ ABI and platform needed: +For Android™ build, ensure the `NDK_PATH` is set to installed Android™ NDK, specify Android™ ABI and platform if required or use a default preset e.g. android-arm64-release-kleidi-on-v82a-dotprod-i8mm ```shell cmake -B build \ -DCMAKE_TOOLCHAIN_FILE=${NDK_PATH}/build/cmake/android.toolchain.cmake \ diff --git a/scripts/cmake/configuration-presets.json b/scripts/cmake/configuration-presets.json index 2d1cd70..1c76472 100644 --- a/scripts/cmake/configuration-presets.json +++ b/scripts/cmake/configuration-presets.json @@ -82,6 +82,28 @@ "value": "OFF" } } + }, + { + "name": "kleidi-on", + "description": "Enable KleidiAI.", + "hidden": true, + "cacheVariables": { + "USE_KLEIDIAI": { + "type": "BOOL", + "value": "ON" + } + } + }, + { + "name": "kleidi-off", + "description": "Disable KleidiAI.", + "hidden": true, + "cacheVariables": { + "USE_KLEIDIAI": { + "type": "BOOL", + "value": "OFF" + } + } } ] } -- GitLab