• 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 
17 #ifndef MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_TENSORDOT_INFO_H_
18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_TENSORDOT_INFO_H_
19 
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23 #include <vector>
24 
25 #include "utils/ms_utils.h"
26 #include "ir/value.h"
27 #include "frontend/parallel/auto_parallel/operator_costmodel.h"
28 #include "frontend/parallel/ops_info/operator_info.h"
29 #include "frontend/parallel/strategy.h"
30 #include "frontend/parallel/tensor_layout/tensor_redistribution.h"
31 
32 namespace mindspore {
33 namespace parallel {
34 enum AxesType {
35   INT_TYPE = 0,
36   TUPLE_TYPE,
37   TUPLE_TUPLE_TYPE,
38 };
39 
40 class TensorDotInfo : public OperatorInfo {
41  public:
TensorDotInfo(const std::string & name,const Shapes & inputs_shape,const Shapes & outputs_shape,const PrimitiveAttrs & attrs)42   TensorDotInfo(const std::string &name, const Shapes &inputs_shape, const Shapes &outputs_shape,
43                 const PrimitiveAttrs &attrs)
44       : OperatorInfo(name, inputs_shape, outputs_shape, attrs, std::make_shared<TensorDotCost>()) {}
45   ~TensorDotInfo() override = default;
46 
47   Status Init(const StrategyPtr &strategy) override;
48   Status InitForCostModel(const StrategyPtr &strategy) override;
49 
50   std::vector<StrategyPtr> GenerateOpStrategies(int64_t stage_id) override;
51   Status SetCostUnderStrategy(const StrategyPtr &strategy) override;
52   Status PrepareStrategy(int32_t stage_id, size_t dev_num, Dimensions combined_partitions, size_t input0_shape_size,
53                          size_t input1_shape_size, StrategyPtr *sp);
54 
55  protected:
56   Status CheckStrategy(const StrategyPtr &strategy) override;
57   Status InferForwardCommunication() override;
58   Status InferDevMatrixShape() override;
59   Status InferTensorMap() override;
60   Status GetAttrs() override;
61   std::shared_ptr<Strategys> GenerateBatchStrategies() override;
62   void InferTensorMapAxesInt(const TensorMap &tensor_map_index);
63   void InferTensorMapAxesTuple(size_t size, const TensorMap &input_a_tensor_map, const TensorMap &tensor_map_index);
64   void ShowAxes();
65   Shape origin_dev_matrix_shape_;
66 
67   AxesType axes_type_ = INT_TYPE;
68   int32_t axes_int_ = 1;
69   std::vector<int32_t> axes_tuple_;
70   std::vector<std::vector<int32_t>> axes_tuple_tuple_;
71 };
72 }  // namespace parallel
73 }  // namespace mindspore
74 #endif  // MINDSPORE_CCSRC_FRONTEND_PARALLEL_OPS_INFO_TENSORDOT_INFO_H_
75