blob: 0d1afbfe15c3d985c4378429dc311290938223c9 [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'
46
47
48def is_windows():
49 return platform.system() == 'Windows'
50
51
52def is_linux():
53 return platform.system() == 'Linux'
54
55
56def is_macos():
57 return platform.system() == 'Darwin'
58
59
60def is_ppc64le():
61 return platform.machine() == 'ppc64le'
62
63
Jonathan Hseu008910f2017-08-25 14:01:05 -070064def is_cygwin():
65 return platform.system().startswith('CYGWIN_NT')
66
67
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070068def get_input(question):
69 try:
70 try:
71 answer = raw_input(question)
72 except NameError:
73 answer = input(question) # pylint: disable=bad-builtin
74 except EOFError:
75 answer = ''
76 return answer
77
78
79def symlink_force(target, link_name):
80 """Force symlink, equivalent of 'ln -sf'.
81
82 Args:
83 target: items to link to.
84 link_name: name of the link.
85 """
86 try:
87 os.symlink(target, link_name)
88 except OSError as e:
89 if e.errno == errno.EEXIST:
90 os.remove(link_name)
91 os.symlink(target, link_name)
92 else:
93 raise e
94
95
96def sed_in_place(filename, old, new):
97 """Replace old string with new string in file.
98
99 Args:
100 filename: string for filename.
101 old: string to replace.
102 new: new string to replace to.
103 """
104 with open(filename, 'r') as f:
105 filedata = f.read()
106 newdata = filedata.replace(old, new)
107 with open(filename, 'w') as f:
108 f.write(newdata)
109
110
111def remove_line_with(filename, token):
112 """Remove lines that contain token from file.
113
114 Args:
115 filename: string for filename.
116 token: string token to check if to remove a line from file or not.
117 """
118 with open(filename, 'r') as f:
119 filedata = f.read()
120
121 with open(filename, 'w') as f:
122 for line in filedata.strip().split('\n'):
123 if token not in line:
124 f.write(line + '\n')
125
126
127def write_to_bazelrc(line):
128 with open(_TF_BAZELRC, 'a') as f:
129 f.write(line + '\n')
130
131
132def write_action_env_to_bazelrc(var_name, var):
133 write_to_bazelrc('build --action_env %s="%s"' % (var_name, str(var)))
134
135
Jonathan Hseu008910f2017-08-25 14:01:05 -0700136def run_shell(cmd, allow_non_zero=False):
137 if allow_non_zero:
138 try:
139 output = subprocess.check_output(cmd)
140 except subprocess.CalledProcessError as e:
141 output = e.output
142 else:
143 output = subprocess.check_output(cmd)
144 return output.decode('UTF-8').strip()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700145
146
147def cygpath(path):
148 """Convert path from posix to windows."""
Martin Wicked57572e2017-09-02 19:21:45 -0700149 return os.path.abspath(path).replace('\\', '/')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700150
151
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700152def get_python_path(environ_cp, python_bin_path):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700153 """Get the python site package paths."""
154 python_paths = []
155 if environ_cp.get('PYTHONPATH'):
156 python_paths = environ_cp.get('PYTHONPATH').split(':')
157 try:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700158 library_paths = run_shell(
159 [python_bin_path, '-c',
160 'import site; print("\\n".join(site.getsitepackages()))']).split("\n")
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700161 except subprocess.CalledProcessError:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700162 library_paths = [run_shell(
163 [python_bin_path, '-c',
164 'from distutils.sysconfig import get_python_lib;'
165 'print(get_python_lib())'])]
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700166
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700167 all_paths = set(python_paths + library_paths)
168
169 paths = []
170 for path in all_paths:
171 if os.path.isdir(path):
172 paths.append(path)
173 return paths
174
175
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700176def get_python_major_version(python_bin_path):
177 """Get the python major version."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700178 return run_shell([python_bin_path, '-c', 'import sys; print(sys.version[0])'])
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700179
180
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700181def setup_python(environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700182 """Setup python related env variables."""
183 # Get PYTHON_BIN_PATH, default is the current running python.
184 default_python_bin_path = sys.executable
185 ask_python_bin_path = ('Please specify the location of python. [Default is '
186 '%s]: ') % default_python_bin_path
187 while True:
188 python_bin_path = get_from_env_or_user_or_default(
189 environ_cp, 'PYTHON_BIN_PATH', ask_python_bin_path,
190 default_python_bin_path)
191 # Check if the path is valid
Jonathan Hseu008910f2017-08-25 14:01:05 -0700192 if os.path.isfile(python_bin_path) and os.access(
193 python_bin_path, os.X_OK):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700194 break
195 elif not os.path.exists(python_bin_path):
196 print('Invalid python path: %s cannot be found.' % python_bin_path)
197 else:
198 print('%s is not executable. Is it the python binary?' % python_bin_path)
199 environ_cp['PYTHON_BIN_PATH'] = ''
200
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700201 # Convert python path to Windows style before checking lib and version
Martin Wicked57572e2017-09-02 19:21:45 -0700202 if is_windows() or is_cygwin():
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700203 python_bin_path = cygpath(python_bin_path)
204
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700205 # Get PYTHON_LIB_PATH
206 python_lib_path = environ_cp.get('PYTHON_LIB_PATH')
207 if not python_lib_path:
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700208 python_lib_paths = get_python_path(environ_cp, python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700209 if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1':
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700210 python_lib_path = python_lib_paths[0]
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700211 else:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700212 print('Found possible Python library paths:\n %s' %
213 '\n '.join(python_lib_paths))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700214 default_python_lib_path = python_lib_paths[0]
215 python_lib_path = get_input(
Jonathan Hseu008910f2017-08-25 14:01:05 -0700216 'Please input the desired Python library path to use. '
217 'Default is [%s]\n' % python_lib_paths[0])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700218 if not python_lib_path:
219 python_lib_path = default_python_lib_path
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700220 environ_cp['PYTHON_LIB_PATH'] = python_lib_path
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700221
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700222 python_major_version = get_python_major_version(python_bin_path)
223
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700224 # Convert python path to Windows style before writing into bazel.rc
Martin Wicked57572e2017-09-02 19:21:45 -0700225 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700226 python_lib_path = cygpath(python_lib_path)
227
228 # Set-up env variables used by python_configure.bzl
229 write_action_env_to_bazelrc('PYTHON_BIN_PATH', python_bin_path)
230 write_action_env_to_bazelrc('PYTHON_LIB_PATH', python_lib_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700231 write_to_bazelrc('build --force_python=py%s' % python_major_version)
232 write_to_bazelrc('build --host_force_python=py%s' % python_major_version)
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700233 write_to_bazelrc('build --python_path=\"%s"' % python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700234 environ_cp['PYTHON_BIN_PATH'] = python_bin_path
235
236 # Write tools/python_bin_path.sh
237 with open('tools/python_bin_path.sh', 'w') as f:
238 f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path)
239
240
241def reset_tf_configure_bazelrc():
242 """Reset file that contains customized config settings."""
243 open(_TF_BAZELRC, 'w').close()
244
245 home = os.path.expanduser('~')
246 if not os.path.exists('.bazelrc'):
247 if os.path.exists(os.path.join(home, '.bazelrc')):
248 with open('.bazelrc', 'a') as f:
Shanqing Caie2e3a942017-09-25 19:35:53 -0700249 f.write('import %s/.bazelrc\n' % home.replace('\\', '/'))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700250 else:
251 open('.bazelrc', 'w').close()
252
253 remove_line_with('.bazelrc', 'tf_configure')
254 with open('.bazelrc', 'a') as f:
255 f.write('import %workspace%/.tf_configure.bazelrc\n')
256
257
258def run_gen_git_source(environ_cp):
259 """Run the gen_git_source to create links.
260
261 The links are for bazel to track dependencies for git hash propagation.
262
263 Args:
264 environ_cp: copy of the os.environ.
265 """
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700266 cmd = '"%s" tensorflow/tools/git/gen_git_source.py --configure %s' % (
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700267 environ_cp.get('PYTHON_BIN_PATH'), os.getcwd())
268 os.system(cmd)
269
270
271def cleanup_makefile():
272 """Delete any leftover BUILD files from the Makefile build.
273
274 These files could interfere with Bazel parsing.
275 """
276 makefile_download_dir = 'tensorflow/contrib/makefile/downloads'
277 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.
298 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
299 query_item: string for feature related to the variable, e.g. "Hadoop File
300 System".
301 enabled_by_default: boolean for default behavior.
302 question: optional string for how to ask for user input.
303 yes_reply: optionanl string for reply when feature is enabled.
304 no_reply: optional string for reply when feature is disabled.
305
306 Returns:
307 boolean value of the variable.
308 """
309 if not question:
310 question = 'Do you wish to build TensorFlow with %s support?' % query_item
311 if not yes_reply:
312 yes_reply = '%s support will be enabled for TensorFlow.' % query_item
313 if not no_reply:
314 no_reply = 'No %s' % yes_reply
315
316 yes_reply += '\n'
317 no_reply += '\n'
318
319 if enabled_by_default:
320 question += ' [Y/n]: '
321 else:
322 question += ' [y/N]: '
323
324 var = environ_cp.get(var_name)
325 while var is None:
326 user_input_origin = get_input(question)
327 user_input = user_input_origin.strip().lower()
328 if user_input == 'y':
329 print(yes_reply)
330 var = True
331 elif user_input == 'n':
332 print(no_reply)
333 var = False
334 elif not user_input:
335 if enabled_by_default:
336 print(yes_reply)
337 var = True
338 else:
339 print(no_reply)
340 var = False
341 else:
342 print('Invalid selection: %s' % user_input_origin)
343 return var
344
345
346def set_build_var(environ_cp, var_name, query_item, option_name,
Michael Case98850a52017-09-14 13:35:57 -0700347 enabled_by_default, bazel_config_name=None):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700348 """Set if query_item will be enabled for the build.
349
350 Ask user if query_item will be enabled. Default is used if no input is given.
351 Set subprocess environment variable and write to .bazelrc if enabled.
352
353 Args:
354 environ_cp: copy of the os.environ.
355 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
356 query_item: string for feature related to the variable, e.g. "Hadoop File
357 System".
358 option_name: string for option to define in .bazelrc.
359 enabled_by_default: boolean for default behavior.
Michael Case98850a52017-09-14 13:35:57 -0700360 bazel_config_name: Name for Bazel --config argument to enable build feature.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700361 """
362
363 var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default)))
364 environ_cp[var_name] = var
365 if var == '1':
366 write_to_bazelrc('build --define %s=true' % option_name)
Michael Case98850a52017-09-14 13:35:57 -0700367 elif bazel_config_name is not None:
368 # TODO(mikecase): Migrate all users of configure.py to use --config Bazel
369 # options and not to set build configs through environment variables.
370 write_to_bazelrc('build:%s --define %s=true'
371 % (bazel_config_name, option_name))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700372
373
374def set_action_env_var(environ_cp,
375 var_name,
376 query_item,
377 enabled_by_default,
378 question=None,
379 yes_reply=None,
380 no_reply=None):
381 """Set boolean action_env variable.
382
383 Ask user if query_item will be enabled. Default is used if no input is given.
384 Set environment variable and write to .bazelrc.
385
386 Args:
387 environ_cp: copy of the os.environ.
388 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
389 query_item: string for feature related to the variable, e.g. "Hadoop File
390 System".
391 enabled_by_default: boolean for default behavior.
392 question: optional string for how to ask for user input.
393 yes_reply: optionanl string for reply when feature is enabled.
394 no_reply: optional string for reply when feature is disabled.
395 """
396 var = int(
397 get_var(environ_cp, var_name, query_item, enabled_by_default, question,
398 yes_reply, no_reply))
399
400 write_action_env_to_bazelrc(var_name, var)
401 environ_cp[var_name] = str(var)
402
403
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700404def convert_version_to_int(version):
405 """Convert a version number to a integer that can be used to compare.
406
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700407 Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The
408 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.
409
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700410 Args:
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700411 version: a version to be converted
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700412
413 Returns:
414 An integer if converted successfully, otherwise return None.
415 """
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700416 version = version.split('-')[0]
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700417 version_segments = version.split('.')
418 for seg in version_segments:
419 if not seg.isdigit():
420 return None
421
422 version_str = ''.join(['%03d' % int(seg) for seg in version_segments])
423 return int(version_str)
424
425
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700426def check_bazel_version(min_version):
427 """Check installed bezel version is at least min_version.
428
429 Args:
430 min_version: string for minimum bazel version.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700431
432 Returns:
433 The bazel version detected.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700434 """
Jonathan Hseu008910f2017-08-25 14:01:05 -0700435 if which('bazel') is None:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700436 print('Cannot find bazel. Please install bazel.')
437 sys.exit(0)
Jonathan Hseu008910f2017-08-25 14:01:05 -0700438 curr_version = run_shell(['bazel', '--batch', 'version'])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700439
440 for line in curr_version.split('\n'):
441 if 'Build label: ' in line:
442 curr_version = line.split('Build label: ')[1]
443 break
444
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700445 min_version_int = convert_version_to_int(min_version)
446 curr_version_int = convert_version_to_int(curr_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700447
448 # Check if current bazel version can be detected properly.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700449 if not curr_version_int:
450 print('WARNING: current bazel installation is not a release version.')
451 print('Make sure you are running at least bazel %s' % min_version)
452 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700453
Michael Cased94271a2017-08-22 17:26:52 -0700454 print('You have bazel %s installed.' % curr_version)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700455
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700456 if curr_version_int < min_version_int:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700457 print('Please upgrade your bazel installation to version %s or higher to '
458 'build TensorFlow!' % min_version)
459 sys.exit(0)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700460 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700461
462
463def set_cc_opt_flags(environ_cp):
464 """Set up architecture-dependent optimization flags.
465
466 Also append CC optimization flags to bazel.rc..
467
468 Args:
469 environ_cp: copy of the os.environ.
470 """
471 if is_ppc64le():
472 # gcc on ppc64le does not support -march, use mcpu instead
473 default_cc_opt_flags = '-mcpu=native'
474 else:
475 default_cc_opt_flags = '-march=native'
476 question = ('Please specify optimization flags to use during compilation when'
477 ' bazel option "--config=opt" is specified [Default is %s]: '
478 ) % default_cc_opt_flags
479 cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',
480 question, default_cc_opt_flags)
481 for opt in cc_opt_flags.split():
Michael Case00177422017-11-10 13:14:03 -0800482 write_to_bazelrc('build:opt --copt=%s' % opt)
483 # It should be safe on the same build host.
484 write_to_bazelrc('build:opt --host_copt=-march=native')
Michael Casebb3355d2017-11-09 08:46:31 -0800485 write_to_bazelrc('build:opt --define with_default_optimizations=true')
Michael Case00177422017-11-10 13:14:03 -0800486 # TODO(mikecase): Remove these default defines once we are able to get
487 # TF Lite targets building without them.
Andrew Selle0b154392017-11-10 10:35:35 -0800488 write_to_bazelrc('build --copt=-DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK')
489 write_to_bazelrc('build --host_copt=-DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700490
491
492def set_tf_cuda_clang(environ_cp):
493 """set TF_CUDA_CLANG action_env.
494
495 Args:
496 environ_cp: copy of the os.environ.
497 """
498 question = 'Do you want to use clang as CUDA compiler?'
499 yes_reply = 'Clang will be used as CUDA compiler.'
500 no_reply = 'nvcc will be used as CUDA compiler.'
501 set_action_env_var(
502 environ_cp,
503 'TF_CUDA_CLANG',
504 None,
505 False,
506 question=question,
507 yes_reply=yes_reply,
508 no_reply=no_reply)
509
510
511def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
512 var_default):
513 """Get var_name either from env, or user or default.
514
515 If var_name has been set as environment variable, use the preset value, else
516 ask for user input. If no input is provided, the default is used.
517
518 Args:
519 environ_cp: copy of the os.environ.
520 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
521 ask_for_var: string for how to ask for user input.
522 var_default: default value string.
523
524 Returns:
525 string value for var_name
526 """
527 var = environ_cp.get(var_name)
528 if not var:
529 var = get_input(ask_for_var)
Michael Cased94271a2017-08-22 17:26:52 -0700530 print('\n')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700531 if not var:
532 var = var_default
533 return var
534
535
536def set_clang_cuda_compiler_path(environ_cp):
537 """Set CLANG_CUDA_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700538 default_clang_path = which('clang') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700539 ask_clang_path = ('Please specify which clang should be used as device and '
540 'host compiler. [Default is %s]: ') % default_clang_path
541
542 while True:
543 clang_cuda_compiler_path = get_from_env_or_user_or_default(
544 environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path,
545 default_clang_path)
546 if os.path.exists(clang_cuda_compiler_path):
547 break
548
549 # Reset and retry
550 print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path)
551 environ_cp['CLANG_CUDA_COMPILER_PATH'] = ''
552
553 # Set CLANG_CUDA_COMPILER_PATH
554 environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path
555 write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',
556 clang_cuda_compiler_path)
557
558
559def set_gcc_host_compiler_path(environ_cp):
560 """Set GCC_HOST_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700561 default_gcc_host_compiler_path = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700562 cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH')
563
564 if os.path.islink(cuda_bin_symlink):
565 # os.readlink is only available in linux
Jonathan Hseu008910f2017-08-25 14:01:05 -0700566 default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700567
568 ask_gcc_path = (
569 'Please specify which gcc should be used by nvcc as the '
570 'host compiler. [Default is %s]: ') % default_gcc_host_compiler_path
571 while True:
572 gcc_host_compiler_path = get_from_env_or_user_or_default(
573 environ_cp, 'GCC_HOST_COMPILER_PATH', ask_gcc_path,
574 default_gcc_host_compiler_path)
575
576 if os.path.exists(gcc_host_compiler_path):
577 break
578
579 # Reset and retry
580 print('Invalid gcc path. %s cannot be found' % gcc_host_compiler_path)
581 environ_cp['GCC_HOST_COMPILER_PATH'] = ''
582
583 # Set GCC_HOST_COMPILER_PATH
584 environ_cp['GCC_HOST_COMPILER_PATH'] = gcc_host_compiler_path
585 write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)
586
587
588def set_tf_cuda_version(environ_cp):
589 """Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION."""
590 ask_cuda_version = (
591 'Please specify the CUDA SDK version you want to use, '
592 'e.g. 7.0. [Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
593
594 while True:
595 # Configure the Cuda SDK version to use.
596 tf_cuda_version = get_from_env_or_user_or_default(
597 environ_cp, 'TF_CUDA_VERSION', ask_cuda_version, _DEFAULT_CUDA_VERSION)
598
599 # Find out where the CUDA toolkit is installed
600 default_cuda_path = _DEFAULT_CUDA_PATH
Martin Wicked57572e2017-09-02 19:21:45 -0700601 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700602 default_cuda_path = cygpath(
603 environ_cp.get('CUDA_PATH', _DEFAULT_CUDA_PATH_WIN))
604 elif is_linux():
605 # If the default doesn't exist, try an alternative default.
606 if (not os.path.exists(default_cuda_path)
607 ) and os.path.exists(_DEFAULT_CUDA_PATH_LINUX):
608 default_cuda_path = _DEFAULT_CUDA_PATH_LINUX
609 ask_cuda_path = ('Please specify the location where CUDA %s toolkit is'
610 ' installed. Refer to README.md for more details. '
611 '[Default is %s]: ') % (tf_cuda_version, default_cuda_path)
612 cuda_toolkit_path = get_from_env_or_user_or_default(
613 environ_cp, 'CUDA_TOOLKIT_PATH', ask_cuda_path, default_cuda_path)
614
615 if is_windows():
616 cuda_rt_lib_path = 'lib/x64/cudart.lib'
617 elif is_linux():
618 cuda_rt_lib_path = 'lib64/libcudart.so.%s' % tf_cuda_version
619 elif is_macos():
620 cuda_rt_lib_path = 'lib/libcudart.%s.dylib' % tf_cuda_version
621
622 cuda_toolkit_path_full = os.path.join(cuda_toolkit_path, cuda_rt_lib_path)
623 if os.path.exists(cuda_toolkit_path_full):
624 break
625
626 # Reset and retry
627 print('Invalid path to CUDA %s toolkit. %s cannot be found' %
628 (tf_cuda_version, cuda_toolkit_path_full))
629 environ_cp['TF_CUDA_VERSION'] = ''
630 environ_cp['CUDA_TOOLKIT_PATH'] = ''
631
632 # Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION
633 environ_cp['CUDA_TOOLKIT_PATH'] = cuda_toolkit_path
634 write_action_env_to_bazelrc('CUDA_TOOLKIT_PATH', cuda_toolkit_path)
635 environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
636 write_action_env_to_bazelrc('TF_CUDA_VERSION', tf_cuda_version)
637
638
639def set_tf_cunn_version(environ_cp):
640 """Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION."""
641 ask_cudnn_version = (
Jonathan Hseu008910f2017-08-25 14:01:05 -0700642 'Please specify the cuDNN version you want to use. '
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700643 '[Leave empty to default to cuDNN %s.0]: ') % _DEFAULT_CUDNN_VERSION
644
645 while True:
646 tf_cudnn_version = get_from_env_or_user_or_default(
647 environ_cp, 'TF_CUDNN_VERSION', ask_cudnn_version,
648 _DEFAULT_CUDNN_VERSION)
649
650 default_cudnn_path = environ_cp.get('CUDA_TOOLKIT_PATH')
651 ask_cudnn_path = (r'Please specify the location where cuDNN %s library is '
652 'installed. Refer to README.md for more details. [Default'
653 ' is %s]:') % (tf_cudnn_version, default_cudnn_path)
654 cudnn_install_path = get_from_env_or_user_or_default(
655 environ_cp, 'CUDNN_INSTALL_PATH', ask_cudnn_path, default_cudnn_path)
656
657 # Result returned from "read" will be used unexpanded. That make "~"
658 # unusable. Going through one more level of expansion to handle that.
659 cudnn_install_path = os.path.realpath(
660 os.path.expanduser(cudnn_install_path))
Martin Wicked57572e2017-09-02 19:21:45 -0700661 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700662 cudnn_install_path = cygpath(cudnn_install_path)
663
664 if is_windows():
665 cuda_dnn_lib_path = 'lib/x64/cudnn.lib'
666 cuda_dnn_lib_alt_path = 'lib/x64/cudnn.lib'
667 elif is_linux():
668 cuda_dnn_lib_path = 'lib64/libcudnn.so.%s' % tf_cudnn_version
669 cuda_dnn_lib_alt_path = 'libcudnn.so.%s' % tf_cudnn_version
670 elif is_macos():
671 cuda_dnn_lib_path = 'lib/libcudnn.%s.dylib' % tf_cudnn_version
672 cuda_dnn_lib_alt_path = 'libcudnn.%s.dylib' % tf_cudnn_version
673
674 cuda_dnn_lib_path_full = os.path.join(cudnn_install_path, cuda_dnn_lib_path)
675 cuda_dnn_lib_alt_path_full = os.path.join(cudnn_install_path,
676 cuda_dnn_lib_alt_path)
677 if os.path.exists(cuda_dnn_lib_path_full) or os.path.exists(
678 cuda_dnn_lib_alt_path_full):
679 break
680
681 # Try another alternative for Linux
682 if is_linux():
Jonathan Hseu008910f2017-08-25 14:01:05 -0700683 ldconfig_bin = which('ldconfig') or '/sbin/ldconfig'
684 cudnn_path_from_ldconfig = run_shell([ldconfig_bin, '-p'])
685 cudnn_path_from_ldconfig = re.search('.*libcudnn.so .* => (.*)',
A. Unique TensorFlowere7223582017-09-06 17:57:04 -0700686 cudnn_path_from_ldconfig)
687 if cudnn_path_from_ldconfig:
688 cudnn_path_from_ldconfig = cudnn_path_from_ldconfig.group(1)
689 if os.path.exists('%s.%s' % (cudnn_path_from_ldconfig,
690 tf_cudnn_version)):
691 cudnn_install_path = os.path.dirname(cudnn_path_from_ldconfig)
692 break
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700693
694 # Reset and Retry
695 print(
696 'Invalid path to cuDNN %s toolkit. None of the following files can be '
697 'found:' % tf_cudnn_version)
698 print(cuda_dnn_lib_path_full)
699 print(cuda_dnn_lib_alt_path_full)
700 if is_linux():
701 print('%s.%s' % (cudnn_path_from_ldconfig, tf_cudnn_version))
702
703 environ_cp['TF_CUDNN_VERSION'] = ''
704
705 # Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION
706 environ_cp['CUDNN_INSTALL_PATH'] = cudnn_install_path
707 write_action_env_to_bazelrc('CUDNN_INSTALL_PATH', cudnn_install_path)
708 environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
709 write_action_env_to_bazelrc('TF_CUDNN_VERSION', tf_cudnn_version)
710
711
712def get_native_cuda_compute_capabilities(environ_cp):
713 """Get native cuda compute capabilities.
714
715 Args:
716 environ_cp: copy of the os.environ.
717 Returns:
718 string of native cuda compute capabilities, separated by comma.
719 """
720 device_query_bin = os.path.join(
721 environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery')
Jonathan Hseu008910f2017-08-25 14:01:05 -0700722 if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK):
723 try:
724 output = run_shell(device_query_bin).split('\n')
725 pattern = re.compile('[0-9]*\\.[0-9]*')
726 output = [pattern.search(x) for x in output if 'Capability' in x]
727 output = ','.join(x.group() for x in output if x is not None)
728 except subprocess.CalledProcessError:
729 output = ''
730 else:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700731 output = ''
732 return output
733
734
735def set_tf_cuda_compute_capabilities(environ_cp):
736 """Set TF_CUDA_COMPUTE_CAPABILITIES."""
737 while True:
738 native_cuda_compute_capabilities = get_native_cuda_compute_capabilities(
739 environ_cp)
740 if not native_cuda_compute_capabilities:
741 default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES
742 else:
743 default_cuda_compute_capabilities = native_cuda_compute_capabilities
744
745 ask_cuda_compute_capabilities = (
746 'Please specify a list of comma-separated '
747 'Cuda compute capabilities you want to '
748 'build with.\nYou can find the compute '
749 'capability of your device at: '
750 'https://developer.nvidia.com/cuda-gpus.\nPlease'
751 ' note that each additional compute '
752 'capability significantly increases your '
753 'build time and binary size. [Default is: %s]' %
754 default_cuda_compute_capabilities)
755 tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
756 environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
757 ask_cuda_compute_capabilities, default_cuda_compute_capabilities)
758 # Check whether all capabilities from the input is valid
759 all_valid = True
760 for compute_capability in tf_cuda_compute_capabilities.split(','):
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700761 m = re.match('[0-9]+.[0-9]+', compute_capability)
762 if not m:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700763 print('Invalid compute capability: ' % compute_capability)
764 all_valid = False
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700765 else:
766 ver = int(m.group(0).split('.')[0])
767 if ver < 3:
768 print('Only compute capabilities 3.0 or higher are supported.')
769 all_valid = False
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700770
771 if all_valid:
772 break
773
774 # Reset and Retry
775 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = ''
776
777 # Set TF_CUDA_COMPUTE_CAPABILITIES
778 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities
779 write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES',
780 tf_cuda_compute_capabilities)
781
782
783def set_other_cuda_vars(environ_cp):
784 """Set other CUDA related variables."""
785 if is_windows():
786 # The following three variables are needed for MSVC toolchain configuration
787 # in Bazel
788 environ_cp['CUDA_PATH'] = environ_cp.get('CUDA_TOOLKIT_PATH')
789 environ_cp['CUDA_COMPUTE_CAPABILITIES'] = environ_cp.get(
790 'TF_CUDA_COMPUTE_CAPABILITIES')
791 environ_cp['NO_WHOLE_ARCHIVE_OPTION'] = 1
792 write_action_env_to_bazelrc('CUDA_PATH', environ_cp.get('CUDA_PATH'))
793 write_action_env_to_bazelrc('CUDA_COMPUTE_CAPABILITIE',
794 environ_cp.get('CUDA_COMPUTE_CAPABILITIE'))
795 write_action_env_to_bazelrc('NO_WHOLE_ARCHIVE_OPTION',
796 environ_cp.get('NO_WHOLE_ARCHIVE_OPTION'))
797 write_to_bazelrc('build --config=win-cuda')
798 write_to_bazelrc('test --config=win-cuda')
799 else:
800 # If CUDA is enabled, always use GPU during build and test.
801 if environ_cp.get('TF_CUDA_CLANG') == '1':
802 write_to_bazelrc('build --config=cuda_clang')
803 write_to_bazelrc('test --config=cuda_clang')
804 else:
805 write_to_bazelrc('build --config=cuda')
806 write_to_bazelrc('test --config=cuda')
807
808
809def set_host_cxx_compiler(environ_cp):
810 """Set HOST_CXX_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700811 default_cxx_host_compiler = which('g++') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700812 ask_cxx_host_compiler = (
813 'Please specify which C++ compiler should be used as'
814 ' the host C++ compiler. [Default is %s]: ') % default_cxx_host_compiler
815
816 while True:
817 host_cxx_compiler = get_from_env_or_user_or_default(
818 environ_cp, 'HOST_CXX_COMPILER', ask_cxx_host_compiler,
819 default_cxx_host_compiler)
820 if os.path.exists(host_cxx_compiler):
821 break
822
823 # Reset and retry
824 print('Invalid C++ compiler path. %s cannot be found' % host_cxx_compiler)
825 environ_cp['HOST_CXX_COMPILER'] = ''
826
827 # Set HOST_CXX_COMPILER
828 environ_cp['HOST_CXX_COMPILER'] = host_cxx_compiler
829 write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler)
830
831
832def set_host_c_compiler(environ_cp):
833 """Set HOST_C_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700834 default_c_host_compiler = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700835 ask_c_host_compiler = (
836 'Please specify which C compiler should be used as the'
837 ' host C compiler. [Default is %s]: ') % default_c_host_compiler
838
839 while True:
840 host_c_compiler = get_from_env_or_user_or_default(
841 environ_cp, 'HOST_C_COMPILER', ask_c_host_compiler,
842 default_c_host_compiler)
843 if os.path.exists(host_c_compiler):
844 break
845
846 # Reset and retry
847 print('Invalid C compiler path. %s cannot be found' % host_c_compiler)
848 environ_cp['HOST_C_COMPILER'] = ''
849
850 # Set HOST_C_COMPILER
851 environ_cp['HOST_C_COMPILER'] = host_c_compiler
852 write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler)
853
854
855def set_computecpp_toolkit_path(environ_cp):
856 """Set COMPUTECPP_TOOLKIT_PATH."""
857 ask_computecpp_toolkit_path = ('Please specify the location where ComputeCpp '
858 'for SYCL %s is installed. [Default is %s]: '
859 ) % (_TF_OPENCL_VERSION,
860 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
861
862 while True:
863 computecpp_toolkit_path = get_from_env_or_user_or_default(
864 environ_cp, 'COMPUTECPP_TOOLKIT_PATH', ask_computecpp_toolkit_path,
865 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
866 if is_linux():
867 sycl_rt_lib_path = 'lib/libComputeCpp.so'
868 else:
869 sycl_rt_lib_path = ''
870
871 sycl_rt_lib_path_full = os.path.join(computecpp_toolkit_path,
872 sycl_rt_lib_path)
873 if os.path.exists(sycl_rt_lib_path_full):
874 break
875
876 print('Invalid SYCL %s library path. %s cannot be found' %
877 (_TF_OPENCL_VERSION, sycl_rt_lib_path_full))
878 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = ''
879
880 # Set COMPUTECPP_TOOLKIT_PATH
881 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = computecpp_toolkit_path
882 write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH',
883 computecpp_toolkit_path)
884
885
886def set_mpi_home(environ_cp):
887 """Set MPI_HOME."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700888 default_mpi_home = which('mpirun') or which('mpiexec') or ''
889 default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home))
890
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700891 ask_mpi_home = ('Please specify the MPI toolkit folder. [Default is %s]: '
892 ) % default_mpi_home
893 while True:
894 mpi_home = get_from_env_or_user_or_default(environ_cp, 'MPI_HOME',
895 ask_mpi_home, default_mpi_home)
896
897 if os.path.exists(os.path.join(mpi_home, 'include')) and os.path.exists(
898 os.path.join(mpi_home, 'lib')):
899 break
900
901 print('Invalid path to the MPI Toolkit. %s or %s cannot be found' %
902 (os.path.join(mpi_home, 'include'),
903 os.path.exists(os.path.join(mpi_home, 'lib'))))
904 environ_cp['MPI_HOME'] = ''
905
906 # Set MPI_HOME
907 environ_cp['MPI_HOME'] = str(mpi_home)
908
909
910def set_other_mpi_vars(environ_cp):
911 """Set other MPI related variables."""
912 # Link the MPI header files
913 mpi_home = environ_cp.get('MPI_HOME')
914 symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h')
915
916 # Determine if we use OpenMPI or MVAPICH, these require different header files
917 # to be included here to make bazel dependency checker happy
918 if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')):
919 symlink_force(
920 os.path.join(mpi_home, 'include/mpi_portable_platform.h'),
921 'third_party/mpi/mpi_portable_platform.h')
922 # TODO(gunan): avoid editing files in configure
923 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False',
924 'MPI_LIB_IS_OPENMPI=True')
925 else:
926 # MVAPICH / MPICH
927 symlink_force(
928 os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h')
929 symlink_force(
930 os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h')
931 # TODO(gunan): avoid editing files in configure
932 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True',
933 'MPI_LIB_IS_OPENMPI=False')
934
935 if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')):
936 symlink_force(
937 os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so')
938 else:
939 raise ValueError('Cannot find the MPI library file in %s/lib' % mpi_home)
940
941
942def set_mkl():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700943 write_to_bazelrc('build:mkl --define using_mkl=true')
944 write_to_bazelrc('build:mkl -c opt')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700945 print(
946 'Add "--config=mkl" to your bazel command to build with MKL '
947 'support.\nPlease note that MKL on MacOS or windows is still not '
948 'supported.\nIf you would like to use a local MKL instead of '
949 'downloading, please set the environment variable \"TF_MKL_ROOT\" every '
950 'time before build.')
951
952
Allen Lavoie5c7f9e32017-09-21 11:29:45 -0700953def set_monolithic():
954 # Add --config=monolithic to your bazel command to use a mostly-static
955 # build and disable modular op registration support (this will revert to
956 # loading TensorFlow with RTLD_GLOBAL in Python). By default (without
957 # --config=monolithic), TensorFlow will build with a dependence on
958 # //tensorflow:libtensorflow_framework.so.
959 write_to_bazelrc('build:monolithic --define framework_shared_object=false')
960 # For projects which use TensorFlow as part of a Bazel build process, putting
961 # nothing in a bazelrc will default to a monolithic build. The following line
962 # opts in to modular op registration support by default:
963 write_to_bazelrc('build --define framework_shared_object=true')
964
965
Michael Casef1ecdd62017-10-24 18:07:59 -0700966def create_android_bazelrc_configs():
967 # Flags for --config=android
968 write_to_bazelrc('build:android --crosstool_top=//external:android/crosstool')
969 write_to_bazelrc(
970 'build:android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain')
971 # Flags for --config=android_arm
972 write_to_bazelrc('build:android_arm --config=android')
973 write_to_bazelrc('build:android_arm --cpu=armeabi-v7a')
974 # Flags for --config=android_arm64
975 write_to_bazelrc('build:android_arm64 --config=android')
976 write_to_bazelrc('build:android_arm64 --cpu=arm64-v8a')
977
978
A. Unique TensorFlower061c3592017-11-13 14:21:04 -0800979def set_grpc_build_flags():
980 write_to_bazelrc('build --define grpc_no_ares=true')
981
982
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700983def main():
984 # Make a copy of os.environ to be clear when functions and getting and setting
985 # environment variables.
986 environ_cp = dict(os.environ)
987
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700988 check_bazel_version('0.5.4')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700989
990 reset_tf_configure_bazelrc()
991 cleanup_makefile()
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700992 setup_python(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700993 run_gen_git_source(environ_cp)
994
995 if is_windows():
Benoit Steiner355e25e2017-10-24 19:47:46 -0700996 environ_cp['TF_NEED_S3'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700997 environ_cp['TF_NEED_GCP'] = '0'
998 environ_cp['TF_NEED_HDFS'] = '0'
999 environ_cp['TF_NEED_JEMALLOC'] = '0'
1000 environ_cp['TF_NEED_OPENCL'] = '0'
1001 environ_cp['TF_CUDA_CLANG'] = '0'
1002
1003 if is_macos():
1004 environ_cp['TF_NEED_JEMALLOC'] = '0'
1005
1006 set_build_var(environ_cp, 'TF_NEED_JEMALLOC', 'jemalloc as malloc',
1007 'with_jemalloc', True)
1008 set_build_var(environ_cp, 'TF_NEED_GCP', 'Google Cloud Platform',
Benoit Steiner355e25e2017-10-24 19:47:46 -07001009 'with_gcp_support', True, 'gcp')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001010 set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
Benoit Steiner355e25e2017-10-24 19:47:46 -07001011 'with_hdfs_support', True, 'hdfs')
Michael Case7e4e3362017-10-09 13:31:15 -07001012 set_build_var(environ_cp, 'TF_NEED_S3', 'Amazon S3 File System',
1013 'with_s3_support', True, 's3')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001014 set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
Michael Case98850a52017-09-14 13:35:57 -07001015 False, 'xla')
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -07001016 set_build_var(environ_cp, 'TF_NEED_GDR', 'GDR', 'with_gdr_support',
Michael Case98850a52017-09-14 13:35:57 -07001017 False, 'gdr')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001018 set_build_var(environ_cp, 'TF_NEED_VERBS', 'VERBS', 'with_verbs_support',
Michael Case98850a52017-09-14 13:35:57 -07001019 False, 'verbs')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001020
1021 set_action_env_var(environ_cp, 'TF_NEED_OPENCL', 'OpenCL', False)
1022 if environ_cp.get('TF_NEED_OPENCL') == '1':
1023 set_host_cxx_compiler(environ_cp)
1024 set_host_c_compiler(environ_cp)
1025 set_computecpp_toolkit_path(environ_cp)
1026
1027 set_action_env_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)
A. Unique TensorFlower24cbb2a2017-09-08 07:45:44 -07001028 if (environ_cp.get('TF_NEED_CUDA') == '1' and
1029 'TF_CUDA_CONFIG_REPO' not in environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001030 set_tf_cuda_version(environ_cp)
1031 set_tf_cunn_version(environ_cp)
1032 set_tf_cuda_compute_capabilities(environ_cp)
1033
1034 set_tf_cuda_clang(environ_cp)
1035 if environ_cp.get('TF_CUDA_CLANG') == '1':
1036 # Set up which clang we should use as the cuda / host compiler.
1037 set_clang_cuda_compiler_path(environ_cp)
1038 else:
1039 # Set up which gcc nvcc should use as the host compiler
1040 # No need to set this on Windows
1041 if not is_windows():
1042 set_gcc_host_compiler_path(environ_cp)
1043 set_other_cuda_vars(environ_cp)
1044
1045 set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False)
1046 if environ_cp.get('TF_NEED_MPI') == '1':
1047 set_mpi_home(environ_cp)
1048 set_other_mpi_vars(environ_cp)
1049
A. Unique TensorFlower061c3592017-11-13 14:21:04 -08001050 set_grpc_build_flags()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001051 set_cc_opt_flags(environ_cp)
1052 set_mkl()
Allen Lavoie5c7f9e32017-09-21 11:29:45 -07001053 set_monolithic()
Michael Casef1ecdd62017-10-24 18:07:59 -07001054 create_android_bazelrc_configs()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001055
1056if __name__ == '__main__':
1057 main()