• 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_COMMON_GRAPH_KERNEL_CORE_SPLIT_SCHEMER_H_
17 #define MINDSPORE_CCSRC_COMMON_GRAPH_KERNEL_CORE_SPLIT_SCHEMER_H_
18 #include <map>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 #include "ir/anf.h"
23 #include "ir/func_graph.h"
24 #include "utils/hash_map.h"
25 
26 namespace mindspore::graphkernel {
27 class SplitSchemer {
28  public:
29   SplitSchemer() = default;
30   virtual ~SplitSchemer() = default;
31   virtual bool Split(const FuncGraphPtr &func_graph) = 0;
32   virtual bool NeedInline(size_t group_id) const;
split_plan()33   const std::vector<AnfNodePtrList> &split_plan() const { return split_plan_; }
34 
35  protected:
36   std::vector<AnfNodePtrList> split_plan_;
37   std::vector<int> need_inline_;
38 };
39 using SplitSchemerPtr = std::shared_ptr<SplitSchemer>;
40 
41 class CommonSplitSchemer : public SplitSchemer {
42  protected:
43   // add a new group
44   size_t AddGroup(AnfNodePtrList &&nodes, bool need_inline);
45 
46   // group the return node and last MakeTuple node (if exists).
47   void GroupReturnNode(const FuncGraphPtr &func_graph);
48 
49   mindspore::HashMap<AnfNodePtr, size_t> node_group_;
50 };
51 }  // namespace mindspore::graphkernel
52 #endif  // MINDSPORE_CCSRC_COMMON_GRAPH_KERNEL_CORE_SPLIT_SCHEMER_H_
53