Some questions about building CLBlast and OpenCL for android device

210 Views Asked by At

What I'm Doing

I'm coding an android app with JNI, and I want to accelerate c++ codes with CLBlast.

Background

cmake .. \
 -DCMAKE_SYSTEM_NAME=Android \
 -DCMAKE_SYSTEM_VERSION=19 \             # Set the appropriate Android API level
 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a \  # Set the appropriate device architecture (e.g. armeabi-v7a or arm64-v8a)
 -DCMAKE_ANDROID_NDK=$ANDROID_NDK_PATH \ # Assumes $ANDROID_NDK_PATH points to your NDK installation
 -DCMAKE_ANDROID_STL_TYPE=gnustl_static \
 -DOPENCL_ROOT=/path/to/vendor/OpenCL/lib/folder/   # Should contain libOpenCL.so and CL/cl.h

My Question

  • Q1. If my android app is built with CLBlast and OpenCL, but the android device doesn't support OpenCL (e.g. no /system/vendor/libOpenCL.so in android device). Will my app work properly?
  • Q2. Building CLBlast requires OpenCL library, should I use static library libOpenCL.a or dynamic library libOpenCL.so and what's the difference?
  • Q3. Do I have to cross-compile OpenCL too? Does it depend on the building type, such as libOpenCL.a and libOpenCL.so?
1

There are 1 best solutions below

0
On

Q1 - The answer is depends on vendor's support. Depends on device architecture it will be /lib64 or /lib folder on device, but in case if you can not find any libOpenCL.so in there the Android OS can't used it due to system was not build with it. You can try deliver it with the app directly and load it during app initialization. But in this case it will depends on the vendor GPU OpenCL support. You can check older answer here Does Android support OpenCL?

Q2 - You have to use .so from device to compile CLBLAST. In other cases (if your device doesn't have libOpenCL.so) you have to build libOpenCL.so from scratch for device architecture (e.g. arm64-v8a etc.) and then build CLBLAST with it. You can build it with .a also but it has some disadvantages. General answer .a vs .so What are .a and .so files?

Q3 - In general yes, but take into account above answer.