For cases when you need to override the default template implementation to
handle a particular type in a different way, Vitis Model Composer
supports template specialization. Consider the following example where a class MyClass
has two different interfaces than the generic
MyClass
. One specialized version is declared to
implement the cint16
datatype and other version to
implement the uint32
datatype.
template_specialization.h
#include <adf.h>
template<typename T,int N>
class MyClass
{
};
template<>
class MyClass<cint16,1> {
int m_count;
int16 var_1;
int16 var_2;
int16 var_3;
uint16 var_4;
public:
MyClass();
MyClass(int16 q_var1,int16 q_var2,int16 q_var3,uint16 q_var4);
MyClass(int16 q_var1,int16 q_var2);
MyClass(int16 q_var1,int16 q_var2,int16 q_var3);
void func_mem(input_stream<cint16> *i1,
output_stream<cint16> *o1,
output_stream<int> *o2);
static void registerKernelClass()
{
REGISTER_FUNCTION(MyClass::func_mem);
}
};
template<>
class MyClass<uint32,2> {
int m_count;
int16 var;
public:
MyClass(uint32 q_var1);
void func_mem(input_stream<uint32> *i1,
output_stream<uint32> *o1,
output_stream<int> *o2);
static void registerKernelClass()
{
REGISTER_FUNCTION(MyClass::func_mem);
}
};
You can see that two functions are registered separately in two specialized classes.
When you try to import the kernel func_mem
as a block into Model
Composer using the AIE Class kernel block, the Kernel Class
tab in block GUI parameters looks as shown.
After selecting one of the Kernel Class Variants from the list, the Class Template Parameters update accordingly. The list of Kernel Class Constructors for the corresponding class variant, is updated and you can select from the list (see the following figure).