3
我有一个计算能力2.0的GTX 570(费米架构)。我在我的电脑上有Cuda 4.0版本,我正在使用Ubuntu 10.10在Cuda 4.0中使用printf()编译错误
使用Cuda 4.0,可以在内核中使用printf()
。下面是一个例子代码125页在CUDA 4.0 programming guide
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ < 200)
#define printf(f, ...) ((void)(f, __VA_ARGS__),0)
#endif
__global__ void helloCUDA(float f)
{
printf(“Hello thread %d, f=%f\n”, threadIdx.x, f);
}
void main()
{
helloCUDA<<<1, 5>>>(1.2345f);
cudaDeviceReset();
}
我正在以下编译错误。
gaurish108 MyPractice: nvcc printf_inkernel.cu -o printf_inkernel
printf_inkernel.cu(10): error: unrecognized token
printf_inkernel.cu(10): error: expected an expression
printf_inkernel.cu(10): error: unrecognized token
printf_inkernel.cu(10): error: unrecognized token
printf_inkernel.cu(10): error: unrecognized token
printf_inkernel.cu(10): error: unrecognized token
printf_inkernel.cu(10): error: unrecognized token
printf_inkernel.cu(10): error: unrecognized token
printf_inkernel.cu(15): warning: return type of function "main" must be "int"
8 errors detected in the compilation of "/tmp/tmpxft_000014cd_00000000-4_printf_inkernel.cpp1.ii".
为什么不识别printf?我试图加入国旗-arch=sm_20
,但我得到了同样的错误。
嘿非常感谢!代码现在正在工作。顺便说一句,你是来自斯坦福在线GPU视频讲座的Jared Hoberock吗?这些讲座很棒!非常感谢! – smilingbuddha