Skip to content

Commit

Permalink
* fix for bfloat16 class (#1908)
Browse files Browse the repository at this point in the history
  • Loading branch information
shurale-nkn authored and Daniel Lowell committed Jul 23, 2019
1 parent 7d268a3 commit 4e39a83
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/include/miopen/bfloat16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ class bfloat16 : boost::totally_ordered<bfloat16, boost::arithmetic<bfloat16>>
bfloat16() : data_{0} {}
explicit bfloat16(float rhs)
{
static union
union
{
std::uint32_t bf16_st;
float float_st;
} bits_st;

bits_st.float_st = rhs;
std::uint32_t bf16_st;
} bits_st = {rhs};

// BF16 round and NaN preservation code matches
// https://github.com/ROCmSoftwarePlatform/rocBLAS/blob/develop/library/include/rocblas_bfloat16.h
Expand Down Expand Up @@ -89,13 +87,12 @@ class bfloat16 : boost::totally_ordered<bfloat16, boost::arithmetic<bfloat16>>
}
operator float() const
{
static union
union
{
std::uint32_t bf16_st;
float float_st;
} bits_st;
} bits_st = {data_};

bits_st.bf16_st = data_;
bits_st.bf16_st = bits_st.bf16_st << 16;
return bits_st.float_st;
}
Expand Down

0 comments on commit 4e39a83

Please sign in to comment.