VisionWorks Toolkit Reference

September 29, 2015 | 1.0 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

This section demonstrates user custom kernel registration.

You must register the new kernel in a context object (Object: Context).

Each kernel has 2 identifiers:

You must define both identifiers:

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";
Note
If the user custom node is implemented on CUDA or it uses CUDA libraries, use gpu: prefix for the kernel name to notify the framework that the kernel should be assigned to a GPU target:
vx_char keypoint_array_sort_name[] = "gpu:user.kernel.keypoint_array_sort";

Do the registration in 3 steps:

4.1. Create kernel object:

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.2. Add parameters description to the newly created kernel object:

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

4.3. Finalize the kernel:

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

The Full Code for the Node 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;
}