From d429fe193f4c235cde8223804ea888c2eaa5ce68 Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Tue, 27 Feb 2018 11:57:09 -0800 Subject: Improve our handling of bitcasts. - Do not fuse bitcasts in the CPU backend. Fused instructions lose their layout and a bitcast is meaningless without a layout. We were explicitly testing for this so I've changed the corresponding tests to use a reshape instead. - Fail the layout assignment if we see a bitcast. bitcasts are inherently layout sensitive and so a bitcast instruction present in the IR before layout assignment is a bug. PiperOrigin-RevId: 187210151 --- .../compiler/xla/service/layout_assignment_test.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tensorflow/compiler/xla/service/layout_assignment_test.cc') diff --git a/tensorflow/compiler/xla/service/layout_assignment_test.cc b/tensorflow/compiler/xla/service/layout_assignment_test.cc index 62feb7c1e9..4b1c9bad41 100644 --- a/tensorflow/compiler/xla/service/layout_assignment_test.cc +++ b/tensorflow/compiler/xla/service/layout_assignment_test.cc @@ -796,5 +796,26 @@ TEST_F(LayoutAssignmentTest, ConditionalAsymmetricLayout) { EXPECT_THAT(false_result->opcode(), HloOpcode::kCopy); } +TEST_F(LayoutAssignmentTest, InternalErrorOnBitcast) { + auto builder = HloComputation::Builder(TestName()); + auto constant0 = builder.AddInstruction( + HloInstruction::CreateConstant(Literal::CreateR2WithLayout( + {{1.0, 2.0}, {3.0, 4.0}}, LayoutUtil::MakeLayout({0, 1})))); + builder.AddInstruction(HloInstruction::CreateUnary( + constant0->shape(), HloOpcode::kBitcast, constant0)); + auto module = CreateNewModule(); + module->AddEntryComputation(builder.Build()); + + ComputationLayout computation_layout( + module->entry_computation()->ComputeProgramShape()); + LayoutAssignment layout_assignment(&computation_layout); + Status error_status = layout_assignment.Run(module.get()).status(); + EXPECT_FALSE(error_status.ok()); + EXPECT_THAT( + error_status.error_message(), + ::testing::HasSubstr( + "Unexpected bitcast operation seen during layout assignment")); +} + } // namespace } // namespace xla -- cgit v1.2.3