I have a project that requires C++11, so I separate the files into two categories: those that use C++11, and those that use C++03 and hence are compatible with the nvcc compiler. When I have a kernel that is not a template function, it is easy to load the module and find the function name using cuModuleGetDataEx
. However, when the kernel is a template, the function name is mangled after explicit specialization. This makes it difficult to obtain a handle to the function after loading the module using the CUDA Driver API. For example, consider this function.
template <class T, class SizeType>
global void
vector_add(const T* a, const T* b, T* c, const SizeType dim)
{
const SizeType i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < dim) { c[i] = a[i] + b[i]; }
}
After I compile it into PTX code, the mangled name is _Z10vector_addIfjEvPKT_S2_PS0_T0_
. How can I find and load template kernel functions easily from my host code, without manually finding them in the file and copying their names?