AI Engine API Overview - 2021.2 English

AI Engine Kernel Coding Best Practices Guide (UG1079)

Document ID
Release Date
2021.2 English

AI Engine API is a portable programming interface for AI Engine accelerators. It is implemented as a C++ header-only library that provides types and operations that get translated into efficient low-level intrinsics. The API also provides higher-level abstractions such as iterators.

Usually, two header files are needed in kernel source code:

AI Engine main entry point.
Graph window and stream interfaces.

AI Engine API provides a helper file to print aie::vector and aie::mask values in simulation when profiling is enabled:

  • aie_api/utils.hpp: aie::print function is provided.

To support operator overloading on some operations, include header file aie_api/operators.hpp and use namespace aie::operators. For additional information, see Operator Overloading.

An example code for AI Engine kernel is as follows.

#include <aie_api/aie.hpp>
#include <aie_api/aie_adf.hpp>
#include <aie_api/utils.hpp>

void vec_incr(input_window<int32>* data,output_window<int32>* out){
  aie::vector<int32,16> vec1=aie::broadcast(1);//set all elements to 1
  for(int i=0;i<16;i++)
    aie::vector<int32,16> vdata=window_readincr_v<16>(data);
    aie::print(vdata,true,"vdata=");//print vector in a line
    aie::vector<int32,16> vresult=aie::add(vdata,vec1);

For more information about the window interface API usage, see Window and Streaming Data API in the AI Engine User Guide (UG1076). Vector data type and operations are covered in following sections.