aboutsummaryrefslogtreecommitdiffhomepage
path: root/configure.py
diff options
context:
space:
mode:
authorGravatar Sami Kama <samikama@users.noreply.github.com>2018-08-14 15:00:46 -0700
committerGravatar GitHub <noreply@github.com>2018-08-14 15:00:46 -0700
commit4e368d7143757113d9c4d7e943be80fa5283d5e4 (patch)
tree057029e86f3ce34b87e91ce6f332ed7353855032 /configure.py
parent303ad054d555891be25aa9a6e8d63719327f09c3 (diff)
parenta00fba38681fa28d6d20cd730fe362864b819a0d (diff)
Merge branch 'master' into BazelNoStrip
Diffstat (limited to 'configure.py')
-rw-r--r--configure.py207
1 files changed, 123 insertions, 84 deletions
diff --git a/configure.py b/configure.py
index 708b2dfea9..023d317c67 100644
--- a/configure.py
+++ b/configure.py
@@ -35,8 +35,8 @@ except ImportError:
_DEFAULT_CUDA_VERSION = '9.0'
_DEFAULT_CUDNN_VERSION = '7'
-_DEFAULT_NCCL_VERSION = '1.3'
-_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,5.2'
+_DEFAULT_NCCL_VERSION = '2.2'
+_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,7.0'
_DEFAULT_CUDA_PATH = '/usr/local/cuda'
_DEFAULT_CUDA_PATH_LINUX = '/opt/cuda'
_DEFAULT_CUDA_PATH_WIN = ('C:/Program Files/NVIDIA GPU Computing '
@@ -680,7 +680,7 @@ def create_android_sdk_rule(environ_cp):
if is_windows() or is_cygwin():
default_sdk_path = cygpath('%s/Android/Sdk' % environ_cp['APPDATA'])
elif is_macos():
- default_sdk_path = '%s/library/Android/Sdk/ndk-bundle' % environ_cp['HOME']
+ default_sdk_path = '%s/library/Android/Sdk' % environ_cp['HOME']
else:
default_sdk_path = '%s/Android/Sdk' % environ_cp['HOME']
@@ -835,17 +835,20 @@ def set_tf_cuda_version(environ_cp):
'[Default is %s]: ') % (tf_cuda_version, default_cuda_path)
cuda_toolkit_path = get_from_env_or_user_or_default(
environ_cp, 'CUDA_TOOLKIT_PATH', ask_cuda_path, default_cuda_path)
+ if is_windows() or is_cygwin():
+ cuda_toolkit_path = cygpath(cuda_toolkit_path)
if is_windows():
- cuda_rt_lib_path = 'lib/x64/cudart.lib'
+ cuda_rt_lib_paths = ['lib/x64/cudart.lib']
elif is_linux():
- cuda_rt_lib_path = 'lib64/libcudart.so.%s' % tf_cuda_version
+ cuda_rt_lib_paths = ['%s/libcudart.so.%s' % (x, tf_cuda_version)
+ for x in ['lib64', 'lib/x86_64-linux-gnu']]
elif is_macos():
- cuda_rt_lib_path = 'lib/libcudart.%s.dylib' % tf_cuda_version
+ cuda_rt_lib_paths = ['lib/libcudart.%s.dylib' % tf_cuda_version]
- cuda_toolkit_path_full = os.path.join(cuda_toolkit_path, cuda_rt_lib_path)
- if os.path.exists(cuda_toolkit_path_full):
- break
+ cuda_toolkit_paths_full = [os.path.join(cuda_toolkit_path, x) for x in cuda_rt_lib_paths]
+ if any([os.path.exists(x) for x in cuda_toolkit_paths_full]):
+ break
# Reset and retry
print('Invalid path to CUDA %s toolkit. %s cannot be found' %
@@ -880,7 +883,7 @@ def set_tf_cudnn_version(environ_cp):
default_cudnn_path = environ_cp.get('CUDA_TOOLKIT_PATH')
ask_cudnn_path = (r'Please specify the location where cuDNN %s library is '
'installed. Refer to README.md for more details. [Default'
- ' is %s]:') % (tf_cudnn_version, default_cudnn_path)
+ ' is %s]: ') % (tf_cudnn_version, default_cudnn_path)
cudnn_install_path = get_from_env_or_user_or_default(
environ_cp, 'CUDNN_INSTALL_PATH', ask_cudnn_path, default_cudnn_path)
@@ -943,6 +946,35 @@ def set_tf_cudnn_version(environ_cp):
write_action_env_to_bazelrc('TF_CUDNN_VERSION', tf_cudnn_version)
+def is_cuda_compatible(lib, cuda_ver, cudnn_ver):
+ """Check compatibility between given library and cudnn/cudart libraries."""
+ ldd_bin = which('ldd') or '/usr/bin/ldd'
+ ldd_out = run_shell([ldd_bin, lib], True)
+ ldd_out = ldd_out.split(os.linesep)
+ cudnn_pattern = re.compile('.*libcudnn.so\\.?(.*) =>.*$')
+ cuda_pattern = re.compile('.*libcudart.so\\.?(.*) =>.*$')
+ cudnn = None
+ cudart = None
+ cudnn_ok = True # assume no cudnn dependency by default
+ cuda_ok = True # assume no cuda dependency by default
+ for line in ldd_out:
+ if 'libcudnn.so' in line:
+ cudnn = cudnn_pattern.search(line)
+ cudnn_ok = False
+ elif 'libcudart.so' in line:
+ cudart = cuda_pattern.search(line)
+ cuda_ok = False
+ if cudnn and len(cudnn.group(1)):
+ cudnn = convert_version_to_int(cudnn.group(1))
+ if cudart and len(cudart.group(1)):
+ cudart = convert_version_to_int(cudart.group(1))
+ if cudnn is not None:
+ cudnn_ok = (cudnn == cudnn_ver)
+ if cudart is not None:
+ cuda_ok = (cudart == cuda_ver)
+ return cudnn_ok and cuda_ok
+
+
def set_tf_tensorrt_install_path(environ_cp):
"""Set TENSORRT_INSTALL_PATH and TF_TENSORRT_VERSION.
@@ -959,8 +991,8 @@ def set_tf_tensorrt_install_path(environ_cp):
raise ValueError('Currently TensorRT is only supported on Linux platform.')
# Ask user whether to add TensorRT support.
- if str(int(get_var(
- environ_cp, 'TF_NEED_TENSORRT', 'TensorRT', False))) != '1':
+ if str(int(get_var(environ_cp, 'TF_NEED_TENSORRT', 'TensorRT',
+ False))) != '1':
return
for _ in range(_DEFAULT_PROMPT_ASK_ATTEMPTS):
@@ -973,47 +1005,29 @@ def set_tf_tensorrt_install_path(environ_cp):
# Result returned from "read" will be used unexpanded. That make "~"
# unusable. Going through one more level of expansion to handle that.
- trt_install_path = os.path.realpath(
- os.path.expanduser(trt_install_path))
+ trt_install_path = os.path.realpath(os.path.expanduser(trt_install_path))
def find_libs(search_path):
"""Search for libnvinfer.so in "search_path"."""
fl = set()
if os.path.exists(search_path) and os.path.isdir(search_path):
- fl.update([os.path.realpath(os.path.join(search_path, x))
- for x in os.listdir(search_path) if 'libnvinfer.so' in x])
+ fl.update([
+ os.path.realpath(os.path.join(search_path, x))
+ for x in os.listdir(search_path)
+ if 'libnvinfer.so' in x
+ ])
return fl
possible_files = find_libs(trt_install_path)
possible_files.update(find_libs(os.path.join(trt_install_path, 'lib')))
possible_files.update(find_libs(os.path.join(trt_install_path, 'lib64')))
-
- def is_compatible(tensorrt_lib, cuda_ver, cudnn_ver):
- """Check the compatibility between tensorrt and cudnn/cudart libraries."""
- ldd_bin = which('ldd') or '/usr/bin/ldd'
- ldd_out = run_shell([ldd_bin, tensorrt_lib]).split(os.linesep)
- cudnn_pattern = re.compile('.*libcudnn.so\\.?(.*) =>.*$')
- cuda_pattern = re.compile('.*libcudart.so\\.?(.*) =>.*$')
- cudnn = None
- cudart = None
- for line in ldd_out:
- if 'libcudnn.so' in line:
- cudnn = cudnn_pattern.search(line)
- elif 'libcudart.so' in line:
- cudart = cuda_pattern.search(line)
- if cudnn and len(cudnn.group(1)):
- cudnn = convert_version_to_int(cudnn.group(1))
- if cudart and len(cudart.group(1)):
- cudart = convert_version_to_int(cudart.group(1))
- return (cudnn == cudnn_ver) and (cudart == cuda_ver)
-
cuda_ver = convert_version_to_int(environ_cp['TF_CUDA_VERSION'])
cudnn_ver = convert_version_to_int(environ_cp['TF_CUDNN_VERSION'])
nvinfer_pattern = re.compile('.*libnvinfer.so.?(.*)$')
highest_ver = [0, None, None]
for lib_file in possible_files:
- if is_compatible(lib_file, cuda_ver, cudnn_ver):
+ if is_cuda_compatible(lib_file, cuda_ver, cudnn_ver):
matches = nvinfer_pattern.search(lib_file)
if len(matches.groups()) == 0:
continue
@@ -1029,12 +1043,13 @@ def set_tf_tensorrt_install_path(environ_cp):
# Try another alternative from ldconfig.
ldconfig_bin = which('ldconfig') or '/sbin/ldconfig'
ldconfig_output = run_shell([ldconfig_bin, '-p'])
- search_result = re.search(
- '.*libnvinfer.so\\.?([0-9.]*).* => (.*)', ldconfig_output)
+ search_result = re.search('.*libnvinfer.so\\.?([0-9.]*).* => (.*)',
+ ldconfig_output)
if search_result:
libnvinfer_path_from_ldconfig = search_result.group(2)
if os.path.exists(libnvinfer_path_from_ldconfig):
- if is_compatible(libnvinfer_path_from_ldconfig, cuda_ver, cudnn_ver):
+ if is_cuda_compatible(libnvinfer_path_from_ldconfig, cuda_ver,
+ cudnn_ver):
trt_install_path = os.path.dirname(libnvinfer_path_from_ldconfig)
tf_tensorrt_version = search_result.group(1)
break
@@ -1083,8 +1098,10 @@ def set_tf_nccl_install_path(environ_cp):
raise ValueError('Currently NCCL is only supported on Linux platforms.')
ask_nccl_version = (
- 'Please specify the NCCL version you want to use. '
- '[Leave empty to default to NCCL %s]: ') % _DEFAULT_NCCL_VERSION
+ 'Please specify the NCCL version you want to use. If NCCL %s is not '
+ 'installed, then you can use version 1.3 that can be fetched '
+ 'automatically but it may have worse performance with multiple GPUs. '
+ '[Default is %s]: ') % (_DEFAULT_NCCL_VERSION, _DEFAULT_NCCL_VERSION)
for _ in range(_DEFAULT_PROMPT_ASK_ATTEMPTS):
tf_nccl_version = get_from_env_or_user_or_default(
@@ -1185,7 +1202,7 @@ def set_tf_cuda_compute_capabilities(environ_cp):
'https://developer.nvidia.com/cuda-gpus.\nPlease'
' note that each additional compute '
'capability significantly increases your '
- 'build time and binary size. [Default is: %s]' %
+ 'build time and binary size. [Default is: %s]: ' %
default_cuda_compute_capabilities)
tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
@@ -1220,28 +1237,13 @@ def set_tf_cuda_compute_capabilities(environ_cp):
def set_other_cuda_vars(environ_cp):
"""Set other CUDA related variables."""
- if is_windows():
- # The following three variables are needed for MSVC toolchain configuration
- # in Bazel
- environ_cp['CUDA_PATH'] = environ_cp.get('CUDA_TOOLKIT_PATH')
- environ_cp['CUDA_COMPUTE_CAPABILITIES'] = environ_cp.get(
- 'TF_CUDA_COMPUTE_CAPABILITIES')
- environ_cp['NO_WHOLE_ARCHIVE_OPTION'] = 1
- write_action_env_to_bazelrc('CUDA_PATH', environ_cp.get('CUDA_PATH'))
- write_action_env_to_bazelrc('CUDA_COMPUTE_CAPABILITIE',
- environ_cp.get('CUDA_COMPUTE_CAPABILITIE'))
- write_action_env_to_bazelrc('NO_WHOLE_ARCHIVE_OPTION',
- environ_cp.get('NO_WHOLE_ARCHIVE_OPTION'))
- write_to_bazelrc('build --config=win-cuda')
- write_to_bazelrc('test --config=win-cuda')
+ # If CUDA is enabled, always use GPU during build and test.
+ if environ_cp.get('TF_CUDA_CLANG') == '1':
+ write_to_bazelrc('build --config=cuda_clang')
+ write_to_bazelrc('test --config=cuda_clang')
else:
- # If CUDA is enabled, always use GPU during build and test.
- if environ_cp.get('TF_CUDA_CLANG') == '1':
- write_to_bazelrc('build --config=cuda_clang')
- write_to_bazelrc('test --config=cuda_clang')
- else:
- write_to_bazelrc('build --config=cuda')
- write_to_bazelrc('test --config=cuda')
+ write_to_bazelrc('build --config=cuda')
+ write_to_bazelrc('test --config=cuda')
def set_host_cxx_compiler(environ_cp):
@@ -1401,14 +1403,36 @@ def set_build_strip_flag():
write_to_bazelrc('build --strip=always')
-def set_windows_build_flags():
- if is_windows():
- # The non-monolithic build is not supported yet
- write_to_bazelrc('build --config monolithic')
- # Suppress warning messages
- write_to_bazelrc('build --copt=-w --host_copt=-w')
- # Output more verbose information when something goes wrong
- write_to_bazelrc('build --verbose_failures')
+def set_windows_build_flags(environ_cp):
+ """Set Windows specific build options."""
+ # The non-monolithic build is not supported yet
+ write_to_bazelrc('build --config monolithic')
+ # Suppress warning messages
+ write_to_bazelrc('build --copt=-w --host_copt=-w')
+ # Output more verbose information when something goes wrong
+ write_to_bazelrc('build --verbose_failures')
+ # The host and target platforms are the same in Windows build. So we don't
+ # have to distinct them. This avoids building the same targets twice.
+ write_to_bazelrc('build --distinct_host_configuration=false')
+ # Enable short object file path to avoid long path issue on Windows.
+ # TODO(pcloudy): Remove this flag when upgrading Bazel to 0.16.0
+ # Short object file path will be enabled by default.
+ write_to_bazelrc('build --experimental_shortened_obj_file_path=true')
+
+ if get_var(
+ environ_cp, 'TF_OVERRIDE_EIGEN_STRONG_INLINE', 'Eigen strong inline',
+ True,
+ ('Would you like to override eigen strong inline for some C++ '
+ 'compilation to reduce the compilation time?'),
+ 'Eigen strong inline overridden.',
+ 'Not overriding eigen strong inline, '
+ 'some compilations could take more than 20 mins.'):
+ # Due to a known MSVC compiler issue
+ # https://github.com/tensorflow/tensorflow/issues/10521
+ # Overriding eigen strong inline speeds up the compiling of
+ # conv_grad_ops_3d.cc and conv_ops_3d.cc by 20 minutes,
+ # but this also hurts the performance. Let users decide what they want.
+ write_to_bazelrc('build --define=override_eigen_strong_inline=true')
def config_info_line(name, help_text):
@@ -1428,14 +1452,14 @@ def main():
# environment variables.
environ_cp = dict(os.environ)
- check_bazel_version('0.10.0')
+ check_bazel_version('0.15.0')
reset_tf_configure_bazelrc(args.workspace)
cleanup_makefile()
setup_python(environ_cp)
if is_windows():
- environ_cp['TF_NEED_S3'] = '0'
+ environ_cp['TF_NEED_AWS'] = '0'
environ_cp['TF_NEED_GCP'] = '0'
environ_cp['TF_NEED_HDFS'] = '0'
environ_cp['TF_NEED_JEMALLOC'] = '0'
@@ -1448,19 +1472,31 @@ def main():
# TODO(ibiryukov): Investigate using clang as a cpu or cuda compiler on
# Windows.
environ_cp['TF_DOWNLOAD_CLANG'] = '0'
+ environ_cp['TF_ENABLE_XLA'] = '0'
+ environ_cp['TF_NEED_GDR'] = '0'
+ environ_cp['TF_NEED_VERBS'] = '0'
+ environ_cp['TF_NEED_MPI'] = '0'
+ environ_cp['TF_SET_ANDROID_WORKSPACE'] = '0'
if is_macos():
environ_cp['TF_NEED_JEMALLOC'] = '0'
environ_cp['TF_NEED_TENSORRT'] = '0'
+ # The numpy package on ppc64le uses OpenBLAS which has multi-threading
+ # issues that lead to incorrect answers. Set OMP_NUM_THREADS=1 at
+ # runtime to allow the Tensorflow testcases which compare numpy
+ # results to Tensorflow results to succeed.
+ if is_ppc64le():
+ write_action_env_to_bazelrc("OMP_NUM_THREADS", 1)
+
set_build_var(environ_cp, 'TF_NEED_JEMALLOC', 'jemalloc as malloc',
'with_jemalloc', True)
set_build_var(environ_cp, 'TF_NEED_GCP', 'Google Cloud Platform',
'with_gcp_support', True, 'gcp')
set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
'with_hdfs_support', True, 'hdfs')
- set_build_var(environ_cp, 'TF_NEED_S3', 'Amazon S3 File System',
- 'with_s3_support', True, 's3')
+ set_build_var(environ_cp, 'TF_NEED_AWS', 'Amazon AWS Platform',
+ 'with_aws_support', True, 'aws')
set_build_var(environ_cp, 'TF_NEED_KAFKA', 'Apache Kafka Platform',
'with_kafka_support', True, 'kafka')
set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
@@ -1523,9 +1559,8 @@ def main():
set_grpc_build_flags()
set_cc_opt_flags(environ_cp)
- if environ_cp.get("BAZEL_STRIP") != "0":
- set_build_strip_flag()
- set_windows_build_flags()
+ if is_windows():
+ set_windows_build_flags(environ_cp)
if get_var(
environ_cp, 'TF_SET_ANDROID_WORKSPACE', 'android workspace',
@@ -1537,11 +1572,15 @@ def main():
create_android_ndk_rule(environ_cp)
create_android_sdk_rule(environ_cp)
- print('Preconfigured Bazel build configs. You can use any of the below by '
- 'adding "--config=<>" to your build command. See tools/bazel.rc for '
- 'more details.')
- config_info_line('mkl', 'Build with MKL support.')
- config_info_line('monolithic', 'Config for mostly static monolithic build.')
+ # On Windows, we don't have MKL support and the build is always monolithic.
+ # So no need to print the following message.
+ # TODO(pcloudy): remove the following if check when they make sense on Windows
+ if not is_windows():
+ print('Preconfigured Bazel build configs. You can use any of the below by '
+ 'adding "--config=<>" to your build command. See tools/bazel.rc for '
+ 'more details.')
+ config_info_line('mkl', 'Build with MKL support.')
+ config_info_line('monolithic', 'Config for mostly static monolithic build.')
if __name__ == '__main__':
main()