• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019 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_TENSOR_LAYOUT_CONSTRUCT_OPERATOR_H_
18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_CONSTRUCT_OPERATOR_H_
19 
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "ir/value.h"
25 #include "frontend/parallel/auto_parallel/costmodel.h"
26 #include "frontend/parallel/status.h"
27 
28 namespace mindspore {
29 namespace parallel {
30 using Args = std::vector<std::int64_t>;
31 enum class ReshapeMode : int64_t {
32   NO_RESHAPE = 0,
33   FROM_ORIGIN_BASE_SLICE_TO_TO_ORIGIN_BASE_SLICE,
34   FROM_ORIGIN_SLICE_TO_FROM_LAYOUT_SLICE,
35   FROM_ORIGIN_BASE_SLICE_TO_FROM_ORIGIN_SLICE,
36   TO_ORIGIN_SLICE_TO_TO_LAYOUT_SLICE,
37   TO_ORIGIN_SLICE_TO_TO_ORIGIN_BASE_SLICE,
38 };
39 
40 Operator CreateStridedSliceOp(int64_t value, const Shape &begin, const Shape &end, const Shape &strides);
41 class ConstructOperator {
42  public:
43   const int64_t DEFAULT = 0;
ConstructOperator()44   ConstructOperator() : dev_size_(0) {}
45   ~ConstructOperator() = default;
46   Status Init(const RankList &dev_list, const Shape &dev_matrix_shape, bool is_cost_model = false,
47               bool is_dynamic_shape = false);
48   OperatorVector SkipRedisReshapeOP(const Shape &shape) const;
49   Status ReshapeOP(const Shape &shape, bool use_origin_shape = false,
50                    enum ReshapeMode reshape_mode = ReshapeMode::NO_RESHAPE);
51   Status StridedSliceOP(const Args &args);
52   Status ReplaceStridedSliceOpToSplitOp(const Args &args);
53   Status AllGatherOP(int64_t dev_dim);
54   Status SplitOP(int64_t split_count);
55   Status ConcatOP(int64_t concat_dim);
56   Status AlltoAllOP(const Args &args);
GetOperator()57   Operator GetOperator() const { return op_; }
UpdateTensorShape(const Shape & tensor_shape)58   void UpdateTensorShape(const Shape &tensor_shape) { tensor_shape_ = tensor_shape; }
SetVirtualRank(const int64_t virtual_rank)59   void SetVirtualRank(const int64_t virtual_rank) { virtual_rank_ = virtual_rank; }
60 
61  private:
62   Operator op_;
63   size_t dev_size_;
64   Shape tensor_shape_;
65   RankList dev_list_;
66   Shape dev_matrix_shape_;
67   bool is_cost_model_ = false;
68   bool is_dynamic_shape_ = false;
69   int64_t virtual_rank_ = -1;
check_group()70   bool check_group() { return virtual_rank_ < 0; }
71   Status CreateGroupByDim(size_t axis, std::vector<Group> *group);
72 };
73 }  // namespace parallel
74 }  // namespace mindspore
75 
76 #endif  // MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_CONSTRUCT_OPERATOR_H_
77