Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile bug: ARMv7 NEON FP16 Intrinsic Errors When Cross-Compiling with Android NDK r26b #11636

Open
Namitjain07 opened this issue Feb 4, 2025 · 2 comments

Comments

@Namitjain07
Copy link

Namitjain07 commented Feb 4, 2025

Git commit

b4623

Here's a refined GitHub issue description with clearer output formatting and explicit error context:


Description
Cross-compiling for Android ARMv7 (armeabi-v7a) fails with missing NEON FP16 intrinsics despite proper toolchain configuration. The errors occur specifically in sgemm.cpp when using NDK r26b's Clang 17 compiler.


Environment

Component Version
Android NDK r26b
Host OS Ubuntu 22.04.4 LTS
CMake 3.28.3
llama.cpp commit 21c84b5d
Target ABI armeabi-v7a
Android API 24

Steps to Reproduce

# 1. Fresh clone
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
git checkout 21c84b5d

# 2. Configure for ARMv7
mkdir build-android && cd build-android
cmake .. \
  -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=armeabi-v7a \
  -DANDROID_ARM_NEON=ON \
  -DANDROID_NATIVE_API_LEVEL=24 \
  -DCMAKE_CXX_FLAGS="-march=armv7-a -mfpu=neon-fp16"

# 3. Build
make -j4 llama

Observed Errors

[42%] Building CXX object ggml/src/CMakeFiles/ggml-cpu.dir/ggml-cpu/llamafile/sgemm.cpp.o
/home/user/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp:223:12: error: use of undeclared identifier 'vld1q_f16'
    return vld1q_f16((const float16_t *)p);  // <--- Missing NEON FP16 intrinsic
           ^
/home/user/llama.cpp/ggml/src/ggml-cpu/llamafile/sgemm.cpp:226:25: error: use of undeclared identifier 'vld1_f16'
    return vcvt_f32_f16(vld1_f16((const float16_t *)p));  // <--- FP16 conversion failure
                        ^
2 errors generated.
make[2]: *** [ggml/src/CMakeFiles/ggml-cpu.dir/build.make:188] Error 1

Expected Behavior

Successful compilation of NEON-accelerated FP16 code paths for ARMv7 targets.


Diagnostic Evidence

  1. Compiler Feature Check:

    -- Performing Test GGML_COMPILER_SUPPORTS_FP16_FORMAT_I3E -- Failed
    

    Indicates compiler doesn't recognize ARMv7 FP16 extensions despite -mfpu=neon-fp16.

  2. Architecture Validation:

    -- CMAKE_SYSTEM_PROCESSOR: armv7-a
    -- ANDROID_ARM_NEON: TRUE
    

    Confirms ARMv7+NEON target configuration.

  3. Header Dependency:
    Missing #include <arm_neon.h> in files using NEON intrinsics.


Workarounds Attempted

Attempt Result
Manual #include <arm_neon.h> Compilation progresses but fails at linking
-D__ARM_FEATURE_FP16_VECTOR_ARITHMETIC=1 No change in intrinsic availability
NDK r25c downgrade Build succeeds but breaks OpenCL compatibility
ARM64-v8a target Builds successfully (confirms ARMv7-specific issue)

Reproduction Rate

  • 100% reproducible on clean builds
  • Affects all ARMv7 NEON FP16 code paths
  • Verified across multiple Ubuntu 22.04 machines

Request:
Guidance on either:

  1. Correct compiler flags to enable ARMv7 FP16 vector arithmetic in NDK r26b, or
  2. Source modifications to make NEON FP16 code paths compatible with NDK's Clang 17 toolchain
  3. complete commands to compile for ARMv7 to create libllama.so.

@ag2s20150909
Copy link
Contributor

-DGGML_LLAMAFILE=OFF

@Namitjain07
Copy link
Author

Can u please tell the complete commands to compile libllama.so in armv7 and armv8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants