Generating Code

Intel's Vision Algorithm Designer (VAD) supports generating code from any OpenVX* graph. VAD generates C-code which is organized into multiple modules.

The code generation capability is accessible from both the VAD UI () and via the VAD CLI (using the "-g" option).

The generated code is divided into multiple files:

  • main.c: Main function code including the setup and teardown of OpenVX boilerplate code such as OpenVX context creation and graph verification
  • common.c/.h: Common functionality such as generic functions for keeping track of and releasing OpenVX primitives and other allocated objects.

  • <graph_name>.graphml.c/.h: Graph factory function responsible for building the complete graph, including creation of node instances from kernels, all primitives and bindings.
  • <subgraph name>.c/.h: Subgraph function: Kernels, nodes and primitive specific to a subgraph reside in separate files.
  • CMakeLists.txt: CMake* make file for flexible cross platform builds
  • build.sh/.bat: Helper script for invoking CMake build. Check for required dependencies and supports build for multiple configurations

To generate C code for a graph, simply load (or create) a graph in the VAD UI canvas, then Build and Verify the graph to ensure correct syntax. Successful verification will activate the  Code Generation ()  button.

Click this button to generate the code corresponding to the graph workload. Generated code is stored in the generated_code folder relative to the root VAD execution folder. Use the Configuration () button to specify the code generation options as follows:  

Code generation configuration

  • Generate build script – Specify whether to generate the CmakeList.txt and the build.sh/.bat files
  • Generate sub graphs in separate source – If selected, any sub graph will generate a separate source file. Otherwise, all graphs will be generated in the same file and in the same method
  • Generate code for continues execution – If selected, the generated code will contains code to execute the graph in loop. For example, this option can be used for graphs that use grab_video_from_file kernel in order to read next frame on each iteration.
  • Copy graph resources to executable location after build – If selected, when building the generated code, the resources will be copied to the executable location. In addtion, the generated code will include relative path for the resources (relative to the executable).  Use this option in order to generate code that should run on a remote machine. After building the code you can copy the executable and the resources to the remote machine. Since the pathes for the resources are relative, the executed application must be executed from the application location. If not selected, the resources will not be copied to the executable location and the generated code will include absolute path for the resources, so after building the code the executable will be able to executed from any location but only on the local machine.
  • Ignore Kernels –  List of kernels to be ignored in the code generation. The generated code will not contain code for these kernels
  • Ignore Modules - List of modules to be ignored in the code generation. The generated code will not contain code for kernels which are part of these modules.

Each code generation operation generates code into a subfolder (named according to graph project) in this folder.

If the VAD is installed with root permissions the location of the generated code folder must be mapped to a different path where the current user has write permissions.

Building the Generated code

You may setup a build project to build the generated code manually. However, by default, the VAD code generator creates CMake* build file and a build script.

Building for Linux*

Prior to building the generated code, the following prerequisites should be met:

  • GCC* compiler and build-essentials packages are installed.
  • The OPENVX_FOLDER environment variable is set to the location of the OpenVX* runtime installation. OpenVX runtime path should contain the include and lib folders.
  • The location of the OpenVX binaries (typically located in the lib folder) and VAD folder (if org.khronos.openvx-debug or com.intel.helpers kernels are used) are added to the LD_LIBRARY_PATH environment variable, for example:
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/myuser/intel/cvsdk/openvx/lib: /home/myuser/intel/cvsdk/vad
  • OpenCV location is added to the LD_LIBRARY_PATH in order to enable loading of OpenCV com.intel.helpers based kernels, and, in some cases, user kernels. For example:
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/myuser/intel/cvsdk/opencv/lib
  • (Optional) user_kernels folder location is added to the LD_LIBRARY_PATH in order to enable loading of user kernels for example:
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/myuser/intel/cvsdk/vad/user_kernels

To build the generated code, run build.sh Debug|Release x64.

As a result the install directory will be created. The executable can be found at install/Release|Debug/x64/bin.

Building for Windows*

Prior to building the generated code, the following prerequisites should be met:

  1. Microsoft VisualStudio* 2012, 2013, or 2015 is installed.
  2. The OPENVX_FOLDER environment variable is set to the location of the OpenVX* runtime installation. OpenVX runtime path should contain the include and bin folders.
  3. The location of the OpenVX binaries (typically located in the bin folder) and VAD folder (if org.khronos.openvx-debug or com.intel.helpers kernels are used) are added to the PATH environment variable, for example:
    set PATH=%PATH%;%CVSDK_ROOT%\openvx\bin;%CVSDK_ROOT%\vad
  4. OpenCV location is added to the PATH in order to enable loading of OpenCV com.intel.helpers -based kernels and in some cases for user kernels, for example:
    set PATH=%PATH%;%CVSDK_ROOT%\opencv\x64\vc14\bin
  5. (Optional) user_kernels folder location is added to the PATH in order to enable loading of user kernels, for example:
    set PATH=%PATH%;%CVSDK_ROOT%\vad\user_kernels

To build the generated code, run build.bat Debug|Release x64.

As a result install directory will be created. The executable can be found at install\Release|Debug\x64\bin.

For more complete information about compiler optimizations, see our Optimization Notice.