[Q&A] Cross-Compiling: Ubuntu-x86_64 to R-Car (AArch64 - ARM)

How to cross-compile SYCL applications from Ubuntu_x86-64 to ARM_aarch64?
with ComputeCpp

The following information provides a summarized guide which can be used as a reference when doing cross-compilation targeting arm64 architecture.


Prerequisite:

  • ComputeCpp-CE (latest) for Ubuntu16.04-x86_64 : ComputeCpp_HOST_DIR
  • ComputeCpp-CE (latest) Ubuntu16.04-arm : ComputeCpp_DIR
  • Yocto - poky-2.1.3 : gcc-arm toolchain

Using compute++ to produce the SYCL integration header and g++ compiler from the poky toolchain to compile the final application binary. Demonstrating two approaches - compiling directly from the terminal and using Cmake with Codeplay’s FindComputeCpp.cmake and arm-gcc-poky.cmake which glue everything together.

From Terminal:

INTEGRATION HEADER

/path/to/computecpp-ce-xyz-x86/bin/compute++ -std=c++14 -O2 -mllvm \ 
 -inline-threshold=1000 -no-serial-memop -sycl -intelspirmetadata \ 
 --sysroot=/path/to/poky/version/sysroots/aarch64-poky-linux \ 
 -target aarch64-poky-linux -sycl-target spir64 \ 
 -I /path/to/computecpp-ce-xyz-arm/include -I /path/to/opencl-arm/inc \ 
 -o my-sycl-app.cpp.bc -c my-sycl-app.cpp

OBJECT FILE (HOST + DEVICE CODE)

/path/to/poky/version/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++   \ 
 --sysroot=/path/to/poky/version/sysroots/aarch64-poky-linux \ 
 -DBUILD_PLATFORM_SPIR -I /path/to/computecpp-ce-xyz-arm/include \ 
 -I /path/to/opencl-arm/inc -O2 -include my-sycl-app.cpp.sycl \ 
 -std=c++1z -pthread -o my-sycl-app.cpp.o -c my-sycl-app.cpp

FINAL BINARY (PROGRAM EXECUTABLE)

/path/to/poky/version/sysroots/x86_64-pokysdk-linux/usr/bin/aarch64-poky-linux/aarch64-poky-linux-g++ \ 
 --sysroot=/path/to/poky/version/sysroots/aarch64-poky-linux -std=c++1z \
 -pthread my-sycl-app.cpp.o -rdynamic -O2 -o my-sycl-app \
 -L /path/to/computecpp-ce-xyz-arm/lib -L /path/to/opencl-arm/lib \ 
 -lComputeCpp -lOpenCL

For more information on the compiler flags passed to compute++, refer to: compute-compiler manual


Using CMake:

export SDK_POKY_ROOT=/path/to/poky/version/sysroots
cmake .. -DCMAKE_BUILD_TYPE=<Debug/Release> \ 
 -DComputeCpp_HOST_DIR=/path/to/computecpp-ce-xyz-x86 \ 
 -DComputeCpp_DIR=/path/to/computecpp-ce-xyz-arm \
 -DOpenCL_LIBRARY=/path/to/opencl-arm/lib/libOpenCL.so.1.2 \
 -DOpenCL_INCLUDE_DIR=/path/to/opencl-arm/include \
 -DCMAKE_TOOLCHAIN_FILE=/path/to/cmake/toolchains/arm-gcc-poky.cmake \
 -DCOMPUTECPP_USER_FLAGS="-mllvm -inline-threshold=1000 -no-serial-memop" \
 -DCOMPUTECPP_BITCODE=spir64 # or 'spir'

make -j4