Browse Source

!973 Enhance add_memcpy_async pass

Merge pull request !973 from huanghui/enhance-add-memcpy-async-pass
tags/v0.3.0-alpha
mindspore-ci-bot Gitee 5 years ago
parent
commit
aa80712ac4
1 changed files with 8 additions and 1 deletions
  1. +8
    -1
      mindspore/ccsrc/pre_activate/ascend/enhancer/add_memcpy_async.cc

+ 8
- 1
mindspore/ccsrc/pre_activate/ascend/enhancer/add_memcpy_async.cc View File

@@ -23,6 +23,12 @@
namespace mindspore {
namespace opt {
namespace {
bool InputIsParameterOrValueNode(const AnfNodePtr &node) {
MS_EXCEPTION_IF_NULL(node);
auto kernel_with_index = AnfAlgo::VisitKernel(node, 0);
return kernel_with_index.first->isa<Parameter>() || kernel_with_index.first->isa<ValueNode>();
}

const AnfNodePtr AddMemcpyAsyncIfInputIsUsedByOthers(const FuncGraphPtr &graph, const CNodePtr &node) {
MS_EXCEPTION_IF_NULL(graph);
MS_EXCEPTION_IF_NULL(node);
@@ -39,7 +45,8 @@ const AnfNodePtr AddMemcpyAsyncIfInputIsUsedByOthers(const FuncGraphPtr &graph,
if (manager->node_users().find(input) == manager->node_users().end()) {
MS_LOG(EXCEPTION) << "node has no output in manager";
}
if (manager->node_users()[input].size() > 1) {
// when input is used by others or is a parameter or is a value node, insert a memcpy_async
if (manager->node_users()[input].size() > 1 || InputIsParameterOrValueNode(input)) {
replace = true;
new_inputs.push_back(CreateMemcpyAsyncOp(graph, input));
} else {


Loading…
Cancel
Save