• 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_MAP_H_
18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_MAP_H_
19 
20 #include <cstdint>
21 #include <map>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 #include "frontend/parallel/status.h"
26 #include "frontend/parallel/tensor_layout/arrangement.h"
27 #include "frontend/parallel/tensor_layout/array.h"
28 
29 namespace mindspore {
30 namespace parallel {
31 constexpr int64_t MAP_NONE = -1;
32 
33 class Map : public Array {
34  public:
35   Map() = default;
36   ~Map() override = default;
37   Status Init(const Shape &array) override;
38   int64_t GetMaxItem() const;
39   int64_t GetIndexByValue(int64_t value) const;
40   std::shared_ptr<Map> ExpandMapByNone(const Arrangement &expand_num_list) const;
41   std::shared_ptr<Map> ExpandMapByDecreaseNumber(const Arrangement &expand_num_list) const;
42   std::shared_ptr<std::vector<Arrangement>> ReMapVector(const std::vector<Arrangement> &input_vector) const;
43   bool CheckNoneByIdxList(std::vector<size_t> idx_list) const;
44   Map SqueezeMapByIdxList(std::vector<size_t> idx_list) const;
45 
46  private:
47   bool IsValidMap();
48 };
49 }  // namespace parallel
50 }  // namespace mindspore
51 
52 #endif  // MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_MAP_H_
53