4

I've spent many hours today trying to accomplish this seemingly very simple task so my frustration may seem strange to you.

I want to "run"/execute a program that contains OpenCL functions on my Samsung Galaxy S7 (Exynos SoC). Support for OpenCL shouldn't be an issue because: 1) It's a well supported flagship phone from a well-known manufacturer 2) libOpenCL.so is present in /system/vendor/lib/libOpenCL.so 3) OpenCL-Z reports a valid platform and device (GPU only for some reason)

Things that I tried: Rooted the phone. Installed cppdroid. Tried to compile a simple program that contains references to standard OpenCL functions like clGetPlatformIDs().

Header files should be included somewhere, but I could not for the life of me find where to put them (using the same path where cppdroid stores standard header files did not work), so I manually included the headers in the .c file itself, making it barely editable on the phone itself.

My understanding is that I should link the library (libOpenCL.so) to the output of gcc during the linking phase. There seems to be an option to do that in cppdroid, under "Settings" "Project settings" "Link options" so I add:

-L/system/vendor/lib/libOpenCL.so

to that field. However compilation still fails and I'm getting "undefined references to clGetPlatformIDs()" as if I hadn't included the library at all.

After searching online for a solution, a possible remedy (see below) proved useless: -Wl,--whole-archive -L/system/vendor/lib/libOpenCL.so

I thought I'd get gcc on its own since this is the compiler used by cppdroid and try to compile that way. Found out that it's supposed to be deprecated, and replaced by "clang". But cppdroid does include gcc, so I navigated to the folder containing the executable (I believe it's an executable, there seem to be no extensions here, and I'm a Windows person) which appears to be:

/data/data/name.antonsmirnov.android.cppdroid/sdk/gcc#4.8#2/bin

and tried to "execute" gcc-4.8 (which appears to be the executable compiler) from termux (a terminal emulator for Android). Much to my surprise I got the error message:

sush: gcc-4.8: not found

Even though ls -1 lists the file normally!

I tried various other stuff that did not work, but here's my question:

How do I go about compiling a simple OpenCL program that I've written in C, so as to execute it on my Android mobile device?

Why do I get the

sush: gcc-4.8: not found

error message?

Shoomla
  • 131
  • 6
  • Unless you find special pleasure in running compiler in your phone, you may get around much less painfully by building your executable on the PC. You can pull the relevant so files to your development machine (feel free to use adb or device explorer of Android Studio). – Alex Cohn Jan 30 '19 at 21:33

3 Answers3

0

First -L provides a search directory for libraries to link, you should be using -L/system/vendor/lib you can use -l to link to a library in your case -lOpenCL without the lib prefix.

cleblanc
  • 3,678
  • 1
  • 13
  • 16
0

I got it working on my Samsung S9+ Exynos phone. Here is what I did to use OpenCL in the Termux app:

apt update
apt upgrade
apt autoremove
apt install vim openssh clang git
vim ~/.bashrc
# press the i key, then paste the line below, then save and exit with :wq
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/system/vendor/lib64:/system/vendor/lib64/egl

# restart Termux
exit

And finally, to compile a C++ OpenCL program with headers as described here:

cd Test/src
g++ *.cpp -o Test.exe -std=c++11 -pthread -w -I./OpenCL/include -L/system/vendor/lib64 -lOpenCL
./Test.exe

To install clinfo do the following:

apt install cmake make
cd ~
mkdir opencl
cd ~/opencl
git clone https://github.com/KhronosGroup/OpenCL-Headers
cd ~/opencl/OpenCL-Headers
cmake -S . -B build -DCMAKE_INSTALL_PREFIX=$PREFIX
cmake --build build --target install
cd ~/opencl
git clone https://github.com/Oblomov/clinfo
cd ~/opencl/clinfo
make OS=Android
./clinfo
ProjectPhysX
  • 4,535
  • 2
  • 14
  • 34
-1

My understanding is that I should link the library (libOpenCL.so) to the output of gcc during the linking phase. There seems to be an option to do that in cppdroid, under "Settings" "Project settings" "Link options" so I add:

-L/system/vendor/lib/libOpenCL.so

to that field. However compilation still fails and I'm getting "undefined references to clGetPlatformIDs()" as if I hadn't included the library at all.

You need to add -lOpenCL and -L/system/vendor/lib to the linker flags. The second option may not be required, as this directory should be in a default search path already.

Community
  • 1
  • 1