我是cuda編程的新手(而不是在C++中經驗豐富),所以我一直在閱讀以嘗試找到解決此問題的方法,但通常不瞭解人們嘗試和解釋,並沒有得到它的工作。在cuda/c + +代碼中使用模板類
基本上,我有一個包含兩件事.CU文件:
template <class ModelType>
__global__ void Stepkernel(ModelType *particles)
和:
template <class ModelType>
void runTest(ModelType *particles)
我然後有一個頭文件,其中SamplerI.h我沒寫,但我試圖包含上面的void函數的調用,所以,低於所有#包括我有:
template <class ModelType>
void runTest(ModelType *particles);
和在後面的標題裏有一個函數,其中包含了對上述的調用。
頭和相關文件在庫libdnest被編譯,我編譯NVCC -c step.cu的.CU文件,然後用鏈接:
g++ -o main main.cpp step.o -ldnest
現在,如果模板心不是存在(即我只是有沒有提到ModelType的void函數)所有這一切都變大了,它編譯和運行,但只要我嘗試,包括模板,我得到以下編譯錯誤:
../../include/SamplerImpl.h: In member function ‘bool DNest3::Sampler<ModelType>::step() [with ModelType = Banana]’:
../../include/SamplerImpl.h:121: instantiated from ‘void DNest3::Sampler<ModelType>::run() [with ModelType = Banana]’
main.cpp:37: instantiated from here
../../include/SamplerImpl.h:159: error: no matching function for call to ‘runTest(Banana*)’
和我不知道該怎麼做來修復它...
有沒有人有任何想法?如果我沒有解釋得夠好,讓我知道,我會嘗試,幷包括更多的信息,我真的不知道什麼是重要的。
乾杯 林德利
你說你在C++中不是很有經驗。如果你在C#中更加舒適,你可以看看CUDA編程的C#工具包[CUDAfy.NET](http://cudafy.codeplex.com/)。 – 2013-02-28 19:48:16