Difference between revisions of "GPGPU"

From ArchWiki
Jump to: navigation, search
m (Language bindings: remove old package)
 
(144 intermediate revisions by 41 users not shown)
Line 1: Line 1:
[[Category:Category:Development (English)]]
+
[[Category:Development]]
[[Category:Category:Graphics (English)]]
+
[[Category:Graphics]]
{{Note|This article is a non-public work in progress as of yet}}
+
[[ja:GPGPU]]
 +
{{Related articles start}}
 +
{{Related|Catalyst}}
 +
{{Related|Nvidia}}
 +
{{Related|Hardware video acceleration}}
 +
{{Related articles end}}
  
{{Lorem Ipsum}}
+
GPGPU stands for [[Wikipedia:GPGPU|General-purpose computing on graphics processing units]].
 +
In Linux, there are currently two major GPGPU frameworks: [[Wikipedia:OpenCL|OpenCL]] and [[Wikipedia:CUDA|CUDA]]
  
==Installation==
+
==OpenCL==
===OpenCL===
 
A distribution of the OpenCL framework generally constists of:
 
* Library's shared object (libOpenCL.so, for detailed information [[#The OpenCL ICD model|see bellow]])
 
* One or more vendor-specific OpenCL implementation packages
 
* Device drivers
 
  
For the OpenCL shared object, installing {{Package Official|libcl}} should do in general case:
+
OpenCL (Open Computing Language) is an open, royalty-free parallel programming specification developed by the Khronos Group, a non-profit consortium.
# pacman -S libcl
 
  
See [[#Implementations|Implementations]] on how to install implementation and device driver packages.
+
The OpenCL specification describes a programming language, a general environment that is required to be present, and a C API to enable programmers to call into this environment.
  
====The OpenCL ICD model====
+
===OpenCL Runtime===
OpenCL offers the option to install multiple vendor-specific implementations on the same machine at the same time.
+
To '''execute''' programs that use OpenCL, a compatible hardware runtime needs to be installed.
In practice, this is implemented using the Installable Client Driver (ICD) model.
 
The center point of this model is the ICD Loader (which on linux is in fact the libOpenCL.so object).
 
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 Archlinux, there are currently two options:
+
====AMD/ATI====
* extra/{{Package Official|libcl}} by Nvidia. Provides OpenCL version 1.0 and is thus slightly outdated. It's behaviour with OpenCL 1.1 code has not been tested as of yet.
+
* {{Pkg|opencl-mesa}}: free runtime for [[AMDGPU]] and [[Radeon]]
* unsupported/{{Package AUR|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.
+
* {{AUR|opencl-amd}}: proprietary standalone runtime for [[AMDGPU]]
 +
* {{AUR|amdgpu-pro-opencl}}: proprietary runtime for [[AMDGPU PRO]]
 +
* {{AUR|opencl-catalyst}}: AMD proprietary runtime, soon to be deprecated in favor of [[AMDGPU]]
 +
* {{AUR|amdapp-sdk}}: AMD CPU runtime
  
For basic usage, extra/libcl is recommended, as it's installation and updating is convenient. For advanced usage, libopencl is recommended.  Both libcl and libopencl should still work with all the implementations.
+
====NVIDIA====
 +
* {{Pkg|opencl-nvidia}}: official [[NVIDIA]] runtime
  
===CUDA===
+
====Intel====
{{Expansion}}
+
* {{AUR|intel-opencl-runtime}}: official Intel CPU runtime, also supports non-Intel CPUs
 +
* {{pkg|beignet}}: open-source implementation for Intel IvyBridge+ iGPUs
  
==Implementations==
+
====Others====
===Nvidia===
+
* {{AUR|pocl}}: LLVM-based OpenCL implementation
{{Expansion}}
 
  
===AMD===
+
===OpenCL ICD loader (libOpenCL.so)===
{{Lorem Ipsum}}
 
  
===Intel===
+
The OpenCL ICD loader is supposed to be a platform-agnostic library that provides the means to load device-specific drivers through the OpenCL API.
{{Lorem Ipsum}}
+
Most OpenCL vendors provide their own implementation of an OpenCL ICD loader, and these should all work with the other vendors' OpenCL implementations.
 +
Unfortunately, most vendors do not provide completely up-to-date ICD loaders, and therefore Arch Linux has decided to provide this library from a separate project ({{Pkg|ocl-icd}}) which currently provides a functioning implementation of the current OpenCL API.
  
==Developement==
+
The other ICD loader libraries are installed as part of each vendor's SDK. If you want to ensure the ICD loader from the {{Pkg|ocl-icd}} package is used, you can create a file in {{ic|/etc/ld.so.conf.d}} which adds {{ic|/usr/lib}} to the dynamic program loader's search directories:
{{Lorem Ipsum}}
+
 
 +
{{hc|/etc/ld.so.conf.d/00-usrlib.conf|2=<nowiki>
 +
/usr/lib</nowiki>}}
 +
 
 +
This is necessary because all the SDKs add their runtime's lib directories to the search path through {{ic|ld.so.conf.d}} files.
 +
 
 +
The available packages containing various OpenCL ICDs are:
 +
* {{Pkg|ocl-icd}}: recommended, most up-to-date
 +
* {{AUR|libopencl}} by AMD. Provides OpenCL 2.0. It is distributed by AMD under a restrictive license and therefore cannot be included into the official repositories.
 +
* {{AUR|intel-opencl}} by Intel. Provides OpenCL 2.0.
 +
 
 +
{{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).}}
 +
 
 +
===OpenCL Development===
 +
For OpenCL '''development''', the bare minimum additional packages required, are:
 +
* {{Pkg|ocl-icd}}: OpenCL ICD loader implementation, up to date with the latest OpenCL specification.
 +
* {{Pkg|opencl-headers}}: OpenCL C/C++ API headers.
 +
 
 +
The vendors' SDKs provide a multitude of tools and support libraries:
 +
* {{AUR|intel-opencl-sdk}}: [http://software.intel.com/en-us/articles/opencl-sdk/ Intel OpenCL SDK] (old version, new OpenCL SDKs are included in the INDE and Intel Media Server Studio)
 +
* {{AUR|amdapp-sdk}}: This package is installed as {{ic|/opt/AMDAPP}} and apart from SDK files it also contains a number of code samples ({{ic|/opt/AMDAPP/SDK/samples/}}). It also provides the {{ic|clinfo}} utility which lists OpenCL platforms and devices present in the system and displays detailed information about them. As [http://developer.amd.com/sdks/AMDAPPSDK/Pages/default.aspx AMD APP SDK] itself contains CPU OpenCL driver, no extra driver is needed to execute OpenCL on CPU devices (regardless of its vendor). GPU OpenCL drivers are provided by the {{AUR|catalyst}} package (an optional dependency).
 +
* {{Pkg|cuda}}: Nvidia's GPU SDK which includes support for OpenCL 1.1.
 +
 
 +
===Implementations===
 +
To see which OpenCL implementations are currently active on your system, use the following command:
 +
$ ls /etc/OpenCL/vendors
 +
 
 +
====Language bindings====
 +
* '''JavaScript/HTML5''': [http://www.khronos.org/webcl/ WebCL]
 +
* '''[[Python]]''': {{pkg|python-pyopencl}}
 +
* '''[[D]]''': [https://bitbucket.org/trass3r/cl4d/wiki/Home cl4d]
 +
* '''[[Java]]''': [http://jogamp.org/jocl/www/ JOCL] (a part of [http://jogamp.org/ JogAmp])
 +
* '''[[Mono|Mono/.NET]]''': [http://sourceforge.net/projects/opentk/ Open Toolkit]
 +
* '''[[Go]]''': [https://github.com/samuel/go-opencl OpenCL bindings for Go]
 +
* '''Racket''': Racket has a native interface [http://planet.racket-lang.org/display.ss?owner=jaymccarthy&package=opencl.plt on PLaneT] that can be installed via raco.
 +
* '''[[Rust]]''': [https://github.com/cogciprocate/ocl ocl]
 +
 
 +
==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 {{ic|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 {{Pkg|nvidia}} and {{Pkg|opencl-nvidia}}. The "runtime" library and the rest of the CUDA toolkit are available in {{Pkg|cuda}}. The library is available [https://projects.archlinux.org/svntogit/community.git/commit/trunk?h=packages/cuda&id=1b62c8bcb9194b2de1b750bd62a8dce1e7e549f5 only in 64-bit version]. {{ic|cuda-gdb}} needs {{aur|ncurses5-compat-libs}} to be installed, see {{Bug|46598}}.
 +
 
 +
===Development===
 +
 
 +
The {{Pkg|cuda}} package installs all components in the directory {{ic|/opt/cuda}}. For compiling CUDA code, add {{ic|/opt/cuda/include}} to your include path in the compiler instructions. For example this can be accomplished by adding {{ic|-I/opt/cuda/include}} to the compiler flags/options. To use {{ic|nvcc}}, a {{ic|gcc}} wrapper provided by NVIDIA, just add {{ic|/opt/cuda/bin}} to your path.
 +
 
 +
To find whether the installation was successful and if cuda is up and running, you can compile the samples installed on {{ic|/opt/cuda/samples}} (you can simply run {{ic|make}} inside the directory, altough is a good practice to copy the {{ic|/opt/cuda/samples}} directory to your home directory before compiling) and running the compiled examples. A nice way to check the installation is to run one of the examples, called {{ic|deviceQuery}}.
 +
 
 +
{{Note|CUDA 9.0 is not compatible with GCC 7 (see {{Bug|49272}} for the history). Therefore the {{Pkg|cuda}} package depends on {{Pkg|gcc6}} and creates symbolic links in {{ic|/opt/cuda/bin/}} for the older version to be picked up by {{ic|nvcc}}. You might also need to configure your build system to use the same GCC version for compiling host code.}}
 +
 
 +
===Language bindings===
 +
* '''Fortran''': [http://www.pgroup.com/resources/cudafortran.htm PGI CUDA Fortran Compiler]
 +
* '''[[Haskell]]''': The [http://hackage.haskell.org/package/accelerate accelerate package] lists available CUDA backends
 +
* '''[[Java]]''': [http://www.jcuda.org/jcuda/JCuda.html JCuda]
 +
* '''[[Mathematica]]''': [http://reference.wolfram.com/mathematica/CUDALink/tutorial/Overview.html CUDAlink]
 +
* '''[[Mono|Mono/.NET]]''': [http://www.hoopoe-cloud.com/Solutions/CUDA.NET/Default.aspx CUDA.NET], [http://www.hybriddsp.com/ CUDAfy.NET]
 +
* '''Perl''': [http://psilambda.com/download/kappa-for-perl Kappa], [https://github.com/run4flat/perl-CUDA-Minimal CUDA-Minimal]
 +
* '''[[Python]]''': {{pkg|python-pycuda}} or [http://psilambda.com/download/kappa-for-python Kappa]
 +
* '''[[Ruby]]''', '''Lua''': [http://psilambda.com/products/kappa/ Kappa]
 +
 
 +
===Driver issues===
 +
 
 +
It might be necessary to use the legacy driver {{Pkg|nvidia-304xx}} or {{Pkg|nvidia-304xx-lts}} to resolve permissions issues when running CUDA programs on systems with multiple GPUs.
 +
 
 +
==List of OpenCL and CUDA accelerated software==
 +
{{Expansion|More application may support OpenCL.}}
 +
* [[Bitcoin]]
 +
* [[HandBrake]]
 +
* [[GIMP]] (experimental - see [http://www.h-online.com/open/news/item/GIMP-2-8-RC-1-arrives-with-GPU-acceleration-1518417.html])
 +
* {{Pkg|opencv}}
 +
* {{Pkg|pyrit}}
 +
* {{Pkg|darktable}} - OpenCL feature requires at least 1 GB RAM on GPU and ''Image support'' (check output of clinfo command).
 +
* {{Pkg|aircrack-ng}}
 +
* {{AUR|cuda_memtest}} - a GPU memtest. Despite its name, is supports both CUDA and OpenCL
 +
* [[Blender]] - CUDA support for Nvidia GPUs and OpenCL support for AMD GPUs. More information [http://blender.org/manual/render/cycles/features.html#features here].
 +
* [[BOINC]]
  
 
==Links and references==
 
==Links and references==
 +
* [http://www.khronos.org/opencl/ OpenCL official homepage]
 +
* [http://www.nvidia.com/object/cuda_home_new.html CUDA official homepage]
 +
* [http://www.khronos.org/registry/cl/extensions/khr/cl_khr_icd.txt The ICD extension specification]
 +
* [http://developer.amd.com/appsdk AMD APP SDK homepage]
 +
* [https://developer.nvidia.com/cuda-toolkit CUDA Toolkit homepage]
 +
* [https://software.intel.com/en-us/intel-opencl Intel SDK for OpenCL Applications homepage]

Latest revision as of 16:28, 16 December 2017

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

OpenCL

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

The OpenCL specification describes a programming language, a general environment that is required to be present, and a C API to enable programmers to call into this environment.

OpenCL Runtime

To execute programs that use OpenCL, a compatible hardware runtime needs to be installed.

AMD/ATI

NVIDIA

Intel

  • intel-opencl-runtimeAUR: official Intel CPU runtime, also supports non-Intel CPUs
  • beignet: open-source implementation for Intel IvyBridge+ iGPUs

Others

  • poclAUR: LLVM-based OpenCL implementation

OpenCL ICD loader (libOpenCL.so)

The OpenCL ICD loader is supposed to be a platform-agnostic library that provides the means to load device-specific drivers through the OpenCL API. Most OpenCL vendors provide their own implementation of an OpenCL ICD loader, and these should all work with the other vendors' OpenCL implementations. Unfortunately, most vendors do not provide completely up-to-date ICD loaders, and therefore Arch Linux has decided to provide this library from a separate project (ocl-icd) which currently provides a functioning implementation of the current OpenCL API.

The other ICD loader libraries are installed as part of each vendor's SDK. If you want to ensure the ICD loader from the ocl-icd package is used, you can create a file in /etc/ld.so.conf.d which adds /usr/lib to the dynamic program loader's search directories:

/etc/ld.so.conf.d/00-usrlib.conf
/usr/lib

This is necessary because all the SDKs add their runtime's lib directories to the search path through ld.so.conf.d files.

The available packages containing various OpenCL ICDs are:

  • ocl-icd: recommended, most up-to-date
  • libopenclAUR by AMD. Provides OpenCL 2.0. It is distributed by AMD under a restrictive license and therefore cannot be included into the official repositories.
  • intel-openclAUR by Intel. Provides OpenCL 2.0.
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).

OpenCL Development

For OpenCL development, the bare minimum additional packages required, are:

  • ocl-icd: OpenCL ICD loader implementation, up to date with the latest OpenCL specification.
  • opencl-headers: OpenCL C/C++ API headers.

The vendors' SDKs provide a multitude of tools and support libraries:

  • intel-opencl-sdkAUR: Intel OpenCL SDK (old version, new OpenCL SDKs are included in the INDE and Intel Media Server Studio)
  • amdapp-sdkAUR: 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 execute OpenCL on CPU devices (regardless of its vendor). GPU OpenCL drivers are provided by the catalystAUR package (an optional dependency).
  • cuda: Nvidia's GPU SDK which includes support for OpenCL 1.1.

Implementations

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

$ ls /etc/OpenCL/vendors

Language bindings

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. cuda-gdb needs ncurses5-compat-libsAUR to be installed, see FS#46598.

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. To use nvcc, a gcc wrapper provided by NVIDIA, just add /opt/cuda/bin to your path.

To find whether the installation was successful and if cuda is up and running, you can compile the samples installed on /opt/cuda/samples (you can simply run make inside the directory, altough is a good practice to copy the /opt/cuda/samples directory to your home directory before compiling) and running the compiled examples. A nice way to check the installation is to run one of the examples, called deviceQuery.

Note: CUDA 9.0 is not compatible with GCC 7 (see FS#49272 for the history). Therefore the cuda package depends on gcc6 and creates symbolic links in /opt/cuda/bin/ for the older version to be picked up by nvcc. You might also need to configure your build system to use the same GCC version for compiling host code.

Language bindings

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

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: More application may support OpenCL. (Discuss in Talk:GPGPU#)

Links and references