blob: 1f205861f142c350a3d4b8d8df65a945c382f704 [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
21import errno
22import os
23import platform
24import re
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070025import subprocess
26import sys
27
Andrew Sellec9885ea2017-11-06 09:37:03 -080028# pylint: disable=g-import-not-at-top
Jonathan Hseu008910f2017-08-25 14:01:05 -070029try:
30 from shutil import which
31except ImportError:
32 from distutils.spawn import find_executable as which
Andrew Sellec9885ea2017-11-06 09:37:03 -080033# pylint: enable=g-import-not-at-top
Jonathan Hseu008910f2017-08-25 14:01:05 -070034
Michael Casefe2c8d82017-10-02 13:54:34 -070035_TF_BAZELRC = os.path.join(os.path.dirname(os.path.abspath(__file__)),
36 '.tf_configure.bazelrc')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070037_DEFAULT_CUDA_VERSION = '8.0'
38_DEFAULT_CUDNN_VERSION = '6'
39_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,5.2'
40_DEFAULT_CUDA_PATH = '/usr/local/cuda'
41_DEFAULT_CUDA_PATH_LINUX = '/opt/cuda'
42_DEFAULT_CUDA_PATH_WIN = ('C:/Program Files/NVIDIA GPU Computing '
43 'Toolkit/CUDA/v%s' % _DEFAULT_CUDA_VERSION)
44_TF_OPENCL_VERSION = '1.2'
45_DEFAULT_COMPUTECPP_TOOLKIT_PATH = '/usr/local/computecpp'
Yifei Fengb1d8c592017-11-22 13:42:21 -080046_DEFAULT_TRISYCL_INCLUDE_DIR = '/usr/local/triSYCL/include'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070047
48
49def is_windows():
50 return platform.system() == 'Windows'
51
52
53def is_linux():
54 return platform.system() == 'Linux'
55
56
57def is_macos():
58 return platform.system() == 'Darwin'
59
60
61def is_ppc64le():
62 return platform.machine() == 'ppc64le'
63
64
Jonathan Hseu008910f2017-08-25 14:01:05 -070065def is_cygwin():
66 return platform.system().startswith('CYGWIN_NT')
67
68
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070069def get_input(question):
70 try:
71 try:
72 answer = raw_input(question)
73 except NameError:
74 answer = input(question) # pylint: disable=bad-builtin
75 except EOFError:
76 answer = ''
77 return answer
78
79
80def symlink_force(target, link_name):
81 """Force symlink, equivalent of 'ln -sf'.
82
83 Args:
84 target: items to link to.
85 link_name: name of the link.
86 """
87 try:
88 os.symlink(target, link_name)
89 except OSError as e:
90 if e.errno == errno.EEXIST:
91 os.remove(link_name)
92 os.symlink(target, link_name)
93 else:
94 raise e
95
96
97def sed_in_place(filename, old, new):
98 """Replace old string with new string in file.
99
100 Args:
101 filename: string for filename.
102 old: string to replace.
103 new: new string to replace to.
104 """
105 with open(filename, 'r') as f:
106 filedata = f.read()
107 newdata = filedata.replace(old, new)
108 with open(filename, 'w') as f:
109 f.write(newdata)
110
111
112def remove_line_with(filename, token):
113 """Remove lines that contain token from file.
114
115 Args:
116 filename: string for filename.
117 token: string token to check if to remove a line from file or not.
118 """
119 with open(filename, 'r') as f:
120 filedata = f.read()
121
122 with open(filename, 'w') as f:
123 for line in filedata.strip().split('\n'):
124 if token not in line:
125 f.write(line + '\n')
126
127
128def write_to_bazelrc(line):
129 with open(_TF_BAZELRC, 'a') as f:
130 f.write(line + '\n')
131
132
133def write_action_env_to_bazelrc(var_name, var):
134 write_to_bazelrc('build --action_env %s="%s"' % (var_name, str(var)))
135
136
Jonathan Hseu008910f2017-08-25 14:01:05 -0700137def run_shell(cmd, allow_non_zero=False):
138 if allow_non_zero:
139 try:
140 output = subprocess.check_output(cmd)
141 except subprocess.CalledProcessError as e:
142 output = e.output
143 else:
144 output = subprocess.check_output(cmd)
145 return output.decode('UTF-8').strip()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700146
147
148def cygpath(path):
149 """Convert path from posix to windows."""
Martin Wicked57572e2017-09-02 19:21:45 -0700150 return os.path.abspath(path).replace('\\', '/')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700151
152
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700153def get_python_path(environ_cp, python_bin_path):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700154 """Get the python site package paths."""
155 python_paths = []
156 if environ_cp.get('PYTHONPATH'):
157 python_paths = environ_cp.get('PYTHONPATH').split(':')
158 try:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700159 library_paths = run_shell(
160 [python_bin_path, '-c',
161 'import site; print("\\n".join(site.getsitepackages()))']).split("\n")
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700162 except subprocess.CalledProcessError:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700163 library_paths = [run_shell(
164 [python_bin_path, '-c',
165 'from distutils.sysconfig import get_python_lib;'
166 'print(get_python_lib())'])]
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700167
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700168 all_paths = set(python_paths + library_paths)
169
170 paths = []
171 for path in all_paths:
172 if os.path.isdir(path):
173 paths.append(path)
174 return paths
175
176
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700177def get_python_major_version(python_bin_path):
178 """Get the python major version."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700179 return run_shell([python_bin_path, '-c', 'import sys; print(sys.version[0])'])
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700180
181
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700182def setup_python(environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700183 """Setup python related env variables."""
184 # Get PYTHON_BIN_PATH, default is the current running python.
185 default_python_bin_path = sys.executable
186 ask_python_bin_path = ('Please specify the location of python. [Default is '
187 '%s]: ') % default_python_bin_path
188 while True:
189 python_bin_path = get_from_env_or_user_or_default(
190 environ_cp, 'PYTHON_BIN_PATH', ask_python_bin_path,
191 default_python_bin_path)
192 # Check if the path is valid
Jonathan Hseu008910f2017-08-25 14:01:05 -0700193 if os.path.isfile(python_bin_path) and os.access(
194 python_bin_path, os.X_OK):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700195 break
196 elif not os.path.exists(python_bin_path):
197 print('Invalid python path: %s cannot be found.' % python_bin_path)
198 else:
199 print('%s is not executable. Is it the python binary?' % python_bin_path)
200 environ_cp['PYTHON_BIN_PATH'] = ''
201
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700202 # Convert python path to Windows style before checking lib and version
Martin Wicked57572e2017-09-02 19:21:45 -0700203 if is_windows() or is_cygwin():
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700204 python_bin_path = cygpath(python_bin_path)
205
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700206 # Get PYTHON_LIB_PATH
207 python_lib_path = environ_cp.get('PYTHON_LIB_PATH')
208 if not python_lib_path:
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700209 python_lib_paths = get_python_path(environ_cp, python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700210 if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1':
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700211 python_lib_path = python_lib_paths[0]
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700212 else:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700213 print('Found possible Python library paths:\n %s' %
214 '\n '.join(python_lib_paths))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700215 default_python_lib_path = python_lib_paths[0]
216 python_lib_path = get_input(
Jonathan Hseu008910f2017-08-25 14:01:05 -0700217 'Please input the desired Python library path to use. '
218 'Default is [%s]\n' % python_lib_paths[0])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700219 if not python_lib_path:
220 python_lib_path = default_python_lib_path
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700221 environ_cp['PYTHON_LIB_PATH'] = python_lib_path
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700222
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700223 python_major_version = get_python_major_version(python_bin_path)
224
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700225 # Convert python path to Windows style before writing into bazel.rc
Martin Wicked57572e2017-09-02 19:21:45 -0700226 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700227 python_lib_path = cygpath(python_lib_path)
228
229 # Set-up env variables used by python_configure.bzl
230 write_action_env_to_bazelrc('PYTHON_BIN_PATH', python_bin_path)
231 write_action_env_to_bazelrc('PYTHON_LIB_PATH', python_lib_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700232 write_to_bazelrc('build --force_python=py%s' % python_major_version)
233 write_to_bazelrc('build --host_force_python=py%s' % python_major_version)
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700234 write_to_bazelrc('build --python_path=\"%s"' % python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700235 environ_cp['PYTHON_BIN_PATH'] = python_bin_path
236
237 # Write tools/python_bin_path.sh
238 with open('tools/python_bin_path.sh', 'w') as f:
239 f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path)
240
241
242def reset_tf_configure_bazelrc():
243 """Reset file that contains customized config settings."""
244 open(_TF_BAZELRC, 'w').close()
245
246 home = os.path.expanduser('~')
247 if not os.path.exists('.bazelrc'):
248 if os.path.exists(os.path.join(home, '.bazelrc')):
249 with open('.bazelrc', 'a') as f:
Shanqing Caie2e3a942017-09-25 19:35:53 -0700250 f.write('import %s/.bazelrc\n' % home.replace('\\', '/'))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700251 else:
252 open('.bazelrc', 'w').close()
253
254 remove_line_with('.bazelrc', 'tf_configure')
255 with open('.bazelrc', 'a') as f:
256 f.write('import %workspace%/.tf_configure.bazelrc\n')
257
258
259def run_gen_git_source(environ_cp):
260 """Run the gen_git_source to create links.
261
262 The links are for bazel to track dependencies for git hash propagation.
263
264 Args:
265 environ_cp: copy of the os.environ.
266 """
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700267 cmd = '"%s" tensorflow/tools/git/gen_git_source.py --configure %s' % (
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700268 environ_cp.get('PYTHON_BIN_PATH'), os.getcwd())
269 os.system(cmd)
270
271
272def cleanup_makefile():
273 """Delete any leftover BUILD files from the Makefile build.
274
275 These files could interfere with Bazel parsing.
276 """
277 makefile_download_dir = 'tensorflow/contrib/makefile/downloads'
278 if os.path.isdir(makefile_download_dir):
279 for root, _, filenames in os.walk(makefile_download_dir):
280 for f in filenames:
281 if f.endswith('BUILD'):
282 os.remove(os.path.join(root, f))
283
284
285def get_var(environ_cp,
286 var_name,
287 query_item,
288 enabled_by_default,
289 question=None,
290 yes_reply=None,
291 no_reply=None):
292 """Get boolean input from user.
293
294 If var_name is not set in env, ask user to enable query_item or not. If the
295 response is empty, use the default.
296
297 Args:
298 environ_cp: copy of the os.environ.
299 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
300 query_item: string for feature related to the variable, e.g. "Hadoop File
301 System".
302 enabled_by_default: boolean for default behavior.
303 question: optional string for how to ask for user input.
304 yes_reply: optionanl string for reply when feature is enabled.
305 no_reply: optional string for reply when feature is disabled.
306
307 Returns:
308 boolean value of the variable.
309 """
310 if not question:
311 question = 'Do you wish to build TensorFlow with %s support?' % query_item
312 if not yes_reply:
313 yes_reply = '%s support will be enabled for TensorFlow.' % query_item
314 if not no_reply:
315 no_reply = 'No %s' % yes_reply
316
317 yes_reply += '\n'
318 no_reply += '\n'
319
320 if enabled_by_default:
321 question += ' [Y/n]: '
322 else:
323 question += ' [y/N]: '
324
325 var = environ_cp.get(var_name)
326 while var is None:
327 user_input_origin = get_input(question)
328 user_input = user_input_origin.strip().lower()
329 if user_input == 'y':
330 print(yes_reply)
331 var = True
332 elif user_input == 'n':
333 print(no_reply)
334 var = False
335 elif not user_input:
336 if enabled_by_default:
337 print(yes_reply)
338 var = True
339 else:
340 print(no_reply)
341 var = False
342 else:
343 print('Invalid selection: %s' % user_input_origin)
344 return var
345
346
347def set_build_var(environ_cp, var_name, query_item, option_name,
Michael Case98850a52017-09-14 13:35:57 -0700348 enabled_by_default, bazel_config_name=None):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700349 """Set if query_item will be enabled for the build.
350
351 Ask user if query_item will be enabled. Default is used if no input is given.
352 Set subprocess environment variable and write to .bazelrc if enabled.
353
354 Args:
355 environ_cp: copy of the os.environ.
356 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
357 query_item: string for feature related to the variable, e.g. "Hadoop File
358 System".
359 option_name: string for option to define in .bazelrc.
360 enabled_by_default: boolean for default behavior.
Michael Case98850a52017-09-14 13:35:57 -0700361 bazel_config_name: Name for Bazel --config argument to enable build feature.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700362 """
363
364 var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default)))
365 environ_cp[var_name] = var
366 if var == '1':
367 write_to_bazelrc('build --define %s=true' % option_name)
Michael Case98850a52017-09-14 13:35:57 -0700368 elif bazel_config_name is not None:
369 # TODO(mikecase): Migrate all users of configure.py to use --config Bazel
370 # options and not to set build configs through environment variables.
371 write_to_bazelrc('build:%s --define %s=true'
372 % (bazel_config_name, option_name))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700373
374
375def set_action_env_var(environ_cp,
376 var_name,
377 query_item,
378 enabled_by_default,
379 question=None,
380 yes_reply=None,
381 no_reply=None):
382 """Set boolean action_env variable.
383
384 Ask user if query_item will be enabled. Default is used if no input is given.
385 Set environment variable and write to .bazelrc.
386
387 Args:
388 environ_cp: copy of the os.environ.
389 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
390 query_item: string for feature related to the variable, e.g. "Hadoop File
391 System".
392 enabled_by_default: boolean for default behavior.
393 question: optional string for how to ask for user input.
394 yes_reply: optionanl string for reply when feature is enabled.
395 no_reply: optional string for reply when feature is disabled.
396 """
397 var = int(
398 get_var(environ_cp, var_name, query_item, enabled_by_default, question,
399 yes_reply, no_reply))
400
401 write_action_env_to_bazelrc(var_name, var)
402 environ_cp[var_name] = str(var)
403
404
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700405def convert_version_to_int(version):
406 """Convert a version number to a integer that can be used to compare.
407
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700408 Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The
409 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.
410
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700411 Args:
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700412 version: a version to be converted
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700413
414 Returns:
415 An integer if converted successfully, otherwise return None.
416 """
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700417 version = version.split('-')[0]
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700418 version_segments = version.split('.')
419 for seg in version_segments:
420 if not seg.isdigit():
421 return None
422
423 version_str = ''.join(['%03d' % int(seg) for seg in version_segments])
424 return int(version_str)
425
426
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700427def check_bazel_version(min_version):
428 """Check installed bezel version is at least min_version.
429
430 Args:
431 min_version: string for minimum bazel version.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700432
433 Returns:
434 The bazel version detected.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700435 """
Jonathan Hseu008910f2017-08-25 14:01:05 -0700436 if which('bazel') is None:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700437 print('Cannot find bazel. Please install bazel.')
438 sys.exit(0)
Jonathan Hseu008910f2017-08-25 14:01:05 -0700439 curr_version = run_shell(['bazel', '--batch', 'version'])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700440
441 for line in curr_version.split('\n'):
442 if 'Build label: ' in line:
443 curr_version = line.split('Build label: ')[1]
444 break
445
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700446 min_version_int = convert_version_to_int(min_version)
447 curr_version_int = convert_version_to_int(curr_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700448
449 # Check if current bazel version can be detected properly.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700450 if not curr_version_int:
451 print('WARNING: current bazel installation is not a release version.')
452 print('Make sure you are running at least bazel %s' % min_version)
453 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700454
Michael Cased94271a2017-08-22 17:26:52 -0700455 print('You have bazel %s installed.' % curr_version)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700456
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700457 if curr_version_int < min_version_int:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700458 print('Please upgrade your bazel installation to version %s or higher to '
459 'build TensorFlow!' % min_version)
460 sys.exit(0)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700461 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700462
463
464def set_cc_opt_flags(environ_cp):
465 """Set up architecture-dependent optimization flags.
466
467 Also append CC optimization flags to bazel.rc..
468
469 Args:
470 environ_cp: copy of the os.environ.
471 """
472 if is_ppc64le():
473 # gcc on ppc64le does not support -march, use mcpu instead
474 default_cc_opt_flags = '-mcpu=native'
475 else:
476 default_cc_opt_flags = '-march=native'
477 question = ('Please specify optimization flags to use during compilation when'
478 ' bazel option "--config=opt" is specified [Default is %s]: '
479 ) % default_cc_opt_flags
480 cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',
481 question, default_cc_opt_flags)
482 for opt in cc_opt_flags.split():
Michael Case00177422017-11-10 13:14:03 -0800483 write_to_bazelrc('build:opt --copt=%s' % opt)
484 # It should be safe on the same build host.
485 write_to_bazelrc('build:opt --host_copt=-march=native')
Michael Casebb3355d2017-11-09 08:46:31 -0800486 write_to_bazelrc('build:opt --define with_default_optimizations=true')
Michael Case00177422017-11-10 13:14:03 -0800487 # TODO(mikecase): Remove these default defines once we are able to get
488 # TF Lite targets building without them.
Andrew Selle0b154392017-11-10 10:35:35 -0800489 write_to_bazelrc('build --copt=-DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK')
490 write_to_bazelrc('build --host_copt=-DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700491
492
493def set_tf_cuda_clang(environ_cp):
494 """set TF_CUDA_CLANG action_env.
495
496 Args:
497 environ_cp: copy of the os.environ.
498 """
499 question = 'Do you want to use clang as CUDA compiler?'
500 yes_reply = 'Clang will be used as CUDA compiler.'
501 no_reply = 'nvcc will be used as CUDA compiler.'
502 set_action_env_var(
503 environ_cp,
504 'TF_CUDA_CLANG',
505 None,
506 False,
507 question=question,
508 yes_reply=yes_reply,
509 no_reply=no_reply)
510
511
512def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
513 var_default):
514 """Get var_name either from env, or user or default.
515
516 If var_name has been set as environment variable, use the preset value, else
517 ask for user input. If no input is provided, the default is used.
518
519 Args:
520 environ_cp: copy of the os.environ.
521 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
522 ask_for_var: string for how to ask for user input.
523 var_default: default value string.
524
525 Returns:
526 string value for var_name
527 """
528 var = environ_cp.get(var_name)
529 if not var:
530 var = get_input(ask_for_var)
Michael Cased94271a2017-08-22 17:26:52 -0700531 print('\n')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700532 if not var:
533 var = var_default
534 return var
535
536
537def set_clang_cuda_compiler_path(environ_cp):
538 """Set CLANG_CUDA_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700539 default_clang_path = which('clang') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700540 ask_clang_path = ('Please specify which clang should be used as device and '
541 'host compiler. [Default is %s]: ') % default_clang_path
542
543 while True:
544 clang_cuda_compiler_path = get_from_env_or_user_or_default(
545 environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path,
546 default_clang_path)
547 if os.path.exists(clang_cuda_compiler_path):
548 break
549
550 # Reset and retry
551 print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path)
552 environ_cp['CLANG_CUDA_COMPILER_PATH'] = ''
553
554 # Set CLANG_CUDA_COMPILER_PATH
555 environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path
556 write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',
557 clang_cuda_compiler_path)
558
559
560def set_gcc_host_compiler_path(environ_cp):
561 """Set GCC_HOST_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700562 default_gcc_host_compiler_path = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700563 cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH')
564
565 if os.path.islink(cuda_bin_symlink):
566 # os.readlink is only available in linux
Jonathan Hseu008910f2017-08-25 14:01:05 -0700567 default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700568
569 ask_gcc_path = (
570 'Please specify which gcc should be used by nvcc as the '
571 'host compiler. [Default is %s]: ') % default_gcc_host_compiler_path
572 while True:
573 gcc_host_compiler_path = get_from_env_or_user_or_default(
574 environ_cp, 'GCC_HOST_COMPILER_PATH', ask_gcc_path,
575 default_gcc_host_compiler_path)
576
577 if os.path.exists(gcc_host_compiler_path):
578 break
579
580 # Reset and retry
581 print('Invalid gcc path. %s cannot be found' % gcc_host_compiler_path)
582 environ_cp['GCC_HOST_COMPILER_PATH'] = ''
583
584 # Set GCC_HOST_COMPILER_PATH
585 environ_cp['GCC_HOST_COMPILER_PATH'] = gcc_host_compiler_path
586 write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)
587
588
589def set_tf_cuda_version(environ_cp):
590 """Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION."""
591 ask_cuda_version = (
592 'Please specify the CUDA SDK version you want to use, '
593 'e.g. 7.0. [Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
594
595 while True:
596 # Configure the Cuda SDK version to use.
597 tf_cuda_version = get_from_env_or_user_or_default(
598 environ_cp, 'TF_CUDA_VERSION', ask_cuda_version, _DEFAULT_CUDA_VERSION)
599
600 # Find out where the CUDA toolkit is installed
601 default_cuda_path = _DEFAULT_CUDA_PATH
Martin Wicked57572e2017-09-02 19:21:45 -0700602 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700603 default_cuda_path = cygpath(
604 environ_cp.get('CUDA_PATH', _DEFAULT_CUDA_PATH_WIN))
605 elif is_linux():
606 # If the default doesn't exist, try an alternative default.
607 if (not os.path.exists(default_cuda_path)
608 ) and os.path.exists(_DEFAULT_CUDA_PATH_LINUX):
609 default_cuda_path = _DEFAULT_CUDA_PATH_LINUX
610 ask_cuda_path = ('Please specify the location where CUDA %s toolkit is'
611 ' installed. Refer to README.md for more details. '
612 '[Default is %s]: ') % (tf_cuda_version, default_cuda_path)
613 cuda_toolkit_path = get_from_env_or_user_or_default(
614 environ_cp, 'CUDA_TOOLKIT_PATH', ask_cuda_path, default_cuda_path)
615
616 if is_windows():
617 cuda_rt_lib_path = 'lib/x64/cudart.lib'
618 elif is_linux():
619 cuda_rt_lib_path = 'lib64/libcudart.so.%s' % tf_cuda_version
620 elif is_macos():
621 cuda_rt_lib_path = 'lib/libcudart.%s.dylib' % tf_cuda_version
622
623 cuda_toolkit_path_full = os.path.join(cuda_toolkit_path, cuda_rt_lib_path)
624 if os.path.exists(cuda_toolkit_path_full):
625 break
626
627 # Reset and retry
628 print('Invalid path to CUDA %s toolkit. %s cannot be found' %
629 (tf_cuda_version, cuda_toolkit_path_full))
630 environ_cp['TF_CUDA_VERSION'] = ''
631 environ_cp['CUDA_TOOLKIT_PATH'] = ''
632
633 # Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION
634 environ_cp['CUDA_TOOLKIT_PATH'] = cuda_toolkit_path
635 write_action_env_to_bazelrc('CUDA_TOOLKIT_PATH', cuda_toolkit_path)
636 environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
637 write_action_env_to_bazelrc('TF_CUDA_VERSION', tf_cuda_version)
638
639
Yifei Fengb1d8c592017-11-22 13:42:21 -0800640def set_tf_cudnn_version(environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700641 """Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION."""
642 ask_cudnn_version = (
Jonathan Hseu008910f2017-08-25 14:01:05 -0700643 'Please specify the cuDNN version you want to use. '
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700644 '[Leave empty to default to cuDNN %s.0]: ') % _DEFAULT_CUDNN_VERSION
645
646 while True:
647 tf_cudnn_version = get_from_env_or_user_or_default(
648 environ_cp, 'TF_CUDNN_VERSION', ask_cudnn_version,
649 _DEFAULT_CUDNN_VERSION)
650
651 default_cudnn_path = environ_cp.get('CUDA_TOOLKIT_PATH')
652 ask_cudnn_path = (r'Please specify the location where cuDNN %s library is '
653 'installed. Refer to README.md for more details. [Default'
654 ' is %s]:') % (tf_cudnn_version, default_cudnn_path)
655 cudnn_install_path = get_from_env_or_user_or_default(
656 environ_cp, 'CUDNN_INSTALL_PATH', ask_cudnn_path, default_cudnn_path)
657
658 # Result returned from "read" will be used unexpanded. That make "~"
659 # unusable. Going through one more level of expansion to handle that.
660 cudnn_install_path = os.path.realpath(
661 os.path.expanduser(cudnn_install_path))
Martin Wicked57572e2017-09-02 19:21:45 -0700662 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700663 cudnn_install_path = cygpath(cudnn_install_path)
664
665 if is_windows():
666 cuda_dnn_lib_path = 'lib/x64/cudnn.lib'
667 cuda_dnn_lib_alt_path = 'lib/x64/cudnn.lib'
668 elif is_linux():
669 cuda_dnn_lib_path = 'lib64/libcudnn.so.%s' % tf_cudnn_version
670 cuda_dnn_lib_alt_path = 'libcudnn.so.%s' % tf_cudnn_version
671 elif is_macos():
672 cuda_dnn_lib_path = 'lib/libcudnn.%s.dylib' % tf_cudnn_version
673 cuda_dnn_lib_alt_path = 'libcudnn.%s.dylib' % tf_cudnn_version
674
675 cuda_dnn_lib_path_full = os.path.join(cudnn_install_path, cuda_dnn_lib_path)
676 cuda_dnn_lib_alt_path_full = os.path.join(cudnn_install_path,
677 cuda_dnn_lib_alt_path)
678 if os.path.exists(cuda_dnn_lib_path_full) or os.path.exists(
679 cuda_dnn_lib_alt_path_full):
680 break
681
682 # Try another alternative for Linux
683 if is_linux():
Jonathan Hseu008910f2017-08-25 14:01:05 -0700684 ldconfig_bin = which('ldconfig') or '/sbin/ldconfig'
685 cudnn_path_from_ldconfig = run_shell([ldconfig_bin, '-p'])
686 cudnn_path_from_ldconfig = re.search('.*libcudnn.so .* => (.*)',
A. Unique TensorFlowere7223582017-09-06 17:57:04 -0700687 cudnn_path_from_ldconfig)
688 if cudnn_path_from_ldconfig:
689 cudnn_path_from_ldconfig = cudnn_path_from_ldconfig.group(1)
690 if os.path.exists('%s.%s' % (cudnn_path_from_ldconfig,
691 tf_cudnn_version)):
692 cudnn_install_path = os.path.dirname(cudnn_path_from_ldconfig)
693 break
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700694
695 # Reset and Retry
696 print(
697 'Invalid path to cuDNN %s toolkit. None of the following files can be '
698 'found:' % tf_cudnn_version)
699 print(cuda_dnn_lib_path_full)
700 print(cuda_dnn_lib_alt_path_full)
701 if is_linux():
702 print('%s.%s' % (cudnn_path_from_ldconfig, tf_cudnn_version))
703
704 environ_cp['TF_CUDNN_VERSION'] = ''
705
706 # Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION
707 environ_cp['CUDNN_INSTALL_PATH'] = cudnn_install_path
708 write_action_env_to_bazelrc('CUDNN_INSTALL_PATH', cudnn_install_path)
709 environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
710 write_action_env_to_bazelrc('TF_CUDNN_VERSION', tf_cudnn_version)
711
712
713def get_native_cuda_compute_capabilities(environ_cp):
714 """Get native cuda compute capabilities.
715
716 Args:
717 environ_cp: copy of the os.environ.
718 Returns:
719 string of native cuda compute capabilities, separated by comma.
720 """
721 device_query_bin = os.path.join(
722 environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery')
Jonathan Hseu008910f2017-08-25 14:01:05 -0700723 if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK):
724 try:
725 output = run_shell(device_query_bin).split('\n')
726 pattern = re.compile('[0-9]*\\.[0-9]*')
727 output = [pattern.search(x) for x in output if 'Capability' in x]
728 output = ','.join(x.group() for x in output if x is not None)
729 except subprocess.CalledProcessError:
730 output = ''
731 else:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700732 output = ''
733 return output
734
735
736def set_tf_cuda_compute_capabilities(environ_cp):
737 """Set TF_CUDA_COMPUTE_CAPABILITIES."""
738 while True:
739 native_cuda_compute_capabilities = get_native_cuda_compute_capabilities(
740 environ_cp)
741 if not native_cuda_compute_capabilities:
742 default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES
743 else:
744 default_cuda_compute_capabilities = native_cuda_compute_capabilities
745
746 ask_cuda_compute_capabilities = (
747 'Please specify a list of comma-separated '
748 'Cuda compute capabilities you want to '
749 'build with.\nYou can find the compute '
750 'capability of your device at: '
751 'https://developer.nvidia.com/cuda-gpus.\nPlease'
752 ' note that each additional compute '
753 'capability significantly increases your '
754 'build time and binary size. [Default is: %s]' %
755 default_cuda_compute_capabilities)
756 tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
757 environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
758 ask_cuda_compute_capabilities, default_cuda_compute_capabilities)
759 # Check whether all capabilities from the input is valid
760 all_valid = True
761 for compute_capability in tf_cuda_compute_capabilities.split(','):
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700762 m = re.match('[0-9]+.[0-9]+', compute_capability)
763 if not m:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700764 print('Invalid compute capability: ' % compute_capability)
765 all_valid = False
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700766 else:
767 ver = int(m.group(0).split('.')[0])
768 if ver < 3:
769 print('Only compute capabilities 3.0 or higher are supported.')
770 all_valid = False
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700771
772 if all_valid:
773 break
774
775 # Reset and Retry
776 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = ''
777
778 # Set TF_CUDA_COMPUTE_CAPABILITIES
779 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities
780 write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES',
781 tf_cuda_compute_capabilities)
782
783
784def set_other_cuda_vars(environ_cp):
785 """Set other CUDA related variables."""
786 if is_windows():
787 # The following three variables are needed for MSVC toolchain configuration
788 # in Bazel
789 environ_cp['CUDA_PATH'] = environ_cp.get('CUDA_TOOLKIT_PATH')
790 environ_cp['CUDA_COMPUTE_CAPABILITIES'] = environ_cp.get(
791 'TF_CUDA_COMPUTE_CAPABILITIES')
792 environ_cp['NO_WHOLE_ARCHIVE_OPTION'] = 1
793 write_action_env_to_bazelrc('CUDA_PATH', environ_cp.get('CUDA_PATH'))
794 write_action_env_to_bazelrc('CUDA_COMPUTE_CAPABILITIE',
795 environ_cp.get('CUDA_COMPUTE_CAPABILITIE'))
796 write_action_env_to_bazelrc('NO_WHOLE_ARCHIVE_OPTION',
797 environ_cp.get('NO_WHOLE_ARCHIVE_OPTION'))
798 write_to_bazelrc('build --config=win-cuda')
799 write_to_bazelrc('test --config=win-cuda')
800 else:
801 # If CUDA is enabled, always use GPU during build and test.
802 if environ_cp.get('TF_CUDA_CLANG') == '1':
803 write_to_bazelrc('build --config=cuda_clang')
804 write_to_bazelrc('test --config=cuda_clang')
805 else:
806 write_to_bazelrc('build --config=cuda')
807 write_to_bazelrc('test --config=cuda')
808
809
810def set_host_cxx_compiler(environ_cp):
811 """Set HOST_CXX_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700812 default_cxx_host_compiler = which('g++') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700813 ask_cxx_host_compiler = (
814 'Please specify which C++ compiler should be used as'
815 ' the host C++ compiler. [Default is %s]: ') % default_cxx_host_compiler
816
817 while True:
818 host_cxx_compiler = get_from_env_or_user_or_default(
819 environ_cp, 'HOST_CXX_COMPILER', ask_cxx_host_compiler,
820 default_cxx_host_compiler)
821 if os.path.exists(host_cxx_compiler):
822 break
823
824 # Reset and retry
825 print('Invalid C++ compiler path. %s cannot be found' % host_cxx_compiler)
826 environ_cp['HOST_CXX_COMPILER'] = ''
827
828 # Set HOST_CXX_COMPILER
829 environ_cp['HOST_CXX_COMPILER'] = host_cxx_compiler
830 write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler)
831
832
833def set_host_c_compiler(environ_cp):
834 """Set HOST_C_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700835 default_c_host_compiler = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700836 ask_c_host_compiler = (
837 'Please specify which C compiler should be used as the'
838 ' host C compiler. [Default is %s]: ') % default_c_host_compiler
839
840 while True:
841 host_c_compiler = get_from_env_or_user_or_default(
842 environ_cp, 'HOST_C_COMPILER', ask_c_host_compiler,
843 default_c_host_compiler)
844 if os.path.exists(host_c_compiler):
845 break
846
847 # Reset and retry
848 print('Invalid C compiler path. %s cannot be found' % host_c_compiler)
849 environ_cp['HOST_C_COMPILER'] = ''
850
851 # Set HOST_C_COMPILER
852 environ_cp['HOST_C_COMPILER'] = host_c_compiler
853 write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler)
854
855
856def set_computecpp_toolkit_path(environ_cp):
857 """Set COMPUTECPP_TOOLKIT_PATH."""
858 ask_computecpp_toolkit_path = ('Please specify the location where ComputeCpp '
859 'for SYCL %s is installed. [Default is %s]: '
860 ) % (_TF_OPENCL_VERSION,
861 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
862
863 while True:
864 computecpp_toolkit_path = get_from_env_or_user_or_default(
865 environ_cp, 'COMPUTECPP_TOOLKIT_PATH', ask_computecpp_toolkit_path,
866 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
867 if is_linux():
868 sycl_rt_lib_path = 'lib/libComputeCpp.so'
869 else:
870 sycl_rt_lib_path = ''
871
872 sycl_rt_lib_path_full = os.path.join(computecpp_toolkit_path,
873 sycl_rt_lib_path)
874 if os.path.exists(sycl_rt_lib_path_full):
875 break
876
877 print('Invalid SYCL %s library path. %s cannot be found' %
878 (_TF_OPENCL_VERSION, sycl_rt_lib_path_full))
879 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = ''
880
881 # Set COMPUTECPP_TOOLKIT_PATH
882 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = computecpp_toolkit_path
883 write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH',
884 computecpp_toolkit_path)
885
886
Yifei Fengb1d8c592017-11-22 13:42:21 -0800887def set_trisycl_include_dir(environ_cp):
888 """Set TRISYCL_INCLUDE_DIR."""
889 ask_trisycl_include_dir = ('Please specify the location of the triSYCL '
890 'include directory. (Use --config=sycl_trisycl '
891 'when building with Bazel) '
892 '[Default is %s]: ') % (
893 _DEFAULT_TRISYCL_INCLUDE_DIR)
894 while True:
895 trisycl_include_dir = get_from_env_or_user_or_default(
896 environ_cp, 'TRISYCL_INCLUDE_DIR', ask_trisycl_include_dir,
897 _DEFAULT_TRISYCL_INCLUDE_DIR)
898 if os.path.exists(trisycl_include_dir):
899 break
900
901 print('Invalid triSYCL include directory, %s cannot be found' %
902 (trisycl_include_dir))
903
904 # Set TRISYCL_INCLUDE_DIR
905 environ_cp['TRISYCL_INCLUDE_DIR'] = trisycl_include_dir
906 write_action_env_to_bazelrc('TRISYCL_INCLUDE_DIR', trisycl_include_dir)
907
908
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700909def set_mpi_home(environ_cp):
910 """Set MPI_HOME."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700911 default_mpi_home = which('mpirun') or which('mpiexec') or ''
912 default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home))
913
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700914 ask_mpi_home = ('Please specify the MPI toolkit folder. [Default is %s]: '
915 ) % default_mpi_home
916 while True:
917 mpi_home = get_from_env_or_user_or_default(environ_cp, 'MPI_HOME',
918 ask_mpi_home, default_mpi_home)
919
920 if os.path.exists(os.path.join(mpi_home, 'include')) and os.path.exists(
921 os.path.join(mpi_home, 'lib')):
922 break
923
924 print('Invalid path to the MPI Toolkit. %s or %s cannot be found' %
925 (os.path.join(mpi_home, 'include'),
926 os.path.exists(os.path.join(mpi_home, 'lib'))))
927 environ_cp['MPI_HOME'] = ''
928
929 # Set MPI_HOME
930 environ_cp['MPI_HOME'] = str(mpi_home)
931
932
933def set_other_mpi_vars(environ_cp):
934 """Set other MPI related variables."""
935 # Link the MPI header files
936 mpi_home = environ_cp.get('MPI_HOME')
937 symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h')
938
939 # Determine if we use OpenMPI or MVAPICH, these require different header files
940 # to be included here to make bazel dependency checker happy
941 if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')):
942 symlink_force(
943 os.path.join(mpi_home, 'include/mpi_portable_platform.h'),
944 'third_party/mpi/mpi_portable_platform.h')
945 # TODO(gunan): avoid editing files in configure
946 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False',
947 'MPI_LIB_IS_OPENMPI=True')
948 else:
949 # MVAPICH / MPICH
950 symlink_force(
951 os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h')
952 symlink_force(
953 os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h')
954 # TODO(gunan): avoid editing files in configure
955 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True',
956 'MPI_LIB_IS_OPENMPI=False')
957
958 if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')):
959 symlink_force(
960 os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so')
961 else:
962 raise ValueError('Cannot find the MPI library file in %s/lib' % mpi_home)
963
964
965def set_mkl():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700966 write_to_bazelrc('build:mkl --define using_mkl=true')
967 write_to_bazelrc('build:mkl -c opt')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700968 print(
969 'Add "--config=mkl" to your bazel command to build with MKL '
970 'support.\nPlease note that MKL on MacOS or windows is still not '
971 'supported.\nIf you would like to use a local MKL instead of '
972 'downloading, please set the environment variable \"TF_MKL_ROOT\" every '
973 'time before build.')
974
975
Allen Lavoie5c7f9e32017-09-21 11:29:45 -0700976def set_monolithic():
977 # Add --config=monolithic to your bazel command to use a mostly-static
978 # build and disable modular op registration support (this will revert to
979 # loading TensorFlow with RTLD_GLOBAL in Python). By default (without
980 # --config=monolithic), TensorFlow will build with a dependence on
981 # //tensorflow:libtensorflow_framework.so.
982 write_to_bazelrc('build:monolithic --define framework_shared_object=false')
983 # For projects which use TensorFlow as part of a Bazel build process, putting
984 # nothing in a bazelrc will default to a monolithic build. The following line
985 # opts in to modular op registration support by default:
986 write_to_bazelrc('build --define framework_shared_object=true')
987
988
Michael Casef1ecdd62017-10-24 18:07:59 -0700989def create_android_bazelrc_configs():
990 # Flags for --config=android
991 write_to_bazelrc('build:android --crosstool_top=//external:android/crosstool')
992 write_to_bazelrc(
993 'build:android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain')
994 # Flags for --config=android_arm
995 write_to_bazelrc('build:android_arm --config=android')
996 write_to_bazelrc('build:android_arm --cpu=armeabi-v7a')
997 # Flags for --config=android_arm64
998 write_to_bazelrc('build:android_arm64 --config=android')
999 write_to_bazelrc('build:android_arm64 --cpu=arm64-v8a')
1000
1001
A. Unique TensorFlower061c3592017-11-13 14:21:04 -08001002def set_grpc_build_flags():
1003 write_to_bazelrc('build --define grpc_no_ares=true')
1004
1005
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001006def main():
1007 # Make a copy of os.environ to be clear when functions and getting and setting
1008 # environment variables.
1009 environ_cp = dict(os.environ)
1010
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -07001011 check_bazel_version('0.5.4')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001012
1013 reset_tf_configure_bazelrc()
1014 cleanup_makefile()
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -07001015 setup_python(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001016 run_gen_git_source(environ_cp)
1017
1018 if is_windows():
Benoit Steiner355e25e2017-10-24 19:47:46 -07001019 environ_cp['TF_NEED_S3'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001020 environ_cp['TF_NEED_GCP'] = '0'
1021 environ_cp['TF_NEED_HDFS'] = '0'
1022 environ_cp['TF_NEED_JEMALLOC'] = '0'
Yifei Fengb1d8c592017-11-22 13:42:21 -08001023 environ_cp['TF_NEED_OPENCL_SYCL'] = '0'
1024 environ_cp['TF_NEED_COMPUTECPP'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001025 environ_cp['TF_NEED_OPENCL'] = '0'
1026 environ_cp['TF_CUDA_CLANG'] = '0'
1027
1028 if is_macos():
1029 environ_cp['TF_NEED_JEMALLOC'] = '0'
1030
1031 set_build_var(environ_cp, 'TF_NEED_JEMALLOC', 'jemalloc as malloc',
1032 'with_jemalloc', True)
1033 set_build_var(environ_cp, 'TF_NEED_GCP', 'Google Cloud Platform',
Benoit Steiner355e25e2017-10-24 19:47:46 -07001034 'with_gcp_support', True, 'gcp')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001035 set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
Benoit Steiner355e25e2017-10-24 19:47:46 -07001036 'with_hdfs_support', True, 'hdfs')
Michael Case7e4e3362017-10-09 13:31:15 -07001037 set_build_var(environ_cp, 'TF_NEED_S3', 'Amazon S3 File System',
1038 'with_s3_support', True, 's3')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001039 set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
Michael Case98850a52017-09-14 13:35:57 -07001040 False, 'xla')
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -07001041 set_build_var(environ_cp, 'TF_NEED_GDR', 'GDR', 'with_gdr_support',
Michael Case98850a52017-09-14 13:35:57 -07001042 False, 'gdr')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001043 set_build_var(environ_cp, 'TF_NEED_VERBS', 'VERBS', 'with_verbs_support',
Michael Case98850a52017-09-14 13:35:57 -07001044 False, 'verbs')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001045
Yifei Fengb1d8c592017-11-22 13:42:21 -08001046 set_action_env_var(environ_cp, 'TF_NEED_OPENCL_SYCL', 'OpenCL SYCL', False)
1047 if environ_cp.get('TF_NEED_OPENCL_SYCL') == '1':
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001048 set_host_cxx_compiler(environ_cp)
1049 set_host_c_compiler(environ_cp)
Yifei Fengb1d8c592017-11-22 13:42:21 -08001050 set_action_env_var(environ_cp, 'TF_NEED_COMPUTECPP', 'ComputeCPP', True)
1051 if environ_cp.get('TF_NEED_COMPUTECPP') == '1':
1052 set_computecpp_toolkit_path(environ_cp)
1053 else:
1054 set_trisycl_include_dir(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001055
1056 set_action_env_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)
A. Unique TensorFlower24cbb2a2017-09-08 07:45:44 -07001057 if (environ_cp.get('TF_NEED_CUDA') == '1' and
1058 'TF_CUDA_CONFIG_REPO' not in environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001059 set_tf_cuda_version(environ_cp)
Yifei Fengb1d8c592017-11-22 13:42:21 -08001060 set_tf_cudnn_version(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001061 set_tf_cuda_compute_capabilities(environ_cp)
1062
1063 set_tf_cuda_clang(environ_cp)
1064 if environ_cp.get('TF_CUDA_CLANG') == '1':
1065 # Set up which clang we should use as the cuda / host compiler.
1066 set_clang_cuda_compiler_path(environ_cp)
1067 else:
1068 # Set up which gcc nvcc should use as the host compiler
1069 # No need to set this on Windows
1070 if not is_windows():
1071 set_gcc_host_compiler_path(environ_cp)
1072 set_other_cuda_vars(environ_cp)
1073
1074 set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False)
1075 if environ_cp.get('TF_NEED_MPI') == '1':
1076 set_mpi_home(environ_cp)
1077 set_other_mpi_vars(environ_cp)
1078
A. Unique TensorFlower061c3592017-11-13 14:21:04 -08001079 set_grpc_build_flags()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001080 set_cc_opt_flags(environ_cp)
1081 set_mkl()
Allen Lavoie5c7f9e32017-09-21 11:29:45 -07001082 set_monolithic()
Michael Casef1ecdd62017-10-24 18:07:59 -07001083 create_android_bazelrc_configs()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001084
1085if __name__ == '__main__':
1086 main()