androidandroid-ndksimdintrinsicsneon

error: use of undeclared identifier 'vmaxq_f16'


I get this error whenever I try to use the NEON 16-bit float intrinsics. I do not face any issues with other data types intrinsics.

Isn't it possible to use NEON 16-bit float intrinsics on Android?

My code:

#include <jni.h>
#include <arm_fp16.h>
#include <arm_neon.h>

void useSIMD_f16() {
    float16_t zero = 0;
    float16x8_t zero_f16x8 = vld1q_dup_f16(&zero);
    float16_t one = 1;
    float16x8_t one_f16x8 = vld1q_dup_f16(&one);
    float16x8_t max = vmaxq_f16(zero_f16x8, one_f16x8);
}

Error:

Execution failed for task ':app:externalNativeBuildDebug'. Build command failed. Error while executing process /home/raed/Android/Sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /home/raed/AndroidStudioProjects/SIMD/app/.cxx/cmake/debug/armeabi-v7a native-lib} ninja: Entering directory `/home/raed/AndroidStudioProjects/SIMD/app/.cxx/cmake/debug/armeabi-v7a' [1/2] Building CXX object CMakeFiles/native-lib.dir/native-lib.cpp.o FAILED: CMakeFiles/native-lib.dir/native-lib.cpp.o /home/raed/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi23 --gcc-toolchain=/home/raed/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/raed/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/sysroot -Dnative_lib_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/native-lib.dir/native-lib.cpp.o -MF CMakeFiles/native-lib.dir/native-lib.cpp.o.d -o CMakeFiles/native-lib.dir/native-lib.cpp.o -c /home/raed/AndroidStudioProjects/SIMD/app/src/main/cpp/native-lib.cpp /home/raed/AndroidStudioProjects/SIMD/app/src/main/cpp/native-lib.cpp:7:30: error: use of undeclared identifier 'vld1q_dup_f16' float16x8_t zero_f16x8 = vld1q_dup_f16(&zero); ^ /home/raed/AndroidStudioProjects/SIMD/app/src/main/cpp/native-lib.cpp:9:29: error: use of undeclared identifier 'vld1q_dup_f16' float16x8_t one_f16x8 = vld1q_dup_f16(&one); ^ /home/raed/AndroidStudioProjects/SIMD/app/src/main/cpp/native-lib.cpp:10:23: error: use of undeclared identifier 'vmaxq_f16' float16x8_t max = vmaxq_f16(zero_f16x8, one_f16x8); ^ 3 errors generated. ninja: build stopped: subcommand failed.


Solution

  • Half-precision floating point isn't available on all Arm targets. Check whether the __ARM_FEATURE_FP16_VECTOR_ARITHMETIC macro is defined to determine whether the functions are available.

    Isn't it possible to use NEON 16-bit float intrinsics on Android?

    It's not really an Android thing; some Android devices will support it, others won't. It depends on the CPU.