From 88063cdfa12e24df56dacf3fd7ff1084a031489c Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 1 Sep 2017 17:10:45 -0700 Subject: Automated g4 rollback of changelist 167320150 PiperOrigin-RevId: 167344016 --- tensorflow/core/framework/bfloat16_test.cc | 3 +-- tensorflow/core/framework/numeric_types.h | 9 +-------- tensorflow/core/kernels/cast_op.h | 9 ++++++++- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'tensorflow') 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(&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 { 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(&a); + return ::tensorflow::bfloat16(p[0]); +#else + static_assert(::tensorflow::port::kLittleEndian, "Not a little endian system!"); + const uint16_t* p = reinterpret_cast(&a); + return ::tensorflow::bfloat16(p[1]); +#endif } }; -- cgit v1.2.3