blob: 650541770afdf2c6cfcc80161e01b82b3cace8c5 [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)
231 write_to_bazelrc('build --define PYTHON_BIN_PATH="%s"' % python_bin_path)
232 write_to_bazelrc('build --define PYTHON_LIB_PATH="%s"' % python_lib_path)
233 write_to_bazelrc('build --force_python=py%s' % python_major_version)
234 write_to_bazelrc('build --host_force_python=py%s' % python_major_version)
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700235 write_to_bazelrc('build --python_path=\"%s"' % python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700236 write_to_bazelrc('test --force_python=py%s' % python_major_version)
237 write_to_bazelrc('test --host_force_python=py%s' % python_major_version)
238 write_to_bazelrc('test --define PYTHON_BIN_PATH="%s"' % python_bin_path)
239 write_to_bazelrc('test --define PYTHON_LIB_PATH="%s"' % python_lib_path)
240 write_to_bazelrc('run --define PYTHON_BIN_PATH="%s"' % python_bin_path)
241 write_to_bazelrc('run --define PYTHON_LIB_PATH="%s"' % python_lib_path)
242 environ_cp['PYTHON_BIN_PATH'] = python_bin_path
243
244 # Write tools/python_bin_path.sh
245 with open('tools/python_bin_path.sh', 'w') as f:
246 f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path)
247
248
249def reset_tf_configure_bazelrc():
250 """Reset file that contains customized config settings."""
251 open(_TF_BAZELRC, 'w').close()
252
253 home = os.path.expanduser('~')
254 if not os.path.exists('.bazelrc'):
255 if os.path.exists(os.path.join(home, '.bazelrc')):
256 with open('.bazelrc', 'a') as f:
Shanqing Caie2e3a942017-09-25 19:35:53 -0700257 f.write('import %s/.bazelrc\n' % home.replace('\\', '/'))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700258 else:
259 open('.bazelrc', 'w').close()
260
261 remove_line_with('.bazelrc', 'tf_configure')
262 with open('.bazelrc', 'a') as f:
263 f.write('import %workspace%/.tf_configure.bazelrc\n')
264
265
266def run_gen_git_source(environ_cp):
267 """Run the gen_git_source to create links.
268
269 The links are for bazel to track dependencies for git hash propagation.
270
271 Args:
272 environ_cp: copy of the os.environ.
273 """
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700274 cmd = '"%s" tensorflow/tools/git/gen_git_source.py --configure %s' % (
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700275 environ_cp.get('PYTHON_BIN_PATH'), os.getcwd())
276 os.system(cmd)
277
278
279def cleanup_makefile():
280 """Delete any leftover BUILD files from the Makefile build.
281
282 These files could interfere with Bazel parsing.
283 """
284 makefile_download_dir = 'tensorflow/contrib/makefile/downloads'
285 if os.path.isdir(makefile_download_dir):
286 for root, _, filenames in os.walk(makefile_download_dir):
287 for f in filenames:
288 if f.endswith('BUILD'):
289 os.remove(os.path.join(root, f))
290
291
292def get_var(environ_cp,
293 var_name,
294 query_item,
295 enabled_by_default,
296 question=None,
297 yes_reply=None,
298 no_reply=None):
299 """Get boolean input from user.
300
301 If var_name is not set in env, ask user to enable query_item or not. If the
302 response is empty, use the default.
303
304 Args:
305 environ_cp: copy of the os.environ.
306 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
307 query_item: string for feature related to the variable, e.g. "Hadoop File
308 System".
309 enabled_by_default: boolean for default behavior.
310 question: optional string for how to ask for user input.
311 yes_reply: optionanl string for reply when feature is enabled.
312 no_reply: optional string for reply when feature is disabled.
313
314 Returns:
315 boolean value of the variable.
316 """
317 if not question:
318 question = 'Do you wish to build TensorFlow with %s support?' % query_item
319 if not yes_reply:
320 yes_reply = '%s support will be enabled for TensorFlow.' % query_item
321 if not no_reply:
322 no_reply = 'No %s' % yes_reply
323
324 yes_reply += '\n'
325 no_reply += '\n'
326
327 if enabled_by_default:
328 question += ' [Y/n]: '
329 else:
330 question += ' [y/N]: '
331
332 var = environ_cp.get(var_name)
333 while var is None:
334 user_input_origin = get_input(question)
335 user_input = user_input_origin.strip().lower()
336 if user_input == 'y':
337 print(yes_reply)
338 var = True
339 elif user_input == 'n':
340 print(no_reply)
341 var = False
342 elif not user_input:
343 if enabled_by_default:
344 print(yes_reply)
345 var = True
346 else:
347 print(no_reply)
348 var = False
349 else:
350 print('Invalid selection: %s' % user_input_origin)
351 return var
352
353
354def set_build_var(environ_cp, var_name, query_item, option_name,
Michael Case98850a52017-09-14 13:35:57 -0700355 enabled_by_default, bazel_config_name=None):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700356 """Set if query_item will be enabled for the build.
357
358 Ask user if query_item will be enabled. Default is used if no input is given.
359 Set subprocess environment variable and write to .bazelrc if enabled.
360
361 Args:
362 environ_cp: copy of the os.environ.
363 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
364 query_item: string for feature related to the variable, e.g. "Hadoop File
365 System".
366 option_name: string for option to define in .bazelrc.
367 enabled_by_default: boolean for default behavior.
Michael Case98850a52017-09-14 13:35:57 -0700368 bazel_config_name: Name for Bazel --config argument to enable build feature.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700369 """
370
371 var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default)))
372 environ_cp[var_name] = var
373 if var == '1':
374 write_to_bazelrc('build --define %s=true' % option_name)
Michael Case98850a52017-09-14 13:35:57 -0700375 elif bazel_config_name is not None:
376 # TODO(mikecase): Migrate all users of configure.py to use --config Bazel
377 # options and not to set build configs through environment variables.
378 write_to_bazelrc('build:%s --define %s=true'
379 % (bazel_config_name, option_name))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700380
381
382def set_action_env_var(environ_cp,
383 var_name,
384 query_item,
385 enabled_by_default,
386 question=None,
387 yes_reply=None,
388 no_reply=None):
389 """Set boolean action_env variable.
390
391 Ask user if query_item will be enabled. Default is used if no input is given.
392 Set environment variable and write to .bazelrc.
393
394 Args:
395 environ_cp: copy of the os.environ.
396 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
397 query_item: string for feature related to the variable, e.g. "Hadoop File
398 System".
399 enabled_by_default: boolean for default behavior.
400 question: optional string for how to ask for user input.
401 yes_reply: optionanl string for reply when feature is enabled.
402 no_reply: optional string for reply when feature is disabled.
403 """
404 var = int(
405 get_var(environ_cp, var_name, query_item, enabled_by_default, question,
406 yes_reply, no_reply))
407
408 write_action_env_to_bazelrc(var_name, var)
409 environ_cp[var_name] = str(var)
410
411
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700412def convert_version_to_int(version):
413 """Convert a version number to a integer that can be used to compare.
414
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700415 Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The
416 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.
417
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700418 Args:
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700419 version: a version to be converted
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700420
421 Returns:
422 An integer if converted successfully, otherwise return None.
423 """
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700424 version = version.split('-')[0]
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700425 version_segments = version.split('.')
426 for seg in version_segments:
427 if not seg.isdigit():
428 return None
429
430 version_str = ''.join(['%03d' % int(seg) for seg in version_segments])
431 return int(version_str)
432
433
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700434def check_bazel_version(min_version):
435 """Check installed bezel version is at least min_version.
436
437 Args:
438 min_version: string for minimum bazel version.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700439
440 Returns:
441 The bazel version detected.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700442 """
Jonathan Hseu008910f2017-08-25 14:01:05 -0700443 if which('bazel') is None:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700444 print('Cannot find bazel. Please install bazel.')
445 sys.exit(0)
Jonathan Hseu008910f2017-08-25 14:01:05 -0700446 curr_version = run_shell(['bazel', '--batch', 'version'])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700447
448 for line in curr_version.split('\n'):
449 if 'Build label: ' in line:
450 curr_version = line.split('Build label: ')[1]
451 break
452
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700453 min_version_int = convert_version_to_int(min_version)
454 curr_version_int = convert_version_to_int(curr_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700455
456 # Check if current bazel version can be detected properly.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700457 if not curr_version_int:
458 print('WARNING: current bazel installation is not a release version.')
459 print('Make sure you are running at least bazel %s' % min_version)
460 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700461
Michael Cased94271a2017-08-22 17:26:52 -0700462 print('You have bazel %s installed.' % curr_version)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700463
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700464 if curr_version_int < min_version_int:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700465 print('Please upgrade your bazel installation to version %s or higher to '
466 'build TensorFlow!' % min_version)
467 sys.exit(0)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700468 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700469
470
471def set_cc_opt_flags(environ_cp):
472 """Set up architecture-dependent optimization flags.
473
474 Also append CC optimization flags to bazel.rc..
475
476 Args:
477 environ_cp: copy of the os.environ.
478 """
479 if is_ppc64le():
480 # gcc on ppc64le does not support -march, use mcpu instead
481 default_cc_opt_flags = '-mcpu=native'
482 else:
483 default_cc_opt_flags = '-march=native'
484 question = ('Please specify optimization flags to use during compilation when'
485 ' bazel option "--config=opt" is specified [Default is %s]: '
486 ) % default_cc_opt_flags
487 cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',
488 question, default_cc_opt_flags)
489 for opt in cc_opt_flags.split():
Andrew Sellec9885ea2017-11-06 09:37:03 -0800490 host_opt = '-march=native' # It should be safe on the same build host.
491 write_to_bazelrc(
492 'build:opt --cxxopt=%s --copt=%s' % (opt, opt) +
493 ' --host_cxxopt=%s --host_copt=%s' % (host_opt, host_opt))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700494
495
496def set_tf_cuda_clang(environ_cp):
497 """set TF_CUDA_CLANG action_env.
498
499 Args:
500 environ_cp: copy of the os.environ.
501 """
502 question = 'Do you want to use clang as CUDA compiler?'
503 yes_reply = 'Clang will be used as CUDA compiler.'
504 no_reply = 'nvcc will be used as CUDA compiler.'
505 set_action_env_var(
506 environ_cp,
507 'TF_CUDA_CLANG',
508 None,
509 False,
510 question=question,
511 yes_reply=yes_reply,
512 no_reply=no_reply)
513
514
515def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
516 var_default):
517 """Get var_name either from env, or user or default.
518
519 If var_name has been set as environment variable, use the preset value, else
520 ask for user input. If no input is provided, the default is used.
521
522 Args:
523 environ_cp: copy of the os.environ.
524 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
525 ask_for_var: string for how to ask for user input.
526 var_default: default value string.
527
528 Returns:
529 string value for var_name
530 """
531 var = environ_cp.get(var_name)
532 if not var:
533 var = get_input(ask_for_var)
Michael Cased94271a2017-08-22 17:26:52 -0700534 print('\n')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700535 if not var:
536 var = var_default
537 return var
538
539
540def set_clang_cuda_compiler_path(environ_cp):
541 """Set CLANG_CUDA_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700542 default_clang_path = which('clang') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700543 ask_clang_path = ('Please specify which clang should be used as device and '
544 'host compiler. [Default is %s]: ') % default_clang_path
545
546 while True:
547 clang_cuda_compiler_path = get_from_env_or_user_or_default(
548 environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path,
549 default_clang_path)
550 if os.path.exists(clang_cuda_compiler_path):
551 break
552
553 # Reset and retry
554 print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path)
555 environ_cp['CLANG_CUDA_COMPILER_PATH'] = ''
556
557 # Set CLANG_CUDA_COMPILER_PATH
558 environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path
559 write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',
560 clang_cuda_compiler_path)
561
562
563def set_gcc_host_compiler_path(environ_cp):
564 """Set GCC_HOST_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700565 default_gcc_host_compiler_path = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700566 cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH')
567
568 if os.path.islink(cuda_bin_symlink):
569 # os.readlink is only available in linux
Jonathan Hseu008910f2017-08-25 14:01:05 -0700570 default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700571
572 ask_gcc_path = (
573 'Please specify which gcc should be used by nvcc as the '
574 'host compiler. [Default is %s]: ') % default_gcc_host_compiler_path
575 while True:
576 gcc_host_compiler_path = get_from_env_or_user_or_default(
577 environ_cp, 'GCC_HOST_COMPILER_PATH', ask_gcc_path,
578 default_gcc_host_compiler_path)
579
580 if os.path.exists(gcc_host_compiler_path):
581 break
582
583 # Reset and retry
584 print('Invalid gcc path. %s cannot be found' % gcc_host_compiler_path)
585 environ_cp['GCC_HOST_COMPILER_PATH'] = ''
586
587 # Set GCC_HOST_COMPILER_PATH
588 environ_cp['GCC_HOST_COMPILER_PATH'] = gcc_host_compiler_path
589 write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)
590
591
592def set_tf_cuda_version(environ_cp):
593 """Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION."""
594 ask_cuda_version = (
595 'Please specify the CUDA SDK version you want to use, '
596 'e.g. 7.0. [Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
597
598 while True:
599 # Configure the Cuda SDK version to use.
600 tf_cuda_version = get_from_env_or_user_or_default(
601 environ_cp, 'TF_CUDA_VERSION', ask_cuda_version, _DEFAULT_CUDA_VERSION)
602
603 # Find out where the CUDA toolkit is installed
604 default_cuda_path = _DEFAULT_CUDA_PATH
Martin Wicked57572e2017-09-02 19:21:45 -0700605 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700606 default_cuda_path = cygpath(
607 environ_cp.get('CUDA_PATH', _DEFAULT_CUDA_PATH_WIN))
608 elif is_linux():
609 # If the default doesn't exist, try an alternative default.
610 if (not os.path.exists(default_cuda_path)
611 ) and os.path.exists(_DEFAULT_CUDA_PATH_LINUX):
612 default_cuda_path = _DEFAULT_CUDA_PATH_LINUX
613 ask_cuda_path = ('Please specify the location where CUDA %s toolkit is'
614 ' installed. Refer to README.md for more details. '
615 '[Default is %s]: ') % (tf_cuda_version, default_cuda_path)
616 cuda_toolkit_path = get_from_env_or_user_or_default(
617 environ_cp, 'CUDA_TOOLKIT_PATH', ask_cuda_path, default_cuda_path)
618
619 if is_windows():
620 cuda_rt_lib_path = 'lib/x64/cudart.lib'
621 elif is_linux():
622 cuda_rt_lib_path = 'lib64/libcudart.so.%s' % tf_cuda_version
623 elif is_macos():
624 cuda_rt_lib_path = 'lib/libcudart.%s.dylib' % tf_cuda_version
625
626 cuda_toolkit_path_full = os.path.join(cuda_toolkit_path, cuda_rt_lib_path)
627 if os.path.exists(cuda_toolkit_path_full):
628 break
629
630 # Reset and retry
631 print('Invalid path to CUDA %s toolkit. %s cannot be found' %
632 (tf_cuda_version, cuda_toolkit_path_full))
633 environ_cp['TF_CUDA_VERSION'] = ''
634 environ_cp['CUDA_TOOLKIT_PATH'] = ''
635
636 # Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION
637 environ_cp['CUDA_TOOLKIT_PATH'] = cuda_toolkit_path
638 write_action_env_to_bazelrc('CUDA_TOOLKIT_PATH', cuda_toolkit_path)
639 environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
640 write_action_env_to_bazelrc('TF_CUDA_VERSION', tf_cuda_version)
641
642
643def set_tf_cunn_version(environ_cp):
644 """Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION."""
645 ask_cudnn_version = (
Jonathan Hseu008910f2017-08-25 14:01:05 -0700646 'Please specify the cuDNN version you want to use. '
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700647 '[Leave empty to default to cuDNN %s.0]: ') % _DEFAULT_CUDNN_VERSION
648
649 while True:
650 tf_cudnn_version = get_from_env_or_user_or_default(
651 environ_cp, 'TF_CUDNN_VERSION', ask_cudnn_version,
652 _DEFAULT_CUDNN_VERSION)
653
654 default_cudnn_path = environ_cp.get('CUDA_TOOLKIT_PATH')
655 ask_cudnn_path = (r'Please specify the location where cuDNN %s library is '
656 'installed. Refer to README.md for more details. [Default'
657 ' is %s]:') % (tf_cudnn_version, default_cudnn_path)
658 cudnn_install_path = get_from_env_or_user_or_default(
659 environ_cp, 'CUDNN_INSTALL_PATH', ask_cudnn_path, default_cudnn_path)
660
661 # Result returned from "read" will be used unexpanded. That make "~"
662 # unusable. Going through one more level of expansion to handle that.
663 cudnn_install_path = os.path.realpath(
664 os.path.expanduser(cudnn_install_path))
Martin Wicked57572e2017-09-02 19:21:45 -0700665 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700666 cudnn_install_path = cygpath(cudnn_install_path)
667
668 if is_windows():
669 cuda_dnn_lib_path = 'lib/x64/cudnn.lib'
670 cuda_dnn_lib_alt_path = 'lib/x64/cudnn.lib'
671 elif is_linux():
672 cuda_dnn_lib_path = 'lib64/libcudnn.so.%s' % tf_cudnn_version
673 cuda_dnn_lib_alt_path = 'libcudnn.so.%s' % tf_cudnn_version
674 elif is_macos():
675 cuda_dnn_lib_path = 'lib/libcudnn.%s.dylib' % tf_cudnn_version
676 cuda_dnn_lib_alt_path = 'libcudnn.%s.dylib' % tf_cudnn_version
677
678 cuda_dnn_lib_path_full = os.path.join(cudnn_install_path, cuda_dnn_lib_path)
679 cuda_dnn_lib_alt_path_full = os.path.join(cudnn_install_path,
680 cuda_dnn_lib_alt_path)
681 if os.path.exists(cuda_dnn_lib_path_full) or os.path.exists(
682 cuda_dnn_lib_alt_path_full):
683 break
684
685 # Try another alternative for Linux
686 if is_linux():
Jonathan Hseu008910f2017-08-25 14:01:05 -0700687 ldconfig_bin = which('ldconfig') or '/sbin/ldconfig'
688 cudnn_path_from_ldconfig = run_shell([ldconfig_bin, '-p'])
689 cudnn_path_from_ldconfig = re.search('.*libcudnn.so .* => (.*)',
A. Unique TensorFlowere7223582017-09-06 17:57:04 -0700690 cudnn_path_from_ldconfig)
691 if cudnn_path_from_ldconfig:
692 cudnn_path_from_ldconfig = cudnn_path_from_ldconfig.group(1)
693 if os.path.exists('%s.%s' % (cudnn_path_from_ldconfig,
694 tf_cudnn_version)):
695 cudnn_install_path = os.path.dirname(cudnn_path_from_ldconfig)
696 break
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700697
698 # Reset and Retry
699 print(
700 'Invalid path to cuDNN %s toolkit. None of the following files can be '
701 'found:' % tf_cudnn_version)
702 print(cuda_dnn_lib_path_full)
703 print(cuda_dnn_lib_alt_path_full)
704 if is_linux():
705 print('%s.%s' % (cudnn_path_from_ldconfig, tf_cudnn_version))
706
707 environ_cp['TF_CUDNN_VERSION'] = ''
708
709 # Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION
710 environ_cp['CUDNN_INSTALL_PATH'] = cudnn_install_path
711 write_action_env_to_bazelrc('CUDNN_INSTALL_PATH', cudnn_install_path)
712 environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
713 write_action_env_to_bazelrc('TF_CUDNN_VERSION', tf_cudnn_version)
714
715
716def get_native_cuda_compute_capabilities(environ_cp):
717 """Get native cuda compute capabilities.
718
719 Args:
720 environ_cp: copy of the os.environ.
721 Returns:
722 string of native cuda compute capabilities, separated by comma.
723 """
724 device_query_bin = os.path.join(
725 environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery')
Jonathan Hseu008910f2017-08-25 14:01:05 -0700726 if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK):
727 try:
728 output = run_shell(device_query_bin).split('\n')
729 pattern = re.compile('[0-9]*\\.[0-9]*')
730 output = [pattern.search(x) for x in output if 'Capability' in x]
731 output = ','.join(x.group() for x in output if x is not None)
732 except subprocess.CalledProcessError:
733 output = ''
734 else:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700735 output = ''
736 return output
737
738
739def set_tf_cuda_compute_capabilities(environ_cp):
740 """Set TF_CUDA_COMPUTE_CAPABILITIES."""
741 while True:
742 native_cuda_compute_capabilities = get_native_cuda_compute_capabilities(
743 environ_cp)
744 if not native_cuda_compute_capabilities:
745 default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES
746 else:
747 default_cuda_compute_capabilities = native_cuda_compute_capabilities
748
749 ask_cuda_compute_capabilities = (
750 'Please specify a list of comma-separated '
751 'Cuda compute capabilities you want to '
752 'build with.\nYou can find the compute '
753 'capability of your device at: '
754 'https://developer.nvidia.com/cuda-gpus.\nPlease'
755 ' note that each additional compute '
756 'capability significantly increases your '
757 'build time and binary size. [Default is: %s]' %
758 default_cuda_compute_capabilities)
759 tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
760 environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
761 ask_cuda_compute_capabilities, default_cuda_compute_capabilities)
762 # Check whether all capabilities from the input is valid
763 all_valid = True
764 for compute_capability in tf_cuda_compute_capabilities.split(','):
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700765 m = re.match('[0-9]+.[0-9]+', compute_capability)
766 if not m:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700767 print('Invalid compute capability: ' % compute_capability)
768 all_valid = False
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700769 else:
770 ver = int(m.group(0).split('.')[0])
771 if ver < 3:
772 print('Only compute capabilities 3.0 or higher are supported.')
773 all_valid = False
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700774
775 if all_valid:
776 break
777
778 # Reset and Retry
779 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = ''
780
781 # Set TF_CUDA_COMPUTE_CAPABILITIES
782 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities
783 write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES',
784 tf_cuda_compute_capabilities)
785
786
787def set_other_cuda_vars(environ_cp):
788 """Set other CUDA related variables."""
789 if is_windows():
790 # The following three variables are needed for MSVC toolchain configuration
791 # in Bazel
792 environ_cp['CUDA_PATH'] = environ_cp.get('CUDA_TOOLKIT_PATH')
793 environ_cp['CUDA_COMPUTE_CAPABILITIES'] = environ_cp.get(
794 'TF_CUDA_COMPUTE_CAPABILITIES')
795 environ_cp['NO_WHOLE_ARCHIVE_OPTION'] = 1
796 write_action_env_to_bazelrc('CUDA_PATH', environ_cp.get('CUDA_PATH'))
797 write_action_env_to_bazelrc('CUDA_COMPUTE_CAPABILITIE',
798 environ_cp.get('CUDA_COMPUTE_CAPABILITIE'))
799 write_action_env_to_bazelrc('NO_WHOLE_ARCHIVE_OPTION',
800 environ_cp.get('NO_WHOLE_ARCHIVE_OPTION'))
801 write_to_bazelrc('build --config=win-cuda')
802 write_to_bazelrc('test --config=win-cuda')
803 else:
804 # If CUDA is enabled, always use GPU during build and test.
805 if environ_cp.get('TF_CUDA_CLANG') == '1':
806 write_to_bazelrc('build --config=cuda_clang')
807 write_to_bazelrc('test --config=cuda_clang')
808 else:
809 write_to_bazelrc('build --config=cuda')
810 write_to_bazelrc('test --config=cuda')
811
812
813def set_host_cxx_compiler(environ_cp):
814 """Set HOST_CXX_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700815 default_cxx_host_compiler = which('g++') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700816 ask_cxx_host_compiler = (
817 'Please specify which C++ compiler should be used as'
818 ' the host C++ compiler. [Default is %s]: ') % default_cxx_host_compiler
819
820 while True:
821 host_cxx_compiler = get_from_env_or_user_or_default(
822 environ_cp, 'HOST_CXX_COMPILER', ask_cxx_host_compiler,
823 default_cxx_host_compiler)
824 if os.path.exists(host_cxx_compiler):
825 break
826
827 # Reset and retry
828 print('Invalid C++ compiler path. %s cannot be found' % host_cxx_compiler)
829 environ_cp['HOST_CXX_COMPILER'] = ''
830
831 # Set HOST_CXX_COMPILER
832 environ_cp['HOST_CXX_COMPILER'] = host_cxx_compiler
833 write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler)
834
835
836def set_host_c_compiler(environ_cp):
837 """Set HOST_C_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700838 default_c_host_compiler = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700839 ask_c_host_compiler = (
840 'Please specify which C compiler should be used as the'
841 ' host C compiler. [Default is %s]: ') % default_c_host_compiler
842
843 while True:
844 host_c_compiler = get_from_env_or_user_or_default(
845 environ_cp, 'HOST_C_COMPILER', ask_c_host_compiler,
846 default_c_host_compiler)
847 if os.path.exists(host_c_compiler):
848 break
849
850 # Reset and retry
851 print('Invalid C compiler path. %s cannot be found' % host_c_compiler)
852 environ_cp['HOST_C_COMPILER'] = ''
853
854 # Set HOST_C_COMPILER
855 environ_cp['HOST_C_COMPILER'] = host_c_compiler
856 write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler)
857
858
859def set_computecpp_toolkit_path(environ_cp):
860 """Set COMPUTECPP_TOOLKIT_PATH."""
861 ask_computecpp_toolkit_path = ('Please specify the location where ComputeCpp '
862 'for SYCL %s is installed. [Default is %s]: '
863 ) % (_TF_OPENCL_VERSION,
864 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
865
866 while True:
867 computecpp_toolkit_path = get_from_env_or_user_or_default(
868 environ_cp, 'COMPUTECPP_TOOLKIT_PATH', ask_computecpp_toolkit_path,
869 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
870 if is_linux():
871 sycl_rt_lib_path = 'lib/libComputeCpp.so'
872 else:
873 sycl_rt_lib_path = ''
874
875 sycl_rt_lib_path_full = os.path.join(computecpp_toolkit_path,
876 sycl_rt_lib_path)
877 if os.path.exists(sycl_rt_lib_path_full):
878 break
879
880 print('Invalid SYCL %s library path. %s cannot be found' %
881 (_TF_OPENCL_VERSION, sycl_rt_lib_path_full))
882 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = ''
883
884 # Set COMPUTECPP_TOOLKIT_PATH
885 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = computecpp_toolkit_path
886 write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH',
887 computecpp_toolkit_path)
888
889
890def set_mpi_home(environ_cp):
891 """Set MPI_HOME."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700892 default_mpi_home = which('mpirun') or which('mpiexec') or ''
893 default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home))
894
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700895 ask_mpi_home = ('Please specify the MPI toolkit folder. [Default is %s]: '
896 ) % default_mpi_home
897 while True:
898 mpi_home = get_from_env_or_user_or_default(environ_cp, 'MPI_HOME',
899 ask_mpi_home, default_mpi_home)
900
901 if os.path.exists(os.path.join(mpi_home, 'include')) and os.path.exists(
902 os.path.join(mpi_home, 'lib')):
903 break
904
905 print('Invalid path to the MPI Toolkit. %s or %s cannot be found' %
906 (os.path.join(mpi_home, 'include'),
907 os.path.exists(os.path.join(mpi_home, 'lib'))))
908 environ_cp['MPI_HOME'] = ''
909
910 # Set MPI_HOME
911 environ_cp['MPI_HOME'] = str(mpi_home)
912
913
914def set_other_mpi_vars(environ_cp):
915 """Set other MPI related variables."""
916 # Link the MPI header files
917 mpi_home = environ_cp.get('MPI_HOME')
918 symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h')
919
920 # Determine if we use OpenMPI or MVAPICH, these require different header files
921 # to be included here to make bazel dependency checker happy
922 if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')):
923 symlink_force(
924 os.path.join(mpi_home, 'include/mpi_portable_platform.h'),
925 'third_party/mpi/mpi_portable_platform.h')
926 # TODO(gunan): avoid editing files in configure
927 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False',
928 'MPI_LIB_IS_OPENMPI=True')
929 else:
930 # MVAPICH / MPICH
931 symlink_force(
932 os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h')
933 symlink_force(
934 os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h')
935 # TODO(gunan): avoid editing files in configure
936 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True',
937 'MPI_LIB_IS_OPENMPI=False')
938
939 if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')):
940 symlink_force(
941 os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so')
942 else:
943 raise ValueError('Cannot find the MPI library file in %s/lib' % mpi_home)
944
945
946def set_mkl():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700947 write_to_bazelrc('build:mkl --define using_mkl=true')
948 write_to_bazelrc('build:mkl -c opt')
949 write_to_bazelrc('build:mkl --copt="-DEIGEN_USE_VML"')
950 print(
951 'Add "--config=mkl" to your bazel command to build with MKL '
952 'support.\nPlease note that MKL on MacOS or windows is still not '
953 'supported.\nIf you would like to use a local MKL instead of '
954 'downloading, please set the environment variable \"TF_MKL_ROOT\" every '
955 'time before build.')
956
957
Allen Lavoie5c7f9e32017-09-21 11:29:45 -0700958def set_monolithic():
959 # Add --config=monolithic to your bazel command to use a mostly-static
960 # build and disable modular op registration support (this will revert to
961 # loading TensorFlow with RTLD_GLOBAL in Python). By default (without
962 # --config=monolithic), TensorFlow will build with a dependence on
963 # //tensorflow:libtensorflow_framework.so.
964 write_to_bazelrc('build:monolithic --define framework_shared_object=false')
965 # For projects which use TensorFlow as part of a Bazel build process, putting
966 # nothing in a bazelrc will default to a monolithic build. The following line
967 # opts in to modular op registration support by default:
968 write_to_bazelrc('build --define framework_shared_object=true')
969
970
Michael Casef1ecdd62017-10-24 18:07:59 -0700971def create_android_bazelrc_configs():
972 # Flags for --config=android
973 write_to_bazelrc('build:android --crosstool_top=//external:android/crosstool')
974 write_to_bazelrc(
975 'build:android --host_crosstool_top=@bazel_tools//tools/cpp:toolchain')
976 # Flags for --config=android_arm
977 write_to_bazelrc('build:android_arm --config=android')
978 write_to_bazelrc('build:android_arm --cpu=armeabi-v7a')
979 # Flags for --config=android_arm64
980 write_to_bazelrc('build:android_arm64 --config=android')
981 write_to_bazelrc('build:android_arm64 --cpu=arm64-v8a')
982
983
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700984def main():
985 # Make a copy of os.environ to be clear when functions and getting and setting
986 # environment variables.
987 environ_cp = dict(os.environ)
988
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700989 check_bazel_version('0.5.4')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700990
991 reset_tf_configure_bazelrc()
992 cleanup_makefile()
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700993 setup_python(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700994 run_gen_git_source(environ_cp)
995
996 if is_windows():
Benoit Steiner355e25e2017-10-24 19:47:46 -0700997 environ_cp['TF_NEED_S3'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700998 environ_cp['TF_NEED_GCP'] = '0'
999 environ_cp['TF_NEED_HDFS'] = '0'
1000 environ_cp['TF_NEED_JEMALLOC'] = '0'
1001 environ_cp['TF_NEED_OPENCL'] = '0'
Andrew Harp88917882017-11-02 15:22:08 -07001002 environ_cp['TF_NEED_S3'] = '0'
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001003 environ_cp['TF_CUDA_CLANG'] = '0'
1004
1005 if is_macos():
1006 environ_cp['TF_NEED_JEMALLOC'] = '0'
1007
1008 set_build_var(environ_cp, 'TF_NEED_JEMALLOC', 'jemalloc as malloc',
1009 'with_jemalloc', True)
1010 set_build_var(environ_cp, 'TF_NEED_GCP', 'Google Cloud Platform',
Benoit Steiner355e25e2017-10-24 19:47:46 -07001011 'with_gcp_support', True, 'gcp')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001012 set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
Benoit Steiner355e25e2017-10-24 19:47:46 -07001013 'with_hdfs_support', True, 'hdfs')
Michael Case7e4e3362017-10-09 13:31:15 -07001014 set_build_var(environ_cp, 'TF_NEED_S3', 'Amazon S3 File System',
1015 'with_s3_support', True, 's3')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001016 set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
Michael Case98850a52017-09-14 13:35:57 -07001017 False, 'xla')
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -07001018 set_build_var(environ_cp, 'TF_NEED_GDR', 'GDR', 'with_gdr_support',
Michael Case98850a52017-09-14 13:35:57 -07001019 False, 'gdr')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001020 set_build_var(environ_cp, 'TF_NEED_VERBS', 'VERBS', 'with_verbs_support',
Michael Case98850a52017-09-14 13:35:57 -07001021 False, 'verbs')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001022
1023 set_action_env_var(environ_cp, 'TF_NEED_OPENCL', 'OpenCL', False)
1024 if environ_cp.get('TF_NEED_OPENCL') == '1':
1025 set_host_cxx_compiler(environ_cp)
1026 set_host_c_compiler(environ_cp)
1027 set_computecpp_toolkit_path(environ_cp)
1028
1029 set_action_env_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)
A. Unique TensorFlower24cbb2a2017-09-08 07:45:44 -07001030 if (environ_cp.get('TF_NEED_CUDA') == '1' and
1031 'TF_CUDA_CONFIG_REPO' not in environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001032 set_tf_cuda_version(environ_cp)
1033 set_tf_cunn_version(environ_cp)
1034 set_tf_cuda_compute_capabilities(environ_cp)
1035
1036 set_tf_cuda_clang(environ_cp)
1037 if environ_cp.get('TF_CUDA_CLANG') == '1':
1038 # Set up which clang we should use as the cuda / host compiler.
1039 set_clang_cuda_compiler_path(environ_cp)
1040 else:
1041 # Set up which gcc nvcc should use as the host compiler
1042 # No need to set this on Windows
1043 if not is_windows():
1044 set_gcc_host_compiler_path(environ_cp)
1045 set_other_cuda_vars(environ_cp)
1046
1047 set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False)
1048 if environ_cp.get('TF_NEED_MPI') == '1':
1049 set_mpi_home(environ_cp)
1050 set_other_mpi_vars(environ_cp)
1051
1052 set_cc_opt_flags(environ_cp)
1053 set_mkl()
Allen Lavoie5c7f9e32017-09-21 11:29:45 -07001054 set_monolithic()
Michael Casef1ecdd62017-10-24 18:07:59 -07001055 create_android_bazelrc_configs()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001056
1057if __name__ == '__main__':
1058 main()