OpenCL

Open Computing Language (OpenCL) is a framework for writing programs that execute across heterogeneous computing platforms (CPUs, GPUs, DSPs, FPGAs, ASICs, ...).

Overview
OpenCL presents itself as a library with a simple interface:
 * standardized API headers (eg. #include CL/cl.h) for C and C++
 * the OpenCL library (eg. libOpenCL.so)

The standard is made to provide many OpenCL platforms on one system, and each platform can see various devices.

Each device has a certain compute characteristics (number of compute units, optimal vector size, memory limits, ...).

The OpenCL standard allows to load OpenCL kernels which are pieces of C99-like code that is JIT-compiled by the OpenCL implementations (most of them rely on LLVM to work), and execute these kernels on the target hardware. Functions are provided to compile the kernels, load them, transfer data back and forth from the target devices, etc.

Hardware vendors can benefit from this standard by implementing the OpenCL primitives for their hardware.

Installing an OpenCL implementation means adding a library implementing the OpenCL API, and a reference to the library path in the ICD (Installable Client Driver) database, as a file in /etc/OpenCL/vendors. There is an ICD loader (which can be provided by a generic loader or one of the implementation) which can be selected on Gentoo using eselect opencl, that finds out the list of implementations and reports this as platforms.

Implementations on Linux
Here are upstream projects that provide an implementation of OpenCL.


 * pocl is an OpenSource, LLVM-based OpenCL implementation for the CPU which is not necessarily the fastest, but is educational
 * mesa has a WIP implementation
 * AMD provides its AMD APP SDK which contains an OpenCL library
 * nVidia provides its CUDA toolkit which contains an OpenCL library
 * Intel, on Linux, has an implementation for CPU devices, and another for GPU devices ("Beignet")

The implementations will be developed in further subsections.

pocl
As of 2014-09-15:


 * the dev-util/pocl package is available on the zougloub overlay.

mesa
TODO document clean setup and limitations.

Intel - CPU
The Intel CPU SDK is provided by the dev-util/intel-ocl-sdk which is in portage.

As of 2014-09-15:


 * Use version 2.* if the 4.* dies on you.

Intel - GPU
The GPU driver from intel is in active development, it is not exactly mature.

As of 2014-09-15:


 * the dev-libs/intel-beignet package is available on overlays.
 * Beignet is known to run on the following devices (add yours here):
 * Ivy Bridge, on Linux v3.16.2, with the following patch:

AMD
The driver is provided by the dev-util/amdapp package, which is maintained in the Science overlay.

nVidia
The driver is provided by the dev-util/nvidia-cuda-toolkit package which is in portage.

Implementation Validation
An implementation (especially the experimental ones) can be checked by running test suites such as:


 * piglit: Open Source OpenGL/OpenCL test suite

TODO detail

LLVM DLL Hell
LLVM is starting to become a central library, and it is used by most of the implementations. If the user/implementer is not careful, linkage issues can occur (symbol collisions, constructors getting called multiple times and not handled, etc.). This is something that can be noticed with many implementations also.

TODO example