Shared Graph-Scoped Tables - 2023.1 English

AI Engine Kernel and Graph Programming Guide (UG1079)

Document ID
UG1079
Release Date
2023-06-23
Version
2023.1 English

Sometimes, the same table definition is used in multiple kernels. Because the AI Engine architecture is a distributed address-space architecture, each processor binary image that executes such a kernel needs to have that table defined in its own local memory. To get the correct graph linkage spread across multiple processors, you must declare the tables as extern within the kernel source file as well as the graph class definition file. Then, the actual table definition needs to be specified in a separate header file that is attached as a property to the kernel as shown below.

#include <adf.h>
extern int16 lutarray[8];
class simple_lut_graph : public adf::graph {
public:
  kernel k;
  parameter p;

  simple_lut_graph() {
    k = kernel::create(simple);
    p = parameter::array(lutarray);
    connect(p,k);

    std::vector<std::string> myheaders;
    myheaders.push_back("./user_parameter.h");
    headers(k) = myheaders;
    location<parameter>(p)={address(0,1,0x1000)};
    ...
  }
}

This ensures that the header file that defines the table is included in the final binary link wherever this kernel is used without causing re-definition errors.

Note: Large look-up tables (>32 KB) are not supported.
Note: Shared data either has to be managed explicitly as run-time parameters or declared at the file scope, which is shared across all kernels mapped to the same AI Engine.