Kernel Class with Default Constructor - 2024.1 English

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2024-05-30
Version
2024.1 English

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);
 }
};

It is necessary to register the kernel function using the registerKernelClass() method. More than one class kernel can be declared in a header file and each class should contain separate registerKernelClass() methods. Only one function can be registered 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 and 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.

Figure 1. AIE Class Kernel: Block Parameters

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.

Figure 2. AIE Class Kernel after Update

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.

Figure 3. Kernel Class Tab: Class Declaration