I get an error when I try to use printf() in a kernel

后端 未结 3 1145
孤独总比滥情好
孤独总比滥情好 2021-01-25 00:47

I\'m using Visual Studio 2010 and a GTX480 with compute capability 2.0.

I have tried setting sm to 2.0, but when I attempt to use printf() in a kernel, I get:

3条回答
  •  甜味超标
    2021-01-25 00:54

    To use printf in kernel code, you have to do three things:

    1. make sure that cstdio or stdio.h are included in the kernel compilation unit. CUDA implements kernel printf by overloading, so you must include that file
    2. Compile your code for compute capability 2.x or 3.x and run it on a supported GPU (so pass something like -arch=sm_20 to nvcc or the IDE equivalent in Visual Studio or Nsight Eclipse edition)
    3. Ensure that the kernel has finished running by including an explicit or implicit synchronization point in your host code (cudaDeviceSynchronize for example).

提交回复
热议问题