0

私は次のCUDAコードを持っています:

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、私が使用しているツールキットのバージョン)は、テンプレートが機能するはずだと示唆していますが、それらを取得できません。

誰かがこのコードをコンパイルするための変更を提案できますか(テンプレートを削除せずに!)?

4

2 に答える 2

3

test_funcの定義が間違っています:

test_func()は単にtest_func()である必要があります

これは私のために働きます:

enum METHOD_E {
    METH_0 = 0,
    METH_1
};

template < enum METHOD_E METH>
__device__
inline
int test_func ()
{
    return int(METH);
}

__global__ void test_kernel()
{
    test_func<METH_0>();
}

void test()
{
    test_kernel<<<1, 1>>>();
}
于 2011-09-16T19:46:49.980 に答える
1

これはあなたが望むものですか、それとも私はあなたの問題を間違えましたか?

enum METHOD_E {
    METH_0 = 0,
    METH_1
};

template <enum METHOD_E METH>
inline __device__ int test_func()
{
    return int(METH);
}

template <>
inline __device__ int test_func<METH_0>()
{
    return -42;
}
于 2011-09-16T17:28:46.200 に答える