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

Function TEST_F

tensorflow/compiler/xla/service/conditional_to_select_test.cc:39–78  ·  view source on GitHub ↗

Test that a conditional of simple constants is transformed to a select

Source from the content-addressed store, hash-verified

37
38// Test that a conditional of simple constants is transformed to a select
39TEST_F(ConditionalToSelectTest, MapConditionalConstants) {
40 const string hlo_text = R"(
41HloModule MapConditionalConstants
42
43if {
44 %pif = () parameter(0)
45 ROOT %cif = f32[] constant(0)
46}
47
48else {
49 %pelse = () parameter(0)
50 ROOT %celse = f32[] constant(1)
51}
52
53mapped {
54 %a = f32[] parameter(0)
55 %b = f32[] parameter(1)
56 %lt = pred[] compare(%a, %b), direction=LT
57 %t = () tuple()
58 ROOT %conditional = f32[] conditional(%lt, %t, %t), true_computation=if, false_computation=else
59}
60
61ENTRY comp {
62 %p1 = f32[1000]{0} parameter(0)
63 %p2 = f32[1000]{0} parameter(1)
64 ROOT %mapped = f32[1000]{0} map(%p1, %p2), dimensions={0}, to_apply=mapped
65}
66)";
67
68 auto module = ParseAndReturnVerifiedModule(hlo_text).ValueOrDie();
69 ConditionalToSelect pass;
70 ASSERT_TRUE(pass.Run(&*module).ValueOrDie());
71
72 HloInstruction* root = module->entry_computation()->root_instruction();
73 ASSERT_EQ(root->opcode(), HloOpcode::kMap);
74 HloComputation* mapped = root->called_computations()[0];
75 EXPECT_THAT(mapped->root_instruction(),
76 op::Select(op::Lt(op::Parameter(0), op::Parameter(1)),
77 op::Constant(), op::Constant()));
78}
79
80// Test that the condition gets broadcasted for feeding into
81// select when the output is non-scalar.

Callers

nothing calls this directly

Calls 12

BroadcastFunction · 0.85
root_instructionMethod · 0.80
entry_computationMethod · 0.80
opcodeMethod · 0.80
LtFunction · 0.70
ParameterFunction · 0.70
GetTupleElementFunction · 0.70
SelectFunction · 0.50
ConstantFunction · 0.50
ReduceFunction · 0.50
AddClass · 0.50
RunMethod · 0.45

Tested by

no test coverage detected