When building large graphs with multiple subgraphs, it is sometimes useful to control the exact mapping of kernels to AI Engine-MLs, either relative to other kernels or in an absolute sense. The AI Engine compiler provides a mechanism to specify location constraints for kernels, which when used with the C++ template class specification, provides a powerful mechanism to create a robust, scalable, and predictable mapping of your graph onto the AI Engine-ML array. It also reduces the choices for the mapper to try, which can considerably speed up the mapper. Consider the following graph specification:
#include <adf.h>
#include "kernels.h
#define NUMCORES (COLS*ROWS)
using namespace adf;
template <int COLS, int ROWS, int STARTCOL, int STARTROW>
class indep_nodes_graph1 : public graph {
public:
kernel kr[NUMCORES];
port<input> datain[NUMCORES] ;
port<output> dataout[NUMCORES] ;
indep_nodes_graph1() {
for (int i = 0; i < COLS; i++) {
for (int j = 0; j < ROWS; j++) {
int k = i*ROWS + j;
kr[k] = kernel::create(mykernel);
source(kr[k]) = "kernels/kernel.cc";
runtime<ratio>(kr[k]) = 0.9;
location<kernel>(kr[k]) = tile(STARTCOL+i, STARTROW+j);
}
}
for (int i = 0; i < NUMCORES; i++) {
connect(datain[i], kr[i].in[0]);
connect(kr[i].out[0], dataout[i]);
}
};
};
The template parameters identify a COLS x ROWS logical array of kernels (COLS x ROWS = NUMCORES) that are placed within a larger logical device of some dimensionality starting at (STARTCOL, STARTROW) as the origin. Each kernel in that graph is constrained to be placed on a specific AI Engine-ML. This is accomplished using an absolute location constraint for each kernel placing it on a specific processor tile. For example, the following declaration would create a 1 x 2 kernel array starting at offset (3,2). When embedded within a 4 x 4 logical device topology, the kernel array is constrained to the top right corner.
indep_nodes_graph1<1,2,3,2> mygraph;
location<absolute>(k), function to specify kernel
constraints and proc(x,y) function to specify a processor
tile location. These functions are now deprecated. Instead, use location<kernel>(k) to specify the kernel constraints and tile(x,y) to identify a specific tile
location.