CNugteren / CLBlast

Tuned OpenCL BLAS
Apache License 2.0
1.06k stars 202 forks source link

Android compilation failing #537

Closed samolego closed 7 months ago

samolego commented 7 months ago

Hello there, I'm trying to compile this library to use with whisper.cpp on my android device.

I've done the following:

Cloned this repo & https://github.com/KhronosGroup/OpenCL-Headers Copied the opencl lib from my phone to pc:

adb pull /system/vendor/lib64/egl/libEGL_adreno.so lib/src/main/jniLibs/arm64-v8a/libOpenCL.so

Created build dir in clblast Then ran the cmake (paths are correct)

$ANDROID_SDK_PATH/cmake/3.22.1/bin/cmake .. \
    -DCMAKE_SYSTEM_NAME=Android \
    -DCMAKE_SYSTEM_VERSION=33 \
    -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
    -DCMAKE_ANDROID_NDK=$ANDROID_NDK_PATH \
    -DCMAKE_ANDROID_STL_TYPE=c++_static \
    -DOPENCL_INCLUDE_DIRS=$(readlink -f ../../OpenCL-Headers) \
    -DOPENCL_ROOT=$(readlink -f ../../OpenCL-Headers) \
    -DOPENCL_LIBRARIES=$(readlink -f ../../../lib/whispercpp/src/main/jniLibs/arm64-v8a/libOpenCL.so)

When running make, I get an error:

[ 64%] Building CXX object CMakeFiles/clblast.dir/src/database/kernels/xger/xger.cpp.o
[ 65%] Building CXX object CMakeFiles/clblast.dir/src/database/kernels/invert/invert.cpp.o
[ 66%] Building CXX object CMakeFiles/clblast.dir/src/database/kernels/gemm_routine/gemm_routine.cpp.o
[ 67%] Building CXX object CMakeFiles/clblast.dir/src/database/kernels/trsv_routine/trsv_routine.cpp.o
[ 68%] Building CXX object CMakeFiles/clblast.dir/src/database/kernels/xconvgemm/xconvgemm.cpp.o
[ 68%] Linking CXX shared library libclblast.so
ld: error: undefined symbol: clCreateKernel
>>> referenced by clpp11.hpp:817 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:817)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(clblast::Kernel::Kernel(std::__ndk1::shared_ptr<clblast::Program>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&))

ld: error: undefined symbol: clSetKernelArg
>>> referenced by clpp11.hpp:828 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:828)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(void clblast::Kernel::SetArgument<int>(unsigned long, int const&))
>>> referenced by clpp11.hpp:828 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:828)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(void clblast::Kernel::SetArgument<_cl_mem*>(unsigned long, _cl_mem* const&))
>>> referenced by clpp11.hpp:828 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:828)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(void clblast::Kernel::SetArgument<float>(unsigned long, float const&))
>>> referenced 3 more times

ld: error: undefined symbol: clGetKernelWorkGroupInfo
>>> referenced by clpp11.hpp:847 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:847)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(clblast::Kernel::LocalMemUsage(clblast::Device const&) const)

ld: error: undefined symbol: clEnqueueNDRangeKernel
>>> referenced by clpp11.hpp:881 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:881)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(clblast::Kernel::Launch(clblast::Queue const&, std::__ndk1::vector<unsigned long, std::__ndk1::allocator<unsigned long> > const&, std::__ndk1::vector<unsigned long, std::__ndk1::allocator<unsigned long> > const&, _cl_event**, std::__ndk1::vector<clblast::Event, std::__ndk1::allocator<clblast::Event> > const&))
>>> referenced by clpp11.hpp:864 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:864)
>>>               CMakeFiles/clblast.dir/src/utilities/timing.cpp.o:(clblast::Kernel::Launch(clblast::Queue const&, std::__ndk1::vector<unsigned long, std::__ndk1::allocator<unsigned long> > const&, std::__ndk1::vector<unsigned long, std::__ndk1::allocator<unsigned long> > const&, _cl_event**))

ld: error: undefined symbol: clReleaseKernel
>>> referenced by clpp11.hpp:806 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:806)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(clblast::Kernel::Kernel(std::__ndk1::shared_ptr<clblast::Program>, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)::'lambda'(_cl_kernel**)::operator()(_cl_kernel**) const)

ld: error: undefined symbol: clGetDeviceInfo
>>> referenced by clpp11.hpp:392 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:392)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(unsigned int clblast::Device::GetInfo<unsigned int>(unsigned int) const)
>>> referenced by clpp11.hpp:394 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:394)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(unsigned int clblast::Device::GetInfo<unsigned int>(unsigned int) const)
>>> referenced by clpp11.hpp:400 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:400)
>>>               CMakeFiles/clblast.dir/src/routines/common.cpp.o:(std::__ndk1::vector<unsigned long, std::__ndk1::allocator<unsigned long> > clblast::Device::GetInfoVector<unsigned long>(unsigned int) const)
>>> referenced 7 more times

ld: error: undefined symbol: clBuildProgram
>>> referenced by clpp11.hpp:500 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:500)
>>>               CMakeFiles/clblast.dir/src/utilities/compile.cpp.o:(clblast::Program::Build(clblast::Device const&, std::__ndk1::vector<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >, std::__ndk1::allocator<std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > > >&))

ld: error: undefined symbol: clGetProgramBuildInfo
>>> referenced by clpp11.hpp:512 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:512)
>>>               CMakeFiles/clblast.dir/src/utilities/compile.cpp.o:(clblast::Program::GetBuildInfo(clblast::Device const&) const)
>>> referenced by clpp11.hpp:515 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:515)
>>>               CMakeFiles/clblast.dir/src/utilities/compile.cpp.o:(clblast::Program::GetBuildInfo(clblast::Device const&) const)

