Tuesday, July 17, 2012

Print to console inside CUDA Kernel

Need to download “cuPrintf.cu” and “cuPrintf.cuh” at .
I am running “main.cpp” at Host and “foo.cu” at Device.
In main.cpp, call

foo( ... parameters ...);

In foo.h:

extern "C" void foo(... parameters ...);
extern "C" void test_print();

In foo.cu

__global__ void test_print()
    int tid;
    tid = blockIdx.x * blockDim.x + threadIdx.x;
    cuPrintf("%d\n", tid);
extern "C"  void foo(... parameters ...){
    cudaPrintfDisplay(stdout, true);

Note: This will affect the performance. In my application, the execute time raised from about 500ms to 1000ms.

No comments:

Post a Comment