The following graph control API shows how to use graph APIs to
initialize, run, wait, and terminate graphs for a specific number of iterations. A graph
object mygraph
is declared using a pre-defined graph
class called simpleGraph
. Then, in the main
application, this graph object is initialized and run.
The init()
method loads the graph to the AI Engine array at prespecified AI Engine tiles. This includes loading the ELF binaries for each AI Engine, configuring the stream switches for routing,
and configuring the DMAs for I/O. It leaves the processors in a disabled state. The
run()
method starts the graph execution by enabling
the processors. The run
API is where a specific number
of iterations of the graph can be run by supplying a positive integer argument at run
time. This form is useful for debugging your graph execution.
#include "project.h"
simpleGraph mygraph;
int main(void) {
mygraph.init();
mygraph.run(3); // run 3 iterations
mygraph.wait(); // wait for 3 iterations to finish
mygraph.run(10); // run 10 iterations
mygraph.end(); // wait for 10 iterations to finish
return 0;
}
The API wait()
is used to wait for the first run to
finish before starting the second run. wait
has the
same blocking effect as end
except that it allows
re-running the graph again without having to re-initialize it. Calling run
back-to-back without an intervening wait
to finish that run can have an unpredictable effect
because the run
API modifies the loop bounds of the
active processors of the graph.