printf() in my CUDA kernel doesn't result produce any output

前端 未结 1 2094
渐次进展
渐次进展 2020-11-28 16:51

I have added some printf() statements in my CUDA program

__device__ __global__ void Kernel(float *, float * ,int );
void DeviceFunc(float *temp_         


        
相关标签:
1条回答
  • 2020-11-28 17:18

    printf() output is only displayed if the kernel finishes successfully, so check the return codes of all CUDA function calls and make sure no errors are reported.

    Furthermore printf() output is only displayed at certain points in the program. Appendix B.20.2 of the Programming Guide lists these as

    • Kernel launch via <<<>>> or cuLaunchKernel() (at the start of the launch, and if the CUDA_LAUNCH_BLOCKING environment variable is set to 1, at the end of the launch as well),
    • Synchronization via cudaDeviceSynchronize(), cuCtxSynchronize(), cudaStreamSynchronize(), cuStreamSynchronize(), cudaEventSynchronize(), or cuEventSynchronize(),
    • Memory copies via any blocking version of cudaMemcpy*() or cuMemcpy*(),
    • Module loading/unloading via cuModuleLoad() or cuModuleUnload(),
    • Context destruction via cudaDeviceReset() or cuCtxDestroy().
    • Prior to executing a stream callback added by cudaStreamAddCallback() or cuStreamAddCallback().

    To easily check this is your problem, put the following code after your kernel invocation:

    {
        cudaError_t cudaerr = cudaDeviceSynchronize();
        if (cudaerr != cudaSuccess)
            printf("kernel launch failed with error \"%s\".\n",
                   cudaGetErrorString(cudaerr));
    }
    

    You should then see either the output of your kernel or an error message.

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