diff options
author | 2017-09-01 17:10:45 -0700 | |
---|---|---|
committer | 2017-09-01 17:14:45 -0700 | |
commit | 88063cdfa12e24df56dacf3fd7ff1084a031489c (patch) | |
tree | 789a09de79c11721fadce2941429718b829cb6bc /tensorflow | |
parent | c54cf14ce2c8c45cb3d8dc2cdd51b068c7f09e55 (diff) |
Automated g4 rollback of changelist 167320150
PiperOrigin-RevId: 167344016
Diffstat (limited to 'tensorflow')
-rw-r--r-- | tensorflow/core/framework/bfloat16_test.cc | 3 | ||||
-rw-r--r-- | tensorflow/core/framework/numeric_types.h | 9 | ||||
-rw-r--r-- | tensorflow/core/kernels/cast_op.h | 9 |
3 files changed, 10 insertions, 11 deletions
diff --git a/tensorflow/core/framework/bfloat16_test.cc b/tensorflow/core/framework/bfloat16_test.cc index af4e6a4411..5bd95b806f 100644 --- a/tensorflow/core/framework/bfloat16_test.cc +++ b/tensorflow/core/framework/bfloat16_test.cc @@ -23,8 +23,7 @@ namespace { TEST(Bfloat16Test, Simple) { bfloat16 a(12); - // Floating point representation of 12: 0x41400000 - EXPECT_EQ(0x4140, a.value); + EXPECT_EQ(12, a.value); } TEST(Bfloat16Test, Conversion) { diff --git a/tensorflow/core/framework/numeric_types.h b/tensorflow/core/framework/numeric_types.h index a630bee38d..31b88707e2 100644 --- a/tensorflow/core/framework/numeric_types.h +++ b/tensorflow/core/framework/numeric_types.h @@ -44,14 +44,7 @@ typedef Eigen::QUInt16 quint16; // see framework/bfloat16.h for description. struct bfloat16 { EIGEN_DEVICE_FUNC bfloat16() {} - EIGEN_DEVICE_FUNC explicit bfloat16(const float v) { - const uint16_t* p = reinterpret_cast<const uint16_t*>(&v); -#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ - value = p[0]; -#else - value = p[1]; -#endif - } + EIGEN_DEVICE_FUNC explicit bfloat16(const uint16_t v) : value(v) {} uint16_t value; }; diff --git a/tensorflow/core/kernels/cast_op.h b/tensorflow/core/kernels/cast_op.h index 59a991b5a8..5c24f164a4 100644 --- a/tensorflow/core/kernels/cast_op.h +++ b/tensorflow/core/kernels/cast_op.h @@ -121,7 +121,14 @@ struct scalar_cast_op<float, ::tensorflow::bfloat16> { typedef ::tensorflow::bfloat16 result_type; EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ::tensorflow::bfloat16 operator()( const float a) const { - return ::tensorflow::bfloat16(a); +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + const uint16_t* p = reinterpret_cast<const uint16_t*>(&a); + return ::tensorflow::bfloat16(p[0]); +#else + static_assert(::tensorflow::port::kLittleEndian, "Not a little endian system!"); + const uint16_t* p = reinterpret_cast<const uint16_t*>(&a); + return ::tensorflow::bfloat16(p[1]); +#endif } }; |