CodeExplorer Posted September 5, 2019 Posted September 5, 2019 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
CodeExplorer Posted September 5, 2019 Author Posted September 5, 2019 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!
身勝手のごくい Posted September 5, 2019 Posted September 5, 2019 Hi, u have output console? try. if (AllocConsole()) { freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stdin); freopen("CONOUT$", "w", stderr); } printf(...
CodeExplorer Posted September 5, 2019 Author Posted September 5, 2019 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! 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now