• 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_BACKEND_OPTIMIZER_ASCEND_MINDIR_OPTIMIZER_UNIFY_OUTPUT_H_
17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_MINDIR_OPTIMIZER_UNIFY_OUTPUT_H_
18 
19 #include "include/backend/optimizer/optimizer.h"
20 #include "include/backend/optimizer/pattern_to_pattern.h"
21 
22 namespace mindspore {
23 namespace opt {
24 class BuildTupleGetFunc {
25  public:
BuildTupleGetFunc(const size_t output_size)26   explicit BuildTupleGetFunc(const size_t output_size) : output_size_(output_size) {}
27   AnfNodePtr operator()(const PatternMap &m, const AnfNodePtr &get_item) const;
28   size_t output_size_;
29 };
30 class FtrlUnifyOutput : public PatternToPatternPass {
31  public:
FtrlUnifyOutput()32   FtrlUnifyOutput() : PatternToPatternPass("ftrl_unify_output", true) {}
33   ~FtrlUnifyOutput() override = default;
34 
35   void DefineSrcPattern(SrcPattern *src_pattern) override;
36   void DefineDstPattern(DstPattern *dst_pattern) override;
37   bool CheckMatchedDAG(const PatternMap &, const FuncGraphPtr &, const AnfNodePtr &) const override;
38 };
39 class MomentumUnifyOutput : public PatternToPatternPass {
40  public:
MomentumUnifyOutput()41   MomentumUnifyOutput() : PatternToPatternPass("momentum_unify_output", true) {}
42   ~MomentumUnifyOutput() override = default;
43 
44   void DefineSrcPattern(SrcPattern *src_pattern) override;
45   void DefineDstPattern(DstPattern *dst_pattern) override;
46   bool CheckMatchedDAG(const PatternMap &, const FuncGraphPtr &, const AnfNodePtr &) const override;
47 };
48 class CenteredRMSPropUnifyOutput : public PatternToPatternPass {
49  public:
CenteredRMSPropUnifyOutput()50   CenteredRMSPropUnifyOutput() : PatternToPatternPass("centered_rmsprop_unify_output", true) {}
51   ~CenteredRMSPropUnifyOutput() override = default;
52 
53   void DefineSrcPattern(SrcPattern *src_pattern) override;
54   void DefineDstPattern(DstPattern *dst_pattern) override;
55   bool CheckMatchedDAG(const PatternMap &, const FuncGraphPtr &, const AnfNodePtr &) const override;
56 };
57 class RMSPropUnifyOutput : public PatternToPatternPass {
58  public:
RMSPropUnifyOutput()59   RMSPropUnifyOutput() : PatternToPatternPass("rmsprop_unify_output", true) {}
60   ~RMSPropUnifyOutput() override = default;
61 
62   void DefineSrcPattern(SrcPattern *src_pattern) override;
63   void DefineDstPattern(DstPattern *dst_pattern) override;
64   bool CheckMatchedDAG(const PatternMap &, const FuncGraphPtr &, const AnfNodePtr &) const override;
65 };
66 }  // namespace opt
67 }  // namespace mindspore
68 #endif  // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_ASCEND_MINDIR_OPTIMIZER_UNIFY_OUTPUT_H_
69