C ++テンプレートを使用すると、NVIDIA NVCC(CUDA 4.0および4.1テスト済み)の奇妙な動作が見られます。私はそれを、振る舞いを示す簡単な例にまとめました。
これはすでにバグレポートの状態にあります。ただし、このサイトはバグや修正の信頼できるソースとして成長しているため、ここに接続します。だから、私はこのページを更新し続けます。
コード:
#include"stdio.h"
#define PETE_DEVICE __device__
template<class T, int N> class ILattice;
template<class T> class IScalar;
template<class T, int IL> struct AddILattice {};
template<class T>
PETE_DEVICE
void printType() {
printf("%s\n",__PRETTY_FUNCTION__);
}
template<class T> class IScalar {
T F;
};
template<class T, int N> class ILattice {
T F[N];
};
template<class T, int N>
struct AddILattice<IScalar<T> , N> {
typedef ILattice< T , N > Type_t;
};
#define IL 16
__global__ void kernel()
{
printf("IL=%d\n",IL); // Here IL==16
typedef typename AddILattice<IScalar<float> ,IL>::Type_t Tnew;
// This still works fine. Output:
// void printType() [with T = ILattice<float, 16>]
//
printType<Tnew>();
// Now problems begin: Output:
// T=4 Tnew=0 IL=64
// Here IL should still be 16
// sizeof(Tnew) should be 16*sizeof(float)
//
printf("T=%d Tnew=%d IL=%d\n",sizeof(IScalar<float> ),sizeof(Tnew),IL);
}
int main()
{
dim3 blocksPerGrid( 1 , 1 , 1 );
dim3 threadsPerBlock( 1 , 1, 1);
kernel<<< blocksPerGrid , threadsPerBlock , 48*1024 >>>( );
cudaDeviceSynchronize();
cudaError_t kernel_call = cudaGetLastError();
printf("call: %s\n",cudaGetErrorString(kernel_call));
}
コンパイラがIL
16から64に変わる理由はありますか?