Linking Multiple Sub-Graphs - 2024.2 English

AI Engine-ML Kernel and Graph Programming Guide (UG1603)

Document ID
UG1603
Release Date
2024-11-28
Version
2024.2 English

You can link several sub-graphs to create a larger test or application graph. You can develop graphs as entities independent from the I/Os, and embed these graphs in other graphs that contain the necessary PLIO and GMIO definitions to connect the graph to the external world. This allows you to independently test your graph and connect it to other graphs to build larger applications.

The benefit of this methodology is that you do not need to know the size of the buffers or the type of connection within the sub-graph. This allows you to independently develop the graphs and the kernels within the graph. When compiling the larger test or application graph the compiler will automatically adapt various I/O port types with the necessary hardware interposers. For example, as long as the connect statement which connects a stream PLIO input of a graph to a buffer input of another graph is specified in the test graph, the compiler will automatically connect the stream PLIO output port of one graph to the buffer input port of another graph.

class TestMoreComplexGraph: public adf::graph {
public:
  adf::input_plio plin;
  adf::output_plio plout;

  SplitGraph AddedGraph;
  MergeGraph AnotherGraph;
  SimplestGraph Simple;

  TestMoreComplexGraph()
  {
    plin = adf::input_plio::create("input2",adf::plio_64_bits,"data/Input_64.txt",500);
    adf::connect(plin.out[0],AddedGraph.din);

    adf::connect(AddedGraph.dout[0],Simple.din);
    adf::connect(Simple.dout,AnotherGraph.din[0]);
    adf::connect(AddedGraph.dout[1],AnotherGraph.din[1]);

    plout = adf::output_plio::create("output2",adf::plio_64_bits,"data/Output2.txt",500);
    adf::connect(AnotherGraph.dout,plout.in[0]);
  };
};
TestMoreComplexGraph MoreComplexUnitTest;

int main(int argc, char ** argv) {

  MoreComplexUnitTest.init();
  MoreComplexUnitTest.run(NFRAMES*NITERATIONS);
  MoreComplexUnitTest.end();
  return 0;
}
Figure 1. Graph View

You do not need to change anything in graph Simple when it is connected to AddedGraph and AnotherGraph. It can be error prone as soon as you start to have many sub-graphs. To avoid errors, it is recommended that SimplestGraph graph definition can be in its own file. Any modifications to the graph file will change the behavior of UnitTest and MoreComplexUnitTest.