[SOLVED] Template kernel


If I want to have a kernel that accept two types of arrays, for example double* and int*, is it possible use templates? Something like this:

template <typename T>
__global__ myKernel(T *data)
    //Some calculates

Is it correct? Could I sent double* and int* arrays?

Thank you.

Yes, its possible to use templates.

A small amount of googling or reading of sample codes will show you some examples. (Or even just try it!)

for example:


and there are many many other examples of templated kernels


Every day I like more CUDA xD

Thank you again txbob.

Templated CUDA kernels are the bees kness, man!

Unfortunately though, kernels oddly enough don’t support the new trailing return syntax. This isn’t related to the issue at hand but it’s the only weird CUDA-ism I’ve encountered that really set it apart from C++.