c++ - Concatenating char* strings at compile-time for CUDA printf() -


in cuda device-side code, don't have access std::string , other standard library goodies, , our strings char*, char arrays or literal constants passed around 1 of above.

anyway, suppose want have variant of printf() prepends thread's index. can't use 2 printf calls, since interleaved other threads' printf's. can't sprintf - unless implement that.

one can pretty use macro (just taking x dimension , ignoring block index, simplicity):

#define tprintf(format_str, ... )  \     printf("%u: " format_str, threadidx.x, __va_args__) 

but don't macros... variable-number-of-arguments issue taken care of variadic template, format string concatenation - not much.

i avoid concatenating strings @ run-time, having malloc-then-free etc. there simple(ish) way this?


Comments