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.

api.py 2.7 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """api definition"""
  16. import threading
  17. from mindspore.parallel._auto_parallel_context import auto_parallel_context
  18. class Hccl():
  19. """Hccl definition"""
  20. _instance_lock = threading.Lock()
  21. _instance = None
  22. _rank_id = 0
  23. _rank_size = 1
  24. def __init__(self):
  25. pass
  26. # pylint: disable=unused-argument
  27. def __new__(cls, *args, **kwargs):
  28. if not hasattr(Hccl, "_instance") or Hccl._instance is None:
  29. with Hccl._instance_lock:
  30. if not hasattr(Hccl,
  31. "_instance") or Hccl._instance is None:
  32. Hccl._instance = object.__new__(cls)
  33. Hccl._instance.__init__()
  34. return Hccl._instance
  35. @property
  36. def rank_id(self):
  37. return self._rank_id
  38. @rank_id.setter
  39. def rank_id(self, rank_id):
  40. self._rank_id = rank_id
  41. @property
  42. def rank_size(self):
  43. return self._rank_size
  44. @rank_size.setter
  45. def rank_size(self, size):
  46. self._rank_size = size
  47. # pylint: disable=unused-argument
  48. def get_rank_id(group=None):
  49. hccl = Hccl()
  50. return hccl.rank_id
  51. def get_rank_size(group=None):
  52. hccl = Hccl()
  53. if group is None or "nccl_world_group" in group:
  54. if auto_parallel_context().get_device_num_is_set() is False:
  55. return 1
  56. return auto_parallel_context().get_device_num()
  57. if isinstance(group, str):
  58. return int(group.split("-")[0])
  59. raise ValueError
  60. # pylint: disable=unused-argument
  61. def get_world_rank_from_group_rank(group, group_rank_id):
  62. return group_rank_id
  63. # pylint: disable=unused-argument
  64. def get_group_rank_from_world_rank(world_rank_id, group):
  65. return world_rank_id
  66. # pylint: disable=unused-argument
  67. def create_group(group, rank_size, rank_ids):
  68. pass
  69. # pylint: disable=unused-argument
  70. def destroy_group(group):
  71. pass
  72. # pylint: disable=unused-argument
  73. def set_fusion_strategy_by_idx():
  74. pass
  75. # pylint: disable=unused-argument
  76. def set_fusion_strategy_by_size():
  77. pass