我正在写可以使用函子的cuda内核,这些函数是作为模板参数传递的。例如:有没有办法避免在很多文件中实例化大量模板?
template<typename Functor> void myKernel(float arg1, float* arg2, Functor f) {
// Do stuff that will involve f
}
这些函子在头文件,我包括在每个CPP文件中定义,并且为每一个我必须与所有的函子实例化所有的内核:
template<> myKernel<Add>(float, float*, Add)
template<> myKernel<Sub>(float, float*, Sub)
这是很多代码重复,我们必须记住为每个新的函子添加一个新行。 有没有办法定义所有这一切?
预处理宏? – Amit
您是否知道显式实例化? https://msdn.microsoft.com/en-us/library/by56e477.aspx –
我希望有一个不涉及marcros的解决方案。 – Pafnouti