In a CUDA C project, I have a pointer to float inside a structure called "p". It is a pointer to device memory and it is called "p->deviceOutput". I am using CUDA-GDB to check the content of this pointer during execution: when I try to print it this is what happens:
(gdb) p *p->deviceOutput
$1 = 0
As you can see the printing returns something that looks like an int, definitely not a float. I am really sure the pointer is a pointer to float so I am really confused by this behaviour. Specifying the float format does not help:
(gdb) p/f *p->deviceOutput
$2 = 0
Actually I get the same behaviour using GDB as well. I am working on Ubuntu 14.10 and my code was compiled with nvcc using -O0 and -g options.
Can anybody please explain what is going on and what should I do to inspect this memory location correctly? Thanks
gdb uses the g
format specifier to printf (internally) when printing floating point values. Here's the interesting part of the description of g
from the man page for printf :
Trailing zeros are removed from the fractional part of the result; a decimal point appears only if it is followed by at least one digit.
So you're getting 0 because the floating point value is 0, and the g
format specifier (used by gdb) prints an exact 0 without a decimal point, or any trailing 0's.
You can check that your variable is of type float using the ptype
command, like this:
(gdb) ptype p->deviceOutput
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.