1 /** 2 * Copyright 2022 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "include/common/debug/anf_dump_utils.h" 18 #include "abstract/abstract_function.h" 19 20 namespace mindspore { 21 namespace { GetAbstractFuncStr(const abstract::AbstractFunctionPtr & abs)22std::string GetAbstractFuncStr(const abstract::AbstractFunctionPtr &abs) { 23 std::ostringstream oss; 24 if (abs->isa<abstract::FuncGraphAbstractClosure>()) { 25 const auto &abstract_func_graph = abs->cast<abstract::FuncGraphAbstractClosurePtr>(); 26 if (abstract_func_graph->func_graph() != nullptr) { 27 oss << "@" << abstract_func_graph->func_graph()->ToString(); 28 } 29 } 30 if (abs->isa<abstract::PartialAbstractClosure>()) { 31 const auto &abstract_partial_func = abs->cast<abstract::PartialAbstractClosurePtr>(); 32 const auto &abstract_fn = abstract_partial_func->fn(); 33 if (abstract_fn->isa<abstract::FuncGraphAbstractClosure>()) { 34 const auto &abstract_func_graph = abstract_fn->cast<abstract::FuncGraphAbstractClosurePtr>(); 35 if (abstract_func_graph->func_graph() != nullptr) { 36 oss << "Partial(@" << abstract_func_graph->func_graph()->ToString() << ")"; 37 } 38 } 39 } 40 return oss.str(); 41 } 42 } // namespace 43 GetNodeFuncStr(const AnfNodePtr & nd)44std::string GetNodeFuncStr(const AnfNodePtr &nd) { 45 MS_EXCEPTION_IF_NULL(nd); 46 std::ostringstream oss; 47 std::string str; 48 const auto &abs = nd->abstract(); 49 50 if (IsValueNode<FuncGraph>(nd) || abs == nullptr || !abs->isa<abstract::AbstractFunction>()) { 51 return str; 52 } 53 const auto &abs_func = abs->cast<abstract::AbstractFunctionPtr>(); 54 55 if (abs_func->isa<abstract::AbstractFuncUnion>()) { 56 oss << "FuncUnion("; 57 bool first_item = true; 58 auto build_oss = [&oss, &first_item](const abstract::AbstractFuncAtomPtr &poss) { 59 auto abs_str = GetAbstractFuncStr(poss); 60 if (!first_item) { 61 oss << ", "; 62 } else { 63 first_item = false; 64 } 65 if (!abs_str.empty()) { 66 oss << abs_str; 67 } 68 }; 69 abs_func->Visit(build_oss); 70 oss << ")"; 71 return oss.str(); 72 } 73 return GetAbstractFuncStr(abs_func); 74 } 75 GetKernelNodeName(const AnfNodePtr & anf_node)76std::string GetKernelNodeName(const AnfNodePtr &anf_node) { 77 MS_EXCEPTION_IF_NULL(anf_node); 78 std::string kernel_name = anf_node->fullname_with_scope(); 79 if (kernel_name.empty()) { 80 kernel_name = anf_node->ToString(); 81 } 82 MS_LOG(DEBUG) << "Full scope kernel name is " << kernel_name << "."; 83 return kernel_name; 84 } 85 } // namespace mindspore 86