Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Unable to use printf in CUDA!

Featured Replies

Posted

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

 

  • Author

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!
 

Hi,

u have output console?

try.

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

printf(...

  • Author

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!
 

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.