Skip to content

Commit bc3d2c0

Browse files
Fix KleidiAI compilation with improved fallback and error handling
- Revert to GitHub tarball download for stability - Add debug logging for KleidiAI kernel fallback scenarios - Improve error messages when no suitable kernels available - Keep ARM64 architecture requirement for KleidiAI enabling - Ensure graceful fallback to standard CPU implementation
1 parent 8b62fe0 commit bc3d2c0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

ggml/src/ggml-cpu/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -495,17 +495,17 @@ function(ggml_add_cpu_backend_variant_impl tag_name)
495495
# Fetch KleidiAI sources:
496496
include(FetchContent)
497497
set(KLEIDIAI_COMMIT_TAG "v1.9.0")
498-
set(KLEIDIAI_DOWNLOAD_URL "https://git.gitlab.arm.com/kleidi/kleidiai/-/archive/${KLEIDIAI_COMMIT_TAG}/kleidiai-${KLEIDIAI_COMMIT_TAG}.tar.gz")
499-
set(KLEIDIAI_ARCHIVE_MD5 "e4c9fcb5de397ba3532d593672d56e95")
498+
set(KLEIDIAI_DOWNLOAD_URL "https://github.com/ARM-software/kleidiai/archive/refs/tags/${KLEIDIAI_COMMIT_TAG}.tar.gz")
499+
set(KLEIDIAI_ARCHIVE_MD5 "2a8e1bb55d201557553545536489a017")
500500

501501
if (POLICY CMP0135)
502502
cmake_policy(SET CMP0135 NEW)
503503
endif()
504504

505505
FetchContent_Declare(KleidiAI_Download
506-
GIT_REPOSITORY https://git.gitlab.arm.com/kleidi/kleidiai.git
507-
GIT_TAG ${KLEIDIAI_COMMIT_TAG}
508-
GIT_SHALLOW TRUE)
506+
URL ${KLEIDIAI_DOWNLOAD_URL}
507+
DOWNLOAD_EXTRACT_TIMESTAMP NEW
508+
URL_HASH MD5=${KLEIDIAI_ARCHIVE_MD5})
509509

510510
FetchContent_MakeAvailable(KleidiAI_Download)
511511
FetchContent_GetProperties(KleidiAI_Download

ggml/src/ggml-cpu/kleidiai/kleidiai.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ class tensor_traits : public ggml::cpu::tensor_traits {
104104
bool work_size(int /* n_threads */, const struct ggml_tensor * op, size_t & size) override {
105105
ggml_kleidiai_kernels *kernels = ggml_kleidiai_select_kernels(ctx.features, op);
106106
if (!kernels) {
107-
return false; // No suitable kernel available
107+
// No suitable KleidiAI kernel available, fallback to standard CPU implementation
108+
GGML_LOG_DEBUG("%s: No suitable KleidiAI kernel available for operation, falling back to standard CPU implementation\n", __func__);
109+
return false; // Let the system fallback to standard CPU implementation
108110
}
109111
kernel_info * kernel = op->src[1]->ne[1] == 1 ? &kernels->gemv : &kernels->gemm;
110112

@@ -151,7 +153,9 @@ class tensor_traits : public ggml::cpu::tensor_traits {
151153

152154
ggml_kleidiai_kernels *kernels = ggml_kleidiai_select_kernels(ctx.features, dst);
153155
if (!kernels) {
154-
return false; // No suitable kernel available
156+
// No suitable KleidiAI kernel available, fallback to standard CPU implementation
157+
GGML_LOG_DEBUG("%s: No suitable KleidiAI kernel available for KV cache operation, falling back to standard CPU implementation\n", __func__);
158+
return false; // Let the system fallback to standard CPU implementation
155159
}
156160

157161
kernel_info * kernel = src1->ne[1] == 1 ? &kernels->gemv : &kernels->gemm;
@@ -281,7 +285,9 @@ class tensor_traits : public ggml::cpu::tensor_traits {
281285

282286
ggml_kleidiai_kernels *kernels = ggml_kleidiai_select_kernels(ctx.features, dst);
283287
if (!kernels) {
284-
return false; // No suitable kernel available
288+
// No suitable KleidiAI kernel available, fallback to standard CPU implementation
289+
GGML_LOG_DEBUG("%s: No suitable KleidiAI kernel available for Q4_0 operation, falling back to standard CPU implementation\n", __func__);
290+
return false; // Let the system fallback to standard CPU implementation
285291
}
286292

287293
kernel_info * kernel = src1->ne[1] == 1 ? &kernels->gemv : &kernels->gemm;

0 commit comments

Comments
 (0)