ld: error: undefined symbol: clCreateProgramWithSource
>>> referenced by clpp11.hpp:470 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:470)
>>>               CMakeFiles/clblast.dir/src/utilities/compile.cpp.o:(clblast::Program::Program(clblast::Context const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&))

ld: error: undefined symbol: clReleaseEvent
>>> referenced by clpp11.hpp:118 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:118)
>>>               CMakeFiles/clblast.dir/src/utilities/timing.cpp.o:(clblast::Event::Event()::'lambda'(_cl_event**)::operator()(_cl_event**) const)

ld: error: undefined symbol: clWaitForEvents
>>> referenced by clpp11.hpp:126 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:126)
>>>               CMakeFiles/clblast.dir/src/utilities/timing.cpp.o:(clblast::Event::WaitForCompletion() const)

ld: error: undefined symbol: clFinish
>>> referenced by clpp11.hpp:590 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:590)
>>>               CMakeFiles/clblast.dir/src/utilities/timing.cpp.o:(clblast::Queue::Finish() const)

ld: error: undefined symbol: clCreateContext
>>> referenced by clpp11.hpp:439 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:439)
>>>               CMakeFiles/clblast.dir/src/api_common.cpp.o:(clblast::Context::Context(clblast::Device const&))

ld: error: undefined symbol: clCreateCommandQueue
>>> referenced by clpp11.hpp:581 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:581)
>>>               CMakeFiles/clblast.dir/src/api_common.cpp.o:(clblast::Queue::Queue(clblast::Context const&, clblast::Device const&))

ld: error: undefined symbol: clReleaseContext
>>> referenced by clpp11.hpp:434 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:434)
>>>               CMakeFiles/clblast.dir/src/api_common.cpp.o:(clblast::Context::Context(clblast::Device const&)::'lambda'(_cl_context**)::operator()(_cl_context**) const)

ld: error: undefined symbol: clReleaseCommandQueue
>>> referenced by clpp11.hpp:577 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:577)
>>>               CMakeFiles/clblast.dir/src/api_common.cpp.o:(clblast::Queue::Queue(clblast::Context const&, clblast::Device const&)::'lambda'(_cl_command_queue**)::operator()(_cl_command_queue**) const)

ld: error: undefined symbol: clGetCommandQueueInfo
>>> referenced by clpp11.hpp:596 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:596)
>>>               CMakeFiles/clblast.dir/src/routine.cpp.o:(clblast::Queue::GetContext() const)
>>> referenced by clpp11.hpp:598 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:598)
>>>               CMakeFiles/clblast.dir/src/routine.cpp.o:(clblast::Queue::GetContext() const)
>>> referenced by clpp11.hpp:603 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:603)
>>>               CMakeFiles/clblast.dir/src/routine.cpp.o:(clblast::Queue::GetDevice() const)
>>> referenced 1 more times

ld: error: undefined symbol: clGetProgramInfo
>>> referenced by clpp11.hpp:522 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:522)
>>>               CMakeFiles/clblast.dir/src/routine.cpp.o:(clblast::Program::GetIR() const)
>>> referenced by clpp11.hpp:526 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:526)
>>>               CMakeFiles/clblast.dir/src/routine.cpp.o:(clblast::Program::GetIR() const)
>>> referenced by clpp11.hpp:547 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:547)
>>>               CMakeFiles/clblast.dir/src/routine.cpp.o:(clblast::Program::GetIR() const)

ld: error: undefined symbol: clCreateProgramWithBinary
>>> referenced by clpp11.hpp:481 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:481)
>>>               CMakeFiles/clblast.dir/src/routine.cpp.o:(clblast::Program::Program(clblast::Device const&, clblast::Context const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&))

ld: error: undefined symbol: clGetMemObjectInfo
>>> referenced by clpp11.hpp:780 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:780)
>>>               CMakeFiles/clblast.dir/src/routines/levelx/xinvert.cpp.o:(clblast::Buffer<unsigned short>::GetSize() const)
>>> referenced by clpp11.hpp:780 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:780)
>>>               CMakeFiles/clblast.dir/src/routines/levelx/xinvert.cpp.o:(clblast::Buffer<float>::GetSize() const)
>>> referenced by clpp11.hpp:780 (/home/samoh/Documents/GitHub/LocalLM/grafa/CLBlast/src/clpp11.hpp:780)
>>>               CMakeFiles/clblast.dir/src/routines/levelx/xinvert.cpp.o:(clblast::Buffer<double>::GetSize() const)
>>> referenced 4 more times

ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [CMakeFiles/clblast.dir/build.make:1378: libclblast.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:114: CMakeFiles/clblast.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

What am I doing wrong?

CNugteren commented 7 months ago

I am not sure what goes wrong, but errors such as ld: error: undefined symbol: clCreateKernel indicate that the linker can't find the most basic OpenCL functions, such as clCreateKernel, which has been in OpenCL since version 1.0. Thus, somehow it must be not properly linking to your OpenCL library, or your OpenCL library is incorrect. You can run make VERBOSE=1 or make -n to see the exact linker command, maybe that will help with debugging the issue. You can also inspect your OpenCL library for symbols by using a tool such as nm on Linux.

Hope this helps.

samolego commented 7 months ago

Found out that I was pulling the wrong library from phone. Was reading the whisper.cpp guide which includes guide for mali (afaik that's mediatek's) so I thought I need to take adreno, as I have a qualcomm chip. Turns out my phone had libopencl.so in /system/vendor/lib64/libOpenCL.so.

Sorry for trouble, should check better next time. Keep up good work!