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

后端 未结 3 1041
孤独总比滥情好
孤独总比滥情好 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).
    0 讨论(0)
  • 2021-01-25 01:01

    You are probably compiling for an architecture that does not support printf(). By default the project is compiled for compute architecture 1.0. To change this, in VS open the project properties -> CUDA C/C++ -> Device and change the "Code Generation" property to "compute_20,sm_20".

    You do not need #include "util\cuPrintf.cu". Please see this for details on how to use printf and how to flush the output so you actually see the result.

    0 讨论(0)
  • 2021-01-25 01:08

    If you're getting that error, it probably means that your GPU does not have Compute capability 2.x or higher. This thread goes into more detail on what your options are for printing inside a kernel function.

    0 讨论(0)
提交回复
热议问题