Skip to content

Commit b45de3a

Browse files
committed
Now use dist_check to check all distributed related and addressed commments
1 parent b5a4201 commit b45de3a

File tree

3 files changed

+71
-81
lines changed

3 files changed

+71
-81
lines changed

setup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@
2525
from tools.setup_helpers.split_types import split_types
2626
from tools.setup_helpers.generate_code import generate_code
2727
from tools.setup_helpers.ninja_builder import NinjaBuilder, ninja_build_ext
28-
from tools.setup_helpers.ib_detect import WITH_IB_DEVICES
28+
from tools.setup_helpers.dist_check import WITH_DISTRIBUTED, \
29+
WITH_DISTRIBUTED_MW, WITH_GLOO_IBVERBS
2930

3031
DEBUG = check_env_flag('DEBUG')
3132

3233
IS_WINDOWS = (platform.system() == 'Windows')
3334
IS_DARWIN = (platform.system() == 'Darwin')
3435
IS_LINUX = (platform.system() == 'Linux')
3536

36-
WITH_DISTRIBUTED = not check_env_flag('NO_DISTRIBUTED') and not IS_WINDOWS
37-
WITH_DISTRIBUTED_MW = WITH_DISTRIBUTED and check_env_flag('WITH_DISTRIBUTED_MW')
3837

3938
WITH_SCALARS = check_env_flag('WITH_SCALARS')
4039

@@ -139,8 +138,7 @@ def build_libs(libs):
139138
my_env["CUDNN_LIBRARY"] = CUDNN_LIBRARY
140139
my_env["CUDNN_INCLUDE_DIR"] = CUDNN_INCLUDE_DIR
141140

142-
if WITH_DISTRIBUTED and (WITH_IB_DEVICES or
143-
check_env_flag("WITH_GLOO_IBVERBS")):
141+
if WITH_GLOO_IBVERBS:
144142
build_libs_cmd += ['--with-gloo-ibverbs']
145143

146144
if subprocess.call(build_libs_cmd + libs, env=my_env) != 0:

tools/setup_helpers/dist_check.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
import platform
3+
import subprocess
4+
5+
from .env import check_env_flag
6+
7+
IS_WINDOWS = (platform.system() == 'Windows')
8+
9+
WITH_DISTRIBUTED = not check_env_flag('NO_DISTRIBUTED') and not IS_WINDOWS
10+
WITH_DISTRIBUTED_MW = WITH_DISTRIBUTED and check_env_flag('WITH_DISTRIBUTED_MW')
11+
WITH_GLOO_IBVERBS = False
12+
13+
IB_DEVINFO_CMD = "ibv_devinfo"
14+
15+
16+
def get_command_path(command):
17+
"""
18+
Helper function that checks if the command exists in the path and gets the
19+
full path of a given linux command if it exists.
20+
"""
21+
def excutable(command_path):
22+
return os.path.isfile(command_path) and os.access(command_path, os.X_OK)
23+
24+
for path in os.environ["PATH"].split(os.pathsep):
25+
command_path = os.path.join(path, command)
26+
if excutable(command_path):
27+
return command_path
28+
29+
return None
30+
31+
32+
def should_build_ib():
33+
"""
34+
Helper function that detects the system's IB support and returns if we
35+
should build with IB support.
36+
"""
37+
try:
38+
# If the command doesn't exist, we can directly return instead of
39+
# making a subprocess call
40+
full_cmd_path = get_command_path(IB_DEVINFO_CMD)
41+
if not full_cmd_path:
42+
return False
43+
subprocess.check_output([full_cmd_path, "--list"])
44+
# Here we just would like to simply run the command to test if IB
45+
# related tools / lib are installed without parsing the output. We
46+
# will enable IB build as long as the command runs successfully.
47+
#
48+
# The output should look like either:
49+
#
50+
# > ibv_devinfo --list
51+
# 0 HCAs founds:
52+
#
53+
# or
54+
#
55+
# > ibv_devinfo --list
56+
# 4 HCAs found:
57+
# mlx5_3
58+
# mlx5_2
59+
# mlx5_1
60+
# mlx5_0
61+
return True
62+
except Exception:
63+
# We just take all the exceptions here without affecting the build
64+
return False
65+
66+
67+
WITH_GLOO_IBVERBS = WITH_DISTRIBUTED and (should_build_ib() or
68+
check_env_flag("WITH_GLOO_IBVERBS"))

tools/setup_helpers/ib_detect.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)