CUDA does not support printf function in non-device emulation mode. During development we used to switch between emulation and non-emulation mode frequently. The switch was done using a compile time flag.
We needed a way to remove the all the printf calls in non-emulation mode and have them execute in the emulation mode. The solution was to use Variadic Macro (Thanks to my friend who found the existence of such a macro).
Finally our solution was:
We used the log variadic macro in our code. Nice learning!!
#ifdef EMU
int log(char*msg, ...) {
va_list args;
va_start(args, msg);
return vprintf(msg, args);
}
#else
#define log(msg, ...)
#endif