printing from cuda kernels

。_饼干妹妹 提交于 2019-12-05 02:28:18

To enable use of plain printf() on devices of Compute Capability >= 2.0, it's important to compile for CC of at least CC 2.0 and disable the default, which includes a build for CC 1.0.

Right-click the .cu file in your project, select Properties, select Configuration Properties | CUDA C/C++ | Device. Click on the Code Generation line, click the triangle, select Edit. In the Code Generation dialog box, uncheck Inherit from parent or project defaults, type compute_20,sm_20 in the top window, click OK.

Heba

you can write this code to print whatever you want from inside the CUDA Kernel:

# if __CUDA_ARCH__>=200
    printf("%d \n", tid);

#endif  

and include < stdio.h >

One way of solving this problem is by using cuPrintf function which is capable of printing from the kernels. Copy the files cuPrintf.cu and cuPrintf.cuh from the folder

C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.2\C\src\simplePrintf

to the project folder. Then add the header file cuPrintf.cuh to your project and add

#include "cuPrintf.cu"

to your code. Then your code should be written in a format mentioned below :

#include “cuPrintf.cu”
__global__ void testKernel(int val)
{
  cuPrintf(“Value is: %d\n”, val);
}

int main()
{
  cudaPrintfInit();
  testKernel<<< 2, 3 >>>(10);
  cudaPrintfDisplay(stdout, true);
  cudaPrintfEnd();
  return 0;
}

By following the above procedure one can get a print on the console window from the device function. Though I solved my issues in the above mentioned way I still don't have the solution of using printf from the device function. If it is true and absolutely necessary to upgrade my nvcc compiler from sm_10 to sm_21 to enable the printf feature then it would be very much helpful if someone could show me the light. Thanks for all your cooperation

I'm have cuda v10.0.130 on Visual Studio 2015 with a GeForce GTX 1060, and all I had to do was add the following include statement:

#include <helper_cuda.h>

Then I was able to use the printf statement without any issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!