• 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_DEVICE_MATRIX_H_
18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_DEVICE_MATRIX_H_
19 
20 #include <cstdint>
21 #include <string>
22 #include <vector>
23 
24 #include "frontend/parallel/status.h"
25 #include "utils/convert_utils.h"
26 
27 namespace mindspore {
28 namespace parallel {
29 using RankList = std::vector<int64_t>;
30 using Shape = std::vector<int64_t>;
31 
32 class DeviceMatrix {
33  public:
34   DeviceMatrix(int64_t rank, RankList devices, Shape dev_shape);
35   DeviceMatrix() = default;
36   ~DeviceMatrix() = default;
group_list()37   std::vector<RankList> group_list() const { return group_list_; }
38   Status CreateGroupList();
39   Status GetDevicesByTensorMap(const Shape &tensor_map, RankList *rank_list);
40   Status GetDevicesAlongDim(const uint64_t &dim, RankList *devices);
41 
42  private:
43   int64_t rank_ = -1;
44   RankList dev_list_;
45   // From low dim to high dim. eg: [D0 D1 D2 D3]
46   Shape dev_shape_;
47   std::vector<RankList> group_list_;
48 };
49 
50 std::string ShapeToString(const Shape &shape);
51 std::string ListToString(const RankList &list);
52 }  // namespace parallel
53 }  // namespace mindspore
54 
55 #endif  // MINDSPORE_CCSRC_FRONTEND_PARALLEL_DEVICE_MATRIX_H_
56