Is it possible to print a decimal representation of (unsigned) char in CUDA’s printf? While hh
size is not explicitly listed in the format specifier section (Programming Guide :: CUDA Toolkit Documentation), the compiler happily accepts it. However, calls to printf
using char and hhd
specifier result in incorrect values.
Please see the example:
#include <stdio.h>
__global__ void helloChar() {
constexpr char hhd = 0x7B; // 123
constexpr short hd = 0x3039; // 12345
constexpr int d = 0x499602D3; // 1234567891
printf("Decimal positive values:\n"
"\thhd: %hhd\n"
"\thd: %hd\n"
"\td: %d\n",
hhd, hd, d);
}
int main() {
helloChar<<<1, 1>>>();
cudaDeviceSynchronize();
return 0;
}
Which generates the following output:
Decimal positive values:
hhd: 123
hd: 16720
d: 12345
Decimal positive values:
hhd: 123
hd: -3760
d: 12345