Hi.
I didn’t find any explanation in NVIDIA CUDA C Programming Guide B.16.
I run the kernel below <<< 1,1 >>> …
uint64_t idx = threadIdx.x;
uint64_t x = 0x0123456789abcdef;
uint64_t y = 0;
uint64_t z = idx;
if (y == z) {
printf("x : %016llX \n", x);
printf("y : %016llX \n", y);
printf("z : %016llX \n", z);
}
// x : 0123456789ABCDEF
// y : 0000000000000000
// z : 0000000000000000
All as expected! Now …
uint64_t idx = threadIdx.x;
uint64_t x = 0x0123456789abcdef;
uint64_t y;
uint64_t z = idx;
if (y == z) {
printf("x : %016llX \n", x);
printf("y : %016llX \n", y);
printf("z : %016llX \n", z);
}
// x : 0123456789ABCDEF
// y : 0123456789ABCDEF
// z : 0000000000000000
Why is omitting the initialization of y
changing the printed result of y. Or the other way around, how can (y == z)
be true if it isn’t true as shown by printf()
?
Then this …
uint64_t x = 0x0123456789abcdef;
uint64_t y;
uint64_t z = 0;
printf("y : %016llX \n", y);
if (y == z) {
printf("x : %016llX \n", x);
printf("y : %016llX \n", y);
printf("z : %016llX \n", z);
}
// y : 0000000000000000
Why is (y == z)
not true? z
is initialized to 0
and y shows 0
as well.
There are quite some printf()
inside kernel posts out there, but I didn’t find any explaining above.
If I do all of the above in main.c
, all works as expected.
What am I missing?