Static File-Scoped Tables - 2022.2 English

AI Engine Kernel and Graph Programming Guide (UG1079)

Document ID
UG1079
Release Date
2022-10-19
Version
2022.2 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 int32 lutarray[8] = {1,2,3,4,5,6,0,0} ; 

#endif

This header file can be included in the kernel source file and the look-up 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 then 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"

void simple_lut(input_window<int32> * in, output_window<int32> * out){
  aie::vector<int32,16> sbuff;
  aie::accum<acc80,4> acc;
  aie::vector<int32,8> coeffs=aie::load_v<8>((int32*)lutarray);

  window_readincr_v<16>(in, sbuff);
  acc = aie::sliding_mul<4,8>(coeffs, 0, sbuff, 0);
  window_writeincr(out, acc.template to_vector(0));
}