blob: a475c026308ea197557b1e72616282de9dbfae5a [file] [log] [blame]
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
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"""configure script to get build parameters from user."""
16
17from __future__ import absolute_import
18from __future__ import division
19from __future__ import print_function
20
Shanqing Cai71445712018-03-12 19:33:52 -070021import argparse
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070022import errno
23import os
24import platform
25import re
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070026import subprocess
27import sys
28
Andrew Sellec9885ea2017-11-06 09:37:03 -080029# pylint: disable=g-import-not-at-top
Jonathan Hseu008910f2017-08-25 14:01:05 -070030try:
31 from shutil import which
32except ImportError:
33 from distutils.spawn import find_executable as which
Andrew Sellec9885ea2017-11-06 09:37:03 -080034# pylint: enable=g-import-not-at-top
Jonathan Hseu008910f2017-08-25 14:01:05 -070035
A. Unique TensorFlower0cb8a072019-04-16 08:16:39 -070036_DEFAULT_CUDA_VERSION = '10'
37_DEFAULT_CUDNN_VERSION = '7'
38_DEFAULT_TENSORRT_VERSION = '5'
Smit Hinsufe7d1d92018-07-14 13:16:58 -070039_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,7.0'
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -070040
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070041_TF_OPENCL_VERSION = '1.2'
42_DEFAULT_COMPUTECPP_TOOLKIT_PATH = '/usr/local/computecpp'
Yifei Fengb1d8c592017-11-22 13:42:21 -080043_DEFAULT_TRISYCL_INCLUDE_DIR = '/usr/local/triSYCL/include'
A. Unique TensorFlower82820ef2018-11-12 13:22:13 -080044_SUPPORTED_ANDROID_NDK_VERSIONS = [10, 11, 12, 13, 14, 15, 16, 17, 18]
Austin Anderson6afface2017-12-05 11:59:17 -080045
46_DEFAULT_PROMPT_ASK_ATTEMPTS = 10
47
Shanqing Cai71445712018-03-12 19:33:52 -070048_TF_BAZELRC_FILENAME = '.tf_configure.bazelrc'
A. Unique TensorFlower7c5eb352018-10-01 07:15:23 -070049_TF_WORKSPACE_ROOT = ''
50_TF_BAZELRC = ''
A. Unique TensorFlowered297342019-03-15 11:25:28 -070051_TF_CURRENT_BAZEL_VERSION = None
Mark Daoust44000ad2019-06-18 09:26:26 -070052_TF_MIN_BAZEL_VERSION = '0.24.1'
53_TF_MAX_BAZEL_VERSION = '0.26.1'
Shanqing Cai71445712018-03-12 19:33:52 -070054
Jason Furmanek7c234152018-09-26 04:44:12 +000055NCCL_LIB_PATHS = [
TensorFlower Gardenerea5c5292018-10-01 17:28:26 -070056 'lib64/', 'lib/powerpc64le-linux-gnu/', 'lib/x86_64-linux-gnu/', ''
Jason Furmanek7c234152018-09-26 04:44:12 +000057]
Austin Anderson6afface2017-12-05 11:59:17 -080058
A. Unique TensorFlower76e879d2019-03-22 00:25:36 -070059# List of files to configure when building Bazel on Apple platforms.
A. Unique TensorFlower93e70732019-02-14 16:45:32 -080060APPLE_BAZEL_FILES = [
A. Unique TensorFlower6a059c02019-04-05 14:28:27 -070061 'tensorflow/lite/experimental/ios/BUILD',
A. Unique TensorFlower93e70732019-02-14 16:45:32 -080062 'tensorflow/lite/experimental/objc/BUILD',
63 'tensorflow/lite/experimental/swift/BUILD'
64]
65
A. Unique TensorFlower76e879d2019-03-22 00:25:36 -070066# List of files to move when building for iOS.
67IOS_FILES = [
68 'tensorflow/lite/experimental/objc/TensorFlowLiteObjC.podspec',
69 'tensorflow/lite/experimental/swift/TensorFlowLiteSwift.podspec',
70]
71
Austin Anderson6afface2017-12-05 11:59:17 -080072
73class UserInputError(Exception):
74 pass
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070075
76
77def is_windows():
78 return platform.system() == 'Windows'
79
80
81def is_linux():
82 return platform.system() == 'Linux'
83
84
85def is_macos():
86 return platform.system() == 'Darwin'
87
88
89def is_ppc64le():
90 return platform.machine() == 'ppc64le'
91
92
Jonathan Hseu008910f2017-08-25 14:01:05 -070093def is_cygwin():
94 return platform.system().startswith('CYGWIN_NT')
95
96
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070097def get_input(question):
98 try:
99 try:
100 answer = raw_input(question)
101 except NameError:
102 answer = input(question) # pylint: disable=bad-builtin
103 except EOFError:
104 answer = ''
105 return answer
106
107
108def symlink_force(target, link_name):
109 """Force symlink, equivalent of 'ln -sf'.
110
111 Args:
112 target: items to link to.
113 link_name: name of the link.
114 """
115 try:
116 os.symlink(target, link_name)
117 except OSError as e:
118 if e.errno == errno.EEXIST:
119 os.remove(link_name)
120 os.symlink(target, link_name)
121 else:
122 raise e
123
124
125def sed_in_place(filename, old, new):
126 """Replace old string with new string in file.
127
128 Args:
129 filename: string for filename.
130 old: string to replace.
131 new: new string to replace to.
132 """
133 with open(filename, 'r') as f:
134 filedata = f.read()
135 newdata = filedata.replace(old, new)
136 with open(filename, 'w') as f:
137 f.write(newdata)
138
139
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700140def write_to_bazelrc(line):
141 with open(_TF_BAZELRC, 'a') as f:
142 f.write(line + '\n')
143
144
145def write_action_env_to_bazelrc(var_name, var):
146 write_to_bazelrc('build --action_env %s="%s"' % (var_name, str(var)))
147
148
Jonathan Hseu008910f2017-08-25 14:01:05 -0700149def run_shell(cmd, allow_non_zero=False):
150 if allow_non_zero:
151 try:
152 output = subprocess.check_output(cmd)
153 except subprocess.CalledProcessError as e:
154 output = e.output
155 else:
156 output = subprocess.check_output(cmd)
157 return output.decode('UTF-8').strip()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700158
159
160def cygpath(path):
161 """Convert path from posix to windows."""
Martin Wicked57572e2017-09-02 19:21:45 -0700162 return os.path.abspath(path).replace('\\', '/')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700163
164
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700165def get_python_path(environ_cp, python_bin_path):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700166 """Get the python site package paths."""
167 python_paths = []
168 if environ_cp.get('PYTHONPATH'):
169 python_paths = environ_cp.get('PYTHONPATH').split(':')
170 try:
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700171 library_paths = run_shell([
172 python_bin_path, '-c',
173 'import site; print("\\n".join(site.getsitepackages()))'
174 ]).split('\n')
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700175 except subprocess.CalledProcessError:
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700176 library_paths = [
177 run_shell([
178 python_bin_path, '-c',
179 'from distutils.sysconfig import get_python_lib;'
180 'print(get_python_lib())'
181 ])
182 ]
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700183
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700184 all_paths = set(python_paths + library_paths)
185
186 paths = []
187 for path in all_paths:
188 if os.path.isdir(path):
189 paths.append(path)
190 return paths
191
192
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700193def get_python_major_version(python_bin_path):
194 """Get the python major version."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700195 return run_shell([python_bin_path, '-c', 'import sys; print(sys.version[0])'])
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700196
197
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700198def setup_python(environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700199 """Setup python related env variables."""
200 # Get PYTHON_BIN_PATH, default is the current running python.
201 default_python_bin_path = sys.executable
202 ask_python_bin_path = ('Please specify the location of python. [Default is '
203 '%s]: ') % default_python_bin_path
204 while True:
A. Unique TensorFlower5001ac02019-04-03 11:59:08 -0700205 python_bin_path = get_from_env_or_user_or_default(environ_cp,
206 'PYTHON_BIN_PATH',
207 ask_python_bin_path,
208 default_python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700209 # Check if the path is valid
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700210 if os.path.isfile(python_bin_path) and os.access(python_bin_path, os.X_OK):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700211 break
212 elif not os.path.exists(python_bin_path):
213 print('Invalid python path: %s cannot be found.' % python_bin_path)
214 else:
215 print('%s is not executable. Is it the python binary?' % python_bin_path)
216 environ_cp['PYTHON_BIN_PATH'] = ''
217
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700218 # Convert python path to Windows style before checking lib and version
Martin Wicked57572e2017-09-02 19:21:45 -0700219 if is_windows() or is_cygwin():
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700220 python_bin_path = cygpath(python_bin_path)
221
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700222 # Get PYTHON_LIB_PATH
223 python_lib_path = environ_cp.get('PYTHON_LIB_PATH')
224 if not python_lib_path:
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700225 python_lib_paths = get_python_path(environ_cp, python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700226 if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1':
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700227 python_lib_path = python_lib_paths[0]
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700228 else:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700229 print('Found possible Python library paths:\n %s' %
230 '\n '.join(python_lib_paths))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700231 default_python_lib_path = python_lib_paths[0]
232 python_lib_path = get_input(
Jonathan Hseu008910f2017-08-25 14:01:05 -0700233 'Please input the desired Python library path to use. '
234 'Default is [%s]\n' % python_lib_paths[0])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700235 if not python_lib_path:
236 python_lib_path = default_python_lib_path
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700237 environ_cp['PYTHON_LIB_PATH'] = python_lib_path
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700238
TensorFlower Gardener61a87202018-10-01 12:25:39 -0700239 _ = get_python_major_version(python_bin_path)
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700240
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700241 # Convert python path to Windows style before writing into bazel.rc
Martin Wicked57572e2017-09-02 19:21:45 -0700242 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700243 python_lib_path = cygpath(python_lib_path)
244
245 # Set-up env variables used by python_configure.bzl
246 write_action_env_to_bazelrc('PYTHON_BIN_PATH', python_bin_path)
247 write_action_env_to_bazelrc('PYTHON_LIB_PATH', python_lib_path)
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700248 write_to_bazelrc('build --python_path=\"%s"' % python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700249 environ_cp['PYTHON_BIN_PATH'] = python_bin_path
250
William D. Ironsdcc76a52018-11-20 10:35:18 -0600251 # If choosen python_lib_path is from a path specified in the PYTHONPATH
252 # variable, need to tell bazel to include PYTHONPATH
253 if environ_cp.get('PYTHONPATH'):
254 python_paths = environ_cp.get('PYTHONPATH').split(':')
255 if python_lib_path in python_paths:
TensorFlower Gardener968cd182018-11-28 11:33:16 -0800256 write_action_env_to_bazelrc('PYTHONPATH', environ_cp.get('PYTHONPATH'))
William D. Ironsdcc76a52018-11-20 10:35:18 -0600257
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700258 # Write tools/python_bin_path.sh
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700259 with open(
260 os.path.join(_TF_WORKSPACE_ROOT, 'tools', 'python_bin_path.sh'),
261 'w') as f:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700262 f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path)
263
264
A. Unique TensorFlower7c5eb352018-10-01 07:15:23 -0700265def reset_tf_configure_bazelrc():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700266 """Reset file that contains customized config settings."""
267 open(_TF_BAZELRC, 'w').close()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700268
TensorFlower Gardenerabb763b2019-02-06 16:23:03 -0800269
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700270def cleanup_makefile():
271 """Delete any leftover BUILD files from the Makefile build.
272
273 These files could interfere with Bazel parsing.
274 """
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700275 makefile_download_dir = os.path.join(_TF_WORKSPACE_ROOT, 'tensorflow',
276 'contrib', 'makefile', 'downloads')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700277 if os.path.isdir(makefile_download_dir):
278 for root, _, filenames in os.walk(makefile_download_dir):
279 for f in filenames:
280 if f.endswith('BUILD'):
281 os.remove(os.path.join(root, f))
282
283
284def get_var(environ_cp,
285 var_name,
286 query_item,
287 enabled_by_default,
288 question=None,
289 yes_reply=None,
290 no_reply=None):
291 """Get boolean input from user.
292
293 If var_name is not set in env, ask user to enable query_item or not. If the
294 response is empty, use the default.
295
296 Args:
297 environ_cp: copy of the os.environ.
R S Nikhil Krishna05e348b2019-04-18 15:58:12 +0530298 var_name: string for name of environment variable, e.g. "TF_NEED_CUDA".
299 query_item: string for feature related to the variable, e.g. "CUDA for
300 Nvidia GPUs".
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700301 enabled_by_default: boolean for default behavior.
302 question: optional string for how to ask for user input.
Michael Cased90054e2018-02-07 14:36:00 -0800303 yes_reply: optional string for reply when feature is enabled.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700304 no_reply: optional string for reply when feature is disabled.
305
306 Returns:
307 boolean value of the variable.
Frank Chenc4ef9272018-01-10 11:36:52 -0800308
309 Raises:
310 UserInputError: if an environment variable is set, but it cannot be
311 interpreted as a boolean indicator, assume that the user has made a
312 scripting error, and will continue to provide invalid input.
313 Raise the error to avoid infinitely looping.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700314 """
315 if not question:
316 question = 'Do you wish to build TensorFlow with %s support?' % query_item
317 if not yes_reply:
318 yes_reply = '%s support will be enabled for TensorFlow.' % query_item
319 if not no_reply:
320 no_reply = 'No %s' % yes_reply
321
322 yes_reply += '\n'
323 no_reply += '\n'
324
325 if enabled_by_default:
326 question += ' [Y/n]: '
327 else:
328 question += ' [y/N]: '
329
330 var = environ_cp.get(var_name)
Frank Chenc4ef9272018-01-10 11:36:52 -0800331 if var is not None:
332 var_content = var.strip().lower()
333 true_strings = ('1', 't', 'true', 'y', 'yes')
334 false_strings = ('0', 'f', 'false', 'n', 'no')
335 if var_content in true_strings:
336 var = True
337 elif var_content in false_strings:
338 var = False
339 else:
340 raise UserInputError(
341 'Environment variable %s must be set as a boolean indicator.\n'
342 'The following are accepted as TRUE : %s.\n'
343 'The following are accepted as FALSE: %s.\n'
A. Unique TensorFlowered297342019-03-15 11:25:28 -0700344 'Current value is %s.' %
345 (var_name, ', '.join(true_strings), ', '.join(false_strings), var))
Frank Chenc4ef9272018-01-10 11:36:52 -0800346
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700347 while var is None:
348 user_input_origin = get_input(question)
349 user_input = user_input_origin.strip().lower()
350 if user_input == 'y':
351 print(yes_reply)
352 var = True
353 elif user_input == 'n':
354 print(no_reply)
355 var = False
356 elif not user_input:
357 if enabled_by_default:
358 print(yes_reply)
359 var = True
360 else:
361 print(no_reply)
362 var = False
363 else:
364 print('Invalid selection: %s' % user_input_origin)
365 return var
366
367
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700368def set_build_var(environ_cp,
369 var_name,
370 query_item,
371 option_name,
372 enabled_by_default,
373 bazel_config_name=None):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700374 """Set if query_item will be enabled for the build.
375
376 Ask user if query_item will be enabled. Default is used if no input is given.
377 Set subprocess environment variable and write to .bazelrc if enabled.
378
379 Args:
380 environ_cp: copy of the os.environ.
R S Nikhil Krishna05e348b2019-04-18 15:58:12 +0530381 var_name: string for name of environment variable, e.g. "TF_NEED_CUDA".
382 query_item: string for feature related to the variable, e.g. "CUDA for
383 Nvidia GPUs".
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700384 option_name: string for option to define in .bazelrc.
385 enabled_by_default: boolean for default behavior.
Michael Case98850a52017-09-14 13:35:57 -0700386 bazel_config_name: Name for Bazel --config argument to enable build feature.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700387 """
388
389 var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default)))
390 environ_cp[var_name] = var
391 if var == '1':
A. Unique TensorFlower5001ac02019-04-03 11:59:08 -0700392 write_to_bazelrc('build:%s --define %s=true' %
393 (bazel_config_name, option_name))
Yifei Fengec451f52018-10-05 12:53:50 -0700394 write_to_bazelrc('build --config=%s' % bazel_config_name)
Michael Case98850a52017-09-14 13:35:57 -0700395 elif bazel_config_name is not None:
396 # TODO(mikecase): Migrate all users of configure.py to use --config Bazel
397 # options and not to set build configs through environment variables.
A. Unique TensorFlower5001ac02019-04-03 11:59:08 -0700398 write_to_bazelrc('build:%s --define %s=true' %
399 (bazel_config_name, option_name))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700400
401
402def set_action_env_var(environ_cp,
403 var_name,
404 query_item,
405 enabled_by_default,
406 question=None,
407 yes_reply=None,
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -0700408 no_reply=None,
409 bazel_config_name=None):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700410 """Set boolean action_env variable.
411
412 Ask user if query_item will be enabled. Default is used if no input is given.
413 Set environment variable and write to .bazelrc.
414
415 Args:
416 environ_cp: copy of the os.environ.
R S Nikhil Krishna05e348b2019-04-18 15:58:12 +0530417 var_name: string for name of environment variable, e.g. "TF_NEED_CUDA".
418 query_item: string for feature related to the variable, e.g. "CUDA for
419 Nvidia GPUs".
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700420 enabled_by_default: boolean for default behavior.
421 question: optional string for how to ask for user input.
Michael Cased90054e2018-02-07 14:36:00 -0800422 yes_reply: optional string for reply when feature is enabled.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700423 no_reply: optional string for reply when feature is disabled.
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -0700424 bazel_config_name: adding config to .bazelrc instead of action_env.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700425 """
426 var = int(
427 get_var(environ_cp, var_name, query_item, enabled_by_default, question,
428 yes_reply, no_reply))
429
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -0700430 if not bazel_config_name:
431 write_action_env_to_bazelrc(var_name, var)
432 elif var:
433 write_to_bazelrc('build --config=%s' % bazel_config_name)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700434 environ_cp[var_name] = str(var)
435
436
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700437def convert_version_to_int(version):
438 """Convert a version number to a integer that can be used to compare.
439
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700440 Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The
441 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.
442
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700443 Args:
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700444 version: a version to be converted
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700445
446 Returns:
447 An integer if converted successfully, otherwise return None.
448 """
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700449 version = version.split('-')[0]
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700450 version_segments = version.split('.')
Austin Anderson87ea41d2019-04-04 10:03:50 -0700451 # Treat "0.24" as "0.24.0"
452 if len(version_segments) == 2:
453 version_segments.append('0')
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700454 for seg in version_segments:
455 if not seg.isdigit():
456 return None
457
458 version_str = ''.join(['%03d' % int(seg) for seg in version_segments])
459 return int(version_str)
460
461
Mihai Maruseace7a123f2018-11-30 13:33:25 -0800462def check_bazel_version(min_version, max_version):
463 """Check installed bazel version is between min_version and max_version.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700464
465 Args:
Mihai Maruseac4db860f2019-04-19 08:52:10 -0700466 min_version: string for minimum bazel version (must exist!).
467 max_version: string for maximum bazel version (must exist!).
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700468
469 Returns:
470 The bazel version detected.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700471 """
Jonathan Hseu008910f2017-08-25 14:01:05 -0700472 if which('bazel') is None:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700473 print('Cannot find bazel. Please install bazel.')
474 sys.exit(0)
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700475 curr_version = run_shell(
476 ['bazel', '--batch', '--bazelrc=/dev/null', 'version'])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700477
478 for line in curr_version.split('\n'):
479 if 'Build label: ' in line:
480 curr_version = line.split('Build label: ')[1]
481 break
482
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700483 min_version_int = convert_version_to_int(min_version)
484 curr_version_int = convert_version_to_int(curr_version)
Mihai Maruseace7a123f2018-11-30 13:33:25 -0800485 max_version_int = convert_version_to_int(max_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700486
487 # Check if current bazel version can be detected properly.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700488 if not curr_version_int:
489 print('WARNING: current bazel installation is not a release version.')
490 print('Make sure you are running at least bazel %s' % min_version)
491 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700492
Michael Cased94271a2017-08-22 17:26:52 -0700493 print('You have bazel %s installed.' % curr_version)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700494
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700495 if curr_version_int < min_version_int:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700496 print('Please upgrade your bazel installation to version %s or higher to '
497 'build TensorFlow!' % min_version)
Jason Zamanb41761c2018-10-14 11:28:53 +0800498 sys.exit(1)
TensorFlower Gardener78c246b2018-12-13 12:37:42 -0800499 if (curr_version_int > max_version_int and
500 'TF_IGNORE_MAX_BAZEL_VERSION' not in os.environ):
Mihai Maruseace7a123f2018-11-30 13:33:25 -0800501 print('Please downgrade your bazel installation to version %s or lower to '
Mihai Maruseace0963c42018-12-20 14:27:40 -0800502 'build TensorFlow! To downgrade: download the installer for the old '
503 'version (from https://github.com/bazelbuild/bazel/releases) then '
504 'run the installer.' % max_version)
Jason Zamanb41761c2018-10-14 11:28:53 +0800505 sys.exit(1)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700506 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700507
508
509def set_cc_opt_flags(environ_cp):
510 """Set up architecture-dependent optimization flags.
511
512 Also append CC optimization flags to bazel.rc..
513
514 Args:
515 environ_cp: copy of the os.environ.
516 """
517 if is_ppc64le():
518 # gcc on ppc64le does not support -march, use mcpu instead
519 default_cc_opt_flags = '-mcpu=native'
A. Unique TensorFlower1bba94a2018-04-04 15:45:20 -0700520 elif is_windows():
521 default_cc_opt_flags = '/arch:AVX'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700522 else:
Justin Lebar9ef04f52018-10-10 18:52:45 -0700523 default_cc_opt_flags = '-march=native -Wno-sign-compare'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700524 question = ('Please specify optimization flags to use during compilation when'
525 ' bazel option "--config=opt" is specified [Default is %s]: '
526 ) % default_cc_opt_flags
527 cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',
528 question, default_cc_opt_flags)
529 for opt in cc_opt_flags.split():
Michael Case00177422017-11-10 13:14:03 -0800530 write_to_bazelrc('build:opt --copt=%s' % opt)
531 # It should be safe on the same build host.
A. Unique TensorFlower1bba94a2018-04-04 15:45:20 -0700532 if not is_ppc64le() and not is_windows():
Shanqing Cai71445712018-03-12 19:33:52 -0700533 write_to_bazelrc('build:opt --host_copt=-march=native')
Michael Casebb3355d2017-11-09 08:46:31 -0800534 write_to_bazelrc('build:opt --define with_default_optimizations=true')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700535
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700536
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700537def set_tf_cuda_clang(environ_cp):
538 """set TF_CUDA_CLANG action_env.
539
540 Args:
541 environ_cp: copy of the os.environ.
542 """
543 question = 'Do you want to use clang as CUDA compiler?'
544 yes_reply = 'Clang will be used as CUDA compiler.'
545 no_reply = 'nvcc will be used as CUDA compiler.'
546 set_action_env_var(
547 environ_cp,
548 'TF_CUDA_CLANG',
549 None,
550 False,
551 question=question,
552 yes_reply=yes_reply,
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -0700553 no_reply=no_reply,
554 bazel_config_name='cuda_clang')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700555
556
A. Unique TensorFlowerfd29e952017-12-22 03:07:51 -0800557def set_tf_download_clang(environ_cp):
558 """Set TF_DOWNLOAD_CLANG action_env."""
Ilya Biryukov9e651e42018-03-22 05:33:42 -0700559 question = 'Do you wish to download a fresh release of clang? (Experimental)'
A. Unique TensorFlowerfd29e952017-12-22 03:07:51 -0800560 yes_reply = 'Clang will be downloaded and used to compile tensorflow.'
561 no_reply = 'Clang will not be downloaded.'
562 set_action_env_var(
563 environ_cp,
564 'TF_DOWNLOAD_CLANG',
565 None,
566 False,
567 question=question,
568 yes_reply=yes_reply,
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -0700569 no_reply=no_reply,
570 bazel_config_name='download_clang')
A. Unique TensorFlowerfd29e952017-12-22 03:07:51 -0800571
572
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700573def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
574 var_default):
575 """Get var_name either from env, or user or default.
576
577 If var_name has been set as environment variable, use the preset value, else
578 ask for user input. If no input is provided, the default is used.
579
580 Args:
581 environ_cp: copy of the os.environ.
R S Nikhil Krishna05e348b2019-04-18 15:58:12 +0530582 var_name: string for name of environment variable, e.g. "TF_NEED_CUDA".
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700583 ask_for_var: string for how to ask for user input.
584 var_default: default value string.
585
586 Returns:
587 string value for var_name
588 """
589 var = environ_cp.get(var_name)
590 if not var:
591 var = get_input(ask_for_var)
Michael Cased94271a2017-08-22 17:26:52 -0700592 print('\n')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700593 if not var:
594 var = var_default
595 return var
596
597
598def set_clang_cuda_compiler_path(environ_cp):
599 """Set CLANG_CUDA_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700600 default_clang_path = which('clang') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700601 ask_clang_path = ('Please specify which clang should be used as device and '
602 'host compiler. [Default is %s]: ') % default_clang_path
603
604 while True:
605 clang_cuda_compiler_path = get_from_env_or_user_or_default(
606 environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path,
607 default_clang_path)
608 if os.path.exists(clang_cuda_compiler_path):
609 break
610
611 # Reset and retry
612 print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path)
613 environ_cp['CLANG_CUDA_COMPILER_PATH'] = ''
614
615 # Set CLANG_CUDA_COMPILER_PATH
616 environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path
617 write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',
618 clang_cuda_compiler_path)
619
620
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700621def prompt_loop_or_load_from_env(environ_cp,
622 var_name,
623 var_default,
624 ask_for_var,
625 check_success,
626 error_msg,
627 suppress_default_error=False,
628 n_ask_attempts=_DEFAULT_PROMPT_ASK_ATTEMPTS):
Austin Anderson6afface2017-12-05 11:59:17 -0800629 """Loop over user prompts for an ENV param until receiving a valid response.
630
631 For the env param var_name, read from the environment or verify user input
632 until receiving valid input. When done, set var_name in the environ_cp to its
633 new value.
634
635 Args:
636 environ_cp: (Dict) copy of the os.environ.
637 var_name: (String) string for name of environment variable, e.g. "TF_MYVAR".
638 var_default: (String) default value string.
639 ask_for_var: (String) string for how to ask for user input.
640 check_success: (Function) function that takes one argument and returns a
641 boolean. Should return True if the value provided is considered valid. May
642 contain a complex error message if error_msg does not provide enough
643 information. In that case, set suppress_default_error to True.
644 error_msg: (String) String with one and only one '%s'. Formatted with each
645 invalid response upon check_success(input) failure.
646 suppress_default_error: (Bool) Suppress the above error message in favor of
647 one from the check_success function.
648 n_ask_attempts: (Integer) Number of times to query for valid input before
649 raising an error and quitting.
650
651 Returns:
652 [String] The value of var_name after querying for input.
653
654 Raises:
655 UserInputError: if a query has been attempted n_ask_attempts times without
Frank Chenc4ef9272018-01-10 11:36:52 -0800656 success, assume that the user has made a scripting error, and will
657 continue to provide invalid input. Raise the error to avoid infinitely
658 looping.
Austin Anderson6afface2017-12-05 11:59:17 -0800659 """
660 default = environ_cp.get(var_name) or var_default
661 full_query = '%s [Default is %s]: ' % (
662 ask_for_var,
663 default,
664 )
665
666 for _ in range(n_ask_attempts):
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700667 val = get_from_env_or_user_or_default(environ_cp, var_name, full_query,
Austin Anderson6afface2017-12-05 11:59:17 -0800668 default)
669 if check_success(val):
670 break
671 if not suppress_default_error:
672 print(error_msg % val)
673 environ_cp[var_name] = ''
674 else:
A. Unique TensorFlower5001ac02019-04-03 11:59:08 -0700675 raise UserInputError('Invalid %s setting was provided %d times in a row. '
676 'Assuming to be a scripting mistake.' %
677 (var_name, n_ask_attempts))
Austin Anderson6afface2017-12-05 11:59:17 -0800678
679 environ_cp[var_name] = val
680 return val
681
682
683def create_android_ndk_rule(environ_cp):
684 """Set ANDROID_NDK_HOME and write Android NDK WORKSPACE rule."""
685 if is_windows() or is_cygwin():
A. Unique TensorFlower5001ac02019-04-03 11:59:08 -0700686 default_ndk_path = cygpath('%s/Android/Sdk/ndk-bundle' %
687 environ_cp['APPDATA'])
Austin Anderson6afface2017-12-05 11:59:17 -0800688 elif is_macos():
689 default_ndk_path = '%s/library/Android/Sdk/ndk-bundle' % environ_cp['HOME']
690 else:
691 default_ndk_path = '%s/Android/Sdk/ndk-bundle' % environ_cp['HOME']
692
693 def valid_ndk_path(path):
694 return (os.path.exists(path) and
695 os.path.exists(os.path.join(path, 'source.properties')))
696
697 android_ndk_home_path = prompt_loop_or_load_from_env(
698 environ_cp,
699 var_name='ANDROID_NDK_HOME',
700 var_default=default_ndk_path,
701 ask_for_var='Please specify the home path of the Android NDK to use.',
702 check_success=valid_ndk_path,
703 error_msg=('The path %s or its child file "source.properties" '
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700704 'does not exist.'))
Michael Case51053502018-06-05 17:47:19 -0700705 write_action_env_to_bazelrc('ANDROID_NDK_HOME', android_ndk_home_path)
Jared Dukea0104b72019-04-04 12:23:58 -0700706 write_action_env_to_bazelrc(
707 'ANDROID_NDK_API_LEVEL',
708 get_ndk_api_level(environ_cp, android_ndk_home_path))
Austin Anderson6afface2017-12-05 11:59:17 -0800709
710
711def create_android_sdk_rule(environ_cp):
712 """Set Android variables and write Android SDK WORKSPACE rule."""
713 if is_windows() or is_cygwin():
714 default_sdk_path = cygpath('%s/Android/Sdk' % environ_cp['APPDATA'])
715 elif is_macos():
Shashi Shekharc0ff0cc2018-07-17 09:00:24 -0700716 default_sdk_path = '%s/library/Android/Sdk' % environ_cp['HOME']
Austin Anderson6afface2017-12-05 11:59:17 -0800717 else:
718 default_sdk_path = '%s/Android/Sdk' % environ_cp['HOME']
719
720 def valid_sdk_path(path):
721 return (os.path.exists(path) and
722 os.path.exists(os.path.join(path, 'platforms')) and
723 os.path.exists(os.path.join(path, 'build-tools')))
724
725 android_sdk_home_path = prompt_loop_or_load_from_env(
726 environ_cp,
727 var_name='ANDROID_SDK_HOME',
728 var_default=default_sdk_path,
729 ask_for_var='Please specify the home path of the Android SDK to use.',
730 check_success=valid_sdk_path,
731 error_msg=('Either %s does not exist, or it does not contain the '
732 'subdirectories "platforms" and "build-tools".'))
733
734 platforms = os.path.join(android_sdk_home_path, 'platforms')
735 api_levels = sorted(os.listdir(platforms))
736 api_levels = [x.replace('android-', '') for x in api_levels]
737
738 def valid_api_level(api_level):
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700739 return os.path.exists(
740 os.path.join(android_sdk_home_path, 'platforms',
741 'android-' + api_level))
Austin Anderson6afface2017-12-05 11:59:17 -0800742
743 android_api_level = prompt_loop_or_load_from_env(
744 environ_cp,
745 var_name='ANDROID_API_LEVEL',
746 var_default=api_levels[-1],
747 ask_for_var=('Please specify the Android SDK API level to use. '
748 '[Available levels: %s]') % api_levels,
749 check_success=valid_api_level,
750 error_msg='Android-%s is not present in the SDK path.')
751
752 build_tools = os.path.join(android_sdk_home_path, 'build-tools')
753 versions = sorted(os.listdir(build_tools))
754
755 def valid_build_tools(version):
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700756 return os.path.exists(
757 os.path.join(android_sdk_home_path, 'build-tools', version))
Austin Anderson6afface2017-12-05 11:59:17 -0800758
759 android_build_tools_version = prompt_loop_or_load_from_env(
760 environ_cp,
761 var_name='ANDROID_BUILD_TOOLS_VERSION',
762 var_default=versions[-1],
763 ask_for_var=('Please specify an Android build tools version to use. '
764 '[Available versions: %s]') % versions,
765 check_success=valid_build_tools,
766 error_msg=('The selected SDK does not have build-tools version %s '
767 'available.'))
768
Michael Case51053502018-06-05 17:47:19 -0700769 write_action_env_to_bazelrc('ANDROID_BUILD_TOOLS_VERSION',
770 android_build_tools_version)
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700771 write_action_env_to_bazelrc('ANDROID_SDK_API_LEVEL', android_api_level)
772 write_action_env_to_bazelrc('ANDROID_SDK_HOME', android_sdk_home_path)
Austin Anderson6afface2017-12-05 11:59:17 -0800773
774
Jared Dukea0104b72019-04-04 12:23:58 -0700775def get_ndk_api_level(environ_cp, android_ndk_home_path):
776 """Gets the appropriate NDK API level to use for the provided Android NDK path."""
777
778 # First check to see if we're using a blessed version of the NDK.
Austin Anderson6afface2017-12-05 11:59:17 -0800779 properties_path = '%s/source.properties' % android_ndk_home_path
780 if is_windows() or is_cygwin():
781 properties_path = cygpath(properties_path)
782 with open(properties_path, 'r') as f:
783 filedata = f.read()
784
785 revision = re.search(r'Pkg.Revision = (\d+)', filedata)
786 if revision:
Jared Dukea0104b72019-04-04 12:23:58 -0700787 ndk_version = revision.group(1)
Michael Case51053502018-06-05 17:47:19 -0700788 else:
789 raise Exception('Unable to parse NDK revision.')
Jared Dukea0104b72019-04-04 12:23:58 -0700790 if int(ndk_version) not in _SUPPORTED_ANDROID_NDK_VERSIONS:
791 print('WARNING: The NDK version in %s is %s, which is not '
792 'supported by Bazel (officially supported versions: %s). Please use '
793 'another version. Compiling Android targets may result in confusing '
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -0700794 'errors.\n' %
795 (android_ndk_home_path, ndk_version, _SUPPORTED_ANDROID_NDK_VERSIONS))
Jared Dukea0104b72019-04-04 12:23:58 -0700796
797 # Now grab the NDK API level to use. Note that this is different from the
798 # SDK API level, as the NDK API level is effectively the *min* target SDK
799 # version.
800 platforms = os.path.join(android_ndk_home_path, 'platforms')
801 api_levels = sorted(os.listdir(platforms))
802 api_levels = [
803 x.replace('android-', '') for x in api_levels if 'android-' in x
804 ]
805
806 def valid_api_level(api_level):
807 return os.path.exists(
808 os.path.join(android_ndk_home_path, 'platforms',
809 'android-' + api_level))
810
811 android_ndk_api_level = prompt_loop_or_load_from_env(
812 environ_cp,
813 var_name='ANDROID_NDK_API_LEVEL',
814 var_default='18', # 18 is required for GPU acceleration.
815 ask_for_var=('Please specify the (min) Android NDK API level to use. '
816 '[Available levels: %s]') % api_levels,
817 check_success=valid_api_level,
818 error_msg='Android-%s is not present in the NDK path.')
819
820 return android_ndk_api_level
Austin Anderson6afface2017-12-05 11:59:17 -0800821
822
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700823def set_gcc_host_compiler_path(environ_cp):
824 """Set GCC_HOST_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700825 default_gcc_host_compiler_path = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700826 cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH')
827
828 if os.path.islink(cuda_bin_symlink):
829 # os.readlink is only available in linux
Jonathan Hseu008910f2017-08-25 14:01:05 -0700830 default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700831
Austin Anderson6afface2017-12-05 11:59:17 -0800832 gcc_host_compiler_path = prompt_loop_or_load_from_env(
833 environ_cp,
834 var_name='GCC_HOST_COMPILER_PATH',
835 var_default=default_gcc_host_compiler_path,
TensorFlower Gardenerabb763b2019-02-06 16:23:03 -0800836 ask_for_var='Please specify which gcc should be used by nvcc as the host compiler.',
Austin Anderson6afface2017-12-05 11:59:17 -0800837 check_success=os.path.exists,
838 error_msg='Invalid gcc path. %s cannot be found.',
839 )
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700840
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700841 write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)
842
843
Ankur Taly0e6f39d2018-02-16 18:22:55 -0800844def reformat_version_sequence(version_str, sequence_count):
845 """Reformat the version string to have the given number of sequences.
846
847 For example:
848 Given (7, 2) -> 7.0
849 (7.0.1, 2) -> 7.0
850 (5, 1) -> 5
851 (5.0.3.2, 1) -> 5
852
853 Args:
854 version_str: String, the version string.
855 sequence_count: int, an integer.
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700856
Ankur Taly0e6f39d2018-02-16 18:22:55 -0800857 Returns:
858 string, reformatted version string.
859 """
860 v = version_str.split('.')
861 if len(v) < sequence_count:
862 v = v + (['0'] * (sequence_count - len(v)))
863
864 return '.'.join(v[:sequence_count])
865
866
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700867def set_tf_cuda_paths(environ_cp):
868 """Set TF_CUDA_PATHS."""
869 ask_cuda_paths = (
870 'Please specify the comma-separated list of base paths to look for CUDA '
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -0700871 'libraries and headers. [Leave empty to use the default]: ')
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700872 tf_cuda_paths = get_from_env_or_user_or_default(environ_cp, 'TF_CUDA_PATHS',
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -0700873 ask_cuda_paths, '')
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700874 if tf_cuda_paths:
875 environ_cp['TF_CUDA_PATHS'] = tf_cuda_paths
876
877
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700878def set_tf_cuda_version(environ_cp):
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700879 """Set TF_CUDA_VERSION."""
A. Unique TensorFlower0cb8a072019-04-16 08:16:39 -0700880 ask_cuda_version = (
881 'Please specify the CUDA SDK version you want to use. '
882 '[Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700883 tf_cuda_version = get_from_env_or_user_or_default(environ_cp,
884 'TF_CUDA_VERSION',
A. Unique TensorFlower0cb8a072019-04-16 08:16:39 -0700885 ask_cuda_version,
886 _DEFAULT_CUDA_VERSION)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700887 environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700888
889
Yifei Fengb1d8c592017-11-22 13:42:21 -0800890def set_tf_cudnn_version(environ_cp):
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700891 """Set TF_CUDNN_VERSION."""
A. Unique TensorFlower0cb8a072019-04-16 08:16:39 -0700892 ask_cudnn_version = (
893 'Please specify the cuDNN version you want to use. '
894 '[Leave empty to default to cuDNN %s]: ') % _DEFAULT_CUDNN_VERSION
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700895 tf_cudnn_version = get_from_env_or_user_or_default(environ_cp,
896 'TF_CUDNN_VERSION',
A. Unique TensorFlower0cb8a072019-04-16 08:16:39 -0700897 ask_cudnn_version,
898 _DEFAULT_CUDNN_VERSION)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700899 environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700900
901
Mingxing Tan1e7b0e42018-06-28 19:13:20 -0700902def is_cuda_compatible(lib, cuda_ver, cudnn_ver):
903 """Check compatibility between given library and cudnn/cudart libraries."""
904 ldd_bin = which('ldd') or '/usr/bin/ldd'
905 ldd_out = run_shell([ldd_bin, lib], True)
906 ldd_out = ldd_out.split(os.linesep)
907 cudnn_pattern = re.compile('.*libcudnn.so\\.?(.*) =>.*$')
908 cuda_pattern = re.compile('.*libcudart.so\\.?(.*) =>.*$')
909 cudnn = None
910 cudart = None
911 cudnn_ok = True # assume no cudnn dependency by default
912 cuda_ok = True # assume no cuda dependency by default
913 for line in ldd_out:
914 if 'libcudnn.so' in line:
915 cudnn = cudnn_pattern.search(line)
916 cudnn_ok = False
917 elif 'libcudart.so' in line:
918 cudart = cuda_pattern.search(line)
919 cuda_ok = False
920 if cudnn and len(cudnn.group(1)):
921 cudnn = convert_version_to_int(cudnn.group(1))
922 if cudart and len(cudart.group(1)):
923 cudart = convert_version_to_int(cudart.group(1))
924 if cudnn is not None:
925 cudnn_ok = (cudnn == cudnn_ver)
926 if cudart is not None:
927 cuda_ok = (cudart == cuda_ver)
928 return cudnn_ok and cuda_ok
929
930
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700931def set_tf_tensorrt_version(environ_cp):
932 """Set TF_TENSORRT_VERSION."""
Guangda Lai76f69382018-01-25 23:59:19 -0800933 if not is_linux():
934 raise ValueError('Currently TensorRT is only supported on Linux platform.')
935
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -0700936 if not int(environ_cp.get('TF_NEED_TENSORRT', False)):
Guangda Lai76f69382018-01-25 23:59:19 -0800937 return
938
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700939 ask_tensorrt_version = (
940 'Please specify the TensorRT version you want to use. '
A. Unique TensorFlower0cb8a072019-04-16 08:16:39 -0700941 '[Leave empty to default to TensorRT %s]: ') % _DEFAULT_TENSORRT_VERSION
942 tf_tensorrt_version = get_from_env_or_user_or_default(
943 environ_cp, 'TF_TENSORRT_VERSION', ask_tensorrt_version,
944 _DEFAULT_TENSORRT_VERSION)
Guangda Lai76f69382018-01-25 23:59:19 -0800945 environ_cp['TF_TENSORRT_VERSION'] = tf_tensorrt_version
Guangda Lai76f69382018-01-25 23:59:19 -0800946
947
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700948def set_tf_nccl_version(environ_cp):
949 """Set TF_NCCL_VERSION."""
A. Unique TensorFlower1fda7642018-04-05 03:09:27 -0700950 if not is_linux():
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700951 raise ValueError('Currently NCCL is only supported on Linux platform.')
A. Unique TensorFlower1fda7642018-04-05 03:09:27 -0700952
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -0700953 if 'TF_NCCL_VERSION' in environ_cp:
954 return
955
A. Unique TensorFlower1fda7642018-04-05 03:09:27 -0700956 ask_nccl_version = (
A. Unique TensorFlower53faa312018-10-05 08:46:54 -0700957 'Please specify the locally installed NCCL version you want to use. '
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -0700958 '[Leave empty to use http://github.com/nvidia/nccl]: ')
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -0700959 tf_nccl_version = get_from_env_or_user_or_default(environ_cp,
960 'TF_NCCL_VERSION',
961 ask_nccl_version, '')
A. Unique TensorFlower1fda7642018-04-05 03:09:27 -0700962 environ_cp['TF_NCCL_VERSION'] = tf_nccl_version
TensorFlower Gardenerabb763b2019-02-06 16:23:03 -0800963
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -0700964
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700965def get_native_cuda_compute_capabilities(environ_cp):
966 """Get native cuda compute capabilities.
967
968 Args:
969 environ_cp: copy of the os.environ.
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -0700970
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700971 Returns:
972 string of native cuda compute capabilities, separated by comma.
973 """
974 device_query_bin = os.path.join(
975 environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery')
Jonathan Hseu008910f2017-08-25 14:01:05 -0700976 if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK):
977 try:
978 output = run_shell(device_query_bin).split('\n')
979 pattern = re.compile('[0-9]*\\.[0-9]*')
980 output = [pattern.search(x) for x in output if 'Capability' in x]
981 output = ','.join(x.group() for x in output if x is not None)
982 except subprocess.CalledProcessError:
983 output = ''
984 else:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700985 output = ''
986 return output
987
988
989def set_tf_cuda_compute_capabilities(environ_cp):
990 """Set TF_CUDA_COMPUTE_CAPABILITIES."""
991 while True:
992 native_cuda_compute_capabilities = get_native_cuda_compute_capabilities(
993 environ_cp)
994 if not native_cuda_compute_capabilities:
995 default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES
996 else:
997 default_cuda_compute_capabilities = native_cuda_compute_capabilities
998
999 ask_cuda_compute_capabilities = (
1000 'Please specify a list of comma-separated '
P Sudeepam52093562019-02-17 17:34:01 +05301001 'CUDA compute capabilities you want to '
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001002 'build with.\nYou can find the compute '
1003 'capability of your device at: '
1004 'https://developer.nvidia.com/cuda-gpus.\nPlease'
1005 ' note that each additional compute '
1006 'capability significantly increases your '
P Sudeepam52093562019-02-17 17:34:01 +05301007 'build time and binary size, and that '
1008 'TensorFlow only supports compute '
P Sudeepam765ceda2019-02-17 17:39:08 +05301009 'capabilities >= 3.5 [Default is: %s]: ' %
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001010 default_cuda_compute_capabilities)
1011 tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
1012 environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
1013 ask_cuda_compute_capabilities, default_cuda_compute_capabilities)
1014 # Check whether all capabilities from the input is valid
1015 all_valid = True
Maciejd0f5bc12018-04-30 22:30:58 -05001016 # Remove all whitespace characters before splitting the string
Michael Case51053502018-06-05 17:47:19 -07001017 # that users may insert by accident, as this will result in error
Maciejd0f5bc12018-04-30 22:30:58 -05001018 tf_cuda_compute_capabilities = ''.join(tf_cuda_compute_capabilities.split())
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001019 for compute_capability in tf_cuda_compute_capabilities.split(','):
Andrew Harp6e3e7d12017-08-21 12:10:44 -07001020 m = re.match('[0-9]+.[0-9]+', compute_capability)
1021 if not m:
Austin Anderson32202dc2019-02-19 10:46:27 -08001022 print('Invalid compute capability: %s' % compute_capability)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001023 all_valid = False
Andrew Harp6e3e7d12017-08-21 12:10:44 -07001024 else:
P Sudeepam52093562019-02-17 17:34:01 +05301025 ver = float(m.group(0))
A. Unique TensorFlower8dc2d0e2019-03-12 01:41:05 -07001026 if ver < 3.0:
1027 print('ERROR: TensorFlow only supports CUDA compute capabilities 3.0 '
Austin Anderson32202dc2019-02-19 10:46:27 -08001028 'and higher. Please re-specify the list of compute '
1029 'capabilities excluding version %s.' % ver)
Andrew Harp6e3e7d12017-08-21 12:10:44 -07001030 all_valid = False
A. Unique TensorFlower8dc2d0e2019-03-12 01:41:05 -07001031 if ver < 3.5:
1032 print('WARNING: XLA does not support CUDA compute capabilities '
1033 'lower than 3.5. Disable XLA when running on older GPUs.')
P Sudeepam765ceda2019-02-17 17:39:08 +05301034
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001035 if all_valid:
1036 break
1037
1038 # Reset and Retry
1039 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = ''
1040
1041 # Set TF_CUDA_COMPUTE_CAPABILITIES
1042 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities
1043 write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES',
1044 tf_cuda_compute_capabilities)
1045
1046
1047def set_other_cuda_vars(environ_cp):
1048 """Set other CUDA related variables."""
A. Unique TensorFlowerab391982018-07-11 04:52:49 -07001049 # If CUDA is enabled, always use GPU during build and test.
1050 if environ_cp.get('TF_CUDA_CLANG') == '1':
1051 write_to_bazelrc('build --config=cuda_clang')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001052 else:
A. Unique TensorFlowerab391982018-07-11 04:52:49 -07001053 write_to_bazelrc('build --config=cuda')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001054
1055
1056def set_host_cxx_compiler(environ_cp):
1057 """Set HOST_CXX_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -07001058 default_cxx_host_compiler = which('g++') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001059
Austin Anderson6afface2017-12-05 11:59:17 -08001060 host_cxx_compiler = prompt_loop_or_load_from_env(
1061 environ_cp,
1062 var_name='HOST_CXX_COMPILER',
1063 var_default=default_cxx_host_compiler,
1064 ask_for_var=('Please specify which C++ compiler should be used as the '
1065 'host C++ compiler.'),
1066 check_success=os.path.exists,
1067 error_msg='Invalid C++ compiler path. %s cannot be found.',
1068 )
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001069
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001070 write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler)
1071
1072
1073def set_host_c_compiler(environ_cp):
1074 """Set HOST_C_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -07001075 default_c_host_compiler = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001076
Austin Anderson6afface2017-12-05 11:59:17 -08001077 host_c_compiler = prompt_loop_or_load_from_env(
1078 environ_cp,
1079 var_name='HOST_C_COMPILER',
1080 var_default=default_c_host_compiler,
Shanqing Cai71445712018-03-12 19:33:52 -07001081 ask_for_var=('Please specify which C compiler should be used as the host '
Austin Anderson6afface2017-12-05 11:59:17 -08001082 'C compiler.'),
1083 check_success=os.path.exists,
1084 error_msg='Invalid C compiler path. %s cannot be found.',
1085 )
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001086
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001087 write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler)
1088
1089
1090def set_computecpp_toolkit_path(environ_cp):
1091 """Set COMPUTECPP_TOOLKIT_PATH."""
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001092
Austin Anderson6afface2017-12-05 11:59:17 -08001093 def toolkit_exists(toolkit_path):
1094 """Check if a computecpp toolkit path is valid."""
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001095 if is_linux():
1096 sycl_rt_lib_path = 'lib/libComputeCpp.so'
1097 else:
1098 sycl_rt_lib_path = ''
1099
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001100 sycl_rt_lib_path_full = os.path.join(toolkit_path, sycl_rt_lib_path)
Austin Anderson6afface2017-12-05 11:59:17 -08001101 exists = os.path.exists(sycl_rt_lib_path_full)
1102 if not exists:
1103 print('Invalid SYCL %s library path. %s cannot be found' %
1104 (_TF_OPENCL_VERSION, sycl_rt_lib_path_full))
1105 return exists
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001106
Austin Anderson6afface2017-12-05 11:59:17 -08001107 computecpp_toolkit_path = prompt_loop_or_load_from_env(
1108 environ_cp,
1109 var_name='COMPUTECPP_TOOLKIT_PATH',
1110 var_default=_DEFAULT_COMPUTECPP_TOOLKIT_PATH,
1111 ask_for_var=(
1112 'Please specify the location where ComputeCpp for SYCL %s is '
1113 'installed.' % _TF_OPENCL_VERSION),
1114 check_success=toolkit_exists,
1115 error_msg='Invalid SYCL compiler path. %s cannot be found.',
1116 suppress_default_error=True)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001117
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001118 write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH',
1119 computecpp_toolkit_path)
1120
Michael Cased31531a2018-01-05 14:09:41 -08001121
Dandelion Man?90e42f32017-12-15 18:15:07 -08001122def set_trisycl_include_dir(environ_cp):
Michael Cased31531a2018-01-05 14:09:41 -08001123 """Set TRISYCL_INCLUDE_DIR."""
Frank Chenc4ef9272018-01-10 11:36:52 -08001124
Dandelion Man?90e42f32017-12-15 18:15:07 -08001125 ask_trisycl_include_dir = ('Please specify the location of the triSYCL '
1126 'include directory. (Use --config=sycl_trisycl '
1127 'when building with Bazel) '
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001128 '[Default is %s]: ') % (
1129 _DEFAULT_TRISYCL_INCLUDE_DIR)
Frank Chenc4ef9272018-01-10 11:36:52 -08001130
Dandelion Man?90e42f32017-12-15 18:15:07 -08001131 while True:
1132 trisycl_include_dir = get_from_env_or_user_or_default(
Michael Cased31531a2018-01-05 14:09:41 -08001133 environ_cp, 'TRISYCL_INCLUDE_DIR', ask_trisycl_include_dir,
1134 _DEFAULT_TRISYCL_INCLUDE_DIR)
Dandelion Man?90e42f32017-12-15 18:15:07 -08001135 if os.path.exists(trisycl_include_dir):
1136 break
1137
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001138 print('Invalid triSYCL include directory, %s cannot be found' %
1139 (trisycl_include_dir))
Dandelion Man?90e42f32017-12-15 18:15:07 -08001140
1141 # Set TRISYCL_INCLUDE_DIR
1142 environ_cp['TRISYCL_INCLUDE_DIR'] = trisycl_include_dir
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001143 write_action_env_to_bazelrc('TRISYCL_INCLUDE_DIR', trisycl_include_dir)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001144
Yifei Fengb1d8c592017-11-22 13:42:21 -08001145
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001146def set_mpi_home(environ_cp):
1147 """Set MPI_HOME."""
Austin Anderson6afface2017-12-05 11:59:17 -08001148
Jonathan Hseu008910f2017-08-25 14:01:05 -07001149 default_mpi_home = which('mpirun') or which('mpiexec') or ''
1150 default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home))
1151
Austin Anderson6afface2017-12-05 11:59:17 -08001152 def valid_mpi_path(mpi_home):
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001153 exists = (
1154 os.path.exists(os.path.join(mpi_home, 'include')) and
TensorFlower Gardenerf7c861f2018-11-01 11:29:40 -07001155 (os.path.exists(os.path.join(mpi_home, 'lib')) or
1156 os.path.exists(os.path.join(mpi_home, 'lib64')) or
1157 os.path.exists(os.path.join(mpi_home, 'lib32'))))
Austin Anderson6afface2017-12-05 11:59:17 -08001158 if not exists:
TensorFlower Gardenerf7c861f2018-11-01 11:29:40 -07001159 print(
1160 'Invalid path to the MPI Toolkit. %s or %s or %s or %s cannot be found'
1161 % (os.path.join(mpi_home, 'include'),
Christian Gollba95d092018-10-04 17:06:23 +02001162 os.path.exists(os.path.join(mpi_home, 'lib')),
1163 os.path.exists(os.path.join(mpi_home, 'lib64')),
1164 os.path.exists(os.path.join(mpi_home, 'lib32'))))
Austin Anderson6afface2017-12-05 11:59:17 -08001165 return exists
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001166
Austin Anderson6afface2017-12-05 11:59:17 -08001167 _ = prompt_loop_or_load_from_env(
1168 environ_cp,
1169 var_name='MPI_HOME',
1170 var_default=default_mpi_home,
1171 ask_for_var='Please specify the MPI toolkit folder.',
1172 check_success=valid_mpi_path,
1173 error_msg='',
1174 suppress_default_error=True)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001175
1176
1177def set_other_mpi_vars(environ_cp):
1178 """Set other MPI related variables."""
1179 # Link the MPI header files
1180 mpi_home = environ_cp.get('MPI_HOME')
1181 symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h')
1182
1183 # Determine if we use OpenMPI or MVAPICH, these require different header files
1184 # to be included here to make bazel dependency checker happy
1185 if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')):
1186 symlink_force(
1187 os.path.join(mpi_home, 'include/mpi_portable_platform.h'),
1188 'third_party/mpi/mpi_portable_platform.h')
1189 # TODO(gunan): avoid editing files in configure
1190 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False',
1191 'MPI_LIB_IS_OPENMPI=True')
1192 else:
1193 # MVAPICH / MPICH
1194 symlink_force(
1195 os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h')
1196 symlink_force(
1197 os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h')
1198 # TODO(gunan): avoid editing files in configure
1199 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True',
1200 'MPI_LIB_IS_OPENMPI=False')
1201
1202 if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')):
1203 symlink_force(
1204 os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so')
Christian Gollba95d092018-10-04 17:06:23 +02001205 elif os.path.exists(os.path.join(mpi_home, 'lib64/libmpi.so')):
1206 symlink_force(
1207 os.path.join(mpi_home, 'lib64/libmpi.so'), 'third_party/mpi/libmpi.so')
1208 elif os.path.exists(os.path.join(mpi_home, 'lib32/libmpi.so')):
1209 symlink_force(
1210 os.path.join(mpi_home, 'lib32/libmpi.so'), 'third_party/mpi/libmpi.so')
1211
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001212 else:
TensorFlower Gardenerf7c861f2018-11-01 11:29:40 -07001213 raise ValueError(
1214 'Cannot find the MPI library file in %s/lib or %s/lib64 or %s/lib32' %
Mihai Maruseac91ebeec2019-01-29 17:07:38 -08001215 (mpi_home, mpi_home, mpi_home))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001216
A. Unique TensorFlowered297342019-03-15 11:25:28 -07001217
A. Unique TensorFlowere9797fd2019-03-22 11:02:40 -07001218def system_specific_test_config(env):
A. Unique TensorFlower7bd86372019-03-21 15:19:30 -07001219 """Add default build and test flags required for TF tests to bazelrc."""
Gunhan Gulsoyfff66962019-02-20 15:28:43 -08001220 write_to_bazelrc('test --flaky_test_attempts=3')
1221 write_to_bazelrc('test --test_size_filters=small,medium')
1222 write_to_bazelrc(
1223 'test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial')
1224 write_to_bazelrc('test --build_tag_filters=-benchmark-test,-no_oss')
1225 if is_windows():
Guangda Laibcd701a2019-03-12 21:04:51 -07001226 if env.get('TF_NEED_CUDA', None) == '1':
Gunhan Gulsoyfff66962019-02-20 15:28:43 -08001227 write_to_bazelrc(
1228 'test --test_tag_filters=-no_windows,-no_windows_gpu,-no_gpu')
1229 write_to_bazelrc(
1230 'test --build_tag_filters=-no_windows,-no_windows_gpu,-no_gpu')
1231 else:
1232 write_to_bazelrc('test --test_tag_filters=-no_windows,-gpu')
1233 write_to_bazelrc('test --build_tag_filters=-no_windows,-gpu')
1234 elif is_macos():
1235 write_to_bazelrc('test --test_tag_filters=-gpu,-nomac,-no_mac')
1236 write_to_bazelrc('test --build_tag_filters=-gpu,-nomac,-no_mac')
1237 elif is_linux():
Guangda Laibcd701a2019-03-12 21:04:51 -07001238 if env.get('TF_NEED_CUDA', None) == '1':
Gunhan Gulsoyfff66962019-02-20 15:28:43 -08001239 write_to_bazelrc('test --test_tag_filters=-no_gpu')
1240 write_to_bazelrc('test --build_tag_filters=-no_gpu')
1241 write_to_bazelrc('test --test_env=LD_LIBRARY_PATH')
1242 else:
1243 write_to_bazelrc('test --test_tag_filters=-gpu')
1244 write_to_bazelrc('test --build_tag_filters=-gpu')
1245
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001246
Yifei Feng5198cb82018-08-17 13:53:06 -07001247def set_system_libs_flag(environ_cp):
1248 syslibs = environ_cp.get('TF_SYSTEM_LIBS', '')
TensorFlower Gardener61a87202018-10-01 12:25:39 -07001249 if syslibs:
Jason Zaman5fc39bd2018-09-16 01:38:55 +08001250 if ',' in syslibs:
1251 syslibs = ','.join(sorted(syslibs.split(',')))
1252 else:
1253 syslibs = ','.join(sorted(syslibs.split()))
Yifei Feng5198cb82018-08-17 13:53:06 -07001254 write_action_env_to_bazelrc('TF_SYSTEM_LIBS', syslibs)
1255
Jason Zaman5fc39bd2018-09-16 01:38:55 +08001256 if 'PREFIX' in environ_cp:
1257 write_to_bazelrc('build --define=PREFIX=%s' % environ_cp['PREFIX'])
1258 if 'LIBDIR' in environ_cp:
1259 write_to_bazelrc('build --define=LIBDIR=%s' % environ_cp['LIBDIR'])
1260 if 'INCLUDEDIR' in environ_cp:
1261 write_to_bazelrc('build --define=INCLUDEDIR=%s' % environ_cp['INCLUDEDIR'])
1262
Yifei Feng5198cb82018-08-17 13:53:06 -07001263
A. Unique TensorFlower1b212352018-07-19 13:48:50 -07001264def set_windows_build_flags(environ_cp):
1265 """Set Windows specific build options."""
1266 # The non-monolithic build is not supported yet
1267 write_to_bazelrc('build --config monolithic')
1268 # Suppress warning messages
1269 write_to_bazelrc('build --copt=-w --host_copt=-w')
Loo Rong Jie31f10d22019-02-02 10:03:20 +08001270 # Fix winsock2.h conflicts
TensorFlower Gardener345cccf2019-02-28 15:22:59 -08001271 write_to_bazelrc(
Justin Lebar7b57c5a2019-04-30 12:24:29 -07001272 'build --copt=-DWIN32_LEAN_AND_MEAN --host_copt=-DWIN32_LEAN_AND_MEAN '
1273 '--copt=-DNOGDI --host_copt=-DNOGDI')
A. Unique TensorFlower1b212352018-07-19 13:48:50 -07001274 # Output more verbose information when something goes wrong
1275 write_to_bazelrc('build --verbose_failures')
1276 # The host and target platforms are the same in Windows build. So we don't
1277 # have to distinct them. This avoids building the same targets twice.
1278 write_to_bazelrc('build --distinct_host_configuration=false')
A. Unique TensorFlower1b212352018-07-19 13:48:50 -07001279
1280 if get_var(
1281 environ_cp, 'TF_OVERRIDE_EIGEN_STRONG_INLINE', 'Eigen strong inline',
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001282 True, ('Would you like to override eigen strong inline for some C++ '
1283 'compilation to reduce the compilation time?'),
1284 'Eigen strong inline overridden.', 'Not overriding eigen strong inline, '
A. Unique TensorFlower1b212352018-07-19 13:48:50 -07001285 'some compilations could take more than 20 mins.'):
1286 # Due to a known MSVC compiler issue
1287 # https://github.com/tensorflow/tensorflow/issues/10521
1288 # Overriding eigen strong inline speeds up the compiling of
1289 # conv_grad_ops_3d.cc and conv_ops_3d.cc by 20 minutes,
1290 # but this also hurts the performance. Let users decide what they want.
1291 write_to_bazelrc('build --define=override_eigen_strong_inline=true')
Dandelion Man?90e42f32017-12-15 18:15:07 -08001292
A. Unique TensorFlower061c3592017-11-13 14:21:04 -08001293
Michael Cased31531a2018-01-05 14:09:41 -08001294def config_info_line(name, help_text):
1295 """Helper function to print formatted help text for Bazel config options."""
1296 print('\t--config=%-12s\t# %s' % (name, help_text))
1297
1298
A. Unique TensorFlower76e879d2019-03-22 00:25:36 -07001299def configure_ios():
1300 """Configures TensorFlow for iOS builds.
A. Unique TensorFlower93e70732019-02-14 16:45:32 -08001301
A. Unique TensorFlower76e879d2019-03-22 00:25:36 -07001302 This function will only be executed if `is_macos()` is true.
A. Unique TensorFlower93e70732019-02-14 16:45:32 -08001303 """
1304 if not is_macos():
1305 return
A. Unique TensorFlower76e879d2019-03-22 00:25:36 -07001306 for filepath in APPLE_BAZEL_FILES:
1307 existing_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath + '.apple')
1308 renamed_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath)
1309 symlink_force(existing_filepath, renamed_filepath)
1310 for filepath in IOS_FILES:
1311 filename = os.path.basename(filepath)
1312 new_filepath = os.path.join(_TF_WORKSPACE_ROOT, filename)
1313 symlink_force(filepath, new_filepath)
A. Unique TensorFlower93e70732019-02-14 16:45:32 -08001314
1315
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001316def validate_cuda_config(environ_cp):
1317 """Run find_cuda_config.py and return cuda_toolkit_path, or None."""
1318
1319 def maybe_encode_env(env):
1320 """Encodes unicode in env to str on Windows python 2.x."""
1321 if not is_windows() or sys.version_info[0] != 2:
1322 return env
1323 for k, v in env.items():
1324 if isinstance(k, unicode):
1325 k = k.encode('ascii')
1326 if isinstance(v, unicode):
1327 v = v.encode('ascii')
1328 env[k] = v
1329 return env
1330
1331 cuda_libraries = ['cuda', 'cudnn']
1332 if is_linux():
A. Unique TensorFlower28fc9cc2019-05-01 14:17:54 -07001333 if int(environ_cp.get('TF_NEED_TENSORRT', False)):
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001334 cuda_libraries.append('tensorrt')
A. Unique TensorFlowerb2e7f672019-04-30 09:20:36 -07001335 if environ_cp.get('TF_NCCL_VERSION', None):
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001336 cuda_libraries.append('nccl')
1337
1338 proc = subprocess.Popen(
1339 [environ_cp['PYTHON_BIN_PATH'], 'third_party/gpus/find_cuda_config.py'] +
1340 cuda_libraries,
1341 stdout=subprocess.PIPE,
1342 env=maybe_encode_env(environ_cp))
1343
1344 if proc.wait():
1345 # Errors from find_cuda_config.py were sent to stderr.
A. Unique TensorFlower0cb8a072019-04-16 08:16:39 -07001346 print('Asking for detailed CUDA configuration...\n')
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001347 return False
1348
1349 config = dict(
1350 tuple(line.decode('ascii').rstrip().split(': ')) for line in proc.stdout)
1351
1352 print('Found CUDA %s in:' % config['cuda_version'])
1353 print(' %s' % config['cuda_library_dir'])
1354 print(' %s' % config['cuda_include_dir'])
1355
1356 print('Found cuDNN %s in:' % config['cudnn_version'])
1357 print(' %s' % config['cudnn_library_dir'])
1358 print(' %s' % config['cudnn_include_dir'])
1359
1360 if 'tensorrt_version' in config:
1361 print('Found TensorRT %s in:' % config['tensorrt_version'])
1362 print(' %s' % config['tensorrt_library_dir'])
1363 print(' %s' % config['tensorrt_include_dir'])
1364
1365 if config.get('nccl_version', None):
1366 print('Found NCCL %s in:' % config['nccl_version'])
1367 print(' %s' % config['nccl_library_dir'])
1368 print(' %s' % config['nccl_include_dir'])
1369
1370 print('\n')
1371
1372 environ_cp['CUDA_TOOLKIT_PATH'] = config['cuda_toolkit_path']
1373 return True
1374
1375
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001376def main():
A. Unique TensorFlower7c5eb352018-10-01 07:15:23 -07001377 global _TF_WORKSPACE_ROOT
1378 global _TF_BAZELRC
A. Unique TensorFlowered297342019-03-15 11:25:28 -07001379 global _TF_CURRENT_BAZEL_VERSION
A. Unique TensorFlower7c5eb352018-10-01 07:15:23 -07001380
Shanqing Cai71445712018-03-12 19:33:52 -07001381 parser = argparse.ArgumentParser()
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001382 parser.add_argument(
1383 '--workspace',
1384 type=str,
A. Unique TensorFlower7c5eb352018-10-01 07:15:23 -07001385 default=os.path.abspath(os.path.dirname(__file__)),
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001386 help='The absolute path to your active Bazel workspace.')
Shanqing Cai71445712018-03-12 19:33:52 -07001387 args = parser.parse_args()
1388
A. Unique TensorFlower7c5eb352018-10-01 07:15:23 -07001389 _TF_WORKSPACE_ROOT = args.workspace
1390 _TF_BAZELRC = os.path.join(_TF_WORKSPACE_ROOT, _TF_BAZELRC_FILENAME)
1391
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001392 # Make a copy of os.environ to be clear when functions and getting and setting
1393 # environment variables.
1394 environ_cp = dict(os.environ)
1395
Mark Daoust44000ad2019-06-18 09:26:26 -07001396 current_bazel_version = check_bazel_version(_TF_MIN_BAZEL_VERSION,
1397 _TF_MAX_BAZEL_VERSION)
A. Unique TensorFlowered297342019-03-15 11:25:28 -07001398 _TF_CURRENT_BAZEL_VERSION = convert_version_to_int(current_bazel_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001399
A. Unique TensorFlower7c5eb352018-10-01 07:15:23 -07001400 reset_tf_configure_bazelrc()
Yun Peng03e63a22018-11-07 11:18:53 +01001401
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001402 cleanup_makefile()
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -07001403 setup_python(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001404
1405 if is_windows():
Yifei Fengb1d8c592017-11-22 13:42:21 -08001406 environ_cp['TF_NEED_OPENCL_SYCL'] = '0'
1407 environ_cp['TF_NEED_COMPUTECPP'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001408 environ_cp['TF_NEED_OPENCL'] = '0'
1409 environ_cp['TF_CUDA_CLANG'] = '0'
Guangda Lai76f69382018-01-25 23:59:19 -08001410 environ_cp['TF_NEED_TENSORRT'] = '0'
Ilya Biryukov9e651e42018-03-22 05:33:42 -07001411 # TODO(ibiryukov): Investigate using clang as a cpu or cuda compiler on
1412 # Windows.
1413 environ_cp['TF_DOWNLOAD_CLANG'] = '0'
A. Unique TensorFlower6e97fb32018-07-16 14:07:29 -07001414 environ_cp['TF_NEED_MPI'] = '0'
1415 environ_cp['TF_SET_ANDROID_WORKSPACE'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001416
1417 if is_macos():
Guangda Lai76f69382018-01-25 23:59:19 -08001418 environ_cp['TF_NEED_TENSORRT'] = '0'
A. Unique TensorFlower93e70732019-02-14 16:45:32 -08001419 else:
A. Unique TensorFlower76e879d2019-03-22 00:25:36 -07001420 environ_cp['TF_CONFIGURE_IOS'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001421
Jon Triebenbach6896a742018-06-27 13:29:53 -05001422 # The numpy package on ppc64le uses OpenBLAS which has multi-threading
1423 # issues that lead to incorrect answers. Set OMP_NUM_THREADS=1 at
1424 # runtime to allow the Tensorflow testcases which compare numpy
1425 # results to Tensorflow results to succeed.
1426 if is_ppc64le():
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001427 write_action_env_to_bazelrc('OMP_NUM_THREADS', 1)
Jon Triebenbach6896a742018-06-27 13:29:53 -05001428
Grzegorz Pawelczakec82efd2018-10-09 15:03:46 +01001429 xla_enabled_by_default = is_linux()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001430 set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
Grzegorz Pawelczakec82efd2018-10-09 15:03:46 +01001431 xla_enabled_by_default, 'xla')
Gunhan Gulsoy3da0dff2018-09-26 11:55:50 -07001432
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -07001433 set_action_env_var(
1434 environ_cp,
1435 'TF_NEED_OPENCL_SYCL',
1436 'OpenCL SYCL',
1437 False,
1438 bazel_config_name='sycl')
Yifei Fengb1d8c592017-11-22 13:42:21 -08001439 if environ_cp.get('TF_NEED_OPENCL_SYCL') == '1':
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001440 set_host_cxx_compiler(environ_cp)
1441 set_host_c_compiler(environ_cp)
Yifei Fengb1d8c592017-11-22 13:42:21 -08001442 set_action_env_var(environ_cp, 'TF_NEED_COMPUTECPP', 'ComputeCPP', True)
1443 if environ_cp.get('TF_NEED_COMPUTECPP') == '1':
1444 set_computecpp_toolkit_path(environ_cp)
1445 else:
1446 set_trisycl_include_dir(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001447
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -07001448 set_action_env_var(
1449 environ_cp, 'TF_NEED_ROCM', 'ROCm', False, bazel_config_name='rocm')
Wen-Heng (Jack) Chung69d3b8f2018-06-22 23:09:43 -05001450 if (environ_cp.get('TF_NEED_ROCM') == '1' and
TensorFlower Gardener62e60162018-09-27 10:22:55 -07001451 'LD_LIBRARY_PATH' in environ_cp and
1452 environ_cp.get('LD_LIBRARY_PATH') != '1'):
1453 write_action_env_to_bazelrc('LD_LIBRARY_PATH',
1454 environ_cp.get('LD_LIBRARY_PATH'))
Wen-Heng (Jack) Chung69d3b8f2018-06-22 23:09:43 -05001455
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -07001456 environ_cp['TF_NEED_CUDA'] = str(
1457 int(get_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)))
A. Unique TensorFlower24cbb2a2017-09-08 07:45:44 -07001458 if (environ_cp.get('TF_NEED_CUDA') == '1' and
1459 'TF_CUDA_CONFIG_REPO' not in environ_cp):
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001460
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -07001461 set_action_env_var(
1462 environ_cp,
1463 'TF_NEED_TENSORRT',
1464 'TensorRT',
1465 False,
1466 bazel_config_name='tensorrt')
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001467
1468 environ_save = dict(environ_cp)
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -07001469 for _ in range(_DEFAULT_PROMPT_ASK_ATTEMPTS):
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001470
1471 if validate_cuda_config(environ_cp):
1472 cuda_env_names = [
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -07001473 'TF_CUDA_VERSION',
1474 'TF_CUBLAS_VERSION',
1475 'TF_CUDNN_VERSION',
1476 'TF_TENSORRT_VERSION',
1477 'TF_NCCL_VERSION',
1478 'TF_CUDA_PATHS',
A. Unique TensorFlowerb2e7f672019-04-30 09:20:36 -07001479 # Items below are for backwards compatibility when not using
1480 # TF_CUDA_PATHS.
A. Unique TensorFlowerfef51672019-05-23 04:19:20 -07001481 'CUDA_TOOLKIT_PATH',
1482 'CUDNN_INSTALL_PATH',
1483 'NCCL_INSTALL_PATH',
1484 'NCCL_HDR_PATH',
1485 'TENSORRT_INSTALL_PATH'
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001486 ]
A. Unique TensorFlowerb2e7f672019-04-30 09:20:36 -07001487 # Note: set_action_env_var above already writes to bazelrc.
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001488 for name in cuda_env_names:
1489 if name in environ_cp:
1490 write_action_env_to_bazelrc(name, environ_cp[name])
1491 break
1492
1493 # Restore settings changed below if CUDA config could not be validated.
1494 environ_cp = dict(environ_save)
1495
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -07001496 set_tf_cuda_version(environ_cp)
1497 set_tf_cudnn_version(environ_cp)
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -07001498 if is_linux():
1499 set_tf_tensorrt_version(environ_cp)
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -07001500 set_tf_nccl_version(environ_cp)
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -07001501
A. Unique TensorFlower651b0bc2019-04-16 06:13:43 -07001502 set_tf_cuda_paths(environ_cp)
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -07001503
A. Unique TensorFlower8e9ca662019-04-15 12:47:11 -07001504 else:
1505 raise UserInputError(
1506 'Invalid CUDA setting were provided %d '
1507 'times in a row. Assuming to be a scripting mistake.' %
1508 _DEFAULT_PROMPT_ASK_ATTEMPTS)
1509
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001510 set_tf_cuda_compute_capabilities(environ_cp)
Ankur Taly0e6f39d2018-02-16 18:22:55 -08001511 if 'LD_LIBRARY_PATH' in environ_cp and environ_cp.get(
1512 'LD_LIBRARY_PATH') != '1':
1513 write_action_env_to_bazelrc('LD_LIBRARY_PATH',
1514 environ_cp.get('LD_LIBRARY_PATH'))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001515
1516 set_tf_cuda_clang(environ_cp)
1517 if environ_cp.get('TF_CUDA_CLANG') == '1':
Ilya Biryukov9e651e42018-03-22 05:33:42 -07001518 # Ask whether we should download the clang toolchain.
1519 set_tf_download_clang(environ_cp)
A. Unique TensorFlowerfd29e952017-12-22 03:07:51 -08001520 if environ_cp.get('TF_DOWNLOAD_CLANG') != '1':
1521 # Set up which clang we should use as the cuda / host compiler.
1522 set_clang_cuda_compiler_path(environ_cp)
Ilya Biryukov1c3d02e2018-09-04 03:09:52 -07001523 else:
1524 # Use downloaded LLD for linking.
1525 write_to_bazelrc('build:cuda_clang --config=download_clang_use_lld')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001526 else:
1527 # Set up which gcc nvcc should use as the host compiler
1528 # No need to set this on Windows
1529 if not is_windows():
1530 set_gcc_host_compiler_path(environ_cp)
1531 set_other_cuda_vars(environ_cp)
Ilya Biryukov9e651e42018-03-22 05:33:42 -07001532 else:
1533 # CUDA not required. Ask whether we should download the clang toolchain and
1534 # use it for the CPU build.
1535 set_tf_download_clang(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001536
Wen-Heng (Jack) Chung69d3b8f2018-06-22 23:09:43 -05001537 # SYCL / ROCm / CUDA are mutually exclusive.
1538 # At most 1 GPU platform can be configured.
1539 gpu_platform_count = 0
1540 if environ_cp.get('TF_NEED_OPENCL_SYCL') == '1':
1541 gpu_platform_count += 1
1542 if environ_cp.get('TF_NEED_ROCM') == '1':
1543 gpu_platform_count += 1
1544 if environ_cp.get('TF_NEED_CUDA') == '1':
1545 gpu_platform_count += 1
1546 if gpu_platform_count >= 2:
1547 raise UserInputError('SYCL / CUDA / ROCm are mututally exclusive. '
1548 'At most 1 GPU platform can be configured.')
1549
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001550 set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False)
1551 if environ_cp.get('TF_NEED_MPI') == '1':
1552 set_mpi_home(environ_cp)
1553 set_other_mpi_vars(environ_cp)
1554
1555 set_cc_opt_flags(environ_cp)
Yifei Feng5198cb82018-08-17 13:53:06 -07001556 set_system_libs_flag(environ_cp)
A. Unique TensorFlower1b212352018-07-19 13:48:50 -07001557 if is_windows():
1558 set_windows_build_flags(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001559
Anna Ra9a1d5a2018-09-14 12:44:31 -07001560 # Add a config option to build TensorFlow 2.0 API.
1561 write_to_bazelrc('build:v2 --define=tf_api_version=2')
1562
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001563 if get_var(environ_cp, 'TF_SET_ANDROID_WORKSPACE', 'android workspace', False,
1564 ('Would you like to interactively configure ./WORKSPACE for '
1565 'Android builds?'), 'Searching for NDK and SDK installations.',
1566 'Not configuring the WORKSPACE for Android builds.'):
Michael Case51053502018-06-05 17:47:19 -07001567 create_android_ndk_rule(environ_cp)
1568 create_android_sdk_rule(environ_cp)
Austin Anderson6afface2017-12-05 11:59:17 -08001569
A. Unique TensorFlowere9797fd2019-03-22 11:02:40 -07001570 system_specific_test_config(os.environ)
Gunhan Gulsoyfff66962019-02-20 15:28:43 -08001571
A. Unique TensorFlower5001ac02019-04-03 11:59:08 -07001572 set_action_env_var(environ_cp, 'TF_CONFIGURE_IOS', 'iOS', False)
1573 if environ_cp.get('TF_CONFIGURE_IOS') == '1':
A. Unique TensorFlower76e879d2019-03-22 00:25:36 -07001574 configure_ios()
A. Unique TensorFlower93e70732019-02-14 16:45:32 -08001575
Gunhan Gulsoy34370982018-10-12 15:26:01 -07001576 print('Preconfigured Bazel build configs. You can use any of the below by '
1577 'adding "--config=<>" to your build command. See .bazelrc for more '
1578 'details.')
1579 config_info_line('mkl', 'Build with MKL support.')
1580 config_info_line('monolithic', 'Config for mostly static monolithic build.')
1581 config_info_line('gdr', 'Build with GDR support.')
1582 config_info_line('verbs', 'Build with libverbs support.')
1583 config_info_line('ngraph', 'Build with Intel nGraph support.')
A. Unique TensorFlowera6bf9c82019-02-26 10:08:35 -08001584 config_info_line('numa', 'Build with NUMA support.')
TensorFlower Gardenerabb763b2019-02-06 16:23:03 -08001585 config_info_line(
1586 'dynamic_kernels',
1587 '(Experimental) Build kernels into separate shared objects.')
Anna Raedf6742019-06-12 11:30:51 -07001588 config_info_line('v2', 'Build TensorFlow 2.x instead of 1.x.')
Gunhan Gulsoy34370982018-10-12 15:26:01 -07001589
1590 print('Preconfigured Bazel build configs to DISABLE default on features:')
1591 config_info_line('noaws', 'Disable AWS S3 filesystem support.')
1592 config_info_line('nogcp', 'Disable GCP support.')
1593 config_info_line('nohdfs', 'Disable HDFS support.')
Penporn Koanantakool489f1dc2019-01-10 22:07:22 -08001594 config_info_line('noignite', 'Disable Apache Ignite support.')
Gunhan Gulsoy34370982018-10-12 15:26:01 -07001595 config_info_line('nokafka', 'Disable Apache Kafka support.')
Gunhan Gulsoyeea81682018-11-26 16:51:23 -08001596 config_info_line('nonccl', 'Disable NVIDIA NCCL support.')
Austin Anderson6afface2017-12-05 11:59:17 -08001597
Gunhan Gulsoyffa90fc2018-09-26 01:38:55 -07001598
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001599if __name__ == '__main__':
1600 main()