Skip to content

Commit

Permalink
test=huawei_ascend_npu
Browse files Browse the repository at this point in the history
  • Loading branch information
shentanyue committed Mar 16, 2022
1 parent 92a7887 commit f8517cf
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ void AssignValueCalcOfflinePass::RemoveAssignValuePattern(
auto outlinks = node->outlinks;
bool has_extra_producers = false;
for (auto& out_link : outlinks) {
if (HasExtraProducers(graph, out_link->arg()->name, {"assign_value"})) {
if (HasExtraProducers(
graph.get(), out_link->arg()->name, {"assign_value"})) {
has_extra_producers = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ void FillConstantCalcOfflinePass::RemoveFillConstantPattern(
auto outlinks = node->outlinks;
bool has_extra_producers = false;
for (auto& out_link : outlinks) {
if (HasExtraProducers(graph, out_link->arg()->name, {"fill_constant"})) {
if (HasExtraProducers(
graph.get(), out_link->arg()->name, {"fill_constant"})) {
has_extra_producers = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void RangeCalcOfflinePass::RemoveRangePattern(
auto outlinks = node->outlinks;
bool has_extra_producers = false;
for (auto& out_link : outlinks) {
if (HasExtraProducers(graph, out_link->arg()->name, {"range"})) {
if (HasExtraProducers(graph.get(), out_link->arg()->name, {"range"})) {
has_extra_producers = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void ScaleCalcOfflinePass::RemoveScalePattern(
auto outlinks = node->outlinks;
bool has_extra_producers = false;
for (auto& out_link : outlinks) {
if (HasExtraProducers(graph, out_link->arg()->name, {"scale"})) {
if (HasExtraProducers(graph.get(), out_link->arg()->name, {"scale"})) {
has_extra_producers = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void SSDBoxesCalcOfflinePass::RemovePriorboxPattern(
auto outlinks = node->outlinks;
bool has_extra_producers = false;
for (auto& out_link : outlinks) {
if (HasExtraProducers(graph,
if (HasExtraProducers(graph.get(),
out_link->arg()->name,
{"prior_box", "density_prior_box"})) {
has_extra_producers = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ void UnsqueezeCalcOfflinePass::RemoveUnsqueezePattern(
auto outlinks = node->outlinks;
bool has_extra_producers = false;
for (auto& out_link : outlinks) {
if (HasExtraProducers(
graph, out_link->arg()->name, {"unsqueeze", "unsqueeze2"})) {
if (HasExtraProducers(graph.get(),
out_link->arg()->name,
{"unsqueeze", "unsqueeze2"})) {
has_extra_producers = true;
break;
}
Expand Down
23 changes: 0 additions & 23 deletions lite/core/optimizer/mir/ssa_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,6 @@ static void LocalInferenceType(Node *a, Node *b, const std::string &arg_name) {
}
}

static bool HasExtraProducers(const std::unique_ptr<mir::SSAGraph> &graph,
const std::string &var_name,
const std::set<std::string> &exclude_op_list,
const std::set<std::string> &candidate = {
"while", "conditional_block", "increment"}) {
for (auto &op_node : graph->StmtTopologicalOrder()) {
if (!op_node->IsStmt()) continue;
auto op_info = op_node->AsStmt().op_info();
auto op_type = op_info->Type();
if (exclude_op_list.count(op_type)) continue;
if (candidate.empty() || candidate.count(op_type)) {
for (auto &var_node : op_node->outlinks) {
if (var_name == var_node->AsArg().name ||
var_node->AsArg().name.find(std::string(var_name + "__Mangled_")) !=
std::string::npos) {
return true;
}
}
}
}
return false;
}

} // namespace mir
} // namespace lite
} // namespace paddle
3 changes: 1 addition & 2 deletions lite/core/optimizer/mir/ssa_graph_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ namespace mir {
bool HasExtraProducers(mir::SSAGraph *graph,
const std::string &var_name,
const std::set<std::string> &exclude_op_list,
const std::set<std::string> &candidate_op = {
"while", "conditional_block", "increment"}) {
const std::set<std::string> &candidate_op) {
for (auto &op_node : graph->StmtTopologicalOrder()) {
if (!op_node->IsStmt()) continue;
auto op_info = op_node->AsStmt().op_info();
Expand Down
3 changes: 2 additions & 1 deletion lite/core/optimizer/mir/ssa_graph_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace mir {
bool HasExtraProducers(mir::SSAGraph *graph,
const std::string &var_name,
const std::set<std::string> &exclude_op_list,
const std::set<std::string> &candidate_op);
const std::set<std::string> &candidate_op = {
"while", "conditional_block", "increment"});

} // namespace mir
} // namespace lite
Expand Down

0 comments on commit f8517cf

Please sign in to comment.