TIOVX User Guide
vx_tutorial_graph_user_kernel_pytiovx.c File Reference
#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...
 

Detailed Description

Show example usage of using user kernel in larger graph.

In the tutorial we learn below concepts,

  • Use the user/target kernel defined in tutorial vx_tutorial_graph_user_kernel.c in a larger graph
  • Specify the user defined kernel in .py file in using PyTIOVX APIs
  • Generate the graph code using the user defined kernel and other built-in kernels using the PyTIOVX APIs.

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

#include <ch03_graph/vx_tutorial_graph_user_kernel_pytiovx_uc.h>

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'.

  • When 'add_as_target_kernel' is 'vx_false_e', it is the implementation for user kernel.
  • When 'add_as_target_kernel' is 'vx_true_e', it is the implementation for 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.

Function Documentation

◆ vx_tutorial_graph_user_kernel_pytiovx()

void vx_tutorial_graph_user_kernel_pytiovx ( vx_bool  add_as_target_kernel)

Tutorial Entry Point.

Parameters
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.

/
vx_tutorial_graph_user_kernel_pytiovx_uc_t uc;





























- Define the OpenVX context

/
vx_context context = NULL;



























- 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

/
char *out_file = OUT_USER_KERNEL_FILE_NAME;
if(add_as_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

/
context = vxCreateContext();























- 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.

/
status = phase_rgb_user_kernel_add(context, add_as_target_kernel);
if(status!=(vx_status)VX_SUCCESS)
{
printf(" vx_tutorial_graph_user_kernel_pytiovx: ERROR: unable to add user kernel !!!\n");
}





















- 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

/
vx_tutorial_graph_user_kernel_pytiovx_uc_create(&uc, add_as_target_kernel);



















- 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

/
printf(" Loading file %s ...\n", IN_FILE_NAME);

















- 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

/
vx_tutorial_graph_user_kernel_pytiovx_uc_verify(&uc);


export graph to dot file, which can be coverted to jpg using dot tool
/
tivxExportGraphToDot(uc.graph_0, ".", "vx_tutorial_graph_user_kernel_pytiovx");











- Call generated API to run graphs present in this use-case

/
vx_tutorial_graph_user_kernel_pytiovx_uc_run(&uc);









- Print graph execution info, save output data to file

/
printf(" Saving to file %s ...\n", out_file);
tivx_utils_save_vximage_to_bmpfile(out_file, uc.phase_rgb);







- Call generated API to delete this use-case

This releases the data objects, nodes, graphs and context associated with this use-case

/
vx_tutorial_graph_user_kernel_pytiovx_uc_delete(&uc);





- Unregister user/kernel from the context

This function is implemented in phase_rgb_user_kernel.c



- Finally release the OpenVX context

/
vxReleaseContext(&context);

Definition at line 138 of file vx_tutorial_graph_user_kernel_pytiovx.c.