You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

device_matrix.h 1.7 kB

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