編譯模板函數在CUDA我有以下CUDA代碼:錯誤使用NVCC
enum METHOD_E {
METH_0 = 0,
METH_1
};
template <enum METHOD_E METH>
inline __device__ int test_func<METH>()
{
return int(METH);
}
__global__ void test_kernel()
{
test_func<METH_0>();
}
void test()
{
test_kernel<<<1, 1>>>();
}
我編譯時出現以下錯誤:編程指南
>nvcc --cuda test.cu
test.cu
test.cu(7): error: test_func is not a template
test.cu(14): error: identifier "test_func" is undefined
test.cu(14): error: expected an expression
3 errors detected in the compilation of "C:/Users/BLAH45~1/AppData/Local/Temp/tm
pxft_00000b60_00000000-6_test.cpp1.ii".
第D.1.4( 4.0,我使用的工具包版本)建議模板應該可以工作,但我無法讓他們去。
任何人都可以建議對此代碼進行更改,使其編譯(不刪除模板!)嗎?
爲什麼聲明'INT test_func( )'包含模板參數? –
talonmies
嗯,我想有許多不同的方法來做不同的事情,並根據模板類型來選擇它們。對於時間來說,只有一個簡單的模板函數,但是一旦我能夠編譯它,我將爲METH_0和METH_1增加更復雜的特化。 – user664303