Browse Source

!1137 Bugfix: no_use_reshape_remove_pass unlink single shape_input

From: @hugo1
Reviewed-by: @xchu42,@wqtshg
Signed-off-by: @wqtshg
tags/v1.2.0
mindspore-ci-bot Gitee 4 years ago
parent
commit
7e575d9525
2 changed files with 36 additions and 6 deletions
  1. +33
    -6
      ge/graph/passes/no_use_reshape_remove_pass.cc
  2. +3
    -0
      ge/graph/passes/no_use_reshape_remove_pass.h

+ 33
- 6
ge/graph/passes/no_use_reshape_remove_pass.cc View File

@@ -82,14 +82,41 @@ Status NoUseReshapeRemovePass::Run(ge::NodePtr &node) {
}
}
if (to_be_deleted) {
GELOGI("NoUseReshapeRemovePass remove useless node:%s", node->GetName().c_str());
auto ret = PassUtils::UnlinkNodeWithControlCopy(node, kReshapeShapeIndex);
if (ret != SUCCESS) {
GELOGE(ret, "DimensionAdjustPass unlink node with control copy fail.");
return ret;
}
auto ret = TryRemoveConstShapeInput(node);
GE_CHK_STATUS_RET_NOLOG(ret);
GELOGI("NoUseReshapeRemovePass remove useless reshape node:%s", node->GetName().c_str());
return IsolateAndDeleteNode(node, {kReshapeDataIndex});
}
return SUCCESS;
}

Status NoUseReshapeRemovePass::TryRemoveConstShapeInput(ge::NodePtr &reshape_node) {
auto shape_input_anchor = reshape_node->GetInDataAnchor(kReshapeShapeIndex);
if (shape_input_anchor == nullptr) {
return SUCCESS;
}
GE_CHECK_NOTNULL(shape_input_anchor->GetPeerOutAnchor());
auto shape_input = shape_input_anchor->GetPeerOutAnchor()->GetOwnerNode();
GE_CHECK_NOTNULL(shape_input);
if (shape_input->GetType() != CONSTANT && shape_input->GetType() != CONSTANTOP) {
return SUCCESS;
}
// op(x) const(shape)
// \ /
// reshape
// const input can unlink but should copy control_dependency
auto ret = PassUtils::UnlinkNodeWithControlCopy(reshape_node, kReshapeShapeIndex);
if (ret != SUCCESS) {
GELOGE(ret, "Unlink node %s with control copy failed.", shape_input->GetName().c_str());
return ret;
}

// remove const without any data_output
if (shape_input->GetOutDataNodesSize() == 0) {
auto ret = IsolateAndDeleteNode(shape_input, {});
GE_CHK_GRAPH_STATUS_RET(ret, "Fail to remove node %s", shape_input->GetName().c_str());
GELOGI("Remove useless shape input const %s.", shape_input->GetName().c_str());
}
return SUCCESS;
}
} // namespace ge

+ 3
- 0
ge/graph/passes/no_use_reshape_remove_pass.h View File

@@ -32,6 +32,9 @@ class NoUseReshapeRemovePass : public BaseNodePass {
/// @author
///
Status Run(ge::NodePtr &node) override;

private:
Status TryRemoveConstShapeInput(NodePtr &reshape_node);
};
} // namespace ge



Loading…
Cancel
Save