0

I hope I have a simple problem, but I could not solve it during this day, so I ask for your help.

So, I`m building CUDA project in Visual studio 2010, using CUDA toolkit.

My project contains several files, and the three most important are:

//tvector_traits_kernel.cu

//contains two fuctions, the first is cuda kernel, and the second is it`s wrapper, to call it in .cpp files

template < typename _T >
__ global __ void DaxpyKernel(lint64 _m, lint64 _na, lint64 _nb, _T *_amatr, _T *_bmatr, _T *_cmatr)
{
...
}

template < typename _T >
void DaxpyKernelWrapper(lint64 _m, lint64 _na, lint64 _nb, _T *_amatr, _T *_bmatr, _T *_cmat)
{
...
}

//tvector_traits_kernel.h

//contains wrapper fuction`s prototipe

template < typename _T >
void DaxpyKernelWrapper(lint64 _m, lint64 _na, lint64 _nb, _T *_amatr, _T *_bmatr, _T *_cmat);

//main.cpp

//it just calls  DaxpyKernelWrapper fuction and includes tvector_traits_kernel.h

but while linking I have an error:
Error   3   error LNK2019: external symbol unresolved  "void __cdecl DaxpyKernelWrapper<float>(__int64,__int64,__int64,float *,float *,float *)" (??$DaxpyKernelWrapper@M@@YAX_J00PAM11@Z) in functions "public: static void __cdecl CTVect_traits<float>::CudaBlockDaxpy(__int64,__int64,__int64,float *,float *,float *)" (?CudaBlockDaxpy@?$CTVect_traits@M@@SAX_J00PAM11@Z) C:\Users\ckhgjh\Documents\GPU\Tesis\Test\test.obj   Test

I wonder why, becouse "tvector_traits_kernel.cu" is in projects source files, its objective file was sucsessfully created.

I`m new in Visual studio, previously I used gcc, so I managed linking process myself. So my question may be very stupid :(

Thank you for your attention!

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • unfamiliar with Cuda, but guessing your template isn't expanding because its definition is in the wrong translation unit. If you `dumpbin` the object code from your .cu file I bet it doesn't have what you think it does. Move **all** your template code, including the template code in the .cu file, to single header and include *that* in `main.cpp`. [See this question](http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) for more info if this is indeed the problem. – WhozCraig Aug 11 '14 at 19:56
  • 1
    Your function is a template function. The compiler needs to know what the template argument is in compile time (look [here](http://www.parashift.com/c++-faq-lite/templates-defn-vs-decl.html) for a better explanation, or even better [here](http://www.parashift.com/c++-faq-lite/separate-template-fn-defn-from-decl.html)). You probably need to explicitly ask for a `float` specialization in `main`. – triple_r Aug 11 '14 at 19:57
  • Actually I think you need to ask for a `float` specialization of `DaxpyKernelWrapper` in `tvector_traits_kernel.cu`, where the template definition is. This is a common problem and is a duplicate of other questions on SO (and has nothing to do with CUDA.) – Robert Crovella Aug 13 '14 at 14:52
  • [This question](http://stackoverflow.com/questions/10632251/undefined-reference-to-template-function) also provides a similar set of answers. – Robert Crovella Aug 13 '14 at 14:57

0 Answers0