Defines the User Kernels, which are a method to extend OpenVX with new vision functions.
User Kernels can be loaded by OpenVX and included as nodes in the graph or as immediate functions (if the Client supplies the interface). User Kernels will typically be loaded and executed on High Level Operating System/CPU compatible targets, not on remote processors or other accelerators. This specification does not mandate what constitutes compatible platforms.
Call sequence of User Kernels Installation
Call sequence of a Graph Verify and Release with User Kernels.
Call sequence of a Graph Execution with User Kernels
During the first graph verification, the implementation will perform the following action sequence:
-
Initialize local data node attributes
- If VX_KERNEL_LOCAL_DATA_SIZE == 0, then set VX_NODE_LOCAL_DATA_SIZE to 0 and set VX_NODE_LOCAL_DATA_PTR to NULL.
- If VX_KERNEL_LOCAL_DATA_SIZE != 0, set VX_NODE_LOCAL_DATA_SIZE to VX_KERNEL_LOCAL_DATA_SIZE and set VX_NODE_LOCAL_DATA_PTR to the address of a buffer of VX_KERNEL_LOCAL_DATA_SIZE bytes.
-
Call the vx_kernel_validate_f callback.
-
Call the vx_kernel_initialize_f callback (if not NULL):
- If VX_KERNEL_LOCAL_DATA_SIZE == 0, the callback is allowed to set VX_NODE_LOCAL_DATA_SIZE and VX_NODE_LOCAL_DATA_PTR.
- If VX_KERNEL_LOCAL_DATA_SIZE != 0, then any attempt by the callback to set VX_NODE_LOCAL_DATA_SIZE or VX_NODE_LOCAL_DATA_PTR attributes will generate an error.
-
Provide the buffer optionally requested by the application
- If VX_KERNEL_LOCAL_DATA_SIZE == 0 and VX_NODE_LOCAL_DATA_SIZE != 0, and VX_NODE_LOCAL_DATA_PTR == NULL, then the implementation will set VX_NODE_LOCAL_DATA_PTR to the address of a buffer of VX_NODE_LOCAL_DATA_SIZE bytes.
At node destruction time, the implementation will perform the following action sequence:
-
Call vx_kernel_deinitialize_f callback (if not NULL): If the VX_NODE_LOCAL_DATA_PTR was set earlier by the implementation, then any attempt by the callback to set the VX_NODE_LOCAL_DATA_PTR attributes will generate an error.
-
If the VX_NODE_LOCAL_DATA_PTR was set earlier by the implementation, then the pointed memory must not be used anymore by the application after the vx_kernel_deinitialize_f callback completes.
A user node requires re-verification, if any changes below occurred after the last node verification:
-
The VX_NODE_BORDER node attribute was modified.
-
At least one of the node parameters was replaced by a data object with different meta-data, or was replaced by the 0 reference for optional parameters, or was set to a data object if previously not set because optional.
The node re-verification can by triggered explicitly by the application by calling vxVerifyGraph that will perform a complete graph verification. Otherwise, it will be triggered automatically at the next graph execution.
During user node re-verification, the following action sequence will occur:
-
Call the vx_kernel_deinitialize_f callback (if not NULL): If the VX_NODE_LOCAL_DATA_PTR was set earlier by the OpenVX implementation, then any attempt by the callback to set the VX_NODE_LOCAL_DATA_PTR attributes will generate an error.
-
Reinitialize local data node attributes if needed If VX_KERNEL_LOCAL_DATA_SIZE == 0:
- set VX_NODE_LOCAL_DATA_PTR to NULL.
- set VX_NODE_LOCAL_DATA_SIZE to 0.
-
Call the vx_kernel_validate_f callback.
-
Call the vx_kernel_initialize_f callback (if not NULL):
- If VX_KERNEL_LOCAL_DATA_SIZE == 0, the callback is allowed to set VX_NODE_LOCAL_DATA_SIZE and VX_NODE_LOCAL_DATA_PTR.
- If VX_KERNEL_LOCAL_DATA_SIZE is != 0, then any attempt by the callback to set VX_NODE_LOCAL_DATA_SIZE or VX_NODE_LOCAL_DATA_PTR attributes will generate an error.
-
Provide the buffer optionally requested by the application
- If VX_KERNEL_LOCAL_DATA_SIZE == 0 and VX_NODE_LOCAL_DATA_SIZE != 0, and VX_NODE_LOCAL_DATA_PTR == NULL, then the OpenVX implementation will set VX_NODE_LOCAL_DATA_PTR to the address of a buffer of VX_NODE_LOCAL_DATA_SIZE bytes.
When an OpenVX implementation sets the VX_NODE_LOCAL_DATA_PTR, the data inside the buffer will not be persistent between kernel executions.
|
typedef vx_status(* | vx_kernel_deinitialize_f) (vx_node node, const vx_reference *parameters, vx_uint32 num) |
| The pointer to the kernel deinitializer. If the host code requires a call to deinitialize data during a node garbage collection, this function is called if not NULL. More...
|
|
typedef vx_status(* | vx_kernel_f) (vx_node node, const vx_reference *parameters, vx_uint32 num) |
| The pointer to the Host side kernel. More...
|
|
typedef vx_status(* | vx_kernel_image_valid_rectangle_f) (vx_node node, vx_uint32 index, const vx_rectangle_t *const input_valid[], vx_rectangle_t *const output_valid[]) |
| A user-defined callback function to set the valid rectangle of an output image. More...
|
|
typedef vx_status(* | vx_kernel_initialize_f) (vx_node node, const vx_reference *parameters, vx_uint32 num) |
| The pointer to the kernel initializer. If the host code requires a call to initialize data once all the parameters have been validated, this function is called if not NULL. More...
|
|
typedef vx_status(* | vx_kernel_validate_f) (vx_node node, const vx_reference parameters[], vx_uint32 num, vx_meta_format metas[]) |
| The user-defined kernel node parameters validation function. The function only needs to fill in the meta data structure(s). More...
|
|
typedef struct _vx_meta_format * | vx_meta_format |
| This object is used by output validation functions to specify the meta data of the expected output data object. More...
|
|
typedef vx_status(* | vx_publish_kernels_f) (vx_context context) |
| The type of the vxPublishKernels entry function of modules loaded by vxLoadKernels and unloaded by vxUnloadKernels . More...
|
|
typedef vx_status(* | vx_unpublish_kernels_f) (vx_context context) |
| The type of the vxUnpublishKernels entry function of modules loaded by vxLoadKernels and unloaded by vxUnloadKernels . More...
|
|
|
vx_status VX_API_CALL | vxAddParameterToKernel (vx_kernel kernel, vx_uint32 index, vx_enum dir, vx_enum data_type, vx_enum state) |
| Allows users to set the signatures of the custom kernel. More...
|
|
vx_kernel VX_API_CALL | vxAddUserKernel (vx_context context, const vx_char name[VX_MAX_KERNEL_NAME], vx_enum enumeration, vx_kernel_f func_ptr, vx_uint32 numParams, vx_kernel_validate_f validate, vx_kernel_initialize_f init, vx_kernel_deinitialize_f deinit) |
| Allows users to add custom kernels to a context at run-time. More...
|
|
vx_status VX_API_CALL | vxAllocateUserKernelId (vx_context context, vx_enum *pKernelEnumId) |
| Allocates and registers user-defined kernel enumeration to a context. The allocated enumeration is from available pool of 4096 enumerations reserved for dynamic allocation from VX_KERNEL_BASE(VX_ID_USER,0). More...
|
|
vx_status VX_API_CALL | vxAllocateUserKernelLibraryId (vx_context context, vx_enum *pLibraryId) |
| Allocates and registers user-defined kernel library ID to a context. More...
|
|
vx_status VX_API_CALL | vxFinalizeKernel (vx_kernel kernel) |
| This API is called after all parameters have been added to the kernel and the kernel is ready to be used. Notice that the reference to the kernel created by vxAddUserKernel is still valid after the call to vxFinalizeKernel. If an error occurs, the kernel is not available for usage by the clients of OpenVX. Typically this is due to a mismatch between the number of parameters requested and given. More...
|
|
vx_status VX_API_CALL | vxLoadKernels (vx_context context, const vx_char *module) |
| Loads a library of kernels, called module, into a context. More...
|
|
vx_status VX_API_CALL | vxRemoveKernel (vx_kernel kernel) |
| Removes a custom kernel from its context and releases it. More...
|
|
vx_status VX_API_CALL | vxSetKernelAttribute (vx_kernel kernel, vx_enum attribute, const void *ptr, vx_size size) |
| Sets kernel attributes. More...
|
|
vx_status VX_API_CALL | vxSetMetaFormatAttribute (vx_meta_format meta, vx_enum attribute, const void *ptr, vx_size size) |
| This function allows a user to set the attributes of a vx_meta_format object in a kernel output validator. More...
|
|
vx_status VX_API_CALL | vxSetMetaFormatFromReference (vx_meta_format meta, vx_reference exemplar) |
| Set a meta format object from an exemplar data object reference. More...
|
|
vx_status VX_API_CALL | vxUnloadKernels (vx_context context, const vx_char *module) |
| Unloads all kernels from the OpenVX context that had been loaded from the module using the vxLoadKernels function. More...
|
|
This object is used by output validation functions to specify the meta data of the expected output data object.
- Note
- When the actual output object of the user node is virtual, the information given through the vx_meta_format object allows the OpenVX framework to automatically create the data object when meta data were not specified by the application at object creation time.
Definition at line 320 of file vx_types.h.
The type of the vxPublishKernels
entry function of modules loaded by vxLoadKernels
and unloaded by vxUnloadKernels
.
- Parameters
-
[in] | context | The reference to the context kernels must be added to. |
Definition at line 1744 of file vx_types.h.
The type of the vxUnpublishKernels
entry function of modules loaded by vxLoadKernels
and unloaded by vxUnloadKernels
.
- Parameters
-
[in] | context | The reference to the context kernels have been added to. |
Definition at line 1752 of file vx_types.h.
The pointer to the Host side kernel.
- Parameters
-
[in] | node | The handle to the node that contains this kernel. |
[in] | parameters | The array of parameter references. |
[in] | num | The number of parameters. |
Definition at line 1761 of file vx_types.h.
The pointer to the kernel initializer. If the host code requires a call to initialize data once all the parameters have been validated, this function is called if not NULL.
- Parameters
-
[in] | node | The handle to the node that contains this kernel. |
[in] | parameters | The array of parameter references. |
[in] | num | The number of parameters. |
Definition at line 1772 of file vx_types.h.
The pointer to the kernel deinitializer. If the host code requires a call to deinitialize data during a node garbage collection, this function is called if not NULL.
- Parameters
-
[in] | node | The handle to the node that contains this kernel. |
[in] | parameters | The array of parameter references. |
[in] | num | The number of parameters. |
Definition at line 1783 of file vx_types.h.
The user-defined kernel node parameters validation function. The function only needs to fill in the meta data structure(s).
- Note
- This function is called once for whole set of parameters.
- Parameters
-
[in] | node | The handle to the node that is being validated. |
[in] | parameters | The array of parameters to be validated. |
[in] | num | Number of parameters to be validated. |
[in] | metas | A pointer to a pre-allocated array of structure references that the system holds. The system pre-allocates a number of vx_meta_format structures for the output parameters only, indexed by the same indices as parameters[]. The validation function fills in the correct type, format, and dimensionality for the system to use either to create memory or to check against existing memory. |
- Returns
- An error code describing the validation status on parameters.
Definition at line 1799 of file vx_types.h.
A user-defined callback function to set the valid rectangle of an output image.
The VX_VALID_RECT_CALLBACK
attribute in the vx_meta_format
object should be set to the desired callback during user node's output validator. The callback must not call vxGetValidRegionImage
or vxSetImageValidRectangle
. Instead, an array of the valid rectangles of all the input images is supplied to the callback to calculate the output valid rectangle. The output of the user node may be a pyramid, or just an image. If it is just an image, the 'Out' array associated with that output only has one element. If the output is a pyramid, the array size is equal to the number of pyramid levels. Notice that the array memory allocation passed to the callback is managed by the framework, the application must not allocate or deallocate those pointers.
The behavior of the callback function vx_kernel_image_valid_rectangle_f is undefined if one of the following is true:
- One of the input arguments of a user node is a pyramid or an array of images.
- Either input or output argument of a user node is an array of pyramids.
- Parameters
-
[in,out] | node | The handle to the node that is being validated. |
[in] | index | The index of the output parameter for which a valid region should be set. |
[in] | input_valid | A pointer to an array of valid regions of input images or images contained in image container (e.g. pyramids). They are provided in same order as the parameter list of the kernel's declaration. |
[out] | output_valid | An array of valid regions that should be set for the output images or image containers (e.g. pyramid) after graph processing. The length of the array should be equal to the size of the image container (e.g. number of levels in the pyramid). For a simple output image the array size is always one. Each rectangle supplies the valid region for one image. The array memory allocation is managed by the framework. |
- Returns
- An error code describing the validation status on parameters.
Definition at line 1832 of file vx_types.h.
The meta valid rectangle attributes.
Enumerator |
---|
VX_VALID_RECT_CALLBACK |
Valid rectangle callback during output parameter validation. Write-only.
|
Definition at line 1183 of file vx_types.h.
Allocates and registers user-defined kernel enumeration to a context. The allocated enumeration is from available pool of 4096 enumerations reserved for dynamic allocation from VX_KERNEL_BASE(VX_ID_USER,0).
- Parameters
-
[in] | context | The reference to the implementation context. |
[out] | pKernelEnumId | pointer to return vx_enum for user-defined kernel. |
- Return values
-
VX_SUCCESS | No errors; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | If the context is not a valid vx_context reference. |
VX_ERROR_NO_RESOURCES | The enumerations has been exhausted. |
Allocates and registers user-defined kernel library ID to a context.
The allocated library ID is from available pool of library IDs (1..255) reserved for dynamic allocation. The returned libraryId can be used by user-kernel library developer to specify individual kernel enum IDs in a header file, shown below:
1 #define MY_KERNEL_ID1(libraryId) (VX_KERNEL_BASE(VX_ID_USER,libraryId) + 0);
2 #define MY_KERNEL_ID2(libraryId) (VX_KERNEL_BASE(VX_ID_USER,libraryId) + 1);
3 #define MY_KERNEL_ID3(libraryId) (VX_KERNEL_BASE(VX_ID_USER,libraryId) + 2);
- Parameters
-
[in] | context | The reference to the implementation context. |
[out] | pLibraryId | pointer to vx_enum for user-kernel libraryId. |
- Return values
-
VX_SUCCESS | No errors; any other value indicates failure. |
VX_ERROR_NO_RESOURCES | The enumerations has been exhausted. |
Loads a library of kernels, called module, into a context.
The module must be a dynamic library with by convention, two exported functions named vxPublishKernels
and vxUnpublishKernels
.
vxPublishKernels
must have type vx_publish_kernels_f
, and must add kernels to the context by calling vxAddUserKernel
for each new kernel. vxPublishKernels
is called by vxLoadKernels
.
vxUnpublishKernels
must have type vx_unpublish_kernels_f
, and must remove kernels from the context by calling vxRemoveKernel
for each kernel the vxPublishKernels
has added. vxUnpublishKernels
is called by vxUnloadKernels
.
- Note
- When all references to loaded kernels are released, the module may be automatically unloaded.
- Parameters
-
[in] | context | The reference to the context the kernels must be added to. |
[in] | module | The short name of the module to load. On systems where there are specific naming conventions for modules, the name passed should ignore such conventions. For example: libxyz.so should be passed as just xyz and the implementation will do the right thing that the platform requires. |
- Note
- This API uses the system pre-defined paths for modules.
- Returns
- A
vx_status_e
enumeration.
- Return values
-
VX_SUCCESS | No errors; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | context is not a valid vx_context reference. |
VX_ERROR_INVALID_PARAMETERS | If any of the other parameters are incorrect. |
- See also
- vxGetKernelByName
Unloads all kernels from the OpenVX context that had been loaded from the module using the vxLoadKernels function.
The kernel unloading is performed by calling the vxUnpublishKernels
exported function of the module.
- Note
vxUnpublishKernels
is defined in the description of vxLoadKernels
.
- Parameters
-
[in] | context | The reference to the context the kernels must be removed from. |
[in] | module | The short name of the module to unload. On systems where there are specific naming conventions for modules, the name passed should ignore such conventions. For example: libxyz.so should be passed as just xyz and the implementation will do the right thing that the platform requires. |
- Note
- This API uses the system pre-defined paths for modules.
- Returns
- A
vx_status_e
enumeration.
- Return values
-
VX_SUCCESS | No errors; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | context is not a valid vx_context reference. |
VX_ERROR_INVALID_PARAMETERS | If any of the other parameters are incorrect. |
- See also
- vxLoadKernels
Allows users to add custom kernels to a context at run-time.
- Parameters
-
[in] | context | The reference to the context the kernel must be added to. |
[in] | name | The string to use to match the kernel. |
[in] | enumeration | The enumerated value of the kernel to be used by clients. |
[in] | func_ptr | The process-local function pointer to be invoked. |
[in] | numParams | The number of parameters for this kernel. |
[in] | validate | The pointer to vx_kernel_validate_f , which validates parameters to this kernel. |
[in] | init | The kernel initialization function. |
[in] | deinit | The kernel de-initialization function. |
- Returns
- A
vx_kernel
reference. Any possible errors preventing a successful creation should be checked using vxGetStatus
.
This API is called after all parameters have been added to the kernel and the kernel is ready to be used. Notice that the reference to the kernel created by vxAddUserKernel is still valid after the call to vxFinalizeKernel. If an error occurs, the kernel is not available for usage by the clients of OpenVX. Typically this is due to a mismatch between the number of parameters requested and given.
- Parameters
-
- Returns
- A
vx_status_e
enumeration.
- Return values
-
VX_SUCCESS | No errors; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | kernel is not a valid vx_kernel reference. |
- Precondition
vxAddUserKernel
and vxAddParameterToKernel
Allows users to set the signatures of the custom kernel.
- Parameters
-
[in] | kernel | The reference to the kernel added with vxAddUserKernel . |
[in] | index | The index of the parameter to add. |
[in] | dir | The direction of the parameter. This must be either VX_INPUT or VX_OUTPUT . VX_BIDIRECTIONAL is not supported for this function. |
[in] | data_type | The type of parameter. This must be a value from vx_type_e . |
[in] | state | The state of the parameter (required or not). This must be a value from vx_parameter_state_e . |
- Returns
- A
vx_status_e
enumerated value.
- Return values
-
VX_SUCCESS | Parameter is successfully set on kernel; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | kernel is not a valid vx_kernel reference. |
VX_ERROR_INVALID_PARAMETERS | If the parameter is not valid for any reason. |
- Precondition
vxAddUserKernel
Removes a custom kernel from its context and releases it.
- Parameters
-
[in] | kernel | The reference to the kernel to remove. Returned from vxAddUserKernel . |
- Note
- Any kernel enumerated in the base standard cannot be removed; only kernels added through
vxAddUserKernel
can be removed.
- Returns
- A
vx_status_e
enumeration. The function returns to the application full control over the memory resources provided at the kernel creation time.
- Return values
-
VX_SUCCESS | No errors; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | kernel is not a valid vx_kernel reference. |
VX_ERROR_INVALID_PARAMETERS | If a base kernel is passed in. |
VX_FAILURE | If the application has not released all references to the kernel object OR if the application has not released all references to a node that is using this kernel OR if the application has not released all references to a graph which has nodes that is using this kernel. |
Sets kernel attributes.
- Parameters
-
[in] | kernel | The reference to the kernel. |
[in] | attribute | The enumeration of the attributes. See vx_kernel_attribute_e . |
[in] | ptr | The pointer to the location from which to read the attribute. |
[in] | size | The size in bytes of the data area indicated by ptr in bytes. |
- Note
- After a kernel has been passed to
vxFinalizeKernel
, no attributes can be altered.
- Returns
- A
vx_status_e
enumeration.
- Return values
-
VX_SUCCESS | No errors; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | kernel is not a valid vx_kernel reference. |
This function allows a user to set the attributes of a vx_meta_format
object in a kernel output validator.
The vx_meta_format object contains two types of information: data object meta data and some specific information that defines how the valid region of an image changes
The meta data attributes that can be set are identified by this list:
- vx_image : VX_IMAGE_FORMAT, VX_IMAGE_HEIGHT, VX_IMAGE_WIDTH
- vx_array : VX_ARRAY_CAPACITY, VX_ARRAY_ITEMTYPE
- vx_pyramid : VX_PYRAMID_FORMAT, VX_PYRAMID_HEIGHT, VX_PYRAMID_WIDTH, VX_PYRAMID_LEVELS, VX_PYRAMID_SCALE
- vx_scalar : VX_SCALAR_TYPE
- vx_matrix : VX_MATRIX_TYPE, VX_MATRIX_ROWS, VX_MATRIX_COLUMNS
- vx_distribution : VX_DISTRIBUTION_BINS, VX_DISTRIBUTION_OFFSET, VX_DISTRIBUTION_RANGE
- vx_remap : VX_REMAP_SOURCE_WIDTH, VX_REMAP_SOURCE_HEIGHT, VX_REMAP_DESTINATION_WIDTH, VX_REMAP_DESTINATION_HEIGHT
- vx_lut : VX_LUT_TYPE, VX_LUT_COUNT
- vx_threshold : VX_THRESHOLD_TYPE, VX_THRESHOLD_INPUT_FORMAT, VX_THRESHOLD_INPUT_FORMAT
- vx_object_array : VX_OBJECT_ARRAY_NUMITEMS, VX_OBJECT_ARRAY_ITEMTYPE
- vx_tensor : VX_TENSOR_NUMBER_OF_DIMS, VX_TENSOR_DIMS, VX_TENSOR_DATA_TYPE, VX_TENSOR_FIXED_POINT_POSITION
- VX_VALID_RECT_CALLBACK
- Note
- For vx_image, a specific attribute can be used to specify the valid region evolution. This information is not a meta data.
- Parameters
-
[in] | meta | The reference to the vx_meta_format struct to set |
[in] | attribute | Use the subset of data object attributes that define the meta data of this object or attributes from vx_meta_format . |
[in] | ptr | The input pointer of the value to set on the meta format object. |
[in] | size | The size in bytes of the object to which ptr points. |
- Returns
- A
vx_status_e
enumeration.
- Return values
-
VX_SUCCESS | The attribute was set; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | meta is not a valid vx_meta_format reference. |
VX_ERROR_INVALID_PARAMETERS | size was not correct for the type needed. |
VX_ERROR_NOT_SUPPORTED | the object attribute was not supported on the meta format object. |
VX_ERROR_INVALID_TYPE | attribute type did not match known meta format type. |
Set a meta format object from an exemplar data object reference.
This function sets a vx_meta_format object from the meta data of the exemplar
- Parameters
-
[in] | meta | The meta format object to set |
[in] | exemplar | The exemplar data object. |
- Returns
- A
vx_status_e
enumeration.
- Return values
-
VX_SUCCESS | The meta format was correctly set; any other value indicates failure. |
VX_ERROR_INVALID_REFERENCE | meta is not a valid vx_meta_format reference, or exemplar is not a valid vx_reference reference. |