0

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

4

1 回答 1

1

gdbg在打印浮点值时使用格式说明符(在内部) printf。这是printf 手册页中g描述的有趣部分:

从结果的小数部分中删除尾随零;只有在小数点后跟至少一位数字时才会出现小数点。

所以你得到 0 因为浮点值是 0,g格式说明符(由 gdb 使用)打印一个没有小数点或任何尾随 0 的精确 0。

您可以使用以下命令检查您的变量是否为 float 类型ptype,如下所示:

(gdb) ptype p->deviceOutput
于 2015-12-04T23:08:46.587 回答