In Creating a Data Flow Graph (Including Kernels) the discussion was centered around a very simple AI Engine graph application. The top-level application initialized the graph, ran the graph, and ended the graph. However, for actual AI Engine graph applications the host code must do much more than those simple tasks. The top-level PS application running on the Cortex™-A72, controls the graph and PL kernels: manage data inputs to the graph, handle data outputs from the graph, and control any PL kernels working with the graph.
In addition, AI Engine graph applications can
be run on Linux operating systems or on bare-metal systems. The requirements for
programming in these two systems are significantly different as outlined in the
following topics. Xilinx provides drivers used by the
API calls in the host program to control the graph and PL kernels based on the operating
system. In Linux this is provided by the libadf_api_xrt
library, in bare-metal the AI Engine kernels are
controlled using the graph APIs, and PL kernels are controlled using libUIO
driver calls.
Preventing Multiple Graph Executions
In cases where your graph is implemented in a PS-based host application, you
must define a conditional pragma (#ifdef
) for your
graph.cpp code to ensure the graph is only
initialized once, or run only once. The following example code is the simple
application defined in Creating a Data Flow Graph (Including Kernels) with the
additional guard macros __AIESIM__
and __ADF_FRONTEND__
..
#include "project.h"
simpleGraph mygraph;
simulation::platform<1,1> platform(“input.txt”,”output.txt”);
connect<> net0(platform.src[0], mygraph.in);
connect<> net1(mygraph.out, platform.sink[0]);
#if defined(__AIESIM__) || defined(__ADF_FRONTEND__)
int main(void) {
mygraph.init();
mygraph.run(<number_of_iterations>);
mygraph.end();
return 0;
}
#endif
This conditional directive compiles the application only for use with the AI Engine simulator. It prevents the graph from being initialized or run multiple times, from both the graph and PS host application. The directive lets the graph.cpp run in simulation or in hardware emulation of the system design, which also runs in the AI Engine simulator and x86simulator. However when running in hardware, the graph is initialized and run from the PS application, rather than from the graph.cpp.