TIOVX User Guide
|
#include <stdio.h>
#include <VX/vx.h>
#include <TI/tivx.h>
#include <utility.h>
#include <ch03_graph/phase_rgb_user_kernel.h>
Go to the source code of this file.
Macros | |
#define | IN_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_graph_image_gradients_phase_out.bmp" |
Input file name. | |
#define | OUT_USER_KERNEL_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_graph_user_kernel_out.bmp" |
Output file name when tutorial is run with user kernel. | |
#define | OUT_TARGET_KERNEL_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_graph_target_kernel_out.bmp" |
Output file name when tutorial is run with target kernel. | |
Functions | |
void | vx_tutorial_graph_user_kernel (vx_bool add_as_target_kernel) |
Tutorial Entry Point. More... | |
Show example usage of developing and invoking a user kernel
OpenVX allows users to define their own nodes called user kernels and provides an API to implement and invoke these user kernels. Once defined and implemented, user kernels can be added as any other node in an OpenVX graph
OpenVX user kernels need to run on the "HOST" CPU, i.e CPU where OpenVX APIs are invoked. This can be limiting for users who want to exploit performnance of specialized targets, like DSP, to execute their own functions. For this purpose, TIOVX specifies an API to define and implement "target kernels" . Like user kernels, once a target kernel is defined and implemented on a target (ex, DSP), it can be invoked as a normal node in an OpenVX graph using standard OpenVX APIs.
Most of the host side logic remains same for both user kernel and target kernel. For target kernel, additional target specific implementation is required on the required on target.
In this tutorial we learn below concepts,
The custom kernel (user or target) we define in this tutorial does the below,
NOTE: Make sure to run vx_tutorial_graph_image_gradients.c before running this tutorial, since output file from vx_tutorial_graph_image_gradients.c is used as input by this tutorial
HOST side implementation
NOTE:
The implementation on HOST side for user kernel and target kernel is largely the same. Any difference in implementation between user kernel and target kernel is shown by using using boolen variable 'add_as_target_kernel'.
Include below file to use the HOST callable interface for the user/target kernel
Definition in file vx_tutorial_graph_user_kernel.c.
void vx_tutorial_graph_user_kernel | ( | vx_bool | add_as_target_kernel | ) |
Tutorial Entry Point.
add_as_target_kernel | [in] 'vx_false_e', run this tutorial with custom kernel running as user kernel 'vx_true_e', run this tutorial with custom kernel running as target kernel |
- Define OpenVX object references required to invoke the user/target kernel
We need an OpenVX context, a graph to execute the node, a node to invoke the user target/kernel, and input/output image for the node.
- Specify the output file name
In order to compare and confirm that the user kernel and target kernel generate the same output we specify a different output file for user and target kernel
- Create OpenVX context
- Register user or target kernel into the OpenVX context
This is required so that the user kernel or target can be invoked as any other node within an OpenVX graph. 'add_as_target_kernel' is used specify whether to register kernel as user kernel or target kernel.
This function is implemented in phase_rgb_user_kernel.c
Rest of the implementation post this is same for both user kernel and target kernel.
- Create input image and load input data into it
A name is given to the input image object via vxSetReferenceName. Image attributes are shown for informative purpose and width x height queried for later use.
- Create output image
Output image dimensions as same as input image.
- Create a graph object to execute the user/target kernel node
- Create a node for the registered user/target kernel and insert into the graph
This function is implemented in phase_rgb_user_kernel.c
- Verify the graph using standard OpenVX API
export graph to dot file, which can be coverted to jpg using dot tool
- Excute the graph using standard OpenVX APIs
Ouptut image is saved to specified output file.
- Release image, node, graph objects
- Unregister user/kernel from the context
This function is implemented in phase_rgb_user_kernel.c
- Finally release the OpenVX context
Definition at line 151 of file vx_tutorial_graph_user_kernel.c.