From 2eb7777457c1bd22aedd940b3d7d6c692c2a7f82 Mon Sep 17 00:00:00 2001 From: Qing <7652265+qing321hh@user.noreply.gitee.com> Date: Fri, 11 Mar 2022 01:10:24 +0000 Subject: [PATCH 1/2] add tf_adapter/python/npu_bridge/experimental. --- tf_adapter/python/npu_bridge/experimental/hccl.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tf_adapter/python/npu_bridge/experimental/hccl.py diff --git a/tf_adapter/python/npu_bridge/experimental/hccl.py b/tf_adapter/python/npu_bridge/experimental/hccl.py new file mode 100644 index 000000000..e69de29bb -- Gitee From f9c05bb527690cfe3923e1a7887d9061f60ab137 Mon Sep 17 00:00:00 2001 From: Qing <7652265+qing321hh@user.noreply.gitee.com> Date: Fri, 11 Mar 2022 01:10:34 +0000 Subject: [PATCH 2/2] update tf_adapter/python/npu_bridge/experimental/hccl.py. --- .../python/npu_bridge/experimental/hccl.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tf_adapter/python/npu_bridge/experimental/hccl.py b/tf_adapter/python/npu_bridge/experimental/hccl.py index e69de29bb..2259a2b5e 100644 --- a/tf_adapter/python/npu_bridge/experimental/hccl.py +++ b/tf_adapter/python/npu_bridge/experimental/hccl.py @@ -0,0 +1,31 @@ +import os +import ctypes + +def load_lib(lib_name): + try: + lib = ctypes.CDLL(lib_name) + except Exception as e: + raise ValueError('load lib ', lib_name, ' error') + + return lib + +hccl_graph_adp_ctypes = load_lib('libhcom_graph_adaptor.so') + +def c_str(string): + return ctypes.c_char_p(string.encode('utf-8')) + +def get_actual_rank_size(group="hccl_world_group"): + c_group = c_str(group) + c_rank_size = ctypes.c_uint() + ret = hccl_graph_adp_ctypes.HcomGetActualRankSize(c_group, ctypes.byref(c_rank_size)) + if ret != 0: + raise ValueError('get actual rank size error.') + return c_rank_size.value + +def get_user_rank_size(): + rank_size = int(os.getenv('RANK_SIZE')) + return rank_size + +def get_user_rank_id(): + rank_id = int(os.getenv('RANK_ID')) + return rank_id \ No newline at end of file -- Gitee