GPGPU - ArchWiki

# GPGPU

This article or section is out of date.

Reason: With new versions of OpenCL, the things have changed a little bit. (Discuss)

Related articles

- Catalyst
- Nvidia

GPGPU stands for General-purpose computing on graphics processing units. In Linux, there are currently two major GPGPU frameworks: OpenCL and CUDA

## OpenCL

### Overview

OpenCL (Open Computing Language) is an open, royalty-free parallel programming framework developed by the Khronos Group, a non-profit consortium.

Distribution of the OpenCL framework generally consists of:

- Library providing OpenCL API, known as libCL or libOpenCL (`libOpenCL.so` in linux)
- OpenCL implementation(s), which contain:
  - Device drivers
  - OpenCL/C code compiler
  - SDK *
- Header files *

* only needed for development

### OpenCL library

There are several choices for the libCL. In general case, installing libcl from the official repositories should do.

However, there are situations when another libCL distribution is more suitable. The following paragraph covers this more advanced topic.

### The OpenCL ICD model

OpenCL offers the option to install multiple vendor-specific implementations on the same machine at the same time. In practice, this is implemented using the Installable Client Driver (ICD) model. The center point of this model is the libCL library which in fact imeplements ICD Loader. Through the ICD Loader, an OpenCL application is able to access all platforms and all devices present in the system.

Although itself vendor-agnostic, the ICD Loader still has to be provided by someone. In Arch Linux, there are currently two options:

- libcl by Nvidia. Provides OpenCL version 1.0 (even in the current version) and is thus slightly outdated. Its behaviour with OpenCL 1.1 code has not been tested as of yet.
- libopencl by AMD. Provides up to date version 1.1 of OpenCL. It is currently distributed by AMD under a restrictive license and therefore could not have been pushed into official repo.

