OpenCL Kernel Development - 2020.2 English

Vitis Unified Software Platform Documentation: Application Acceleration Development (UG1393)

Document ID
UG1393
Release Date
2021-03-22
Version
2020.2 English

The following OpenCL™ kernel discussion is based on the information provided in the C/C++ Kernels topic. The same programming techniques for accelerating the performance of a kernel apply to both C/C++ and OpenCL kernels. However, the OpenCL kernel uses the __attribute syntax in place of pragmas. For details of the available attributes, refer to OpenCL Attributes.

The following code examples show some of the elements of an OpenCL kernel for the Vitis™ application acceleration development flow. This is not intended to be a primer on OpenCL or kernel development, but to merely highlight some of the key difference between OpenCL and C/C++ kernels.

Kernel Signature

In C/C++ kernels, the kernel is identified on the Vitis compiler command line using the v++ --kernel option. However, in OpenCL code, the __kernel keyword identifies a kernel in the code. You can have multiple kernels defined in a single .cl file, and the Vitis compiler will compile all of the kernels, unless you specify the --kernel option to identify which kernel to compile.

__kernel __attribute__ ((reqd_work_group_size(1, 1, 1)))
void apply_watermark(__global const TYPE * __restrict input, 
   __global TYPE * __restrict output, int width, int height) {
{
   ...
}
Tip: The complete code for the kernel function above, apply_watermark, can be found in the Global Memory Two Banks (CL) example in theVitis Accel Examples GitHub repository.

In the example above, you can see the watermark kernel has two pointer type arguments: input and output, and has two scalar type int arguments: width and height.

In C/C++ kernels, these arguments would need to be identified with the HLS INTERFACE pragmas. However, in the OpenCL kernel, the Vitis compiler, and Vitis HLS recognize the kernel arguments, and compile them as needed: pointer arguments into m_axi interfaces, and scalar arguments into s_axilite interfaces.