• 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_ARRANGEMENT_H_
18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_ARRANGEMENT_H_
19 
20 #include <cstdint>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 #include "frontend/parallel/status.h"
27 #include "frontend/parallel/tensor_layout/array.h"
28 
29 namespace mindspore {
30 namespace parallel {
31 class Arrangement : public Array {
32  public:
Arrangement()33   Arrangement() : size_(1) {}
34   ~Arrangement() override = default;
35   Status Init(const Shape &array) override;
size()36   int64_t size() const { return size_; }
37   Shape GetFrontElementByValue(int64_t value) const;
38   std::shared_ptr<std::vector<Arrangement>> GetExpandShapeList(const Arrangement &expand_shape) const;
39   Shape ComputeReverseAccumulateSumInReverseOrder() const;
40   std::shared_ptr<Arrangement> GetExpandedShapeByExpandListReserveLeft(
41     const std::vector<Arrangement> &expand_list) const;
42   std::shared_ptr<Arrangement> GetExpandedShapeByExpandListRemoveLeft(
43     const std::vector<Arrangement> &expand_list) const;
44   std::shared_ptr<std::pair<std::vector<Arrangement>, Arrangement>> GetExpandShapeListPair(
45     const Arrangement &expand_shape) const;
46   std::shared_ptr<Arrangement> GetUnifiedShape(const Arrangement &in2) const;
47   std::vector<size_t> GetSqueezeIdx() const;
48   Arrangement GetSqueezeArrangement() const;
49 
50  private:
51   bool IsValidArrangement();
52   void ComputeSize();
53   int64_t size_;
54 };
55 }  // namespace parallel
56 }  // namespace mindspore
57 
58 #endif  // MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_ARRANGEMENT_H_
59