• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PLUGIN_DEVICE_CPU_OPTIMIZER_SOFTMAX_GRAD_FUSION_H_
17 #define MINDSPORE_CCSRC_PLUGIN_DEVICE_CPU_OPTIMIZER_SOFTMAX_GRAD_FUSION_H_
18 
19 #include <memory>
20 #include "include/backend/optimizer/optimizer.h"
21 #include "mindspore/core/ops/math_ops.h"
22 
23 namespace mindspore {
24 namespace opt {
25 class SoftmaxGradFusionCpu : public PatternProcessPass {
26  public:
27   explicit SoftmaxGradFusionCpu(bool multigraph = true) : PatternProcessPass("softmax_grad_fusion_cpu", multigraph) {
28     reduce_sum_ = std::make_shared<Var>(std::make_shared<Primitive>(prim::kPrimReduceSum->name()));
29     input0_ = std::make_shared<Var>();
30     input1_ = std::make_shared<Var>();
31     axis_ = std::make_shared<Var>();
32   }
33   ~SoftmaxGradFusionCpu() override = default;
34   const BaseRef DefinePattern() const override;
35   const AnfNodePtr Process(const FuncGraphPtr &graph, const AnfNodePtr &node, const EquivPtr &equiv) const override;
36 
37  private:
38   VarPtr reduce_sum_;
39   VarPtr input0_;
40   VarPtr input1_;
41   VarPtr axis_;
42 };
43 }  // namespace opt
44 }  // namespace mindspore
45 #endif  // MINDSPORE_CCSRC_PLUGIN_DEVICE_CPU_OPTIMIZER_SOFTMAX_GRAD_FUSION_H_
46