• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 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_PARALLEL_MATMUL_CONCATENATE_H_
17 #define MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_PARALLEL_MATMUL_CONCATENATE_H_
18 
19 #include <vector>
20 #include <string>
21 #include <set>
22 #include <tuple>
23 #include <unordered_set>
24 #include <utility>
25 #include <memory>
26 #include "include/backend/anf_runtime_algorithm.h"
27 #include "include/common/utils/anfalgo.h"
28 #include "kernel/common_utils.h"
29 #include "backend/common/graph_kernel/graph_kernel_helper.h"
30 #include "backend/common/graph_kernel/core/parallel_op_concatenate.h"
31 
32 namespace mindspore::graphkernel {
33 using BMNK = std::tuple<int64_t, int64_t, int64_t, int64_t>;
34 using MMAttr = std::pair<bool, bool>;
35 class ParallelMatMulConcatenater : public ParallelOpConcatenater {
36  public:
ParallelMatMulConcatenater(uint64_t min_num_branches,const std::string & layout)37   explicit ParallelMatMulConcatenater(uint64_t min_num_branches, const std::string &layout)
38       : ParallelOpConcatenater("MatMul", min_num_branches, layout) {}
39 
40  protected:
41   virtual bool CanOpsBeCombined(const AnfNodePtr a, const AnfNodePtr b);
42   virtual bool IsSupportedOp(const AnfNodePtr n);
43   virtual AnfNodePtr MakeCombinedOp(const Group &branches);
44   bool IsArgCompatible(const AnfNodePtr a, const AnfNodePtr b) override;
45 
46  private:
47   ConcatenatePlan Analyse(const Group &branches) const;
48 };
49 
50 AnfNodePtr ConcatParallelMatMul(AnfNodePtr root, uint64_t min_num_branches, const std::string &layout,
51                                 const FuncGraphPtr &func_graph = nullptr);
52 }  // namespace mindspore::graphkernel
53 #endif  // MINDSPORE_CCSRC_BACKEND_OPTIMIZER_GRAPH_KERNEL_PARALLEL_MATMUL_CONCATENATE_H_
54