• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SPLIT_UMONAD_H_
17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_SPLIT_UMONAD_H_
18 
19 #include <memory>
20 #include <string>
21 #include "include/backend/optimizer/optimizer.h"
22 #include "backend/common/graph_kernel/core/graph_kernel_expander.h"
23 
24 namespace mindspore::graphkernel {
25 
26 class SplitNode : public opt::PatternProcessPass {
27  public:
PatternProcessPass(pass_name,multigraph)28   explicit SplitNode(std::string pass_name, bool multigraph = true) : PatternProcessPass(pass_name, multigraph) {}
29   ~SplitNode() override = default;
30   virtual const BaseRef DefinePattern() const = 0;
31   virtual const bool CanSplit(const AnfNodePtr &node) const = 0;
32   const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &node, const EquivPtr &) const override;
33 };
34 
35 class SplitAssign : public SplitNode {
36  public:
37   explicit SplitAssign(bool multigraph = true) : SplitNode("split_assign", multigraph) {}
38   ~SplitAssign() override = default;
39   const BaseRef DefinePattern() const override;
40   const bool CanSplit(const AnfNodePtr &node) const override;
41 };
42 
43 class OpUMonadExpanderDeco : public ExpanderDecorator {
44  public:
OpUMonadExpanderDeco(const ExpanderPtr & decorated,size_t input_idx)45   OpUMonadExpanderDeco(const ExpanderPtr &decorated, size_t input_idx)
46       : ExpanderDecorator(decorated), input_idx_(input_idx) {}
47   ~OpUMonadExpanderDeco() = default;
48 
GetCreator(size_t input_idx)49   static ExpanderCreatorFunc GetCreator(size_t input_idx) {
50     return [input_idx](const ExpanderPtr &decorated) {
51       return std::static_pointer_cast<Expander>(std::make_shared<OpUMonadExpanderDeco>(decorated, input_idx));
52     };
53   }
54   AnfNodePtr Run(const AnfNodePtr &node) override;
55 
56  protected:
57   size_t input_idx_;
58 };
59 }  // namespace mindspore::graphkernel
60 #endif  // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_SPLIT_UMONAD_H_
61