1 /** 2 * Copyright 2021 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 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_CORE_GRAPH_BUILDER_H_ 17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_CORE_GRAPH_BUILDER_H_ 18 19 #include <unordered_map> 20 #include <tuple> 21 #include <string> 22 #include "ir/anf.h" 23 24 namespace mindspore::graphkernel { 25 using AnfNodePtrToAnfNodePtrMap = std::unordered_map<AnfNodePtr, AnfNodePtr>; 26 27 struct ClusterConfig { 28 bool inline_sub_func_graph{true}; 29 bool sort_parameter{false}; 30 AnfNodePtr only_output_basenode{nullptr}; 31 }; 32 33 std::tuple<FuncGraphPtr, AnfNodePtrList, AnfNodePtrList> BuildGraphFromNodes( 34 const AnfNodePtrList &nodes, const ClusterConfig &config = ClusterConfig{}); 35 std::tuple<FuncGraphPtr, AnfNodePtrList, AnfNodePtrList> BuildSingleGraphFromNodes( 36 const AnfNodePtrList &nodes, const ClusterConfig &config = ClusterConfig()); 37 CNodePtr CreateNewFuseCNode(const FuncGraphPtr &main_fg, const FuncGraphPtr &sub_fg, const AnfNodePtrList &inputs); 38 CNodePtr ReplaceNodesWithGraphKernelNode(const AnfNodePtrList &nodes, const FuncGraphPtr &main_graph, 39 const std::string &postfix = "", 40 const ClusterConfig &config = ClusterConfig{}); 41 bool ConvertTensorToParameter(const FuncGraphPtr &fg, AnfNodePtrList *inputs_ptr); 42 /// \brief Put Monads at end of parameters 43 bool SortParameters(const FuncGraphPtr &fg, AnfNodePtrList *inputs_ptr); 44 bool EliminateMaketupleGetitem(const FuncGraphPtr &fg); 45 void EliminateRedundantParameters(const FuncGraphPtr &func_graph, AnfNodePtrList *inputs); 46 } // namespace mindspore::graphkernel 47 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_CORE_GRAPH_BUILDER_H_ 48