As discussed in AI Engine Graphs, a graph is a connection of different compute kernel functions. Unlike when importing kernels, where a kernel function is imported as a block into Model Composer, in this case, graph code is imported as a block. To import the graph as block into Model Composer, you need to select the AI Engine graph block from the AI Engine library (shown in the following figure).
Model Composer allows to connect the AI Engine graph block with the AI Engine kernel block so that the whole design can be simulated in the Simulink environment.
The AIE Graph block supports importing the AI Engine graph into Model Composer in two ways:
- Using the header file(*.h)
- Using the source file(*.cpp)
Using the Header File
To import the graph using the header file (.h), double-click the AIE Graph block and select the Header file (*.h) option in the General tab. Specify the graph header file, class, search path, and preprocessor options as shown in the following figure.
The following table provides further details including names and descriptions of each parameter.
Parameter Name | Parameter Type | Criticality | Description |
---|---|---|---|
Graph Application file(*.h) | String | Mandatory | Specify the file(.h), where the application graph class is defined and the Adaptive Data Flow (ADF) header (adf.h), kernel function prototypes are included. |
Graph Class | String | Mandatory | Specify the name of the graph class. |
Graph Search paths | Vector of strings | Mandatory | Specify search paths where header files, kernels, and other include files can be found and included for simulation. The search path $XILINX_VITIS/adf/include (where adf.h isdefined) is be included by default and does not need to be specified. |
Preprocessor options | Optional | Optional preprocessor arguments for downstream compilation with
specific preprocessor options. The following preprocessor option
formats are accepted and multiple can be selected:
‘-Dname ’ and
‘-Dname=definition ’. That is, the optional
argument must begin with the '-D ' string and if the
option definition value is not provided, it is assumed to be
1. |
graph.h
#include <adf.h>
#include "kernels.h"
class Proj: public adf::graph {
private:
adf::kernel m_kernels[2];
public:
adf::input_port m_in[2];
adf::output_port m_out[2];
Proj() {
for (int ind = 0; ind < 2; ++ind) {
m_kernels[ind] = adf::kernel::create(f1);
adf::runtime<adf::ratio>(m_kernels[ind]) = 0.9;
adf::connect<adf::stream >(m_in[ind], m_kernels[ind].in[0]);
adf::connect<adf::stream >(m_kernels[ind].out[0], m_out[ind]);
}
adf::source(m_kernels[0]) = "f1.cc";
adf::source(m_kernels[1]) = "f2.cc";
}
};
When the GUI parameters are updated, click the Import button. The tool updates the Block parameters GUI as shown. In the Graph Class tab you can see the RTP column with check boxes. You can check this ON, only if the port is a Run Time Parameter. If not, you can directly click Build at the bottom.
You can see the progress window where the tool generates the graph database. After successful import the Function Tab in the updated block parameters GUI appears as shown in the following figures.
Parameters such as the Graph Port Name, Data Type etc. are automatically updated from the graph code. The only user-editable function configuration parameter is the signal size.
User-Editable Parameter | Criticality | Description |
---|---|---|
Signal size | Mandatory | This parameter represents the size of the output signal and should be set to a value equal to or greater than the number of samples that are produced at every invocation of the kernel. |
The AI Engine graph block GUI interface with input and output ports is as shown in the following figure.
In the General tab, the Import button changes to Update, enabling further update of block parameters.
Using the Source File (*.cpp)
To import the graph using the Source file (.cpp), double-click the AIE Graph block and select the Source file (*.cpp) option in the General tab. Specify the graph application file (*.cpp), search paths, and preprocessor options as shown in the following figure.
The following table provides further details including names and descriptions of each parameter.
Parameter Name | Parameter Type | Criticality | Description |
---|---|---|---|
Graph Application file | String | Mandatory | Specify the file(.cpp), where the adf dataflow graph is instantiated and connected to simulation platform. This file should contain the main() function, from where the dataflow graph initializes and runs. |
Graph Search paths | Vector of strings | Mandatory | Specify search paths where header files, kernels, and other include files can be found and included for simulation. The search path $XILINX_VITIS/adf/include (where adf.h isdefined) is be included by default and does not need to be specified. |
Preprocessor options | Optional | Optional preprocessor arguments for downstream compilation with
specific preprocessor options. The following preprocessor option
formats are accepted and multiple can be selected:
‘-Dname ’ and
‘-Dname=definition ’. That is, the optional
argument must begin with the '-D ' string and if the
option definition value is not provided, it is assumed to be
1. |
The following example shows the sample graph .cpp file. The graph is connected to the simulation platform as follows. This file should be pointed to the Graph application file field in the Block parameters GUI.
graph.cpp
#include "proj.h"
Proj mygraph;
adf::simulation::platform<2,2> platform(
"data/i.txt",
"data/i.txt",
"data/o1.txt",
"data/o2.txt");
adf::connect<> net1(platform.src[0], mygraph.m_in[0]);
adf::connect<> net2(platform.src[1], mygraph.m_in[1]);
adf::connect<> net3(mygraph.m_out[0], platform.sink[0]);
adf::connect<> net4(mygraph.m_out[1], platform.sink[1]);
int main(void) {
mygraph.init();
mygraph.run();
mygraph.end();
return 0;
}
When the GUI parameters are updated, click Import. The tool generates the graph database and after successful import the AI Engine graph block gets updated with input and output ports as shown in the following figure.
Notice that the AIE Graph block interface generated when importing the header file and the source file remains the same.
The Function Tab in the AIE Graph block parameters GUI appears similar to the one shown in the Import graph using the header file. You can update the signal size parameter and click OK to exit the Block parameters window.
- To connect an AI Engine
graph
inout
port to an AI Engine graphinput
RTP port, the synchronocities of both ports must be compatible, otherwise, an appropriate error is reported by Model Composer. - If the RTP port's behavior is different from its default
behavior, the connection should appropriately specify it as an
async
orsync
port in graph code.