ComputeCpp supports pocl on ARM CPU board?

Hi.

I am considering to build SYCL and OpenCL environment with the ComputeCpp and pocl by a-head-of-time compile and run them on ARM CPU board.

In theory, I think that is possible if ComputeCpp supports cross-compile. Could you tell me some comment or advice.

Hi,
It’s possible to do this fairly easily using CMake and the correct toolchain file. There is an Arm toolchain file in the SDK located in computecpp-sdk/cmake/toolchains/arm-gcc-poky.cmake, you could use it in the following example command. You’ll need to replace each path with your own. Let me know if you don’t understand what needs to go where. With this command for example you could build the computecpp-sdk source code and the produced binaries will run on the target arm device. Using the file Linux command on the binary will validate if the binary that has been built is the correct binary type for your target.

cmake -DComputeCpp_DIR=/path/to/computecpp/folder \
  -DOpenCL_LIBRARY=path/to/libOpenCL.so.1.2 \
  -DOpenCL_INCLUDE_DIR=/path/to/opencl/include \
  -DCOMPUTECPP_RUNTIME_LIBRARY=/path/to/computecpp-aarch64-linux/lib/libComputeCpp.so \
  -DCMAKE_TOOLCHAIN_FILE=../computecpp-sdk/cmake/toolchains/gcc-generic.cmake \
  -DCOMPUTECPP_BITCODE=spir64 ..
1 Like

Just a couple of quick clarifications: the toolchain file you want is actually the gcc-generic.cmake toolchain, assuming that you’re not targeting a poky platform. Secondly you’ll need to make sure that the bitcode parameter matches the bitness of your platform, which I am assuming will be 64-bit and therefore should be spir64.

I’d be interested to know if this works for anything other than basic programs, pocl’s spir support has been varied over the years and the last time I tried personally I couldn’t get any builtins other than the absolute basics working. This made it difficult to run anything that wasn’t basically trivial.

I’ve just checked the release notes from last year - it sounds like they’ve put a lot of work into the things I ran into trouble with. We’d be very interested to know if you get any success with this!

Thanks @duncan I’ve updated the original response with your tips.

Hi all

Thank you for your reply. I will try it after completed pocl cross-compile setup and installation (I am struggling to do that).

Hi

I have a question.

-DCOMPUTECPP_RUNTIME_LIBRARY=/path/to/computecpp-aarch64-linux/lib/libComputeCpp.so \

I want to cross-compile sycl.cpp to ARM objects with ARM cross-compiler on Ubuntu intel x64 PC.

Did you answer assuming on Ubuntu ARM 64 PC (or platform)?

Hi,
You are correct in that assumption, it’s the Ubuntu version you are pointing to, however we would recommend actually using a different variable to set the location of the ComputeCpp files.

With the computecpp-sdk project it uses the FindComputeCpp.cmake file to set up some variables and ensure the correct object files are used. You should use that in any other projects that you are building.

I’ve updated the command to make it clear which ComputeCpp versions you need to point to with the command:

cmake -DComputeCpp_DIR=/path/to/computecpp-ce-xyz-arm \
  -DComputeCpp_HOST_DIR=/path/to/computecpp-ce-xyz-x86 \ 
  -DOpenCL_LIBRARY=path/to/libOpenCL.so.1.2 \
  -DOpenCL_INCLUDE_DIR=/path/to/opencl/include \
  -DCMAKE_TOOLCHAIN_FILE=../computecpp-sdk/cmake/toolchains/gcc-generic.cmake \
  -DCOMPUTECPP_BITCODE=spir64 ..

Hi
thanks . I tried the way but i got error.

CMake Error at cmake/toolchains/gcc-generic.cmake:10 (message):
Please set all of COMPUTECPP_TARGET_TRIPLE, COMPUTECPP_SYSROOT_DIR and
COMPUTECPP_TOOLCHAIN_DIR in the environment when crosscompiling.

where is COMPUTECPP_SYSROOT_DIR?
I know where COMPUTECPP_TARGET_TRIPLE, COMPUTECPP_TOOLCHAIN_DIR are.

COMPUTECPP_SYSROOT_DIR should be the folder <target>/libc. We could probably infer it but at the time this seemed simplest. It’s the folder where all the system libraries would live (/usr etc.).

Hi
Thanks.
I have completed cmake but make failed.

[ 1%] Building ComputeCpp integration header file /home/k-ojima/build/samples/vptr_vptr.cpp.sycl
In file included from /home/k-ojima/computecpp-sdk/samples/vptr.cpp:29:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/CL/sycl.hpp:1:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/CL/…/SYCL/sycl.hpp:20:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/SYCL/sycl_builtins.h:27:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/SYCL/cpp_to_cl_cast.h:12:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/SYCL/deduce.h:25:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/SYCL/cl_types.h:23:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/SYCL/common.h:19:
In file included from /opt/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/include/SYCL/predefines.h:541:
/usr/lib/gcc-cross/aarch64-linux-gnu/5.4.0/…/…/…/…/include/c++/5.4.0/cmath:41:10: fatal error:
‘bits/c++config.h’ file not found
#include <bits/c++config.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
samples/CMakeFiles/vptr_vptr.cpp_0_ih.dir/build.make:62: recipe for target ‘samples/vptr_vptr.cpp.bc’ failed

