From bd88a6e07c0589a85b25a0f2a5766dd60c8a2f41 Mon Sep 17 00:00:00 2001 From: ttudu Date: Wed, 1 Feb 2023 09:52:46 +0800 Subject: [PATCH] fix ops support tuple review --- .../ccsrc/backend/common/pass/insert_type_transform_op.cc | 2 +- .../plugin/device/ascend/hal/device/kernel_select_ascend.cc | 5 ++--- mindspore/ccsrc/plugin/device/ascend/kernel/kernel_query.cc | 4 +++- .../device/ascend/optimizer/ascend_backend_optimization.cc | 1 - .../ccsrc/plugin/device/ascend/optimizer/ascend_helper.cc | 6 +----- .../ascend_convert_tuple_input_to_dynamic_input.cc | 6 +++--- .../runtime/device/gsm/mem_usage_analyzer_test.py | 4 ++-- tests/ut/cpp/runtime/device/gsm/mem_usage_analyzer_test.cc | 2 +- 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/mindspore/ccsrc/backend/common/pass/insert_type_transform_op.cc b/mindspore/ccsrc/backend/common/pass/insert_type_transform_op.cc index 67c3108f883..cb18643558f 100644 --- a/mindspore/ccsrc/backend/common/pass/insert_type_transform_op.cc +++ b/mindspore/ccsrc/backend/common/pass/insert_type_transform_op.cc @@ -198,7 +198,7 @@ void SetKernelInfoForNewCNode(const CNodePtr &cnode, bool set_format_type) { std::vector input_obj_type; std::vector output_obj_type; GenerateKernelObjectTypeForNewCNode(cnode, &input_obj_type, &output_obj_type); - builder->SetKernelType(CPU_KERNEL); + builder->SetKernelType(UNKNOWN_KERNEL_TYPE); builder->SetInputsKernelObjectType(input_obj_type); builder->SetOutputsKernelObjectType(output_obj_type); diff --git a/mindspore/ccsrc/plugin/device/ascend/hal/device/kernel_select_ascend.cc b/mindspore/ccsrc/plugin/device/ascend/hal/device/kernel_select_ascend.cc index 693bed816e1..3d66e2dbca9 100644 --- a/mindspore/ccsrc/plugin/device/ascend/hal/device/kernel_select_ascend.cc +++ b/mindspore/ccsrc/plugin/device/ascend/hal/device/kernel_select_ascend.cc @@ -320,8 +320,7 @@ bool MatchObjectType(const kernel::KernelObjectType &node_object, const kernel:: return true; } - if ((node_object == kernel::TUPLE || node_object == kernel::TUPLE_UNFOLD || node_object == kernel::SCALAR) && - (kernel_object == kernel::TENSOR)) { + if (node_object == kernel::SCALAR && kernel_object == kernel::TENSOR) { return true; } @@ -392,7 +391,7 @@ bool MatchObjectType(const CNodePtr &cnode, const std::shared_ptrabstract()); std::vector new_output_object_types = {}; - if (node_output_object_type == kObjectTypeTuple) { + if (node_output_object_type == kObjectTypeTuple && kernel_outputs_object_type[0] != kernel::KernelObjectType::TUPLE) { auto tuple_abs = cnode->abstract()->cast(); MS_EXCEPTION_IF_NULL(tuple_abs); auto items = tuple_abs->elements(); diff --git a/mindspore/ccsrc/plugin/device/ascend/kernel/kernel_query.cc b/mindspore/ccsrc/plugin/device/ascend/kernel/kernel_query.cc index 788b7143d44..4d8cf8b3ab2 100644 --- a/mindspore/ccsrc/plugin/device/ascend/kernel/kernel_query.cc +++ b/mindspore/ccsrc/plugin/device/ascend/kernel/kernel_query.cc @@ -53,7 +53,9 @@ void FilterInvalidKernelInfo(const CNodePtr &kernel_node, if (is_fold) { bool is_match = true; if (!common::AnfAlgo::HasNodeAttr(kAttrDynInputSizes, kernel_node)) { - is_match = false; + if (kernel_info->GetInputNum() != fold_input_tensor_num) { + is_match = false; + } } else { // compare input num std::vector dyn_input_sizes = 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 1dc53021463..2d37a8a10fa 100644 --- a/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_backend_optimization.cc +++ b/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_backend_optimization.cc @@ -223,7 +223,6 @@ void AddAscendIRFusionRulesPass(PassManager *ir_fusion_pm) { void AddAscendIRFusionPass(PassManager *ir_fusion_pm) { MS_EXCEPTION_IF_NULL(ir_fusion_pm); - ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); ir_fusion_pm->AddPass(std::make_shared()); diff --git a/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_helper.cc b/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_helper.cc index fc376e8c47d..120fbb6dc6c 100644 --- a/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_helper.cc +++ b/mindspore/ccsrc/plugin/device/ascend/optimizer/ascend_helper.cc @@ -657,11 +657,7 @@ void SelectCallInlineKernelInfo(const CNodePtr &node) { for (size_t i = 0; i < AnfUtils::GetOutputTensorNum(node); ++i) { output_formats.push_back(AnfAlgo::GetOutputFormat(sub_ret, i)); output_types.push_back(common::AnfAlgo::GetOutputInferDataType(sub_ret, i)); - if (AnfAlgo::GetOutputObjectType(node, i) == TypeId::kObjectTypeTuple) { - output_object_types.push_back(kernel::KernelObjectType::TUPLE_UNFOLD); - } else { - output_object_types.push_back(kernel::KernelObjectType::TENSOR); - } + output_object_types.push_back(kernel::KernelObjectType::TENSOR); } auto builder = std::make_shared(); MS_EXCEPTION_IF_NULL(builder); diff --git a/mindspore/ccsrc/plugin/device/ascend/optimizer/ir_fission/ascend_convert_tuple_input_to_dynamic_input.cc b/mindspore/ccsrc/plugin/device/ascend/optimizer/ir_fission/ascend_convert_tuple_input_to_dynamic_input.cc index 7fd0a384372..9a14a8bfd0a 100644 --- a/mindspore/ccsrc/plugin/device/ascend/optimizer/ir_fission/ascend_convert_tuple_input_to_dynamic_input.cc +++ b/mindspore/ccsrc/plugin/device/ascend/optimizer/ir_fission/ascend_convert_tuple_input_to_dynamic_input.cc @@ -38,9 +38,9 @@ const AnfNodePtr AscendConvertTupleInputToDynamicInput::Process(const FuncGraphP } auto cnode = node->cast(); MS_EXCEPTION_IF_NULL(cnode); - // this pass should be in front of concat_fission, pack_fission, addn_fission, since the input should be unfold before - // this passes. - // the auto_monad pass should before this pass + // since the input should be unfold before sone function, this pass should be in front of concat_fission, + // pack_fission, addn_fission, and HandleControlFlow + bool is_communication_op = common::AnfAlgo::IsCommunicationOp(node); static const PrimitiveSet need_unfold_node = {prim::kPrimAddN, prim::kPrimConcatD, prim::kPrimPack, prim::kPrimStack, prim::kPrimCallInline, prim::kPrimPrint, diff --git a/tests/ut/cpp/python_input/gtest_input/runtime/device/gsm/mem_usage_analyzer_test.py b/tests/ut/cpp/python_input/gtest_input/runtime/device/gsm/mem_usage_analyzer_test.py index d29884d1781..952e01f4fa7 100644 --- a/tests/ut/cpp/python_input/gtest_input/runtime/device/gsm/mem_usage_analyzer_test.py +++ b/tests/ut/cpp/python_input/gtest_input/runtime/device/gsm/mem_usage_analyzer_test.py @@ -15,7 +15,7 @@ from mindspore.ops import operations as P add = P.Add() -addn = P.AddN() +mul = P.Mul() def add_net(x1, x2, x3, x4, x5): @@ -23,5 +23,5 @@ def add_net(x1, x2, x3, x4, x5): sum2 = add(sum1, x3) sum3 = add(sum2, x4) sum4 = add(sum3, x5) - ret = addn((sum4, sum1, sum2)) + ret = mul(sum4, sum1) return ret diff --git a/tests/ut/cpp/runtime/device/gsm/mem_usage_analyzer_test.cc b/tests/ut/cpp/runtime/device/gsm/mem_usage_analyzer_test.cc index 2732e597c67..7bf4f53483c 100644 --- a/tests/ut/cpp/runtime/device/gsm/mem_usage_analyzer_test.cc +++ b/tests/ut/cpp/runtime/device/gsm/mem_usage_analyzer_test.cc @@ -48,7 +48,7 @@ TEST_F(TestMemUsageAnalyzer, test_mem_usage_analyzer) { auto tensor_infos = analyzer->GetMemUsageTensorInfos(); ASSERT_EQ(5, kernel_infos.size()); - ASSERT_EQ(16, tensor_infos.size()); + ASSERT_EQ(15, tensor_infos.size()); for (size_t i = 0; i < kernel_infos.size(); ++i) { ASSERT_NE(nullptr, analyzer->GetMemUsageKernelInfo(i)); }