MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TEST_F

Function TEST_F

tensorflow/compiler/xla/service/map_inliner_test.cc:41–75  ·  view source on GitHub ↗

Test that `map` with `max` is transformed to `max`

Source from the content-addressed store, hash-verified

39
40// Test that `map` with `max` is transformed to `max`
41TEST_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`.
78TEST_F(MapInlinerTest, MapConstant) {

Callers

nothing calls this directly

Calls 15

MakeShapeFunction · 0.85
TestNameFunction · 0.85
BroadcastFunction · 0.85
AddEntryComputationMethod · 0.80
root_instructionMethod · 0.80
entry_computationMethod · 0.80
BuilderClass · 0.70
MaximumClass · 0.50
EqualClass · 0.50
ConstantFunction · 0.50
SubtractClass · 0.50

Tested by

no test coverage detected