OpenCL

From LinuxReviews
Jump to navigationJump to search
OpenCL C/C++
ParadigmImperative (procedural), structured , Object oriented (C++ only)
FamilyC
Stable release
OpenCL C++ 1.0 revision V2.2-11

OpenCL C 3.0 revision V3.0.1

Type systemStatic, weak, manifest, nominal
Implementation languageImplementation specific
Filename extensions.cl
Major implementations
AMD (ROCm), Apple, freeocl, Gallium Compute, IBM, Intel Beignet, Intel SDK, Mesa Clover, Texas Instruments, Nvidia, pocl
Influenced by
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.

Standards[edit]

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.

Practical Use[edit]

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[edit]

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.

Lovelyz Kei ProTip.jpg
TIP: You can use the clinfo utility to see what OpenCL implementation you are using and what version(s) it supports. Packages with OpenCL implementations will install a .icd file in /etc/OpenCL/vendors/ which specify what library should be used to execute OpenCL. You should ideally only have one file in that folder.

MESA Gallium Compute (clover)[edit]

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 mesa-libOpenCL.

Beignet[edit]

Beignet is a Intel-iGPU specific OpenCL implementation developed by Intel China in 2013. It was maintained until around 2017 before it was abandoned in favor of Intel's Neo OpenCL library.

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[edit]

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."

Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driver README.md

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
Sandy Bridge 6-8th Unsupported
Ivy Bridge
Bay Trail
Haswell
Broadwell 8th 3.0
Braswell
Skylake 9th
Apollo Lake (SoC) 9th 3.0
Gemini Lake (SoC)
Kaby Lake 9.5 3.0
Whiskey Lake
Coffee Lake
Ice Lake 11th
Tiger Lake 12th 3.0
Sapphire Rapids Blond-anime-girl-with-red-questionmark.png

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[edit]

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)[edit]

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).

AMD ROCm Support
GPU Family ROCm status GPU(s) Generation
CAPE VERDE, PITCAIRN, TAHITI, OLAND, HAINAN Dialog-cancel.svg gfx6
BONAIRE, KABINI, MULLINS, KAVERI, HAWAII Dialog-cancel.svg gfx7
HAWAII Dialog-ok.svg
  • AMD Radeon R9 390X
  • FirePro W9100
gfx7
TONGA, ICELAND/TOPAZ, CARRIZO, STONEY, VEGAM Dialog-cancel.svg gfx8
FIJI Dialog-ok.svg
  • Radeon R9 Fury
  • Radeon R9 Nano
  • Radeon R9 Fury X
  • Radeon Pro Duo (Fiji)
  • FirePro S9300 X2
  • Radeon Instinct MI8
gfx8
POLARIS10, POLARIS11, POLARIS12 Dialog-ok.svg
  • Radeon RX 470
  • Radeon RX 480
  • Radeon RX 570
  • Radeon RX 580
  • Radeon Pro Duo (Polaris)
  • Radeon Pro WX 5100
  • Radeon Pro WX 7100
  • Radeon Instinct MI6
gfx8
POLARIS11 Dialog-ok.svg
  • Radeon RX 460
  • Radeon RX 560
  • Radeon Pro WX 4100
gfx8
POLARIS12 Dialog-ok.svg
  • Radeon RX 540
  • Radeon RX 550
  • Radeon Pro WX 2100
  • Radeon Pro WX 3100
gfx8
VEGA10 Dialog-ok.svg
  • Radeon RX Vega 56
  • Radeon RX Vega 64
  • Radeon Vega Frontier Edition
  • Radeon Pro WX 8200
  • Radeon Pro WX 9100
  • Radeon Pro V340
  • Radeon Pro V340 MxGPU
  • Radeon Instinct MI25
gfx9
VEGA12, VEGA20 ("Vega 7nm") Dialog-ok.svg
  • Radeon VII
  • Radeon Instinct MI50
  • Radeon Instinct MI60
  • Vega Workstation (Vega20 GL-XE)
gfx9
RAVEN, RENOIR Dialog-cancel.svg gfx9
NAVI10, NAVI14 Dialog-cancel.svg gfx10
CICHLID, FLOUNDER, VANGOGH Blond-anime-girl-with-red-questionmark.png 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.

See Radeon Open Compute for additional information about Radeon Open Compute.

Linux System Configuration[edit]

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.

Running 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 /etc/OpenCL/vendors/.

It is, mostly, not possible to tell applications what implementation you prefer. Applications like LibreOffice have a simple [ ] Enable OpenCL 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:

File: /etc/OpenCL/vendors/mesa.icd
# libMesaOpenCL.so.1

Keeping the .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 /etc/OpenCL/vendors/ called vendor.icd which links to some actual implementations ICD file in /etc/alternatives/.

Use the clinfo tool to see what implementation is selected and actually used.

Applications[edit]

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


avatar

Anonymous (566daa8df8)

22 days ago
Score 0
Thank god for this article. I was going mad, I finally got at least OCL 1.2 working, so at least its not totally rubbish. Too bad Blender foundation are dropping it and so are AMD.
Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.