c++config.h is located at /usr/aarch64-linux-gnu/include/c++/5/aarch64-linux-gnu/bits in my environment so I think include path have something wrong. I am looking for the source that set the path but I have not found it yet. Or there are another way to solve it?

Hi,
I have seen problems when cross-compiling before that result in this sort of error. The first to check is the OpenCL headers being found in a “system” location, like /usr/include (most distributions I’ve seen will install them to /usr/include/CL). This can cause header search path problems, where the order they are used changes. To fix this, I normally use a separate directory with a known copy of the OpenCL headers, and specify them with a CMake cache variable like -DOpenCL_INCLUDE_DIR.

I hope this helps,
Duncan.

Hi

Thanks. I have solved the problem of include path but I got new error that seems to relate setting of ComputeCpp.

I specified libOpenCL.so path to computecpp but it seems to also need libOpenCL.so.1 and so on. But pocl library is only libOpenCL.so. Can I change computecpp setting to link libOpenCL.so only?

[ 1%] Built target vptr_vptr.cpp_0_ih
[ 2%] Linking CXX executable vptr
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: libOpenCL.so.1, needed by /home/k-ojima/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/lib/libComputeCpp.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: libOpenCL.so.1, needed by /home/k-ojima/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/lib/libComputeCpp.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: libpthread.so.0, needed by /home/k-ojima/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/lib/libComputeCpp.so, not found (try using -rpath or -rpath-link)

Hi,

Unfortunately you can’t do this out-of-the box. It is not a problem with ComputeCpp per se. Let me explain. When we build ComputeCpp, we use the upstream Khronos OpenCL ICD loader, in other words, we use the official libOpenCL.so as provided here. When you build that you get the following files

libOpenCL.so -> libOpenCL.so.1
libOpenCL.so.1 -> libOpenCL.so.1.2
libOpenCL.so.1.2

When you link your application/library against libOpenCL.so, the linker will actually use the library SONAME, which in this case will be libOpenCL.so.1.

From what you’re saying it seems that pocl is not ICD compatible, since they provide their whole implementation in libOpenCL.so.

With that said, I have two solutions that can work for you:

  1. The easiest solution for you would be to cp libOpenCL.so libOpenCL.so.1 or create a symlink.
  2. Another, more complicated, but better solution would be to create a file in /etc/OpenCL/vendors called pocl.icd containing the full path to your libOpenCL.so. By doing this, you will have installed pocl in an ICD compatible way.

Thank you for your reply.

Sorry, I misunderstood the library is only one because I don’t know the ICD spec well. After knowing that, I confirmed libraries of pocl again, there are 3 files like you said.

So I put the libraries and I tried to make again, but an another error outs.

[ 1%] Built target vptr_vptr.cpp_0_ih
[ 2%] Linking CXX executable vptr
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld:/opt/pocl/libOpenCL.so: file format not recognized; treating as linker script
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld:/opt/pocl/libOpenCL.so:1: syntax error
collect2: error: ld returned 1 exit status

May be it is not problem of ComputeCpp, can you tell me comment or advice if you have any idea.

It looks like you are trying to link the wrong version of pocl, by wrong I mean one that was not cross-compiled for ARM in your case. Can you double check your pocl library is the ARM version?

You can check this by running the command

file /opt/pocl/libOpenCL.so

You should see something like the following

ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked

If you see x86_64 it means you are trying to link against the wrong version.

Thanks!

I had confirmed that the lib are correct with the file command. I just wonder why .so and .so2 say simply “data”.

/opt/pocl/libOpenCL.so: data
/opt/pocl/libOpenCL.so.2: data
/opt/pocl/libOpenCL.so.2.5.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=74136f9675d4262bda2c03fd6c3883fdd733ec53, not stripped

I have solved problems of libOpenCL.so link but another link error appears.

/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: libdl.so.2, needed by /home/k-ojima/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/lib/libComputeCpp.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: libpthread.so.0, needed by /home/k-ojima/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64/lib/libComputeCpp.so, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: libz.so.1, needed by /home/k-ojima/pocllib64/lib64/libOpenCL.so.1, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: librt.so.1, needed by /home/k-ojima/pocllib64/lib64/libOpenCL.so.1, not found (try using -rpath or -rpath-link)
/usr/lib/gcc-cross/aarch64-linux-gnu/5/…/…/…/…/aarch64-linux-gnu/bin/ld: warning: libtinfo.so.5, needed by /home/k-ojima/pocllib64/lib64/libOpenCL.so.1, not found (try using -rpath or -rpath-link

I want to link the libs by-rpath but I could not find cmake file where set -rpath in the computecpp sdk.

Can you update your post with the latest build command you are using please?

I use below.

cmake -DComputeCpp_DIR=…/ComputeCpp-CE-1.3.0-Ubuntu-16.04-ARM_64 -DComputeCpp_HOST_DIR=…/ComputeCpp-CE-1.3.0-Ubuntu-16.04-x86_64 -DOpenCL_LIBRARY=/home/k-ojima/pocllib64/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/include -DCMAKE_TOOLCHAIN_FILE=./cmake/toolchains/gcc-generic.cmake -DCOMPUTECPP_BITCODE=spir64 …

It looks like you are pointing to the wrong library file. Note that the actual pocl library you need, the ARM one, is located in /opt/pocl/libOpenCL.so, the one you are linking is located in /home/k-ojima/pocllib64/lib64/libOpenCL.so, I think that these files are different.