• 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 
17 #include <memory>
18 #include <utility>
19 #include <set>
20 #include <string>
21 #include <unordered_map>
22 #include "ir/anf.h"
23 #include "tools/optimizer/common/gllo_utils.h"
24 #include "backend/optimizer/common/node_pass.h"
25 #include "tools/optimizer/parallel/split_strategy.h"
26 #include "tools/optimizer/parallel/operator_info.h"
27 
28 #ifndef MINDSPORE_LITE_SRC_PASS_PARALLEL_PARALLEL_PASS_H_
29 #define MINDSPORE_LITE_SRC_PASS_PARALLEL_PARALLEL_PASS_H_
30 
31 namespace mindspore {
32 namespace opt {
33 class ParallelPass : public opt::NodePass {
34  public:
ParallelPass(const std::unordered_map<std::string,SplitStrategy> & strategys,const int32_t fmk_type)35   explicit ParallelPass(const std::unordered_map<std::string, SplitStrategy> &strategys, const int32_t fmk_type)
36       : NodePass("parallel_pass"), split_strategys_(strategys), fmk_type_(fmk_type) {}
37   ~ParallelPass() override = default;
38   AnfNodePtr Run(const FuncGraphPtr &func_graph, const AnfNodePtr &node) override;
39 
40  private:
41   // to check this node whether support to parallel && split
42   bool IsParallelCareNode(const AnfNodePtr &node);
43 
44   // set curr_node a new op_name with parallel symbol
45   bool SetParallelOpName(const AnfNodePtr &node, std::string *parallel_name);
46 
47   // create a parallel operator from different scope_name
48   OperatorInfoPtr CreateParallelOperator(const CNodePtr &cnode, const std::string &scope_name,
49                                          const std::string &parallel_op_name);
50 
51  private:
52   bool is_depth_wise_{false};
53   std::string type_name_;
54   std::unordered_map<std::string, SplitStrategy> split_strategys_;
55   int32_t fmk_type_{};
56 };
57 
58 }  // namespace opt
59 }  // namespace mindspore
60 
61 #endif  // MINDSPORE_LITE_SRC_PASS_PARALLEL_PARALLEL_PASS_H_
62