Template Partial Specialization - 2022.2 English

Vitis Model Composer User Guide (UG1483)

Document ID
UG1483
Release Date
2023-01-13
Version
2022.2 English

For cases where you write a template that specializes one template parameter and still allows some parameterization, you can use the template partial specialization. Vitis Model Composer allows you to import the class kernels with partial specialization using the AIE Class Kernel block. Consider the following example where a class class_a is partially specialized with a non-type template parameter.

partial_specialization.h

#include <adf.h>
template<typename T,int N>
class class_a
{
};
 
template<typename T>
class class_a<T,2> {
   int m_count;
   T var;
public:
   class_a(T q_var1);
       
   void func_mem(input_stream<T>  *i1,
                      output_stream<T> *o1,
                      output_stream<int> *o2);
 
    static void registerKernelClass()
    {
        REGISTER_FUNCTION(class_a::func_mem);
    }
    
};

Notice that the function func_mem is registered in registerKernelClass() method. When you try to import the kernel function as a block into Model Composer using the AIE Class Kernel block, the Kernel Class tab in the Block Parameters dialog box looks as shown.

Figure 1. Block Parameters: AIE Class Kernel

Because the class is partially specialized with a non-type template parameter, you cannot edit the parameter 'N' from the Kernel Class Template Parameters. However, the value of the template type parameter can be a modified to any valid datatype.