Difference between revisions of "OpenCL"

From NaplesPU Documentation
Jump to: navigation, search
(Build pocl with a custom LLVM)
Line 107: Line 107:
 
set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
 
set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING
 
  </syntaxhighlight>
 
  </syntaxhighlight>
 +
 +
==== Building pocl ====

Revision as of 12:31, 3 October 2017

The OpenCL support for the nu+ architecture is made through pocl.

How to install vanilla pocl

  1. Download following the link.
  2. In order to build pocl, you need the following support libraries and tools:
    • Latest released version of LLVM & Clang
    • GNU make
    • libtool dlopen wrapper files (e.g. libltdl3-dev in Debian)
    • pthread (should be installed by default)
    • hwloc v1.0 or newer (e.g. libhwloc-dev)
    • pkg-config
    • cmake
    • libclang-3.8-dev if you are using Ubuntu 16.04 LTS
    On Ubuntu 16.04 LTS you can run the following code on a terminal
    sudo apt-get install llvm & clang & libltdl3-dev & libhwloc-dev & libhwloc-dev & libclang-3.8-dev & make & cmake
  3. Build and install
    cd <directory-with-pocl-sources>
    mkdir build
    cd build
    cmake [-D<option>=<value> ...] ..
    make && make install

Using pocl

To compile with pocl you have to execute:

gcc example1.c -o example `pkg-config --libs --cflags pocl`

See [1] and [2] for further informations.

Modify pocl

Adding a new device class in pocl

  • Create a directory for the new device class in "lib/CL/devices". In this case the "nuplus" folder is created.
  • Create at least the files newdevice.c and newdevice.h. In this case "nuplus.c" and "nuplus.h"
  • Create the CMakeList.txt file in the device folder, specifying the files created before and the device name.
     if(MSVC)
     set_source_files_properties( nuplus.h nuplus.c PROPERTIES LANGUAGE CXX )
     endif(MSVC)
     add_library("pocl-devices-nuplus" OBJECT nuplus.h nuplus.c)
  • Modify the "lib/CL/devices.c" file including the new header file for the device and adding the init fucntion in the vector pocl_devices_init_ops
    # include "nuplus/nuplus.h"
    
     ...
    
     static init_device_ops pocl_devices_init_ops[] = {
     pocl_pthread_init_device_ops,
     pocl_basic_init_device_ops,
     pocl_nuplus_init_device_ops,
    # if defined(TCE_AVAILABLE)
     pocl_ttasim_init_device_ops,
    # endif
    # if defined(BUILD_HSA)
     pocl_hsa_init_device_ops,
    # endif
     };
    
     ...


  • Modify the "lib/CL/devices/CMakeLists.txt" adding the new device subdirectory name.
     ...
    
     add_subdirectory("nuplus")
    
     ...
  • Modify the "CMakeLists.txt" in the pocl root directory adding the new device name to the "OCL_DRIVERS".
     ...
    
     set(OCL_DRIVERS "basic pthreads nuplus")
    
     ...

Build pocl with a custom LLVM

Prerequisites

Be sure that the LLVM compiler is built with all the targets and the default target is set as the host. For the nu+ toolchain the CMakeLists.txt in the LLVM root folder must be modified as reported below:

  1. Delete the code
    set(LLVM_TARGETS_TO_BUILD "NuPlus"
        CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
  2. modify
    set(LLVM_DEFAULT_TARGET_TRIPLE "nuplus-none-none" CACHE STRING
    in
    set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_HOST_TRIPLE}" CACHE STRING

Building pocl