• 04/03/2020
  • Public Content

Intel's Extensions to the OpenVX* API: OpenCL™ Custom Kernels

Custom OpenCL™ Kernels is the short name for the Intel OpenVX* extension that allows using code from regular OpenCL kernels as OpenVX user kernels. For code examples, please refer to the Sample Applications section.
NOTE: This extension is an experimental feature. It is subject to potential changes without notice. OpenCL custom kernels are supported only for the GPU target.
Current extension's API still limits the OpenVX parameters that OpenCL kernels can access:
OpenVX* Object
OpenCL™ Kernel Argument (OpenCL™ C code)
global uchar*       ptr,
uint  width,        // width of the output image
uint height,        // height of the output image
uint pixelStride,   // pixel stride in bytes
uint  rowPitch,     // row stride in bytes
//repeat for every plain (for multi-plannar images)
global uchar* ptr,
uint32 items,      // number of items
uint32 itemSize,   // size of an item in bytes
uint32 stride      // item stride in bytes
global uchar* ptr, // pointer to matrix items
uint32 rows,       // number of rows
uint32 cols        // number of columns
vx_scalar (VX_TYPE_INT16)
__global short* ptr, uchar size
vx_scalar (VX_TYPE_INT32)
__global int* ptr, uchar size
vx_scalar (VX_TYPE_INT64)
__global long* ptr, uchar size
vx_scalar (VX_TYPE_UINT16)
__global ushort* ptr, uchar size
vx_scalar (VX_TYPE_UINT32)
__global uint* ptr, uchar size
vx_scalar (VX_TYPE_UINT64)
__global ulong* ptr, uchar size
vx_scalar (VX_TYPE_FLOAT32)
__global float* ptr, uchar size
vx_scalar (VX_TYPE_FLOAT64)
__global double* ptr, uchar size
vx_scalar (VX_ENUM)
__global int* ptr, uchar size
int value_or_upper, // value for VX_THRESHOLD_TYPE_BINARY
                    // upper for VX_THRESHOLD_TYPE_RANGE
int lower,      // lower, defined for VX_THRESHOLD_TYPE_RANGE
int true_value, // VX_THRESHOLD_TRUE_VALUE attribute
int false_value // VX_THRESHOLD_FALSE_VALUE attribute
When an application sets an OpenVX data object, like
as an argument to the node, and the OpenVX framework passes the actual data pointer to OpenCL kernel invocation. All work-item built-in functions like
are supported. So, it is the programmer's responsibly to assure correct id-based pointer calculations and legal access to OpenVX data objects from the OpenCL kernel.
Refer to the Sample Applications section to find example of the extension API in use. You can find there dedicated tutorials, which explain the OpenCL custom kernels in further details.
In the case of Custom OpenCL Kernels which support image tiling (added to the context via
), the argument translation is different for
OpenVX* Object
OpenCL™ Tiling Kernel Argument (C code)
global uchar*      // ptr,
int tile_x,        // x coordinate of the tile
int tile_y,        // y coordinate of the tile
int tile_width,    // width of tile
int tile_height,   // height of tile
int image_width,   // width of the full image
int image_height,  // height of the full image
int pixelStride,   // pixel stride in bytes
int rowStride,     // row stride in bytes
//repeat for every plane (for multi-planar images)
corresponds to the starting location of the tile, not the starting location of the full image. Pixels which reside outside of the given tile should not be accessed.
Furthermore, the kernel attribute
should be set with a corresponding
object. This is by the runtime to determine the required size and location of the input tile, given an output tile.
For example, the following code snippet demonstrates the required neighborhood that would be set for a 5x5 filter.
vx_neighborhood_size_intel_t n; n.top = -2; //requires 2 additional input pixel above n.left = -2; //requires 2 additional input pixels to the left n.right = 2; //requires 2 additional input pixels to the right n.bottom = 2; //requires 2 additional input pixels below vxSetKernelAttribute(kernel, VX_KERNEL_INPUT_NEIGHBORHOOD_INTEL, &n, sizeof(vx_neighborhood_size_intel_t));
NOTE: Input tiles in which the set neighborhood causes a portion of the of the input tile to reside outside of the valid region of the input image, such as along the edges of the image, the tile will be cropped to contain only the portion which intersects with the valid region of the image.

Product and Performance Information


Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.