Importing an AI Engine Kernel with Function Template - 2022.1 English

Vitis Model Composer User Guide (UG1483)

Document ID
Release Date
2022.1 English

You may require a generic function that can be used for different datatypes. Using templates, you can pass a datatype as a parameter and Vitis Model Composer supports importing an AI Engine Kernel with a function template. To do this, use the same AIE Kernel block used earlier to import the ordinary C++ functions.

As an example to import the kernel function with templates, consider below header file kernel.h, containing the declaration of a function template. Here, the template has typename template parameter T, and a non-type (integral) template parameter N.


#include <adf.h>
template<typename T, int N>
void myFunc(input_window<T>  *i1,
            output_window<T> *o1
#endif // ifndef _AIE_TEMP_KERNELS_H

The definition of the function template is in the source file kernel.cpp as shown below.


#include "kernel.h"
template<typename T, int N>
myFunc(input_window<T>  *i1,
       output_window<T> *o1
   for(int i = 0;i<8;i++)
       T val = window_readincr(i1);
       val *= N;
       window_writeincr(o1, val);

Notice the usage of the non-type template parameter 'N' in the kernel output computation. To import the template function as a block into Model Composer, double-click the AIE Kernel block and update the parameters as follows.

Kernel header file
Kernel function
Kernel Init function
Leave empty
Kernel source file
Kernel search path
Leave empty
Preprocessor options
Leave empty

When you click the Import button in the Block Parameters dialog box, the Function tab displays automatically. Enter the values of a template type parameter 'T' and a template non-type parameter of integral type within the Function Template Parameters section as shown in the following figure. Double-click the appropriate editable field and enter the values. You can also review the declaration of the template function in the Function declaration section.

Figure 1. AIE Kernel: Function declaration Section

The following typenames are supported as type template parameters:

  • int8, int16, int32, int64
  • uint8, uint16, uint32, uint64
  • float, double
  • cint16, cint32, cfloat

Scroll down to the Port attributes section in the Function tab and enter appropriate user-editable configuration parameters as shown.

Figure 2. AIE Kernel: Port attributes Section

After entering the appropriate values in the Function tab, click Apply. Notice the updated interface of the AIE kernel block GUI as shown in the following figure.

Figure 3. AIE Kernel: Updated