TIOVX User Guide
|
#include <stdio.h>
#include <VX/vx.h>
#include <TI/tivx.h>
#include <ch03_graph/phase_rgb_user_kernel.h>
Go to the source code of this file.
Macros | |
#define | PHASE_RGB_IN0_IMG_IDX (0u) |
Index of input image in parameter list. | |
#define | PHASE_RGB_OUT0_IMG_IDX (1u) |
Index of output image in parameter list. | |
#define | PHASE_RGB_MAX_PARAMS (2u) |
Total number of parameters for this function. | |
Variables | |
static vx_kernel | phase_rgb_user_kernel = NULL |
Handle to the registered user kernel [static global]. | |
static vx_enum | phase_rgb_user_kernel_id = (vx_status)VX_ERROR_INVALID_PARAMETERS |
Kernel ID of the registered user kernel. Used to create a node for the kernel function [static global]. | |
User Kernel implementation for Phase to RGB conversion function
This file shows a sample implementation of a user kernel function.
To implement a user kernel the below top level interface functions are implemented
When registering a user kernel, the following callback function are implemented and registered with the OpenVX context
When working with user kernel or target kernel,
When working with target kernel, additional the target side implementation is done in file phase_rgb_target_kernel.c
Follow the comments for the different functions in the file to understand how a user/target kernel is implemented.
Definition in file phase_rgb_user_kernel.c.
|
static |
User/target kernel init function.
This function gets called during vxGraphVerify after kernel validate function. Typically any resources the kernel needs during its execution should be allocated during kernel init.
node | [in] OpenVX node which will execute the kernel |
parameters | [in] Parameters references for this kernel function |
num | [in] Number of parameter references |
Definition at line 547 of file phase_rgb_user_kernel.c.
|
static |
User/target kernel execute or run function.
This function gets called during graph execution. This where the actual kernel function which reads the input data and writes the output data is implemented.
node | [in] OpenVX node which will execute the kernel |
parameters | [in] Parameters references for this kernel function |
num | [in] Number of parameter references |
Definition at line 568 of file phase_rgb_user_kernel.c.
|
static |
User/target kernel de-init function.
This function gets called during vxReleaseGraph. Typically any resources allcoated during kernel init are released during deinit.
node | [in] OpenVX node which will execute the kernel |
parameters | [in] Parameters references for this kernel function |
num | [in] Number of parameter references |
Definition at line 684 of file phase_rgb_user_kernel.c.
|
static |
User/target kernel validate function.
This function gets called during vxGraphVerify. The node which will runs the kernel, parameter references are passed as input to this function. This function checks the parameters to make sure all attributes of the parameter are as expected. ex, data format checks, image width, height relations between input and output.
node | [in] OpenVX node which will execute the kernel |
parameters | [in] Parameters references for this kernel function |
num | [in] Number of parameter references |
metas | [in/out] Meta references update with attribute values |
Definition at line 417 of file phase_rgb_user_kernel.c.
|
static |
Add kernel as user kernel.
context | [in] OpenVX context to which the kernel will be added |
- Dynamically allocate a kernel ID and store it in the global 'phase_rgb_user_kernel_id'
This is used later to create the node with this kernel function
- Register kernel to OpenVX context
A kernel can be identified with its kernel ID (allocated above).
A kernel can also be identified with its unique kernel name string. "vx_tutorial_graph.phase_rgb" or TIVX_TUTORIAL_KERNEL_PHASE_RGB_NAME defined in file vx_tutorial_kernels.h in this case.
When calling vxAddUserKernel(), additional callbacks are registered including the mandatory phase_rgb_user_kernel_run() function.
Definition at line 252 of file phase_rgb_user_kernel.c.
|
static |
Add kernel as target kernel.
context | [in] OpenVX context to which the kernel will be added |
- Dynamically allocate a kernel ID and store it in the global 'phase_rgb_user_kernel_id'
This is used later to create the node with this kernel function
- Register kernel to OpenVX context
A kernel can be identified with its kernel ID (allocated above).
A kernel can also be identified with its unique kernel name string. "vx_tutorial_graph.phase_rgb" or TIVX_TUTORIAL_KERNEL_PHASE_RGB_NAME defined in file vx_tutorial_kernels.h in this case.
When calling vxAddUserKernel(), additional callbacks are registered. For target kernel, the 'run' callback is set to NULL. Typically 'init' and 'deinit' callbacks are also set to NULL. 'validate' callback is typically set
- Add supported target's on which this target kernel can be run
Definition at line 306 of file phase_rgb_user_kernel.c.
vx_status phase_rgb_user_kernel_add | ( | vx_context | context, |
vx_bool | add_as_target_kernel | ||
) |
Add user/target kernel to OpenVX context.
context | [in] OpenVX context into with the user kernel is added |
add_as_target_kernel | [in] 'vx_false_e', add this kernel as user kernel 'vx_true_e', add this kernel as target kernel |
- Depending on 'add_as_target_kernel' invoke user kernel or target kernel specific registration logic
phase_rgb_user_kernel_id is set as part of this function invocation.
- Checking is kernel was added successfully to OpenVX context
- Now define parameters for the kernel
When specifying the parameters, the below attributes of each parameter are specified, - parameter index in the function parameter list - the parameter direction: VX_INPUT or VX_OUTPUT - parameter data object type - paramater state: VX_PARAMETER_STATE_REQUIRED or VX_PARAMETER_STATE_OPTIONAL
- After all parameters are defined, now the kernel is finalized, i.e it is ready for use.
- Set kernel handle to the global user kernel handle
This global handle is used later to release the kernel when done with it
Definition at line 144 of file phase_rgb_user_kernel.c.
vx_status phase_rgb_user_kernel_remove | ( | vx_context | context | ) |
Remove user/target kernel from context.
context | [in] OpenVX context from which the kernel will be removed |
- Remove user kernel from context and set the global 'phase_rgb_user_kernel' to NULL
Definition at line 375 of file phase_rgb_user_kernel.c.
User/target kernel node create function.
Given a graph reference, this function creates a OpenVX node and inserts it into the graph. The list of parameter references is also provided as input. Exact data type are used instead of base class references to allow some level of compile time type checking. In this example, there is one input image and one output image that are passed as parameters.
graph | [in] OpenVX graph |
in | [in] Input image reference |
out | [in] Output image reference |
- Put parameters into a array of references
- Use TIOVX API to make a node using the graph, kernel ID, and parameter reference array as input
Definition at line 707 of file phase_rgb_user_kernel.c.