Bug 30161 - x/f does not print values of _Float16
Summary: x/f does not print values of _Float16
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 13.1
: P2 minor
Target Milestone: 14.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-02-24 00:06 UTC by Mark Stock
Modified: 2023-03-02 15:55 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-02-24 00:00:00


Attachments
A simple dot product program that uses float and _Float16 (375 bytes, text/x-c++src)
2023-02-24 00:06 UTC, Mark Stock
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Stock 2023-02-24 00:06:20 UTC
Created attachment 14717 [details]
A simple dot product program that uses float and _Float16

'p'rint will successfully print the value of fp16 variables
x/hf or x/f will not, it will print decimal instead

(gdb) p x32[0]
$1 = (__gnu_cxx::__alloc_traits<std::allocator<float>, float>::value_type &) @0x155554eed010: 0.100000001
(gdb) x/wf 0x155554eed010 
0x155554eed010:	0.100000001

(gdb) p x16[0]
$2 = (__gnu_cxx::__alloc_traits<std::allocator<_Float16>, _Float16>::value_type &) @0x1555552c6010: 0.099976
(gdb) x/hf 0x1555552c6010 
0x1555552c6010:	11878

This is relevant to debugging rocm programs (AMD GPUs) as the "print" command under rocgdb does not not show __shared__ memory elements, and we must use 'x' to view the values of __half variables because we only have their addresses. (But that bug is AMD's.)
Comment 1 Tom Tromey 2023-02-24 16:37:27 UTC
I have a fix.
Comment 3 Mark Stock 2023-02-27 23:05:17 UTC
Works perfectly! Thanks for the quick action.

(gdb) p x32[0]
$1 = (__gnu_cxx::__alloc_traits<std::allocator<float>, float>::value_type &) @0x155554eed010: 0.100000001
(gdb) x/wf 0x155554eed010
0x155554eed010:	0.100000001
(gdb) p x16[0]           
$2 = (__gnu_cxx::__alloc_traits<std::allocator<_Float16>, _Float16>::value_type &) @0x1555552c6010: 0.099976
(gdb) x/hf 0x1555552c6010
0x1555552c6010:	0.099976

Is there anything else I can do to help this get into the next release so everyone can enjoy it?
Comment 4 Tom Tromey 2023-02-27 23:16:30 UTC
It'll land relatively soon and then show up in 14.1.
We probably won't put in on the gdb-13 branch, normally we
don't do a lot in the point releases
Comment 5 Sourceware Commits 2023-03-02 15:55:02 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=70728e1d396475e8e630bfdd3fb8e8c8211bdbbd

commit 70728e1d396475e8e630bfdd3fb8e8c8211bdbbd
Author: Tom Tromey <tromey@adacore.com>
Date:   Fri Feb 24 09:19:32 2023 -0700

    Handle half-float in 'x' command
    
    Using 'x/hf' should print bytes as float16, but instead it currently
    prints as an integer.  I tracked this down to a missing case in
    float_type_from_length.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30161
    Approved-By: Simon Marchi <simon.marchi@efficios.com>
Comment 6 Tom Tromey 2023-03-02 15:55:38 UTC
Fixed.