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

Do I have to cross-compile both opencl and clblast for android? #511

Open
DavdGao opened this issue Oct 25, 2023 · 2 comments
Open

Do I have to cross-compile both opencl and clblast for android? #511

DavdGao opened this issue Oct 25, 2023 · 2 comments
Labels

Comments

@DavdGao
Copy link

DavdGao commented Oct 25, 2023

Target

I want to build CLBlast for android app with JNI.

Question

I am cross-compiling clblast for android with the following scripts.

  • Q1. CLBlast requires OpenCL library, but I don't know If I need to cross-compile opencl library too? Or just build OpenCL on my macbook pro as usual.
  • Q2. I'm coding android app with android studio, but I don't know should I use static opencl library libOpenCL.a or libOpenCL.so for CLBlast?
#!/bin/bash

ANDROID_NDK_PATH=/Users/david/Library/Android/sdk/ndk/25.1.8937393/

cmake .. \
	-DCMAKE_SYSTEM_NAME=Android \
	-DCMAKE_SYSTEM_VERSION=33 \
	-DCMAKE_BUILD_TYPE=Release \
	-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
	-DCMAKE_ANDROID_NDK=$ANDROID_NDK_PATH \
	-DCMAKE_ANDRFOID_STL_TYPE=gnustl_static \
	-DBUILD_SHARED_LIBS=OFF \
	-DOPENCL_ROOT=/Users/david/Documents/C++/OpenCL-SDK/build_android/OpenCL/include/ \
	-DOPENCL_INCLUDE_DIRS=/Users/david/Documents/C++/OpenCL-SDK/build_android/OpenCL/include/ \
	-DOPENCL_LIBRARIES=/Users/david/Documents/C++/OpenCL-SDK/build_android/OpenCL/libOpenCL.so

cmake --build . --config Release

cmake --install . --prefix install_android

Update 2023/10/25

  • I cross-compile OpenCL into both static and shared libraries.
  • To cross-compile CLBlast, I try both static and shared libraries for -DOPENCL_LIBRARIES, but only shared libraries work.
  • To enable CLBlast in android app, I import both libOpenCL.a and libclblast.a in android project.
    • Note here I use libOpenCL.a rather than libOpenCL.so
  • However, in this android project, the function clGetPlatformsIDs in JNI code returns -1001!
    Any suggestions?
@CNugteren
Copy link
Owner

Regarding Q1, compiling the OpenCL library yourself seems unusual, I would expect that you simply get one from your vendor or find one on your device and link against that one. In any case, something like clGetPlatformsIDs not working isn't a CLBlast problem, so I can't help you any further with that. You would have to look at your vendors manual for OpenCL.

Regarding Q2, I think linking against either a dynamic or static version of CLBlast should work. Just go with your preference or whatever is easiest.

By the way, there is quite some information spread over various issues regarding Android on CLBlast's GitHub issue tracker, as well as some Android documentation at https://github.com/CNugteren/CLBlast/blob/master/doc/installation.md#android-compilation-from-source.

I hope this helps.

@engineer1109
Copy link
Contributor

build OpenCL lib by mesa or KHR code

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

No branches or pull requests

3 participants