Introduction
A .cl file holds a kernel written in OpenCL C, the language of programs
that run on the devices of the OpenCL
standard: graphics cards, processors and other accelerators. OpenCL is an open,
royalty-free standard kept by the Khronos Group. OpenCL C is based on C99, with
extensions and restrictions for parallel code. A kernel is the function that every
work-item, one of many parallel instances, runs on the device.
A host program, written in another language, reads the kernel source as text,
hands it to the OpenCL library and builds it for the chosen device while it runs. The
file name is only a convention. OpenCL C is the OpenCL counterpart of the kernels in
CUDA files. The .cl extension is also used
for Common Lisp source, an unrelated language.
Structure
An OpenCL C file is plain text with C syntax and a preprocessor. A kernel is a
function marked with __kernel (or kernel) that returns
void. Pointer parameters carry an address space qualifier such as
__global (or global), which says which memory the data
lives in. Built-in functions such as get_global_id tell each work-item
which element is its own. Optional features are signalled by predefined macros
named __opencl_c_<feature_name>.
__kernel void scale(__global float *data, const float factor) {
size_t i = get_global_id(0);
data[i] *= factor;
}
Clang supports OpenCL C versions 1.0 to 3.0 and a related language, C++ for OpenCL.
A kernel file is compiled with a command such as
clang -Xclang -finclude-default-header test.cl.
Not described
Known, not yet covered
- Reference: this overview is the only page. The language has no reference pages: the scalar and vector types, the address spaces (
__global,__local,__constant,__private), the work-item and work-group functions, the built-in maths, image and atomic functions, the pipe and device-side enqueue features of 2.0, and what each version from 1.0 to 3.0 adds. The OpenCL C specification describes them. - Reference: C++ for OpenCL, the host API (
clCreateProgramWithSource,clBuildProgram), the binary and SPIR-V forms a program can be built from, and the extension list are not described. The file extension used for C++ for OpenCL source is not covered. - Viewer: there is no viewer for this format yet, and nothing is compiled or checked.
Also used for
- Common Lisp source code – Common Lisp programs as text: parenthesised forms, read in turn.
Links
Software
Reference
- OpenCL – the Khronos Group’s page for the standard
- The OpenCL C specification – the language reference, version 3.0
- OpenCL support in Clang – supported versions and how to compile