TIOVX User Guide
|
#include <stdio.h>
#include <VX/vx.h>
#include <TI/tivx.h>
#include <utility.h>
#include <ch03_graph/vx_tutorial_graph_user_kernel_pytiovx_uc.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}/colors.bmp" |
Input file name. | |
#define | OUT_USER_KERNEL_FILE_NAME "${VX_TEST_DATA_PATH}/vx_tutorial_graph_user_kernel_pytiovx_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_pytiovx_out.bmp" |
Output file name when tutorial is run with target kernel. | |
Functions | |
void | vx_tutorial_graph_user_kernel_pytiovx (vx_bool add_as_target_kernel) |
Tutorial Entry Point. More... | |
Show example usage of using user kernel in larger graph.
In the tutorial we learn below concepts,
When using PyTIOVX tool, first create a .py file which describes the OpenVX graph. Follow comments in vx_tutorial_graph_user_kernel_pytiovx_uc.py to understand the graph description basic API. In this example, we also use the PyTIOVX API to define a user defined kernel. This allows user to add their own kernels to the tool without having to modify deep within the tool.
Next PyTIOVX tool is run to generate .c/.h file for the graph described in .py file. A .jpg file which shows the graph visually is also generated in the process.
Follow steps mentioned in PyTIOVX user guide [HTML] to install and run the PyTIOVX tool. See also additional APIs provided to describe a graph via PyTIOVX.
For this example, run below command to generate the code and image file
Include the generated C code API header file
Note, that the generated file name and APIs use as prefix the string name passed as input during context create in the .py file.
Follow the comments in the function vx_tutorial_graph_user_kernel_pytiovx() to complete the rest of tutorial code to invoke the generated OpenVX graph.
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_pytiovx.c.
void vx_tutorial_graph_user_kernel_pytiovx | ( | 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 the data structure representing the generated OpenVX use-case code.
This structure includes the context, data object, node, graph handles for the generated code.
- Define the OpenVX context
- 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
Even though the generated use-case creates OpenVX context later, we create it here, so as to allow us to register the user/target kernel, before creating the OpenVX use-case
- 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 the OpenVX use-case using the generated create API.
This creates the OpenVX context, data objects, nodes and graph for this use-case.
NOTE: graph verify is not yet called.
NOTE: Any customization like changing parameter values, loading data to data objects should be done next, before calling graph verify
- Load input into input data reference
NOTE: the data reference names in the use-case structure, match the name specified via name="xyz" in the .py file
- Print data object info for debug purposes
- Call generated API to verify graphs present in this use-case
Also prints graph info for debug purposes
export graph to dot file, which can be coverted to jpg using dot tool
- Call generated API to run graphs present in this use-case
- Print graph execution info, save output data to file
- Call generated API to delete this use-case
This releases the data objects, nodes, graphs and context associated with this use-case
- Unregister user/kernel from the context
This function is implemented in phase_rgb_user_kernel.c
- Finally release the OpenVX context
Definition at line 138 of file vx_tutorial_graph_user_kernel_pytiovx.c.