aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/literal_util_test.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2017-05-18 18:02:32 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-05-18 18:06:21 -0700
commit53cb26d05a5c2080d8022124178b1cc43a30ffe5 (patch)
treeba11f5e078e8300e0a88f96f1029c549ade2a6c0 /tensorflow/compiler/xla/literal_util_test.cc
parentc311af00f2d72940c75ab0fc125ba2949858b2a9 (diff)
Merge changes from github.
END_PUBLIC --- Commit c2b8927f2 authored by Dandelion Man?<dandelion@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Fix another d3v4 regression in the graph visualizer. PiperOrigin-RevId: 156343038 --- Commit 170f0b350 authored by Peter Hawkins<phawkins@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: [TF:XLA] Add XLA implementation of ResourceStridedSliceAssign. PiperOrigin-RevId: 156341053 --- Commit 1390dd68f authored by Vijay Vasudevan<vrv@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: When Op Type is not registered, log the hostname of the machine that it is running on in the error message, since the message could be routed back during a failure on a remote binary, and it is hard to tell which machine it came from. Ideally, we'd somehow log the name of the binary running instead, but we don't have a function to get that right now. PiperOrigin-RevId: 156337679 --- Commit 9ca8a151b authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Internal change. PiperOrigin-RevId: 156335942 --- Commit 40255434c authored by Martin Wicke<wicke@google.com> Committed by TensorFlower Gardener<gardener@tensorflow.org>: Deprecate contrib/learn/dataframe. To be removed June 15. PiperOrigin-RevId: 156333930 --- Commit 7f71b7fbe authored by A. Unique TensorFlower<gardener@tensorflow.org> Committed by TensorFlower Gardener<gardener@tensorflow.org>: BEGIN_PUBLIC Automated g4 rollback of changelist 156123287 PiperOrigin-RevId: 156503903
Diffstat (limited to 'tensorflow/compiler/xla/literal_util_test.cc')
-rw-r--r--tensorflow/compiler/xla/literal_util_test.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/literal_util_test.cc b/tensorflow/compiler/xla/literal_util_test.cc
index 7acb9933da..9a09822174 100644
--- a/tensorflow/compiler/xla/literal_util_test.cc
+++ b/tensorflow/compiler/xla/literal_util_test.cc
@@ -105,6 +105,9 @@ TEST_F(LiteralUtilTest, LiteralScalarToString) {
auto f32_lit = LiteralUtil::CreateR0<float>(3.14f);
ASSERT_EQ("3.14", LiteralUtil::ToString(*f32_lit));
+
+ auto f16_lit = LiteralUtil::CreateR0<half>(static_cast<half>(0.5f));
+ ASSERT_EQ("0.5", LiteralUtil::ToString(*f16_lit));
}
TEST_F(LiteralUtilTest, LiteralVectorToString) {
@@ -373,6 +376,15 @@ TEST_F(LiteralUtilTest, IsAll) {
EXPECT_FALSE(
LiteralUtil::IsAll(*LiteralUtil::CreateR2<uint64>({{9, 8}, {8, 8}}), 8));
+ half h8(8.0f);
+ half h9(9.0f);
+ EXPECT_TRUE(
+ LiteralUtil::IsAll(*LiteralUtil::CreateR2<half>({{h8}, {h8}}), 8));
+ EXPECT_FALSE(
+ LiteralUtil::IsAll(*LiteralUtil::CreateR2<half>({{h8}, {h9}}), 8));
+ EXPECT_FALSE(
+ LiteralUtil::IsAll(*LiteralUtil::CreateR2<half>({{h9}, {h8}}), 8));
+
auto uint64_max = std::numeric_limits<uint64>::max();
EXPECT_FALSE(LiteralUtil::IsAll(
*LiteralUtil::CreateR2<uint64>(
@@ -659,6 +671,30 @@ TEST_F(LiteralUtilTest, PopulateWithValueR2U64) {
EXPECT_TRUE(LiteralUtil::Equal(output, *expected));
}
+TEST_F(LiteralUtilTest, PopulateWithValueR0F16) {
+ Literal output;
+ half h(0.25f);
+ LiteralUtil::PopulateWithValue<half>(h, {}, &output);
+ auto expected = LiteralUtil::CreateR0<half>(h);
+ EXPECT_TRUE(LiteralUtil::Equal(output, *expected));
+}
+
+TEST_F(LiteralUtilTest, PopulateWithValueR1F16) {
+ Literal output;
+ half h(0.5f);
+ LiteralUtil::PopulateWithValue<half>(h, {3}, &output);
+ auto expected = LiteralUtil::CreateR1<half>({h, h, h});
+ EXPECT_TRUE(LiteralUtil::Equal(output, *expected));
+}
+
+TEST_F(LiteralUtilTest, PopulateWithValueR2F16) {
+ Literal output;
+ half h(2.0f);
+ LiteralUtil::PopulateWithValue<half>(h, {2, 2}, &output);
+ auto expected = LiteralUtil::CreateR2<half>({{h, h}, {h, h}});
+ EXPECT_TRUE(LiteralUtil::Equal(output, *expected));
+}
+
TEST_F(LiteralUtilTest, ReplicateR2U32) {
auto input = LiteralUtil::CreateR2<uint32>(
{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}});
@@ -730,6 +766,41 @@ TEST_F(LiteralUtilTest, CopyScalars) {
EXPECT_EQ(LiteralUtil::Get<uint32>(*vect, {4}), 17);
}
+TEST_F(LiteralUtilTest, F16) {
+ // Verify that the internal data views are consistent and that they
+ // are in little endian format
+ // TODO - modify if we make the data format machine endianess dependent
+ auto m1 = LiteralUtil::CreateFromShape(ShapeUtil::MakeShape(F16, {2, 2}));
+ Literal* l1 = m1.get();
+ const char* d1 = (const char*)LiteralUtil::InternalData(*l1);
+ EXPECT_EQ(d1[0], 0);
+ EXPECT_EQ(d1[1], 0);
+ EXPECT_EQ(d1[2], 0);
+ EXPECT_EQ(d1[3], 0);
+ EXPECT_EQ(d1[4], 0);
+ EXPECT_EQ(d1[5], 0);
+ EXPECT_EQ(d1[6], 0);
+ EXPECT_EQ(d1[7], 0);
+ EXPECT_EQ(LiteralUtil::InternalData(*l1),
+ LiteralUtil::MutableInternalData(l1));
+
+ half h1(1.0f);
+ half h2(2.0f);
+ auto m2 = LiteralUtil::CreateR2<half>({{h1, h2}, {h2, h1}});
+ Literal* l2 = m2.get();
+ const char* d2 = (const char*)LiteralUtil::InternalData(*l2);
+ EXPECT_EQ(d2[0], 0);
+ EXPECT_EQ(d2[1], 0x3C);
+ EXPECT_EQ(d2[2], 0);
+ EXPECT_EQ(d2[3], 0x40);
+ EXPECT_EQ(d2[4], 0);
+ EXPECT_EQ(d2[5], 0x40);
+ EXPECT_EQ(d2[6], 0);
+ EXPECT_EQ(d2[7], 0x3C);
+ EXPECT_EQ(LiteralUtil::InternalData(*l2),
+ LiteralUtil::MutableInternalData(l2));
+}
+
TEST_F(LiteralUtilTest, Populate) {
struct PopulateData {
std::vector<int64> dimensions;