As an example, to import the C++ class kernel with the default constructor, consider
the following simple.h header file that defines the kernel class
simple_class with the default constructor.
simple.h
#include "adf.h"
using namespace adf;
class simple_class
{
private:
int16 val;
int16 numSamples;
public:
simple_class();
void mulBytwo(input_buffer<int16> & in, output_buffer<int16> & out);
static void registerKernelClass()
{
REGISTER_FUNCTION(simple_class::mulBytwo);
}
};
.cpp file.You must register the kernel function using the registerKernelClass() method. More than one class kernel can be
declared in a header file and each class must contain separate registerKernelClass() methods. You can register only
one function per class and Vitis Model Composer
can import only functions that are registered using REGISTER_FUNCTION().
The Kernel function is defined in simple.cpp as shown below.
simple.cpp
#include "simple.h"
simple_class::Simple_class()
{
val = 24;
numSamples = 8;
}
void simple_class::mulBytwo(input_buffer<int16> & in, output_buffer<int16> & out)
{
auto pIn = aie::begin(in);
auto pOut = aie::begin(out);
for (int i=0; i<numSamples; i++)
{
*pOut++ = 2*(*pIn++) + val;
}
}
To import the mulBytwo function as a block in
a Vitis Model Composer design, double-click the
AIE Class Kernel block. Then update the parameters as
follows:
- Kernel header file
- simple.h
- Kernel class
-
simple_class - Kernel function
-
mulBytwo - Kernel source file
- simple.cpp
- Kernel search path
- Leave empty
- Preprocessor options
- Leave empty
Click the Import button in the Block Parameters dialog box. After successful import, the Function tab displays. This provides user-editable configuration parameters as shown in the following figure.
After entering the appropriate values in the Function tab, click Apply to see the updated interface of the AIE Class Kernel block GUI as shown.
You can quickly review the function declaration of the imported kernel function and the port names with directions, from the Function tab.
Click the Kernel Class tab to observe the class declaration as shown in the following figure.