I'm writing cuda kernels that can make use of functors, that are passed as a parameter with templates. For example:
template<typename Functor> void myKernel(float arg1, float* arg2, Functor f) {
// Do stuff that will involve f
}
These functors are defined in a header file that I include in each cpp file, and for each one I have to instantiate all the kernels with all the functors:
template<> myKernel<Add>(float, float*, Add)
template<> myKernel<Sub>(float, float*, Sub)
This is a lot of code duplication, and we have to remember to add a new line for each new functor. Is there a way to define all of this once?