Kernel with Class Templates - 2022.1 English

Vitis Model Composer User Guide (UG1483)

Document ID
Release Date
2022.1 English

You may require a class implementation that remains the same for all classes but the data types vary. Vitis Model Composer supports importing the kernels with class templates using the AIE Class Kernel block. Consider the following example which declares the class template in kernel.h.


#include <adf.h>
template<typename T, int N>
class MyKernel {
   int m_count;
   void myFunc(input_stream<T>  *i1,
               output_stream<T> *o1,
               output_stream<int> *o2);
    static void registerKernelClass()

In this case, the default constructor initializer m_count(N) initializes m_count with template parameter N as shown in te following kernel.cpp code.


#include "kernel.h"
template<typename T, int N>
   : m_count(N)
template<typename T, int N>
MyKernel<T,N>::myFunc(input_stream<T>  *i1,
                      output_stream<T> *o1,
                      output_stream<int> *o2)
   put_ms(0, get_ss(0) * N);
   writeincr(o2, m_count);

After successfully importing the kernel with class template using the AIE Class Kernel block, the Function tab displays. Here you can enter appropriate values in the user-editable configuration parameters. Click Apply to see the updated interface in the Block Parameters dialog box the AIE Class Kernel block.

Redirect to the Kernel Class tab in the Block Parameters dialog box to review the template class declaration from the kernel class variant. In the Kernel Class tab, you can enter the value of a template type parameter 'T' and a template non-type parameter of integral type as shown.

Figure 1. Kernel Class Template
  1. Template type parameters can be any valid window, stream, or RTP datatypes.
  2. Only a value that has an integral type is supported for template non-type parameters.
  3. MATLAB variables can be used to specify non-type template parameters.