4 from itertools
import chain
6 from .env
import IS_WINDOWS, IS_DARWIN, IS_CONDA, CONDA_DIR, check_negative_env_flag, \
9 from .cuda
import USE_CUDA, CUDA_HOME
11 USE_NCCL = USE_CUDA
and not check_negative_env_flag(
'USE_NCCL')
and not IS_DARWIN
and not IS_WINDOWS
12 USE_SYSTEM_NCCL =
False 14 NCCL_SYSTEM_LIB =
None 15 NCCL_INCLUDE_DIR =
None 17 USE_STATIC_NCCL = os.getenv(
"USE_STATIC_NCCL")
18 LIBNCCL_PREFIX =
"libnccl" 19 if USE_STATIC_NCCL
is not None:
20 LIBNCCL_PREFIX =
"libnccl_static" 22 if USE_CUDA
and not check_negative_env_flag(
'USE_SYSTEM_NCCL'):
23 ENV_ROOT = os.getenv(
'NCCL_ROOT_DIR',
None)
24 LIB_DIR = os.getenv(
'NCCL_LIB_DIR',
None)
25 INCLUDE_DIR = os.getenv(
'NCCL_INCLUDE_DIR',
None)
27 lib_paths = list(filter(bool, [
30 os.path.join(ENV_ROOT,
'lib')
if ENV_ROOT
is not None else None,
31 os.path.join(ENV_ROOT,
'lib',
'x86_64-linux-gnu')
if ENV_ROOT
is not None else None,
32 os.path.join(ENV_ROOT,
'lib64')
if ENV_ROOT
is not None else None,
33 os.path.join(CUDA_HOME,
'lib'),
34 os.path.join(CUDA_HOME,
'lib64'),
36 '/usr/lib/x86_64-linux-gnu/',
37 '/usr/lib/powerpc64le-linux-gnu/',
38 '/usr/lib/aarch64-linux-gnu/',
45 include_paths = list(filter(bool, [
48 os.path.join(ENV_ROOT,
'include')
if ENV_ROOT
is not None else None,
49 os.path.join(CUDA_HOME,
'include'),
55 lib_paths.append(os.path.join(CONDA_DIR,
'lib'))
56 for path
in lib_paths:
57 path = os.path.expanduser(path)
58 if path
is None or not os.path.exists(path):
60 if glob.glob(os.path.join(path, LIBNCCL_PREFIX +
'*')):
63 preferred_path = glob.glob(os.path.join(path, LIBNCCL_PREFIX +
'*[0-9]*'))
64 if len(preferred_path) == 0:
65 NCCL_SYSTEM_LIB = glob.glob(os.path.join(path, LIBNCCL_PREFIX +
'*'))[0]
67 NCCL_SYSTEM_LIB = os.path.realpath(preferred_path[0])
69 for path
in include_paths:
70 path = os.path.expanduser(path)
71 if path
is None or not os.path.exists(path):
73 if glob.glob(os.path.join(path,
'nccl.h')):
74 NCCL_INCLUDE_DIR = path
76 if NCCL_LIB_DIR
is not None and NCCL_INCLUDE_DIR
is not None:
77 USE_SYSTEM_NCCL =
True 78 NCCL_ROOT_DIR = os.path.commonprefix((NCCL_LIB_DIR, NCCL_INCLUDE_DIR))