aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/layout_util_test.cc
diff options
context:
space:
mode:
authorGravatar Mark Heffernan <meheff@google.com>2018-06-04 16:41:46 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-06-04 16:44:21 -0700
commit14d4d1634dd2bd70ebc1629bc27354309bce0cb4 (patch)
treea5f2c94125a98ebf57e3c815b99b74ad69f2ca74 /tensorflow/compiler/xla/layout_util_test.cc
parentcf01d118ef0762c0554611bef123bf4559071fbf (diff)
Add TOKEN primitive type.
The token type will be threaded through side-effecting ops to order them. Subsequent cls will add new opcodes and change side effecting operations to support this ordering. This CL also does some cleanup in shape_util and layout_util where we have assumed that shapes are either arrays or tuples. PiperOrigin-RevId: 199215963
Diffstat (limited to 'tensorflow/compiler/xla/layout_util_test.cc')
-rw-r--r--tensorflow/compiler/xla/layout_util_test.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/layout_util_test.cc b/tensorflow/compiler/xla/layout_util_test.cc
index 4fd1d818e3..e4c825450d 100644
--- a/tensorflow/compiler/xla/layout_util_test.cc
+++ b/tensorflow/compiler/xla/layout_util_test.cc
@@ -218,6 +218,47 @@ TEST_F(LayoutUtilTest, CopyLayoutBogusLayout) {
"elements, but shape is rank"));
}
+TEST_F(LayoutUtilTest, CopyTokenLayout) {
+ Shape src = ShapeUtil::MakeTokenShape();
+ Shape dst = ShapeUtil::MakeTokenShape();
+
+ // Layouts are trivially the same for token types and copying layouts should
+ // be a nop.
+ EXPECT_TRUE(LayoutUtil::LayoutsInShapesEqual(src, dst));
+ EXPECT_IS_OK(LayoutUtil::CopyLayoutBetweenShapes(src, &dst));
+ EXPECT_TRUE(LayoutUtil::LayoutsInShapesEqual(src, dst));
+}
+
+TEST_F(LayoutUtilTest, CopyOpaqueLayout) {
+ Shape src = ShapeUtil::MakeOpaqueShape();
+ Shape dst = ShapeUtil::MakeOpaqueShape();
+
+ // Layouts are trivially the same for opaque types and copying layouts should
+ // be a nop.
+ EXPECT_TRUE(LayoutUtil::LayoutsInShapesEqual(src, dst));
+ EXPECT_IS_OK(LayoutUtil::CopyLayoutBetweenShapes(src, &dst));
+ EXPECT_TRUE(LayoutUtil::LayoutsInShapesEqual(src, dst));
+}
+
+TEST_F(LayoutUtilTest, CopyTupleLayoutWithTokenAndOpaque) {
+ Shape src = ShapeUtil::MakeTupleShape(
+ {MakeShapeWithLayout(F32, {2, 3}, {0, 1}),
+ MakeShapeWithLayout(F32, {42, 123}, {1, 0}), ShapeUtil::MakeTokenShape(),
+ ShapeUtil::MakeTupleShape(
+ {ShapeUtil::MakeOpaqueShape(), MakeShapeWithLayout(F32, {}, {}),
+ MakeShapeWithLayout(F32, {1, 2, 3}, {0, 2, 1})})});
+ Shape dst = ShapeUtil::MakeTupleShape(
+ {MakeShapeWithLayout(F32, {2, 3}, {1, 0}),
+ MakeShapeWithLayout(F32, {42, 123}, {1, 0}), ShapeUtil::MakeTokenShape(),
+ ShapeUtil::MakeTupleShape(
+ {ShapeUtil::MakeOpaqueShape(), MakeShapeWithLayout(F32, {}, {}),
+ MakeShapeWithLayout(F32, {1, 2, 3}, {1, 2, 0})})});
+
+ EXPECT_FALSE(LayoutUtil::LayoutsInShapesEqual(src, dst));
+ EXPECT_IS_OK(LayoutUtil::CopyLayoutBetweenShapes(src, &dst));
+ EXPECT_TRUE(LayoutUtil::LayoutsInShapesEqual(src, dst));
+}
+
TEST_F(LayoutUtilTest, ClearLayoutTuple) {
Shape shape = ShapeUtil::MakeTupleShape(
{MakeShapeWithLayout(F32, {2, 3}, {1, 0}),
@@ -236,6 +277,16 @@ TEST_F(LayoutUtilTest, ClearLayoutTuple) {
EXPECT_FALSE(shape.tuple_shapes(2).tuple_shapes(1).has_layout());
}
+TEST_F(LayoutUtilTest, ClearLayoutOpaqueAndToken) {
+ // Opaque and token types trivially have layouts.
+ for (Shape shape :
+ {ShapeUtil::MakeOpaqueShape(), ShapeUtil::MakeTokenShape()}) {
+ EXPECT_TRUE(LayoutUtil::HasLayout(shape));
+ LayoutUtil::ClearLayout(&shape);
+ EXPECT_TRUE(LayoutUtil::HasLayout(shape));
+ }
+}
+
TEST_F(LayoutUtilTest, SetToDefaultLayoutTuple) {
Shape shape = ShapeUtil::MakeTupleShape(
{MakeShapeWithLayout(F32, {2, 3, 4}, {1, 0, 2}),