3

I am trying to build OpenCL SDK for ANDROID from this source --> https://github.com/KhronosGroup/OpenCL-SDK
I got build ".so" files or ".a" files but they don't not work at all even if they got linked properly.

I think I can't load all the symbols to my ".so" or ".a" files while I building it. I have to load symbols from my device's /system/vendor/lib64/libOpenCL.so. In other words, OPENCL_ICD_LOADER can't detect my device's opencl platform.

My device is a SM-X700. It contains Adreno 730 GPU.

When I open one of the libOpenCL.a or libOpenCL.so files that I got build in text editor, I see somethings like below

!<arch>
/               0           0     0     0       3808      `
���������������������������7��7��7��7��7��7��\��
failed to load library %s
�_�_    �`��T�����_�����OCL_ICD_ENABLE_TRACE�True�true�T�1�KHR ICD trace at %s:%d:
�already loaded vendor %s, nothing to do here
�clGetExtensionFunctionAddress�failed to get function address clGetExtensionFunctionAddress
�clIcdGetPlatformIDsKHR�failed to get extension function address clIcdGetPlatformIDsKHR
�failed clIcdGetPlatformIDs
�failed to allocate memory
�failed get platform handle to library
�successfully added vendor %s with suffix %s

I installed the triplet for arm64-v8a in vcpkg using the link below --> https://learn.microsoft.com/en-us/vcpkg/users/platforms/android

And this is my cmake configuration

cmake -D CMAKE_BUILD_TYPE=Release \
      -D BUILD_TESTING=OFF \
      -D BUILD_DOCS=OFF \
      -D BUILD_EXAMPLES=OFF \
      -D BUILD_TESTS=OFF \
      -D OPENCL_SDK_BUILD_SAMPLES=OFF \
      -D OPENCL_SDK_TEST_SAMPLES=OFF \
      -D CMAKE_C_COMPILER="/home/my_user_name/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" \
      -D CMAKE_CXX_COMPILER="/home/my_user_name/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" \
      -D CMAKE_TOOLCHAIN_FILE=/home/my_user_name/vcpkg/scripts/buildsystems/vcpkg.cmake \
      -D VCPKG_CHAINLOAD_TOOLCHAIN_FILE=/home/my_user_name/Android/Sdk/ndk/25.0.8775105/build/cmake/android.toolchain.cmake \
      -D VCPKG_TARGET_TRIPLET=arm64-android \
      -D ANDROID_ABI=arm64-v8a \
      -D ANDROID_PLATFORM=33 \
      -D CMAKE_INSTALL_PREFIX=/home/my_user_name/OPENCL_AARCH64_OUT \
      -D BUILD_SHARED_LIBS=OFF \
      ..

I want to use OpenCL in my c++-native project on Android. Please help me.

I tried to compile other NDK versions below 25.0.8775105

I found someone who struggle with same problem in this link--> https://developer.qualcomm.com/forum/qdn-forums/software/adreno-gpu-sdk/68895

Thow
  • 45
  • 6
  • Note OpenCL is not officially supported by Android, so there is no standard .so file to link against. See: [Does Android support OpenCL?](https://stackoverflow.com/q/26795921/295004) – Morrison Chang Jan 27 '23 at 21:45
  • You should then mention the device / GPU. Given the limited number of [android related issues](https://github.com/KhronosGroup/OpenCL-SDK/issues?q=is%3Aissue+android) I expect most directly use OpenCL on Android similar to [Using OpenCL in the new Android Studio](https://stackoverflow.com/a/32153252/295004), apologies if you've already seen it. – Morrison Chang Jan 27 '23 at 23:00
  • "Using OpenCL in the new Android Studio", method 1 in this topic doesn't work beacuse libOpenCL.so from /system/vendor/lib64 is not in the list public.libraries.txt that's why pulling from device and simply using it is not a way for new Android 12 or above devices. I am sure of it beacuse I tried it. method 2, I didn' try it yet but looks promising. But If I can't find a solution I will try it. – Thow Jan 27 '23 at 23:08
  • And I almost forgot. Thanks after all. – Thow Jan 27 '23 at 23:44
  • Not a problem. FYI for future readers: while Vulkan isn't a one-to-one mapping for OpenCL, Android mandates [Vulkan](https://source.android.com/docs/core/graphics/arch-vulkan) support on [recent devices](https://www.androidpolice.com/2019/05/07/vulkan-1-1-will-be-required-on-all-64-bit-devices-running-android-q-or-higher/) and there are projects like: https://github.com/KomputeProject/kompute so access to OpenCL drivers is manufacturer dependant. – Morrison Chang Jan 28 '23 at 00:52
  • Accessing /system/vendor/lib64/libOpenCL.so using dlopen() is impossible because after TargetApı Level 24 accessing private libraries restricted by android developers. – Thow Feb 03 '23 at 09:01

1 Answers1

0

It is not un easy job to do. So first you need to use API < 23

Then you copy libGLES.so and libOpenCL.so from your device to jni/libs armebi-v7a because arm64-v8a is not available on some machine

then during the the onCreate you must check wich librarty are missing.

some library can be accessible using System.loadLibrary but some other will not it depends on the frabicant and the model. In this case you need to copy from the device the needed library to jni/libs armebi-v7a.

In your android.mk file you need to declare for all the library copied to JNI

    # Honnor play
    include $(CLEAR_VARS)
    LOCAL_MODULE := GLES_mali
    LOCAL_SRC_FILES := $(LOCAL_PATH)/arm7/libGLES_mali.so
    include $(PREBUILT_SHARED_LIBRARY)
and LOCAL_ARM_NEON := true   on ARM

in your aplication.mk

APP_STL := gnustl_static
APP_STL := c++_shared
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-23

but too load the librarie that cannot be loaded throw System.loadLibrary, the librarie that belong too the fabricant, you need too use SharedLibraryLoader.java clas. You can find this on old post in stackoverflow.

It is not an easy job too do and you must do it for every new phonne. And the last problem is thzt your openCL code will not run proprely from ARM to ADRENO whytout some small modification, you will see ;))

You can find a good OpenCL example on github androidcl-master.

hterrolle
  • 49
  • 8
  • I have to get a build for Android-31 and above, it's a must for me. – Thow Feb 03 '23 at 10:52
  • And let me tell you something I can run old OpenCL-SDK until Android-30, right now I have to get a build compatible with Android-31 and above, that's why I am struggling. With new OpenCL-SDK they removed old registiries. – Thow Feb 03 '23 at 11:22
  • Yes on Adreno no need to hack but openCL is very slow. Are you sure that your librarie is really in 64bits. I know that on my haiwue the Lib64 is compiled in 32. – hterrolle Feb 03 '23 at 17:39