Test that `map` with `max` is transformed to `max`
| 39 | |
| 40 | // Test that `map` with `max` is transformed to `max` |
| 41 | TEST_F(MapInlinerTest, MapMax) { |
| 42 | Shape r0f32 = ShapeUtil::MakeShape(F32, {}); |
| 43 | |
| 44 | auto max_builder = HloComputation::Builder(TestName()); |
| 45 | auto param1 = max_builder.AddInstruction( |
| 46 | HloInstruction::CreateParameter(0, r0f32, "x")); |
| 47 | auto param2 = max_builder.AddInstruction( |
| 48 | HloInstruction::CreateParameter(1, r0f32, "y")); |
| 49 | max_builder.AddInstruction(HloInstruction::CreateBinary( |
| 50 | param1->shape(), HloOpcode::kMaximum, param1, param2)); |
| 51 | auto max_f32 = max_builder.Build(); |
| 52 | |
| 53 | auto builder = HloComputation::Builder("MapMaxFunction"); |
| 54 | auto lhs = builder.AddInstruction(HloInstruction::CreateConstant( |
| 55 | LiteralUtil::CreateR1<float>({1, 2, 3, 4}))); |
| 56 | auto rhs = builder.AddInstruction(HloInstruction::CreateConstant( |
| 57 | LiteralUtil::CreateR1<float>({4, 3, 2, 1}))); |
| 58 | builder.AddInstruction( |
| 59 | HloInstruction::CreateMap(lhs->shape(), {lhs, rhs}, max_f32.get())); |
| 60 | |
| 61 | auto computation = builder.Build(); |
| 62 | auto hlo_module = CreateNewVerifiedModule(); |
| 63 | hlo_module->AddEmbeddedComputation(std::move(max_f32)); |
| 64 | hlo_module->AddEntryComputation(std::move(computation)); |
| 65 | |
| 66 | MapInliner inliner; |
| 67 | EXPECT_TRUE(inliner.Run(hlo_module.get()).ValueOrDie()); |
| 68 | EXPECT_THAT(hlo_module->entry_computation()->root_instruction(), |
| 69 | op::Maximum(lhs, rhs)); |
| 70 | |
| 71 | // Verify execution on CPU. |
| 72 | auto result = ExecuteAndTransfer(hlo_module->Clone(), {}); |
| 73 | auto expected = LiteralUtil::CreateR1<float>({4, 3, 3, 4}); |
| 74 | EXPECT_TRUE(LiteralTestUtil::Equal(result, expected)); |
| 75 | } |
| 76 | |
| 77 | // Test that `constant` function is changed to `broadcast`. |
| 78 | TEST_F(MapInlinerTest, MapConstant) { |
nothing calls this directly
no test coverage detected