• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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_PRE_ACTIVATE_ASCEND_ENHANCER_SPLIT_INPUTS_FOR_REDUCE_SCATTER_H_
17 #define MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_ENHANCER_SPLIT_INPUTS_FOR_REDUCE_SCATTER_H_
18 
19 #include <memory>
20 #include <vector>
21 #include "backend/optimizer/common/optimizer.h"
22 #include "backend/optimizer/ascend/ascend_helper.h"
23 
24 namespace mindspore {
25 namespace opt {
26 class SplitInputsForReduceScatter : public PatternProcessPass {
27  public:
28   explicit SplitInputsForReduceScatter(bool multigraph = true)
29       : PatternProcessPass("split_inputs_for_reduce_scatter", multigraph),
30         kernel_select_(std::make_shared<KernelSelect>()) {}
31   ~SplitInputsForReduceScatter() override = default;
32   const BaseRef DefinePattern() const override;
33   const AnfNodePtr Process(const FuncGraphPtr &, const AnfNodePtr &, const EquivPtr &) const override;
34 
35  private:
36   AnfNodePtr RearrangeInputsForReduceScatter(const FuncGraphPtr &func_graph, const AnfNodePtr &node,
37                                              const std::vector<AnfNodePtr> &inputs, int64_t rank_size) const;
38   std::vector<AnfNodePtr> InsertSplitForInput(const FuncGraphPtr &func_graph, const CNodePtr &node,
39                                               int64_t rank_size) const;
40   KernelSelectPtr kernel_select_;
41 };
42 }  // namespace opt
43 }  // namespace mindspore
44 #endif  // MINDSPORE_CCSRC_PRE_ACTIVATE_ASCEND_ENHANCER_SPLIT_INPUTS_FOR_REDUCE_SCATTER_H_
45