1 /** 2 * Copyright 2020 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_ASCEND_IR_FUSION_SOFTMAX_GRAD_EXT_FUSION_H_ 17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_IR_FUSION_SOFTMAX_GRAD_EXT_FUSION_H_ 18 19 #include <memory> 20 #include <string> 21 #include "backend/optimizer/common/optimizer.h" 22 23 namespace mindspore { 24 namespace opt { 25 class SoftmaxGradExtFusion : public PatternProcessPass { 26 public: 27 explicit SoftmaxGradExtFusion(const std::string &name = "softmax_grad_ext_fusion", bool multigraph = true) PatternProcessPass(name,multigraph)28 : PatternProcessPass(name, multigraph) { 29 input0_ = std::make_shared<Var>(); 30 input1_ = std::make_shared<Var>(); 31 input2_ = std::make_shared<Var>(); 32 sum_var_ = std::make_shared<Var>(std::make_shared<Primitive>(prim::kPrimReduceSum->name())); 33 } 34 ~SoftmaxGradExtFusion() override = default; 35 const BaseRef DefinePattern() const override; 36 const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override; 37 38 protected: 39 VarPtr input0_; 40 VarPtr input1_; 41 VarPtr input2_; 42 VarPtr sum_var_; 43 }; 44 45 class SoftmaxGradExtFusionV2 : public SoftmaxGradExtFusion { 46 public: 47 explicit SoftmaxGradExtFusionV2(bool multigraph = true) 48 : SoftmaxGradExtFusion("softmax_grad_ext_fusion_v2", multigraph) {} 49 ~SoftmaxGradExtFusionV2() override = default; 50 const BaseRef DefinePattern() const override; 51 }; 52 53 class SoftmaxGradExtFusionV3 : public SoftmaxGradExtFusion { 54 public: 55 explicit SoftmaxGradExtFusionV3(bool multigraph = true) 56 : SoftmaxGradExtFusion("softmax_grad_ext_fusion_v3", multigraph) {} 57 ~SoftmaxGradExtFusionV3() override = default; 58 const BaseRef DefinePattern() const override; 59 }; 60 } // namespace opt 61 } // namespace mindspore 62 #endif // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_IR_FUSION_SOFTMAX_GRAD_EXT_FUSION_H_ 63