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.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. class Hccl():
  18. """Hccl definition"""
  19. _instance_lock = threading.Lock()
  20. _instance = None
  21. _rank_id = 0
  22. _rank_size = 1
  23. def __init__(self):
  24. pass
  25. # pylint: disable=unused-argument
  26. def __new__(cls, *args, **kwargs):
  27. if not hasattr(Hccl, "_instance") or Hccl._instance is None:
  28. with Hccl._instance_lock:
  29. if not hasattr(Hccl,
  30. "_instance") or Hccl._instance is None:
  31. Hccl._instance = object.__new__(cls)
  32. Hccl._instance.__init__()
  33. return Hccl._instance
  34. @property
  35. def rank_id(self):
  36. return self._rank_id
  37. @rank_id.setter
  38. def rank_id(self, rank_id):
  39. self._rank_id = rank_id
  40. @property
  41. def rank_size(self):
  42. return self._rank_size
  43. @rank_size.setter
  44. def rank_size(self, size):
  45. self._rank_size = size
  46. # pylint: disable=unused-argument
  47. def get_rank_id(group=None):
  48. hccl = Hccl()
  49. return hccl.rank_id
  50. def get_rank_size(group=None):
  51. hccl = Hccl()
  52. if group is None:
  53. return hccl.rank_size
  54. if isinstance(group, str):
  55. return int(group.split("-")[0])
  56. raise ValueError
  57. # pylint: disable=unused-argument
  58. def get_world_rank_from_group_rank(group, group_rank_id):
  59. return group_rank_id
  60. # pylint: disable=unused-argument
  61. def get_group_rank_from_world_rank(world_rank_id, group):
  62. return world_rank_id
  63. # pylint: disable=unused-argument
  64. def create_group(group, rank_size, rank_ids):
  65. pass
  66. # pylint: disable=unused-argument
  67. def destroy_group(group):
  68. pass