(There is also Intel's libCL, this one is currently not provided in a separate package though.)

Note: ICD Loader's vendor is mentioned only to identify each loader, it is otherwise completely irrelevant. ICD Loaders are vendor-agnostic and may be used interchangeably. (as long as they are implemented correctly)

For basic usage, libcl is recommended as its installation and updating is convenient. For advanced usage, libopencl is recommended. Both libcl and libopencl should still work with all the implementations.

### Implementations

To see which OpenCL implementations are currently active on your system, use the following command:

    $ ls /etc/OpenCL/vendors

#### AMD

OpenCL implementation from AMD is known as AMD APP SDK, formerly also known as AMD Stream SDK or ATi Stream.

For Arch Linux, AMD APP SDK is currently available in AUR as amdapp-sdk. This package is installed as `/opt/AMDAPP` and apart from SDK files it also contains a number of code samples (`/opt/AMDAPP/SDK/samples/`). It also provides the `clinfo` utility which lists OpenCL platforms and devices present in the system and displays detailed information about them.

As AMD APP SDK itself contains CPU OpenCL driver, no extra driver is needed to use execute OpenCL on CPU devices (regardless of its vendor). GPU OpenCL drivers are provided by the catalyst package (an optional dependency), the open-source driver (xf86-video-ati) does not support OpenCL.

Code is compiled using llvm (dependency).

#### Mesa (Gallium)

OpenCL support from Mesa is in development (see http://www.x.org/wiki/GalliumStatus/). AMD Radeon cards are supported by the r600g driver.

Arch Linux does currently (April 2014; Mesa 10.1.0; LLVM 3.4) not build Mesa with OpenCL support. See http://dri.freedesktop.org/wiki/GalliumCompute/ for installation instructions (use the development branches of LLVM and Mesa for optimal results).

You could also use lordheavy's repo. Install these packages:

- ati-dri-git
- opencl-mesa-git
- libclc-git

Surprisingly, pyrit performs 20% better with radeon+r600g compared to Catalyst 13.11 Beta1 (tested with 7 other CPU cores):

    catalyst     #1: 'OpenCL-Device 'Barts'': 21840.7 PMKs/s (RTT 2.8)
    radeon+r600g #1: 'OpenCL-Device 'AMD BARTS'': 26608.1 PMKs/s (RTT 3.0)

At the time of this writing (30 October 2013), one must apply patches [1] and [2] on top of Mesa commit ac81b6f2be8779022e8641984b09118b57263128 to get this performance improvement. The latest unpatched LLVM trunk was used (SVN rev 193660).

#### Nvidia

The Nvidia implementation is available as opencl-nvidia from the official repositories. It only supports Nvidia GPUs running the nvidia kernel module (nouveau does not support OpenCL yet).

#### Intel

The Intel implementation, named simply Intel OpenCL SDK, provides optimized OpenCL performance on Intel CPUs (mainly Core and Xeon) and CPUs only. Package is available in the AUR: intel-opencl-sdk. The runtime AUR: intel-opencl-runtime is a separated package. OpenCL for integrated graphics hardware is available in the AUR through beignet for Ivy Bridge and newer hardware.

### Development

For development of OpenCL-capable applications, full installation of the OpenCL framework including implementation, drivers and compiler plus the opencl-headers package is needed. Link your code against `libOpenCL`.

#### Language bindings

- C++: A binding by Khronos is part of the official specs. It is included in opencl-headers
- C++/Qt: An experimental binding named QtOpenCL is in Qt Labs - see Blog entry for more information
- JavaScript/HTML5: WebCL
- Python: There are two bindings with the same name: PyOpenCL. One is in [extra]: python2-pyopencl, for the other one see sourceforge
- D: cl4d
- Haskell: The OpenCLRaw package is available in AUR: haskell-openclraw-git
- Java: JOCL (a part of JogAmp)
- Mono/.NET: Open Toolkit
- Go: OpenCL bindings for Go
- Racket: Racket has a native interface on PLaneT that can be installed via raco.

## CUDA

CUDA (Compute Unified Device Architecture) is Nvidia's proprietary, closed-source parallel computing architecture and framework. It requires a Nvidia GPU. It consists of several components:

- required:
  - proprietary Nvidia kernel module
  - CUDA "driver" and "runtime" libraries
- optional:
  - additional libraries: CUBLAS, CUFFT, CUSPARSE, etc.
  - CUDA toolkit, including the `nvcc` compiler
  - CUDA SDK, which contains many code samples and examples of CUDA and OpenCL programs

The kernel module and CUDA "driver" library are shipped in nvidia and opencl-nvidia. The "runtime" library and the rest of the CUDA toolkit are available in cuda. The library is available only in 64-bit version.

### Development

The cuda package installs all components in the directory `/opt/cuda`. For compiling CUDA code, add `/opt/cuda/include` to your include path in the compiler instructions. For example this can be accomplished by adding `-I/opt/cuda/include` to the compiler flags/options.

### Language bindings

- Fortran: FORTRAN CUDA, PGI CUDA Fortran Compiler
- Haskell: The accelerate package lists available CUDA backends
- Java: jCUDA, JCuda
- Mathematica: CUDAlink
- Mono/.NET: CUDA.NET, CUDAfy.NET
- Perl: Kappa, CUDA-Minimal
- Python: In AUR: pycuda-git, also Kappa
- Ruby, Lua: Kappa

### Driver issues

It might be necessary to use the legacy driver nvidia-304xx or nvidia-304xx-lts to resolve permissions issues when running CUDA programs on systems with multiple GPUs.

## List of OpenCL and CUDA accelerated software

This article or section needs expansion.

Reason: please use the first argument of the template to provide a brief explanation. (Discuss)

- Bitcoin
- GIMP (experimental - see [3])
- pyrit
- aircrack-ng
- john-opencl
- cuda_memtest - a GPU memtest. Despite its name, is supports both CUDA and OpenCL

## Links and references

- OpenCL official homepage
- CUDA official homepage
- The ICD extension specification
- AMD APP SDK homepage
- CUDA Toolkit homepage
- Intel OpenCL SDK homepage

Categories:

- Development
- Graphics