Static File-Scoped Tables - 2024.1 English

AI Engine Kernel and Graph Programming Guide (UG1079)

Document ID
UG1079
Release Date
2024-06-05
Version
2024.1 English

Kernel functions can use private, read-only data structures that are accessed as file-scoped variables. The compiler allocates a limited amount of static heap space for such data. As an example, consider the following header file (user_parameter.h).

#ifndef USER_PARAMETER_H
#define USER_PARAMETER_H

#include <adf.h>
static int16 lutarray[8] = {1,2,3,4,5,6,0,0} ; 

#endif

This header file can be included in the kernel source file and the lookup table can be accessed inside a kernel function directly. The static modifier ensures that the array definition is local to this file. The AI Engine compiler allocates this array in static heap space for the processor where this kernel is used.

#include <aie_api/aie.hpp>
#include <aie_api/aie_adf.hpp>
#include "user_parameter.h"

using namespace adf;
void simple_lut(input_buffer<int16> &in, output_buffer<int16> &out){
  aie::vector<int16,32> sbuff;
  aie::vector<int16,8> coeffs=aie::load_v<8>((int16*)lutarray);
  auto inIter=aie::begin_vector<32>(in);
  sbuff=*inIter++;
  auto acc = aie::sliding_mul<8,16>(coeffs, 0, sbuff, 0);
  auto outIter=aie::begin_vector<8>(out);
  *outIter++=acc.to_vector<int16>(0);
}