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.

test_management_api.py 4.2 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. management api
  16. """
  17. import mindspore.communication.management as D
  18. def has_raise_error(func, x):
  19. try:
  20. # pylint:disable=eval-used
  21. if x is None:
  22. func()
  23. else:
  24. func(x)
  25. print("x:{}".format(x))
  26. except (TypeError, ValueError, RuntimeError):
  27. return True
  28. else:
  29. return False
  30. def create_backend(name):
  31. D.Backend(name)
  32. def get_group_size_int(group):
  33. D.get_group_size(group)
  34. def create_group0(x):
  35. D.GlobalComm.BACKEND = D.Backend.HCCL
  36. D.create_group('0-1', x)
  37. def create_group1(x):
  38. D.GlobalComm.BACKEND = D.Backend.HCCL
  39. D.create_group('0-1', x)
  40. def create_group2(x):
  41. D.GlobalComm.BACKEND = D.Backend.HCCL
  42. D.create_group('0-1', x)
  43. def create_group3(x):
  44. D.GlobalComm.BACKEND = D.Backend.UNDEFINED
  45. D.create_group('0-1', x)
  46. def create_group4(x):
  47. D.GlobalComm.BACKEND = D.Backend.HCCL
  48. D.create_group('0-1', x)
  49. def get_world_rank_from_group_rank0():
  50. D.GlobalComm.BACKEND = D.Backend.HCCL
  51. D.get_world_rank_from_group_rank(D.HCCL_WORLD_COMM_GROUP, 0)
  52. def get_world_rank_from_group_rank1():
  53. D.GlobalComm.BACKEND = D.Backend.HCCL
  54. D.get_world_rank_from_group_rank('0-1', '0')
  55. def get_world_rank_from_group_rank2():
  56. D.GlobalComm.BACKEND = D.Backend.UNDEFINED
  57. D.get_world_rank_from_group_rank('0-1', 0)
  58. def get_group_rank_from_world_rank0():
  59. D.GlobalComm.BACKEND = D.Backend.HCCL
  60. D.get_group_rank_from_world_rank(0, D.HCCL_WORLD_COMM_GROUP)
  61. def get_group_rank_from_world_rank1():
  62. D.GlobalComm.BACKEND = D.Backend.HCCL
  63. D.get_group_rank_from_world_rank('0', '0-1')
  64. def get_group_rank_from_world_rank2():
  65. D.GlobalComm.BACKEND = D.Backend.UNDEFINED
  66. D.get_group_rank_from_world_rank(0, '0-1')
  67. def destroy_group0(x):
  68. D.GlobalComm.BACKEND = D.Backend.UNDEFINED
  69. D.destroy_group(x)
  70. def destroy_group1():
  71. D.GlobalComm.BACKEND = D.Backend.HCCL
  72. D.destroy_group(D.HCCL_WORLD_COMM_GROUP)
  73. def destroy_group2(x):
  74. D.GlobalComm.BACKEND = D.Backend.HCCL
  75. D.destroy_group(x)
  76. def test_raise_error_funcs():
  77. """test raise error funcs"""
  78. assert has_raise_error(create_backend, 123) is True
  79. assert has_raise_error(create_backend, 'hccl') is False
  80. assert has_raise_error(create_backend, 'nccl') is False
  81. assert has_raise_error(get_group_size_int, 123) is True
  82. assert has_raise_error(create_group0, (0, 1)) is True
  83. assert has_raise_error(create_group1, [0]) is False
  84. assert has_raise_error(create_group2, [0, 0, 1]) is True
  85. assert has_raise_error(create_group3, [0, 1]) is True
  86. assert has_raise_error(create_group4, [0, 1]) is False
  87. assert has_raise_error(get_world_rank_from_group_rank0, None) is True
  88. assert has_raise_error(get_world_rank_from_group_rank1, None) is True
  89. assert has_raise_error(get_world_rank_from_group_rank2, None) is True
  90. assert has_raise_error(get_group_rank_from_world_rank0, None) is True
  91. assert has_raise_error(get_group_rank_from_world_rank1, None) is True
  92. assert has_raise_error(get_group_rank_from_world_rank2, None) is True
  93. assert has_raise_error(destroy_group0, '0-1') is True
  94. assert has_raise_error(destroy_group1, None) is True
  95. assert has_raise_error(destroy_group2, '0-1') is False
  96. def test_get_rank_none():
  97. assert D.get_rank(group=None) == 0
  98. def test_group_funs():
  99. D.GlobalComm.BACKEND = D.Backend.HCCL
  100. assert D.get_group_size(group=None) == 1
  101. assert D.get_group_size('2-abcd') == 2
  102. assert D.get_world_rank_from_group_rank('0-1', 0) == 0
  103. assert D.get_group_rank_from_world_rank(0, '0-1') == 0