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 #ifndef MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_FLOATSTATUS_ADDN_FUSION_H_ 17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_FLOATSTATUS_ADDN_FUSION_H_ 18 19 #include <string> 20 #include "include/backend/optimizer/pass.h" 21 #include "backend/common/graph_kernel/inplace_assign_builder.h" 22 23 namespace mindspore::graphkernel { 24 /** 25 * @brief Expand FloatStatus+AddN 26 * @example 27 * %1 = op1 28 * %2 = op2 29 * %3 = FloatStatus(%1) 30 * %4 = FloatStatus(%2) 31 * %5 = AddN(%3, %4) 32 * %6 = op3(%5) 33 * ----------> 34 * subgraph1(){ 35 * %1 = BroadCastTo(shape=[1],value=0) 36 * return %1 37 * } 38 * ----- 39 * subgraph2(a,b){ 40 * %1 = IsNan(a) 41 * %2 = IsInf(a) 42 * %3 = LogicalOr(%1, %2) 43 * %4 = ElemAny(%3) 44 * %5 = Assign(b, %4) 45 * return %5 46 * } 47 * ----- 48 * maingraph{ 49 * %0 = subgraph1() 50 * %1 = op1 51 * %2 = op2 52 * %3 = subgraph2(%1, %0) 53 * %4 = subgraph2(%2, %0) 54 * %5 = MakeTuple(%3, %4) 55 * %6 = Depend(%0, %5) 56 * %7 = op3(%6) 57 * return %7 58 * } 59 */ 60 class FloatStatusAddNFusion : public InplaceAssignBuilder { 61 public: InplaceAssignBuilder(name)62 explicit FloatStatusAddNFusion(const std::string &name = "floatstatus_addn_fusion") : InplaceAssignBuilder(name) {} 63 ~FloatStatusAddNFusion() override = default; 64 bool Run(const FuncGraphPtr &func_graph) override; 65 66 protected: 67 void ProcessFloatStatusAddN(const FuncGraphPtr &main_graph, const CNodePtr &addn, const FuncGraphManagerPtr &mng); 68 }; 69 } // namespace mindspore::graphkernel 70 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_FLOATSTATUS_ADDN_FUSION_H_ 71