Skip to content

Commit 6b80fe4

Browse files
committed
Run control dep and DCE on repeat
Summary: Run them until a fixpoint to remove as many instructions as possible. Also remove control deps from parameters. Ref T48127 Test Plan: CI, added new tests Reviewers: vladimirm, markf, #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved Reviewed By: markf, #tensorflow, #framework_ip_review_-_any_oss_or_third-party_code_use_has_been_approved Maniphest Tasks: T48127 Differential Revision: https://phabricator.sourcevertex.net/D56681
1 parent 97db102 commit 6b80fe4

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

tensorflow/compiler/plugin/poplar/driver/passes/dead_control_dependencies_elimination.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ StatusOr<bool> DeadControlDependenciesElimination::Run(HloModule* module) {
3535

3636
for (HloInstruction* inst : comp->MakeInstructionPostOrder()) {
3737
if (inst->user_count() == 0 && comp->root_instruction() != inst &&
38-
inst->opcode() != HloOpcode::kParameter && !inst->HasSideEffect()) {
38+
!inst->HasSideEffect()) {
3939
VLOG(2) << "Dropping control dependencies for " << inst->ToString();
4040
// To preserve topological constraints, make sure that control
4141
// predecessors are copied to control successors.
@@ -44,9 +44,13 @@ StatusOr<bool> DeadControlDependenciesElimination::Run(HloModule* module) {
4444
TF_RETURN_IF_ERROR(predecessor->AddControlDependencyTo(successor));
4545
}
4646
}
47+
changed = inst->control_successors().size() ||
48+
inst->control_predecessors().size();
49+
4750
TF_RETURN_IF_ERROR(inst->DropAllControlDeps());
48-
CHECK(comp->IsSafelyRemovable(inst));
49-
changed = true;
51+
if (inst->opcode() != HloOpcode::kParameter) {
52+
CHECK(comp->IsSafelyRemovable(inst));
53+
}
5054
}
5155
}
5256
}

tensorflow/compiler/plugin/poplar/driver/poplar_compiler.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,13 @@ StatusOr<std::unique_ptr<PoplarExecutableCore>> CompileEngine(
15741574
if (resources.recomputation_enabled) {
15751575
pipeline.AddPass<FlattenCallGraph>();
15761576
}
1577-
pipeline.AddPass<DeadControlDependenciesElimination>();
1578-
pipeline.AddPass<HloDCE>();
1577+
{
1578+
auto& dce_pass = pipeline.AddPass<HloPassFix<HloPassPipeline>>(
1579+
"dead-code-and-control-deps-elimination",
1580+
pipeline_compiler_stats.get());
1581+
dce_pass.AddPass<DeadControlDependenciesElimination>();
1582+
dce_pass.AddPass<HloDCE>();
1583+
}
15791584
// Beyond this point non of the passes in the pipeline are allowed to
15801585
// modify the instructions in the HloModule.
15811586

tensorflow/compiler/plugin/poplar/tests/dead_control_dependencies_elimination_test.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,28 @@ ENTRY c1 {
8585
EXPECT_THAT(log->control_successors(), ::testing::ElementsAre(add));
8686
}
8787

88+
TEST_F(DeadControlDependenciesEliminationTest, TestParameters) {
89+
std::string hlo = R"(
90+
HloModule top
91+
92+
ENTRY c1 {
93+
arg0 = f32[] parameter(0)
94+
arg1 = f32[] parameter(1)
95+
ROOT log = f32[] log(arg0)
96+
arg2 = f32[] parameter(2), control-predecessors={log, arg1}
97+
}
98+
)";
99+
TF_ASSERT_OK_AND_ASSIGN(
100+
auto module, ParseAndReturnVerifiedModule(hlo, GetModuleConfigForTest()));
101+
EXPECT_TRUE(
102+
DeadControlDependenciesElimination().Run(module.get()).ValueOrDie());
103+
104+
HloInstruction* arg2 = FindInstruction(module.get(), "arg2");
105+
106+
EXPECT_TRUE(arg2->control_predecessors().empty());
107+
EXPECT_TRUE(arg2->control_successors().empty());
108+
}
109+
88110
} // namespace
89111
} // namespace poplarplugin
90112
} // namespace xla

0 commit comments

Comments
 (0)