Jump to content
Tuts 4 You

Unable to use printf in CUDA!


CodeExplorer

Recommended Posts

Unable to use printf in CUDA!
Having this code:

__global__ void md5_gpu_bruteforce_thread(unsigned int *data_d, unsigned int *result_d, unsigned int pwd_len, int charset_len)
{

    printf("Hello from block %d, thread %d\n", blockIdx.x, threadIdx.x);

Error:
C:/BarsWF-master/algo/md5/md5_kernel.cu(77): error : calling a host function("printf") from a __device__/__global__ function("md5_gpu_bruteforce_thread") is not allowed

 

Link to comment

Also tried:

__global__ void md5_gpu_bruteforce_thread(unsigned int *data_d, unsigned int *result_d, unsigned int pwd_len, int charset_len)
{

cuPrintf("Hello world, form the device %d \n",5);

It compiles but doesn't print a thing!
 

Link to comment
身勝手のごくい

Hi,

u have output console?

try.

if (AllocConsole())
{
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stdin);
freopen("CONOUT$", "w", stderr);
}

printf(...

Link to comment

I have a console window.
The problem was calling printf from cuda device (__global__  method).
Finally I succeed:
after adding at start of .cu file:
#include "cuPrintf.cu"

First time you should init cuPrintf it using:
#ifdef DebugValues
cudaPrintfInit();  // init print - first step of cuPrintf
#endif

Inside the __global__   method call cuPrintf like this:
cuPrintf("a = %X, b = %X, c = %X, d = %X\n", a, b, c, d);

The final step is calling:
#ifdef DebugValues
    cudaPrintfDisplay(stdout, true);  // part two of cuPrintf
    cudaPrintfEnd();
#endif


All works fine now!
 

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...