Difference between revisions of "OpenCL"
From NaplesPU Documentation
Line 32: | Line 32: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
See [http://portablecl.org/docs/html/using.html] and [https://github.com/pocl/pocl/issues/282] for further informations. | See [http://portablecl.org/docs/html/using.html] and [https://github.com/pocl/pocl/issues/282] for further informations. | ||
+ | |||
+ | == 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. | ||
+ | |||
+ | <syntaxhighlight lang="C"> | ||
+ | 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) | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | * 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''' | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang="C"> | ||
+ | |||
+ | #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 | ||
+ | }; | ||
+ | |||
+ | ... | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | * Modify the "lib/CL/devices/CMakeLists.txt" adding the new device subdirectory name. | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang="C"> | ||
+ | ... | ||
+ | |||
+ | add_subdirectory("nuplus") | ||
+ | |||
+ | ... | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | * Modify the "CMakeLists.txt" in the pocl root directory adding the new device name to the "OCL_DRIVERS". | ||
+ | |||
+ | <syntaxhighlight lang="C"> | ||
+ | ... | ||
+ | |||
+ | set(OCL_DRIVERS "basic pthreads nuplus") | ||
+ | |||
+ | ... | ||
+ | </syntaxhighlight> |
Revision as of 11:09, 3 October 2017
The OpenCL support for the nu+ architecture is made through pocl.
How to install vanilla pocl
- Download following the link.
- 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
- 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.
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")
...