VisionWorks Toolkit Reference

December 18, 2015 | 1.2 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
4. Kernel Registration

This section illustrates the user custom kernel registration.

Custom kernels must be registered in an OpenVX context (Object: Context) before the application can create a node that instantiates this kernel in the context.

This registration is done in 4 steps:

Once a custom kernel is registered, the application can create custom nodes that instantiates this kernel.

4.1. Kernel identifier

Each custom kernel has 2 unique identifiers that must be provided by the application:

In order to prevent an identifier collision between kernels, there are conventions to create both the name and the enum.

enum {
// Library ID
USER_LIBRARY = 0x1,
// Kernel ID
USER_KERNEL_KEYPOINT_ARRAY_SORT = VX_KERNEL_BASE(VX_ID_DEFAULT, USER_LIBRARY) + 0x0,
};
vx_char keypoint_array_sort_name[] = "user.kernel.keypoint_array_sort";

4.2. Kernel object creation

In this step, identifiers, callback functions as well as the number of parameters are provided.

vx_uint32 num_params = 3;
vx_kernel kernel = vxAddKernel(context, keypoint_array_sort_name, USER_KERNEL_KEYPOINT_ARRAY_SORT,
keypointArraySort_kernel,
num_params,
keypointArraySort_input_validate,
keypointArraySort_output_validate,
NULL, // init
NULL // deinit
);
status = vxGetStatus((vx_reference)kernel);
if (status != VX_SUCCESS)
{
vxAddLogEntry((vx_reference)context, status, "Failed to create KeypointArraySort Kernel");
return status;
}

4.3. Kernel parameters declaration

In this step, each kernel parameter must individually be declared, providing information such as its data type, its direction (whether it is an input or output) and whether or not it is optional.

if (status != VX_SUCCESS)
{
vxReleaseKernel(&kernel);
vxAddLogEntry((vx_reference)context, status, "Failed to initialize KeypointArraySort Kernel parameters");
return VX_FAILURE;
}

4.4. Kernel finalization

Once all kernel parameters are declared, the kernel can be finalized, which enables the creation of custom nodes that are instances of this custom kernel.

status = vxFinalizeKernel(kernel);
if (status != VX_SUCCESS)
{
vxReleaseKernel(&kernel);
vxAddLogEntry((vx_reference)context, status, "Failed to finalize KeypointArraySort Kernel");
return VX_FAILURE;
}

Complete Code for the Custom Kernel Registration

enum {
// Library ID
USER_LIBRARY = 0x1,
// Kernel ID
USER_KERNEL_KEYPOINT_ARRAY_SORT = VX_KERNEL_BASE(VX_ID_DEFAULT, USER_LIBRARY) + 0x0,
};
vx_char keypoint_array_sort_name[] = "user.kernel.keypoint_array_sort";
vx_status registerKeypointArraySortKernel(vx_context context)
{
vx_uint32 num_params = 3;
vx_kernel kernel = vxAddKernel(context, keypoint_array_sort_name, USER_KERNEL_KEYPOINT_ARRAY_SORT,
keypointArraySort_kernel,
num_params,
keypointArraySort_input_validate,
keypointArraySort_output_validate,
NULL, // init
NULL // deinit
);
status = vxGetStatus((vx_reference)kernel);
if (status != VX_SUCCESS)
{
vxAddLogEntry((vx_reference)context, status, "Failed to create KeypointArraySort Kernel");
return status;
}
if (status != VX_SUCCESS)
{
vxReleaseKernel(&kernel);
vxAddLogEntry((vx_reference)context, status, "Failed to initialize KeypointArraySort Kernel parameters");
return VX_FAILURE;
}
status = vxFinalizeKernel(kernel);
if (status != VX_SUCCESS)
{
vxReleaseKernel(&kernel);
vxAddLogEntry((vx_reference)context, status, "Failed to finalize KeypointArraySort Kernel");
return VX_FAILURE;
}
return status;
}