From b294db6b05c17a07794b3e4f321c16ef733342c6 Mon Sep 17 00:00:00 2001 From: wYann Date: Fri, 3 Mar 2023 10:28:13 +0800 Subject: [PATCH] delete ENABLE_TUPLE_UNFOLD --- cmake/options.cmake | 2 -- .../common/optimizer/common_backend_optimization.cc | 5 ----- .../common/pass/convert_tuple_output_to_maketuple.cc | 7 ------- .../backend/common/session/anf_runtime_algorithm.cc | 10 ---------- .../plugin/device/cpu/hal/device/kernel_select_cpu.cc | 10 ---------- .../device/cpu/hal/hardware/cpu_device_context.cc | 2 -- .../plugin/device/gpu/hal/device/kernel_info_setter.cc | 10 ---------- .../device/gpu/hal/hardware/gpu_device_context.cc | 2 -- 8 files changed, 48 deletions(-) diff --git a/cmake/options.cmake b/cmake/options.cmake index 1b6cc34963f..391e64aa70c 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -76,8 +76,6 @@ if(ENABLE_ASAN) endif() endif() -add_compile_definitions(ENABLE_TUPLE_UNFOLD) - if(DEBUG_MODE) set(CMAKE_BUILD_TYPE "Debug") add_compile_definitions(MEM_REUSE_DEBUG) diff --git a/mindspore/ccsrc/backend/common/optimizer/common_backend_optimization.cc b/mindspore/ccsrc/backend/common/optimizer/common_backend_optimization.cc index f9e6a82fc80..dea720c42e4 100644 --- a/mindspore/ccsrc/backend/common/optimizer/common_backend_optimization.cc +++ b/mindspore/ccsrc/backend/common/optimizer/common_backend_optimization.cc @@ -55,14 +55,9 @@ PassManagerPtr GetBackendCommonOptimizationPassManagerPtr(const FuncGraphPtr &gr common_pm->AddPass(std::make_shared()); common_pm->AddPass(std::make_shared()); common_pm->AddPass(std::make_shared()); -#ifdef ENABLE_TUPLE_UNFOLD - MS_LOG(INFO) << "Enable tuple unfold."; if (graph->has_flag(kAttrMutableKernel) || graph->has_flag(kFlagEnableRunGraphBySingleOp)) { common_pm->AddPass(std::make_shared()); } -#else - common_pm->AddPass(std::make_shared()); -#endif common_pm->AddPass(std::make_shared()); common_pm->AddPass(std::make_shared()); return common_pm; diff --git a/mindspore/ccsrc/backend/common/pass/convert_tuple_output_to_maketuple.cc b/mindspore/ccsrc/backend/common/pass/convert_tuple_output_to_maketuple.cc index d8d7641794c..77c367ce942 100644 --- a/mindspore/ccsrc/backend/common/pass/convert_tuple_output_to_maketuple.cc +++ b/mindspore/ccsrc/backend/common/pass/convert_tuple_output_to_maketuple.cc @@ -49,25 +49,18 @@ AnfNodePtr ConvertTupleInputToMakeTuple(const FuncGraphPtr &graph, const AnfNode return make_tuple; } -#ifdef ENABLE_TUPLE_UNFOLD bool IsKerenlGraphOutput(const FuncGraphPtr &func_graph, const AnfNodePtr &node) { const auto &outputs = common::AnfAlgo::GetAllOutputIndexByReturnTypes(func_graph->output(), {prim::kPrimTupleGetItem}); return std::find_if(outputs.begin(), outputs.end(), [&node](const auto &output) { return output.first == node; }) != outputs.end(); } -#endif bool IsNeedConvert(const FuncGraphPtr &func_graph, const AnfNodePtr &input) { -#ifdef ENABLE_TUPLE_UNFOLD MS_EXCEPTION_IF_NULL(input); return (input->Type() != nullptr && AnfUtils::IsRealKernel(input) && common::AnfAlgo::IsTupleOutput(input) && !common::AnfAlgo::CheckPrimitiveType(input, prim::kPrimCall) && (input->isa() || input->isa() || IsKerenlGraphOutput(func_graph, input))); -#else - return (input->Type() != nullptr && AnfUtils::IsRealKernel(input) && common::AnfAlgo::IsTupleOutput(input) && - !common::AnfAlgo::CheckPrimitiveType(input, prim::kPrimCall)); -#endif } } // namespace diff --git a/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc b/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc index 2981075faff..3119d0bc537 100644 --- a/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc +++ b/mindspore/ccsrc/backend/common/session/anf_runtime_algorithm.cc @@ -139,7 +139,6 @@ tensor::TensorPtr GetForwardOutputTensor(const AnfNodePtr &node) { return nullptr; } -#ifdef ENABLE_TUPLE_UNFOLD size_t GetOutputTensorNumByKernelInfo(const AnfNodePtr &node) { MS_EXCEPTION_IF_NULL(node); MS_EXCEPTION_IF_NULL(node->kernel_info()); @@ -149,7 +148,6 @@ size_t GetOutputTensorNumByKernelInfo(const AnfNodePtr &node) { MS_EXCEPTION_IF_NULL(build_info); return build_info->GetAllOutputDeviceTypes().size(); } -#endif } // namespace AnfNodePtr AnfRuntimeAlgorithm::MakeMonadValueNode(const KernelGraphPtr &kg) { @@ -196,7 +194,6 @@ void AnfRuntimeAlgorithm::KeepOrder(const KernelGraphPtr &kg, const AnfNodePtr & } size_t AnfRuntimeAlgorithm::GetOutputTensorNum(const AnfNodePtr &node) { -#ifdef ENABLE_TUPLE_UNFOLD MS_EXCEPTION_IF_NULL(node); size_t res; TypePtr type = node->Type(); @@ -225,13 +222,9 @@ size_t AnfRuntimeAlgorithm::GetOutputTensorNum(const AnfNodePtr &node) { res = 1; } return res; -#else - return AnfUtils::GetOutputTensorNum(node); -#endif } size_t AnfRuntimeAlgorithm::GetOutputNumWithoutKernelInfo(const AnfNodePtr &node) { -#ifdef ENABLE_TUPLE_UNFOLD MS_EXCEPTION_IF_NULL(node); const auto &kernel_info = node->kernel_info(); if (kernel_info != nullptr) { @@ -261,9 +254,6 @@ size_t AnfRuntimeAlgorithm::GetOutputNumWithoutKernelInfo(const AnfNodePtr &node res = 1; } return res; -#else - return AnfUtils::GetOutputTensorNum(node); -#endif } namespace { diff --git a/mindspore/ccsrc/plugin/device/cpu/hal/device/kernel_select_cpu.cc b/mindspore/ccsrc/plugin/device/cpu/hal/device/kernel_select_cpu.cc index fdf388075dd..de8bc584d6f 100644 --- a/mindspore/ccsrc/plugin/device/cpu/hal/device/kernel_select_cpu.cc +++ b/mindspore/ccsrc/plugin/device/cpu/hal/device/kernel_select_cpu.cc @@ -82,13 +82,11 @@ void GetOutputDtypes(const CNodePtr &kernel_node, std::vector *output_ty } } -#ifdef ENABLE_TUPLE_UNFOLD // Real tuple isn't expanded. void GetOutputDtypesForRealTuple(const CNodePtr &kernel_node, std::vector *output_types) { TypeId dtype = common::AnfAlgo::GetOutputInferDataType(kernel_node, 0); (void)output_types->emplace_back(dtype); } -#endif void GetOutputFormat(const CNodePtr &kernel_node, std::vector *output_formats) { size_t output_num = AnfAlgo::GetOutputElementNum(kernel_node); @@ -544,7 +542,6 @@ bool SelectKernel(const CNodePtr &kernel_node, kernel::KernelAttr *selected_kern bool input_matched = false; for (auto kernel_attr : kernel_attrs) { output_types.clear(); -#ifdef ENABLE_TUPLE_UNFOLD // The real tuple and allsame don't fold the tuple. if (kernel_attr.GetAllSame() || (kernel_attr.GetOutputSize() != 0 && kernel_attr.GetOutputAttr(0).object_type == kObjectTypeTuple)) { @@ -552,9 +549,6 @@ bool SelectKernel(const CNodePtr &kernel_node, kernel::KernelAttr *selected_kern } else { GetOutputDtypes(kernel_node, &output_types); } -#else - GetOutputDtypes(kernel_node, &output_types); -#endif MS_LOG(DEBUG) << "Select kernel for op: " << kernel_node->fullname_with_scope() << ", input types:" << input_types << ", output types:" << output_types; @@ -647,7 +641,6 @@ std::pair SetKernelInfoWithMsg(const CNodePtr &kerne // First select the kernel object types. std::vector object_selected_kernel_attrs; const auto &kernel_attrs = kernel::NativeCpuKernelMod::GetCpuSupportedList(op_name); -#ifdef ENABLE_TUPLE_UNFOLD if (kernel_attrs.empty()) { return KernelNotSupportWarning(kernel_node, false); } else if (kernel_attrs[0].GetSkipCheck()) { @@ -656,9 +649,6 @@ std::pair SetKernelInfoWithMsg(const CNodePtr &kerne !kernel::SelectKernelByObjectType(kernel_node, kernel_attrs, &object_selected_kernel_attrs, false)) { return kernel::KernelObjectTypeNotSupportWarning(kernel_node); } -#else - object_selected_kernel_attrs = kernel_attrs; -#endif // Second select the matched kernel attr. kernel::KernelAttr selected_kernel_attr; 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 88500446bdb..216d1366e8c 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 @@ -236,9 +236,7 @@ void CPUKernelExecutor::OptimizeGraphImpl(const KernelGraphPtr &graph) const { MS_EXCEPTION_IF_NULL(graph); auto optimizer = std::make_shared(); auto pm = std::make_shared(); -#ifdef ENABLE_TUPLE_UNFOLD pm->AddPass(std::make_shared("insert_type_transform_op")); -#endif pm->AddPass(std::make_shared("insert_format_transform_op_cpu")); pm->AddPass(std::make_shared()); pm->AddPass(std::make_shared("insert_cast")); diff --git a/mindspore/ccsrc/plugin/device/gpu/hal/device/kernel_info_setter.cc b/mindspore/ccsrc/plugin/device/gpu/hal/device/kernel_info_setter.cc index 366ad09cee2..b9670870994 100644 --- a/mindspore/ccsrc/plugin/device/gpu/hal/device/kernel_info_setter.cc +++ b/mindspore/ccsrc/plugin/device/gpu/hal/device/kernel_info_setter.cc @@ -593,7 +593,6 @@ bool GetSelectKernelResult(const CNodePtr &kernel_node, return result; } -#ifdef ENABLE_TUPLE_UNFOLD bool GetSelectKernelObjectTypeResult(const CNodePtr &kernel_node, KernelType kernel_type) { auto kernel_name = common::AnfAlgo::GetCNodeName(kernel_node); // Only the kernel nodes that register kernel attr can support the backoff. @@ -631,7 +630,6 @@ bool GetSelectKernelObjectTypeResult(const CNodePtr &kernel_node, KernelType ker kernel::SetKernelObjectTypeWithSelectedAttr(kernel_node, object_selected_kernel_attrs[0]); return true; } -#endif std::pair SetKernelInfoWithMsg(const CNodePtr &kernel_node, KernelType kernel_type) { MS_EXCEPTION_IF_NULL(kernel_node); @@ -643,12 +641,10 @@ std::pair SetKernelInfoWithMsg(const CNodePtr &kerne } auto builder = std::make_shared(); AnfAlgo::SetSelectKernelBuildInfo(builder->Build(), kernel_node.get()); -#ifdef ENABLE_TUPLE_UNFOLD bool selected = GetSelectKernelObjectTypeResult(kernel_node, kernel_type); if (!selected) { return kernel::KernelObjectTypeNotSupportWarning(kernel_node); } -#endif std::vector inputs_format; std::vector inputs_type; size_t input_num = common::AnfAlgo::GetInputTensorNum(kernel_node); @@ -659,21 +655,17 @@ std::pair SetKernelInfoWithMsg(const CNodePtr &kerne std::vector outputs_format; std::vector outputs_type; -#ifdef ENABLE_TUPLE_UNFOLD auto output_kernel_object_types = builder->Build()->GetAllOutputKernelObjectTypes(); if (output_kernel_object_types.size() == 1 && output_kernel_object_types[0] == kernel::KernelObjectType::TUPLE) { outputs_type = {common::AnfAlgo::GetOutputInferDataType(kernel_node, 0)}; outputs_format = {kOpFormat_DEFAULT}; } else { -#endif size_t output_num = AnfAlgo::GetOutputElementNum(kernel_node); for (size_t output_index = 0; output_index < output_num; ++output_index) { outputs_format.emplace_back(kOpFormat_DEFAULT); outputs_type.push_back(common::AnfAlgo::GetOutputInferDataType(kernel_node, output_index)); } -#ifdef ENABLE_TUPLE_UNFOLD } -#endif std::string origin_data_format = kOpFormat_DEFAULT; if (IsNeedProcessFormatInfo(kernel_node, inputs_type)) { UpdateKernelFormatInfo(kernel_node, inputs_type, &inputs_format, &outputs_format, &origin_data_format); @@ -683,12 +675,10 @@ std::pair SetKernelInfoWithMsg(const CNodePtr &kerne builder->SetInputsDeviceType(inputs_type); builder->SetOutputsFormat(outputs_format); builder->SetOutputsDeviceType(outputs_type); -#ifdef ENABLE_TUPLE_UNFOLD kernel::UnfoldKernelBuildInfo(kernel_node); if (!common::AnfAlgo::HasNodeAttr(kAttrDynInputSizes, kernel_node)) { kernel::SetDynamicInputSizeAttr(kernel_node); } -#endif MS_LOG(INFO) << kernel_node->fullname_with_scope() << " kernel attr info: " << kernel::FetchPrintInfoByKernelAttr(kernel::GetKernelAttrFromBuildInfo(builder->Build())); 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 1c434edde8d..7a818f98891 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 @@ -356,9 +356,7 @@ void GPUKernelExecutor::OptimizeGraphWithDeviceInfo(const KernelGraphPtr &graph) // Graph optimization relevant to device data format auto optimizer = std::make_shared(); auto pm = std::make_shared(); -#ifdef ENABLE_TUPLE_UNFOLD pm->AddPass(std::make_shared("insert_type_transform_op")); -#endif // ReplaceAddNFusion depends on the input expansion of AddN, so must be after the operator select. pm->AddPass(std::make_shared()); // PrintReduceFusion depends on the input expansion of Print, so must be after the operator select.