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:
-
aie_api/aie.hpp
- AI Engine main entry point.
-
aie_api/aie_adf.hpp
- 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++)
chess_prepare_for_pipelining
chess_loop_range(4,)
{
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);
window_writeincr(out,vresult);
}
}
For more information about the window interface API usage, see Window and Streaming Data API in the Versal ACAP AI Engine Programming Environment User Guide (UG1076). Vector data type and operations are covered in following sections.