OpenCL™ (Open Computing Language) is an open, royalty-free standard for cross-platform, parallel programming of diverse accelerators found in supercomputers, cloud servers, personal computers, mobile devices and embedded platforms. OpenCL greatly improves the speed and responsiveness of a wide spectrum of applications in numerous market categories including professional creative tools, scientific and medical software, vision processing, and neural network training and inferencing.
OpenCL speeds applications by offloading their most computationally intensive code onto accelerator processors - or devices. OpenCL developers use C or C++-based kernel languages to code programs that are passed through a device compiler for parallel execution on accelerator devices. The OpenCL standard provides API calls to discover what accelerators devices are available in a system, compile and load kernel programs to those processors and coordinate their parallel execution from a host CPU.
OpenCL provides the industry with the lowest ‘close-to-metal’ processor-agile execution layer for accelerating applications, libraries and engines, and also providing a code generation target for compilers. Unlike ‘GPU-only’ APIs, such as Vulkan, OpenCL enables use of a diverse range of accelerators including multi-core CPUs, GPUs, DSPs, FPGAs and dedicated hardware such as inferencing engines.
OpenCL is being actively evolved to meet the growing demands of the industry to use parallel processing to deliver ever higher levels of compute performance. OpenCL can deploy new functionality though extensions, that if proven to be useful to developers can be absorbed into new versions of the core specification. The OpenCL working group at Khronos regularly extends OpenCL for enhanced functionality and flexibility as well as increasing the quality and diversity of tools, libraries and language compilers.
As the industry landscape of platforms and devices grows more complex, tools are evolving the enable OpenCL applications to be deployed onto platforms that do not have available native OpenCL drivers. For example, the open source clspv compiler and clvk API translator enable OpenCL applications to be run over a Vulkan run-time. This gives OpenCL developers significant flexibility on where and how they can deploy their OpenCL applications.
An OpenCL application is split into host and device parts with host code written using a general programming language such as C or C++ and compiled by a conventional compiler for execution on a host CPU.
The device compilation phase can be done online, i.e. during execution of an application using special API calls. It can alternatively be compiled before executing the application into the machine binary or special portable intermediate representation defined by Khronos called SPIR-V. There are also domain specific languages and frameworks that can compile to OpenCL either using source-to-source translations or generating binary/SPIR-V, for example Halide.
Application host code is frequently written in C or C++ but bindings for other languages are also available, such as Python. Kernel programs can be written in a dialect of C (OpenCL C) or C++ (C++ for OpenCL) that enables a developer to program computationally intensive parts of their application in a kernel program. All versions of the OpenCL C language are based on C99. The community driven C++ for OpenCL language brings together capabilities of OpenCL and C++17.
The OpenCL working group has transitioned from the original OpenCL C++ kernel language first defined in OpenCL 2.0 to C++ for OpenCL developed by the open source community to provide improved features and compatibility with OpenCL C. C++ for OpenCL is supported by Clang and its documentation can be found here. It enables developers to use most C++17 features in OpenCL kernels. It is largely backwards compatible with OpenCL C 2.0 enabling it to be used to program accelerators with OpenCL 2.0 or above with conformant drivers that support SPIR-V. Its implementation in Clang can be tracked via the OpenCL Support Page.
Some extensions are available to the existing published kernel language standards. The full list of such extensions is documented here . Conformant compilers and drivers may optionally support the extensions and so there is a mechanism to detect their support at the compile time. Developers should be aware that not all extensions may be supported across all devices.
Below is the full list of OpenCL API and languages versions that are currently supported.
|OpenCL API||Supported OpenCL Kernel Languages|
|OpenCL 2.0, 2.1, 2.2||OpenCL C 1.0, 1.1, 1.2, 2.0, C++ for OpenCL|
|OpenCL 1.2||OpenCL C 1.0, 1.1, 1.2|
|OpenCL 1.1||OpenCL C 1.0, 1.1|
|OpenCL 1.0||OpenCL C 1.0|
The Khronos OpenCL working group makes as much information as possible about OpenCL publicly available, including open sourcing the specification document and conformance tests:
Here you can view a list of hardware vendors with Conformant OpenCL Implementations