Skip to content
Permalink
Browse files

CMake: fix pocl building on ARM architectures

Also update README.ARM. A bunch of tests still fail, but
pocl should at least build on ARM / ARM64.
  • Loading branch information
franz committed Jul 31, 2017
1 parent 4fb00ef commit 5d38f49abb70fa73a61ecccb454f0ec27ef20b69
Showing with 61 additions and 23 deletions.
  1. +41 −8 CMakeLists.txt
  2. +20 −15 README.ARM
@@ -72,11 +72,17 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "mips")
set(MIPS 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7")
set(ARMV7 1)
set(ARM32 1)
set(ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv6")
set(ARMV6 1)
set(ARM32 1)
set(ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(ARM64 1)
set(ARM 1)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(i.86|AMD64|x86_64)")
set(X86 1)
if(POCL_DEVICE_ADDRESS_BITS MATCHES "32")
set(I386 1)
else()
@@ -274,7 +280,12 @@ if (OCS_AVAILABLE)
set(HOST_DEVICE_BUILD_HASH "${LLC_TRIPLE}-${LLC_HOST_CPU}")
endif()

if(ARM AND LLVM_3_9)
message(FATAL_ERROR "pocl does not build on ARM with LLVM 3.9 unless is was patched. Try LLVM 3.8 or (preferably) 4.0+")
endif()

else()

if(NOT DEFINED HOST_DEVICE_BUILD_HASH)
message(FATAL_ERROR "For compiler-less builds, you must define HOST_DEVICE_BUILD_HASH")
endif()
@@ -645,7 +656,12 @@ endif()
set(DEFAULT_HOST_CLANG_FLAGS "${CLANG_TARGET_OPTION}${LLC_TRIPLE}")
set(DEFAULT_HOST_LLC_FLAGS "-relocation-model=pic -mtriple=${LLC_TRIPLE}")

if(LLC_TRIPLE MATCHES "^arm")
if(ARM AND (NOT LLVM_OLDER_THAN_4_0))
#ARMs need to enable FP64 manually with 4.0
option(ENABLE_FP64 "Enable FP64" ON)
endif()

if(ARM32 OR (LLC_TRIPLE MATCHES "^arm"))
if(LLC_TRIPLE MATCHES "gnueabihf")
# hardfloat
set(DEFAULT_HOST_LLC_FLAGS "${DEFAULT_HOST_LLC_FLAGS} -float-abi=hard")
@@ -658,11 +674,6 @@ if(LLC_TRIPLE MATCHES "^arm")
set(DEFAULT_HOST_CLANG_FLAGS "${DEFAULT_HOST_CLANG_FLAGS} -mfloat-abi=soft")
set(DEFAULT_HOST_AS_FLAGS "${DEFAULT_HOST_AS_FLAGS} -mfloat-abi=soft")
endif()
#This is very much a Q&D solution. We assume every modern ARM out there
#has the vfp4 floating point unit.
#This used to be implicitly assumed in clang < 3.9. With 3.9, we have to pass
#this flag, or intrinsics in vecmathlib are not defined.
set(DEFAULT_HOST_CLANG_FLAGS "${DEFAULT_HOST_CLANG_FLAGS} -mfpu=vfp4")
endif()

if(CL_DISABLE_LONG)
@@ -676,26 +687,48 @@ set(HOST_DEVICE_CL_VERSION "120")
set(HOST_DEVICE_CL_STD "1.2")

# define it here, b/c we'll need these both at runtime and buildtime
set(HOST_DEVICE_EXTENSIONS "cl_khr_byte_addressable_store cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_3d_image_writes")
if(X86 OR ARM)
set(HOST_DEVICE_EXTENSIONS "cl_khr_byte_addressable_store cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_3d_image_writes")
else()
# set some conservative defaults
set(HOST_DEVICE_EXTENSIONS "cl_khr_global_int32_base_atomics cl_khr_local_int32_base_atomics cl_khr_3d_image_writes")
endif()

if((HOST_DEVICE_CL_VERSION GREATER 199) AND (CLANG_SPIR))
set(HOST_DEVICE_EXTENSIONS "${HOST_DEVICE_EXTENSIONS} cl_khr_spir")
endif()

if(NOT CL_DISABLE_HALF)
set(HOST_DEVICE_EXTENSIONS "${HOST_DEVICE_EXTENSIONS} cl_khr_fp16")
endif()

if(NOT CL_DISABLE_LONG)
set(HOST_DEVICE_EXTENSIONS "${HOST_DEVICE_EXTENSIONS} cl_khr_fp64 cl_khr_int64_base_atomics cl_khr_int64_extended_atomics")
# must not be defined in HOST_DEVICE_EXTENSIONS list, because
# this extension doesn't exist in official extension list
set(HOST_DEVICE_EXTENSION_DEFINES "-Dcl_khr_int64")

# fp64 requires int64
if(X86)
set(HOST_DEVICE_EXTENSIONS "${HOST_DEVICE_EXTENSIONS} cl_khr_fp64 cl_khr_int64_base_atomics cl_khr_int64_extended_atomics")
endif()
if(ENABLE_FP64 AND (NOT LLVM_OLDER_THAN_4_0))
# 32bit arm doesnt always uspport doubles
set(HOST_DEVICE_EXTENSIONS "${HOST_DEVICE_EXTENSIONS} cl_khr_fp64")
endif()
endif()

set(TEMP_EXT "${HOST_DEVICE_EXTENSIONS}")
separate_arguments(TEMP_EXT)
set(TEMP_CLEXT "-Xclang -cl-ext=")
foreach(EXT ${TEMP_EXT})
set(HOST_DEVICE_EXTENSION_DEFINES "${HOST_DEVICE_EXTENSION_DEFINES} -D${EXT}")
set(TEMP_CLEXT "${TEMP_CLEXT}+${EXT},")
endforeach()

if (NOT LLVM_OLDER_THAN_4_0)
set(HOST_DEVICE_EXTENSION_DEFINES "${HOST_DEVICE_EXTENSION_DEFINES} ${TEMP_CLEXT}")
endif()

if(NOT DEFINED KERNELLIB_HOST_CPU_VARIANTS)
set(KERNELLIB_HOST_CPU_VARIANTS "native")
# else TODO test cpu list for unknown values
@@ -1,15 +1,20 @@
pocl works (as of 2012-11-21) quite well on a Panda board with
Ubuntu.

Current known issues:

- You might need to install libhwloc from the sources if
the Ubuntu in Panda doesn't ship a new enough one.
http://www.open-mpi.org/projects/hwloc/
- ABI/ISA compatibility issue (soft float or not). This is
producible in the example1 which takes float4 buffers as args.
example2, which uses scalar buffers works ok.
- On Ubuntu 12.04, clang 3.2 and 3.3 cannot compile a simple
C program due to wrong internal paths. This leads to all tests
failing. Description on how to fix this issue is here:
http://sourceforge.net/mailarchive/forum.php?thread_name=20130723124515.7995bb36%40fx8&forum_name=pocl-devel
pocl builds (as of Aug 2017) on ODROID XU3 and ODROID C2
but some tests fail.

How to build:

* get a clang / llvm. DO NOT use the ones downloaded from llvm.org, they only work
on the distro where they were compiled. Ubuntu LTS these days ships multiple llvm
versions even quite recent ones; get the clang+llvm from your distro's packages.

* read the pocl build instructions in docs

* LLVM will likely not recognize your cpu, and running cmake will give you a warning.
run cmake with -DLLC_HOST_CPU=<yourcpu>. "yourcpu" must be something LLVM recognizes,
usually it's simply "cortex-aXX" like cortex-a15 etc. You can get the full list by
running `llc -mcpu=help`.

* example for building pocl on Ubuntu 16.04 + ARM:

apt install ocl-icd-libopencl1 ocl-icd-opencl-dev cmake libltdl-dev libhwloc-dev pkg-config
build-essential llvm-4.0-dev llvm-4.0 clang-4.0 libclang-4.0-dev

0 comments on commit 5d38f49

Please sign in to comment.
You can’t perform that action at this time.