Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we use cuPrintf()?

Tags:

cuda

nvcc

What do we have to do to use cuPrintf()? (device compute capability 1.2, Ubuntu 12) I couldn't find "cuPrintf.cu" and "cudaPrintf.cuh", so i downloaded their code and include them:

#include "cuPrintf.cuh"
#include "cuPrintf.cu"

By the way this is the rest of the code:

__global__ void hello_kernel (float f) {
printf ("Thread number %d. f = %d\n", threadIdx.x, f);
}

    int main () {
    dim3 gridSize = dim3 (1);
    dim3 blockSize = dim3 (16);
    cudaPrintfInit ();
    hello_kernel <<< gridSize, blockSize >>> (1.2345f);
    cudaPrintfDisplay (stdout, true);
    cudaPrintfEnd ();
    return (0);
}

But nvcc still gives a mistake:

max@max-Lenovo-G560:~/CUDA/matrixMult$ nvcc printfTest.cu -o printfTest

printfTest.cu(5): error: calling a __host__ function("printf") from a __global__
function("hello_kernel") is not allowed

Thanks!

like image 300
Max Avatar asked Dec 11 '25 01:12

Max


1 Answers

In your kernel instead of this:

printf ("Thread number %d. f = %d\n", threadIdx.x, f);

you should do this:

cuPrintf ("Thread number %d. f = %d\n", threadIdx.x, f);

Other than that, I believe your code is correct (it works for me).

This SO question/answer gives more tips about using cuPrintf properly.

like image 108
Robert Crovella Avatar answered Dec 14 '25 13:12

Robert Crovella



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!