You may require a generic function that can be used for different datatypes. Using templates, you can pass a datatype as a parameter and Model Composer supports importing an AI Engine Kernel with a function template. To do this, use the AIE Template Kernel block from the AI Engine library.
Double-Clicking the block symbol displays the parameters of the AIE Template Kernel block as shown in the following figure.
The block mask parameters need to be updated in order to import the kernel function as a block. The following table provides details on the parameters and description for each parameter.
Parameter Name | Parameter Type | Criticality | Description |
---|---|---|---|
Kernel header file | String | Mandatory | Name of the header file that contains the kernel function declaration. The string could be just the file name, a relative path to the file, or an absolute path of the file. Use the browse button to choose the file. |
Kernel function | String | Mandatory | Name of the kernel function for which the block is to be created. This function should be declared in the Kernel header file. |
Kernel init function | String | Optional | Name of the initialization function used by the kernel function. |
Kernel source file | String | Mandatory | Name of the source file that contains the kernel function definition. The string could be the file name, a relative path to the file or an absolute path of the file. |
Kernel search paths | Vector of Strings | Optional |
If the kernel header file or the kernel source file are not found using the value provided through the Kernel header file or Kernel source file fields, respectively, then the paths provided through Kernel search paths are used to find the files. This parameter allows use of environment variables while specifying
paths for the kernel header file and the kernel source file. The
environment variable can be used in either |
Preprocessor options | Optional | Optional preprocessor arguments for downstream compilation with
specific preprocessor options. The following two preprocessor option
formats are accepted and multiple can be selected:
|
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.
kernel.h
#ifndef _AIE_TEMP_KERNELS_H_
#define _AIE_TEMP_KERNELS_H_
#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.
kernel.cpp
#include "kernel.h"
template<typename T, int N>
void
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 Template Kernel block and update the parameters as follows.
- Kernel header file
- kernels/include/kernel.h
- Kernel function
-
myFunc
- Kernel Init function
- Leave empty
- Kernel source file
- kernels/source/kernel.cpp
- Kernel search path
- Leave empty
- Preprocessor options
- Leave empty
When you click the Import button in the block parameters GUI, 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 Parameter section as shown in the folowing 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.
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.
After entering the appropriate values in the Function tab, click Apply. Notice the updated interface of theAIE Template kernel block GUI as shown in the following figure.