Kernel Class with Default Constructor - 2022.1 English

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2022-05-26
Version
2022.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"
  
class simple_class
{
private:
    int16 val;
    int16 numSamples;
  
public:
    simple_class();
 
    void mulBytwo(input_window_int16* in, output_window_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_window_int16* in, output_window_int16* out)
{
    for (int i=0; i<numSamples; i++)
    {
        int16 value = window_readincr(in);
        window_writeincr(out, (in*2)+val);
    }
}

To import the mulBytwo function as a block in a Model Composer design, double click the AIE Class Kernel block and update the parameters as follows.

Kernel header file
kernels/include/simple.h
Kernel class
simple_class
Kernel function
mulBytwo
Kernel source file
kernels/source/simple_kernel.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