|Paradigm||Imperative (procedural), structured , Object oriented (C++ only)|
OpenCL C++ 1.0 revision V2.2-11
OpenCL C 3.0 revision V3.0.1
|Type system||Static, weak, manifest, nominal|
|Implementation language||Implementation specific|
|AMD (ROCm), Apple, freeocl, Gallium Compute, IBM, Intel Beignet, Intel SDK, Mesa Clover, Texas Instruments, Nvidia, pocl|
|C99, CUDA, C++14|
OpenCL (short for Open Computing Language) is a open framework for writing programs for heterogeneous platforms. OpenCL specifies a programming language based on C++11 and APIs. It is mostly used to accelerate compute operations using graphics cards. OpenCL programs can be executed on or across other devices like CPUs, FPGAs and digital signal processors.
The OpenCL standard has been maintained by the Khronos Group since 2008. It was originally developed by Apple.
There are three main OpenCL standards, 1.0 from 2009, 2.0 from 2013 and OpenCL 3.0 from 2020 (still in "provisional" mode).
OpenCL 2.0, specified in 2013, added support for shared virtual memory, nested parallelism, pipes and C11 atomics. It was expanded with OpenCL 2.1 in 2015. OpenCL 2.2, specified in 2017, added support for the OpenCL C++ kernel language. It is a subset of the C++14 standard. OpenCL 2.2 will run on any hardware capable of running OpenCL 2.0 code if the OpenCL implementation for that hardware supports OpenCL 2.2.
Researches in computer science, mathematics and related subjects tend to use graphics cards to do accelerate calculations that would take far longer on a CPU. They are mostly doing this using the proprietary CUDA framework from Nvidia to do this. There are a whole lot of code written for CUDA and very little in terms of developer tools and libraries for OpenCL even though OpenCL is a open standard and CUDA is not.
There are, as of 2020, not that many fields or places where OpenCL is used for anything. That does not mean OpenCL could not be used where CUDA is, and it does not mean that CUDA is better. It simply means that one of the two competing standard became dominant and the other became mostly irrelevant.
Implementations Available To GNU/Linux Users
Most GNU/Linux distribution carry several OpenCL implementations in their repositories, most of which are not at all useful for anything.
You will want to use ROCm if you have a newer AMD GPU, NEO if you have a newer Intel processor with Intel integrated grahpics and Mesa Clover, which only provides OpenCL 1.2, is you have an AMD APU, an older AMD GPU not supported by ROCm or an older Intel graphics card.
|TIP: You can use the |
MESA Gallium Compute (clover)
The Mesa graphics library comes with a OpenCL implementation called "Clover". Is is only capable of executing OpenCL 1.1 code regardless of what the hardware supports. All the distributions have this available and most of them install it along with the base system. There is a fair chance that you have Mesa Clover installed and set as the system default for OpenCL.
The Mesa "clover" OpenCL implementation is not very useful for anything because it is limited to the OpenCL 1.1 specification. The vast majority of the OpenCL software out there expects and requires OpenCL 2.x. You can, of course, use the Mesa "Clover" OpenCL implementation you want to run an old application that works with OpenCL 1.1. The applications will work with it. Most won't. In the meantime, the newly released package Octave-ocl in 2021 adopts OpenCL 1.1 in order to support more devices for high-performance computing similar to Matlab.
The Mesa Clover package is typically named something like
Beignet can be used to do OpenCL 1.2 on Ivy Bridge processors a higher and it will provide limited OpenCL 2.0 support on Skylake and newer processors. You will have to install it yourself because most distributions have removed it from their repositories due to the lack of upstream support and maintenance.
Beignet isn't really very useful or worth installing even if you have one of the supported Intel graphics cards.
NEO is a OpenCL implementation from Intel, for Intel graphics only, with OpenCL 3.0 support on all Intel chips going back to Broadwell since version 20.40.18075. Earlier versions are limited to OpenCL 1.2, 2.1 or 3.0 depending on what CPU/iGPU you have chip.
Intel has begun calling it "Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driver". The NEO GitHub page states that:
"NEO is the shorthand name for Compute Runtime contained within this repository. It is also a development mindset that we adopted when we first started the implementation effort for OpenCL."
How, exactly, NEO is short for "Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driver" is somewhat unclear.
|Micro-architecture||Graphics Gen||Neo OpenCL support|
|Apollo Lake (SoC)||9th||3.0|
|Gemini Lake (SoC)|
Intel is only releasing Ubuntu packages for Neo. Those packages are available at from github.com /intel/compute-runtime/releases. It is possible to get Neo working on other distributions but it takes require effort.
pocl is a portable OpenCL 1.2 implementation for CPUs and CUDA-supported Nvidia graphics cards with many OpenCL 2.0 features implemented. Running OpenCL on a CPU misses the whole point of it and translating OpenCL to CUDA is slower than using CUDA directly. pocl is therefore mostly useless and a complete waste of time.
ROCm (Radeon Open Compute)
Radeon Open Compute (ROCm) is in marketing "universal platform for GPU-accelerated computing". It is in practice framework which, among other things, provides OpenCL 2.2 support to newer AMD graphics cards (Vega/Navi) and a limited number older AMD cards (the Hawaii, Fiji and Polaris families).
|GPU Family||ROCm status||GPU(s)||Generation|
|CAPE VERDE, PITCAIRN, TAHITI, OLAND, HAINAN||gfx6|
|BONAIRE, KABINI, MULLINS, KAVERI, HAWAII||gfx7|
|TONGA, ICELAND/TOPAZ, CARRIZO, STONEY, VEGAM||gfx8|
|POLARIS10, POLARIS11, POLARIS12||
|VEGA12, VEGA20 ("Vega 7nm")||
|CICHLID, FLOUNDER, VANGOGH||gfx10.3|
|A CPU with PCIe Gen3 + PCIe Atomics is required (AMD Ryzen CPUs/APUs, EPYC CPUs, Intel Xeon E7 v3+, Intel Xeon E5 v3+, Intel Xeon E3 v3+, Haswell family or newer Core i3/i5/i7/i9).|
ROCm is not in any major distributions repositories. You will have to follow the instructions at https://github.com/RadeonOpenCompute/ROCm to get this technology. Documentation for it is at rocm-documentation.readthedocs.io/en/latest/.
ROCm is the best option if you want to use OpenCL for anything on a GNU/Linux machine with a AMD graphics card (or APU) if you use one of the supported Linux operating systems - which are recent versions of Ubuntu, CentOS, RHEL and SLES (using the RHEL packages on Fedora is possible and easy to do).
Getting ROCm to work for your use-case can be a bit problematic even if your distribution is among the supported ones. As an example, the video editor Davinci Resolve used to work fine with ROCm 2.2 but not ROCm 2.1 or 3.0. Enabling OpenCL in applications like LibreOffice 7.0 works perfectly. Some of the crypt-currency mining applications like ethminer work fine with ROCm. Others, like XMRig, do not.
Linux System Configuration
What "Vendors" or devices are available to OpenCL applications is defined by configuration files in
/etc/OpenCL/vendors/ ending with
.icd ("Installable Client Drivers").
Client applications ask the
libOpenCL.so library for OpenCL funtionality,
libOpenCL.so opens one (or more) "Installable Client Drivers" file(s) and the library listed in that file (like
libamdocl64.so) is used to provide the actual OpenCL functionality.
clinfo with two OpenCL implementations installed (like ROCm and Mesa Clover) will show 2 different platforms/devices available to OpenCL applications if there are two
.icd files in
It is, mostly, not possible to tell applications what implementation you prefer. Applications like LibreOffice have a simple box and that it's. A really simple solution is to just comment out whatever library is listed in the
.icd files of implementations you don't like/want:
.icd files with comments is preferable to removing them since that would only cause them to re-appear the next the package that provided it is upgraded.
Some distributions solve this by creating a symbolic in
vendor.icd which links to some actual implementations ICD file in
clinfo tool to see what implementation is selected and actually used.
LibreOffice can, as of version 7+, use OpenCL 2.0 for acceleration in a few of it's applications like Calc. It can't use Mesa Clover because it supports OpenCL 1.1.
Octave can, as of version 4.2+, use OpenCL 1.1 for parallel computing using functions similar to Matlab with the help of Octave-ocl package. It should be compatible with Mesa Clover. Comments from: Jinchuan Tang