From be6ea59b3e8491c75e10f3e1647b06f673ffb159 Mon Sep 17 00:00:00 2001 From: reku1997 Date: Thu, 15 Sep 2022 19:45:23 +0800 Subject: [PATCH] fix error in akg --- .../common/pass/insert_tensor_move_for_ref.cc | 42 ----------------- .../common/pass/insert_tensor_move_for_ref.h | 37 --------------- .../hal/hardware/ascend_kernel_executor.cc | 1 + .../optimizer/ascend_backend_optimization.cc | 2 - .../insert_tensor_move_for_cascade.cc | 6 +-- .../enhancer/insert_tensor_move_for_ref.cc | 47 ------------------- .../enhancer/insert_tensor_move_for_ref.h | 39 --------------- .../cpu/hal/hardware/cpu_device_context.cc | 3 +- .../gpu/hal/hardware/gpu_device_context.cc | 2 +- .../device/gpu/hal/hardware/optimizer.h | 1 - 10 files changed, 4 insertions(+), 176 deletions(-) delete mode 100644 mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.cc delete mode 100644 mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.h delete mode 100644 mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.cc delete mode 100644 mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.h diff --git a/mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.cc b/mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.cc deleted file mode 100644 index 6fb1b87f297..00000000000 --- a/mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.cc +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2022 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "backend/common/pass/insert_tensor_move_for_ref.h" -#include "include/common/utils/anfalgo.h" -#include "utils/ms_context.h" - -namespace mindspore { -namespace opt { -namespace { -constexpr auto kNopNodeRealInputIndex = 1; -} - -bool InsertTensorMoveForGraphOutputRefNode::Run(const FuncGraphPtr &graph) { - MS_EXCEPTION_IF_NULL(graph); - - auto context_ptr = MsContext::GetInstance(); - MS_EXCEPTION_IF_NULL(context_ptr); - if (context_ptr->get_param(MS_CTX_MEMORY_OPTIMIZE_LEVEL) == kOptimizeO0) { - // not use somas - return true; - } - - // Need to insert TensorMove if the output of RefOp is GraphOutput - (void)InsertRefTensorMoveForGraphOutput(graph); - return true; -} -} // namespace opt -} // namespace mindspore diff --git a/mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.h b/mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.h deleted file mode 100644 index 586a0444af6..00000000000 --- a/mindspore/ccsrc/backend/common/pass/insert_tensor_move_for_ref.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2022 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MINDSPORE_INSERT_TENSOR_MOVE_FOR_REF_H -#define MINDSPORE_INSERT_TENSOR_MOVE_FOR_REF_H - -#include -#include -#include -#include "backend/common/optimizer/optimizer.h" - -namespace mindspore { -namespace opt { -// When RefNode's output is a GraphOutput, need insert a TensorMove -class BACKEND_EXPORT InsertTensorMoveForGraphOutputRefNode : public Pass { - public: - InsertTensorMoveForGraphOutputRefNode() : Pass("insert_tensor_move_for_graphoutput_ref_node") {} - ~InsertTensorMoveForGraphOutputRefNode() override = default; - bool Run(const FuncGraphPtr &graph) override; -}; -} // namespace opt -} // namespace mindspore - -#endif // MINDSPORE_INSERT_TENSOR_MOVE_FOR_REF_H diff --git a/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_kernel_executor.cc b/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_kernel_executor.cc index 21281281658..c36a77a5705 100644 --- a/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_kernel_executor.cc +++ b/mindspore/ccsrc/plugin/device/ascend/hal/hardware/ascend_kernel_executor.cc @@ -222,6 +222,7 @@ void AscendKernelExecutor::PreprocessBeforeRunGraph(const KernelGraphPtr &graph) void AscendKernelExecutor::DoSomas(const KernelGraphPtr &graph) { auto ms_context = MsContext::GetInstance(); MS_EXCEPTION_IF_NULL(ms_context); + // somas if (ms_context->get_param(MS_CTX_MEMORY_OPTIMIZE_LEVEL) != kOptimizeO0) { auto somas = std::make_shared(); bool ret = somas->Assign(graph); diff --git a/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_backend_optimization.cc b/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_backend_optimization.cc index 3ae12cce4dc..7b0715c271f 100644 --- a/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_backend_optimization.cc +++ b/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_backend_optimization.cc @@ -130,7 +130,6 @@ #include "plugin/device/ascend/optimizer/format_type/deal_ref_output.h" #include "plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_hccl_op.h" #include "plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_cascade.h" -#include "plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.h" #include "plugin/device/ascend/optimizer/enhancer/insert_pad_for_nms_with_mask.h" #include "plugin/device/ascend/optimizer/format_type/insert_transdata_for_runop.h" #include "plugin/device/ascend/optimizer/enhancer/insert_transpose_for_sort.h" @@ -531,7 +530,6 @@ void AscendBackendOptimization(const std::shared_ptr &kern other_pm->AddPass(std::make_shared()); other_pm->AddPass(std::make_shared()); other_pm->AddPass(std::make_shared()); - other_pm->AddPass(std::make_shared()); other_pm->AddPass(std::make_shared()); other_pm->AddPass(std::make_shared()); other_pm->AddPass(std::make_shared()); diff --git a/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_cascade.cc b/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_cascade.cc index 6455dd88045..91ce4dfc913 100644 --- a/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_cascade.cc +++ b/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_cascade.cc @@ -123,14 +123,10 @@ void InsertTensorMoveForCascade::InsertOutputTensorMove(const FuncGraphPtr &grap return; } - if (!common::AnfAlgo::IsFusedCommunicationOp(hccl_node)) { - return; - } - AnfNodePtr node = nullptr; auto outputs = common::AnfAlgo::GetAllOutputWithIndex(graph->output()); for (const auto &output_with_index : outputs) { - if (!common::AnfAlgo::IsFusedCommunicationOp(output_with_index.first)) { + if (!common::AnfAlgo::IsCommunicationOp(output_with_index.first)) { continue; } auto cnode = output_with_index.first->cast(); diff --git a/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.cc b/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.cc deleted file mode 100644 index d07e1df0166..00000000000 --- a/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.cc +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2022 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.h" -#include "include/common/utils/anfalgo.h" -#include "utils/ms_context.h" - -namespace mindspore { -namespace opt { -namespace { -constexpr auto kNopNodeRealInputIndex = 1; -} - -bool InsertTensorMoveForGraphOutputRefNode::Run(const FuncGraphPtr &graph) { - MS_EXCEPTION_IF_NULL(graph); - - auto ms_context = MsContext::GetInstance(); - MS_EXCEPTION_IF_NULL(ms_context); - auto task_sink = ms_context->get_param(MS_CTX_ENABLE_TASK_SINK); - auto opt_level = ms_context->get_param(MS_CTX_MEMORY_OPTIMIZE_LEVEL); - if (!task_sink && (opt_level == kOptimizeO0)) { - // not use somas - return false; - } - - // Need to insert TensorMove if the output of RefOp is GraphOutput - auto tensor_move_list = InsertRefTensorMoveForGraphOutput(graph); - for (auto &tensor_move : tensor_move_list) { - kernel_select_->SelectKernel(tensor_move->cast()); - } - return true; -} -} // namespace opt -} // namespace mindspore diff --git a/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.h b/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.h deleted file mode 100644 index cb038ab93c0..00000000000 --- a/mindspore/ccsrc/plugin/device/ascend/optimizer/enhancer/insert_tensor_move_for_ref.h +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2020 Huawei Technologies Co., Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MINDSPORE_INSERT_TENSOR_MOVE_FOR_REF_H -#define MINDSPORE_INSERT_TENSOR_MOVE_FOR_REF_H - -#include -#include "backend/common/optimizer/optimizer.h" -#include "plugin/device/ascend/optimizer/ascend_helper.h" - -namespace mindspore { -namespace opt { -// When RefNode's output is a GraphOutput, need insert a TensorMove -class InsertTensorMoveForGraphOutputRefNode : public Pass { - public: - InsertTensorMoveForGraphOutputRefNode() - : Pass("insert_tensor_move_for_graphoutput_ref_node"), kernel_select_(std::make_shared()) {} - ~InsertTensorMoveForGraphOutputRefNode() override = default; - bool Run(const FuncGraphPtr &graph) override; - - private: - KernelSelectPtr kernel_select_; -}; -} // namespace opt -} // namespace mindspore - -#endif // MINDSPORE_INSERT_TENSOR_MOVE_FOR_REF_H diff --git a/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.cc b/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.cc index b16b8fabbfe..79b68a9753b 100644 --- a/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.cc +++ b/mindspore/ccsrc/plugin/device/cpu/hal/hardware/cpu_device_context.cc @@ -39,7 +39,6 @@ #include "backend/common/pass/replace_node_by_proxy.h" #include "backend/common/pass/erase_visit_attr.h" #include "backend/common/pass/insert_tensor_move_for_communication.h" -#include "backend/common/pass/insert_tensor_move_for_ref.h" #include "common/graph_kernel/adapter/graph_kernel_optimization.h" #include "common/graph_kernel/adapter/expander.h" #ifdef ENABLE_AKG @@ -179,7 +178,6 @@ void CPUKernelExecutor::OptimizeGraphImpl(const KernelGraphPtr &graph) const { pm->AddPass(std::make_shared("insert_cast")); pm->AddPass(std::make_shared()); pm->AddPass(std::make_shared()); - pm->AddPass(std::make_shared()); optimizer->AddPassManager(pm); (void)optimizer->Optimize(graph); graph->SetExecOrderByDefault(); @@ -348,6 +346,7 @@ void CPUKernelExecutor::PreprocessBeforeRun(const FuncGraphPtr &graph) const { } auto ms_context = MsContext::GetInstance(); MS_EXCEPTION_IF_NULL(ms_context); + // somas if (ms_context->get_param(MS_CTX_MEMORY_OPTIMIZE_LEVEL) != kOptimizeO0) { auto somas = std::make_shared(); bool ret = somas->Assign(kernel_graph); diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.cc b/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.cc index 76e726f3278..742bbd8c468 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.cc +++ b/mindspore/ccsrc/plugin/device/gpu/hal/hardware/gpu_device_context.cc @@ -265,6 +265,7 @@ void GPUKernelExecutor::PreprocessBeforeRun(const FuncGraphPtr &graph) const { MS_EXCEPTION_IF_NULL(kernel_graph); auto ms_context = MsContext::GetInstance(); MS_EXCEPTION_IF_NULL(ms_context); + // somas if (ms_context->get_param(MS_CTX_MEMORY_OPTIMIZE_LEVEL) != kOptimizeO0) { auto somas = std::make_shared(); bool ret = somas->Assign(kernel_graph); @@ -314,7 +315,6 @@ void GPUKernelExecutor::OptimizeGraphWithDeviceInfo(const KernelGraphPtr &graph) pm->AddPass(std::make_shared()); pm->AddPass(std::make_shared("reduce_precision")); pm->AddPass(std::make_shared()); - pm->AddPass(std::make_shared()); optimizer->AddPassManager(pm); (void)optimizer->Optimize(graph); graph->SetExecOrderByDefault(); diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/hardware/optimizer.h b/mindspore/ccsrc/plugin/device/gpu/hal/hardware/optimizer.h index 8d7167bbc68..a6f13b76dcc 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/hardware/optimizer.h +++ b/mindspore/ccsrc/plugin/device/gpu/hal/hardware/optimizer.h @@ -23,7 +23,6 @@ #include "backend/common/optimizer/common_backend_optimization.h" #include "backend/common/pass/adjust_depend_for_parallel_optimizer_recompute_all_gather.h" #include "backend/common/pass/insert_tensor_move_for_communication.h" -#include "backend/common/pass/insert_tensor_move_for_ref.h" #include "plugin/device/gpu/optimizer/adam_weight_decay_fusion.h" #include "plugin/device/gpu/optimizer/adam_fusion.h" #include "plugin/device/gpu/optimizer/alltoall_fusion.h"