blob: df2c74d23d8ea306028c8c0406c5475d31fa884f [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
Jonathan Hseu008910f2017-08-25 14:01:05 -070028try:
29 from shutil import which
30except ImportError:
31 from distutils.spawn import find_executable as which
32
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070033_TF_BAZELRC = '.tf_configure.bazelrc'
34_DEFAULT_CUDA_VERSION = '8.0'
35_DEFAULT_CUDNN_VERSION = '6'
36_DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,5.2'
37_DEFAULT_CUDA_PATH = '/usr/local/cuda'
38_DEFAULT_CUDA_PATH_LINUX = '/opt/cuda'
39_DEFAULT_CUDA_PATH_WIN = ('C:/Program Files/NVIDIA GPU Computing '
40 'Toolkit/CUDA/v%s' % _DEFAULT_CUDA_VERSION)
41_TF_OPENCL_VERSION = '1.2'
42_DEFAULT_COMPUTECPP_TOOLKIT_PATH = '/usr/local/computecpp'
43
44
45def is_windows():
46 return platform.system() == 'Windows'
47
48
49def is_linux():
50 return platform.system() == 'Linux'
51
52
53def is_macos():
54 return platform.system() == 'Darwin'
55
56
57def is_ppc64le():
58 return platform.machine() == 'ppc64le'
59
60
Jonathan Hseu008910f2017-08-25 14:01:05 -070061def is_cygwin():
62 return platform.system().startswith('CYGWIN_NT')
63
64
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -070065def get_input(question):
66 try:
67 try:
68 answer = raw_input(question)
69 except NameError:
70 answer = input(question) # pylint: disable=bad-builtin
71 except EOFError:
72 answer = ''
73 return answer
74
75
76def symlink_force(target, link_name):
77 """Force symlink, equivalent of 'ln -sf'.
78
79 Args:
80 target: items to link to.
81 link_name: name of the link.
82 """
83 try:
84 os.symlink(target, link_name)
85 except OSError as e:
86 if e.errno == errno.EEXIST:
87 os.remove(link_name)
88 os.symlink(target, link_name)
89 else:
90 raise e
91
92
93def sed_in_place(filename, old, new):
94 """Replace old string with new string in file.
95
96 Args:
97 filename: string for filename.
98 old: string to replace.
99 new: new string to replace to.
100 """
101 with open(filename, 'r') as f:
102 filedata = f.read()
103 newdata = filedata.replace(old, new)
104 with open(filename, 'w') as f:
105 f.write(newdata)
106
107
108def remove_line_with(filename, token):
109 """Remove lines that contain token from file.
110
111 Args:
112 filename: string for filename.
113 token: string token to check if to remove a line from file or not.
114 """
115 with open(filename, 'r') as f:
116 filedata = f.read()
117
118 with open(filename, 'w') as f:
119 for line in filedata.strip().split('\n'):
120 if token not in line:
121 f.write(line + '\n')
122
123
124def write_to_bazelrc(line):
125 with open(_TF_BAZELRC, 'a') as f:
126 f.write(line + '\n')
127
128
129def write_action_env_to_bazelrc(var_name, var):
130 write_to_bazelrc('build --action_env %s="%s"' % (var_name, str(var)))
131
132
Jonathan Hseu008910f2017-08-25 14:01:05 -0700133def run_shell(cmd, allow_non_zero=False):
134 if allow_non_zero:
135 try:
136 output = subprocess.check_output(cmd)
137 except subprocess.CalledProcessError as e:
138 output = e.output
139 else:
140 output = subprocess.check_output(cmd)
141 return output.decode('UTF-8').strip()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700142
143
144def cygpath(path):
145 """Convert path from posix to windows."""
Martin Wicked57572e2017-09-02 19:21:45 -0700146 return os.path.abspath(path).replace('\\', '/')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700147
148
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700149def get_python_path(environ_cp, python_bin_path):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700150 """Get the python site package paths."""
151 python_paths = []
152 if environ_cp.get('PYTHONPATH'):
153 python_paths = environ_cp.get('PYTHONPATH').split(':')
154 try:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700155 library_paths = run_shell(
156 [python_bin_path, '-c',
157 'import site; print("\\n".join(site.getsitepackages()))']).split("\n")
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700158 except subprocess.CalledProcessError:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700159 library_paths = [run_shell(
160 [python_bin_path, '-c',
161 'from distutils.sysconfig import get_python_lib;'
162 'print(get_python_lib())'])]
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700163
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700164 all_paths = set(python_paths + library_paths)
165
166 paths = []
167 for path in all_paths:
168 if os.path.isdir(path):
169 paths.append(path)
170 return paths
171
172
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700173def get_python_major_version(python_bin_path):
174 """Get the python major version."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700175 return run_shell([python_bin_path, '-c', 'import sys; print(sys.version[0])'])
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700176
177
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700178def setup_python(environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700179 """Setup python related env variables."""
180 # Get PYTHON_BIN_PATH, default is the current running python.
181 default_python_bin_path = sys.executable
182 ask_python_bin_path = ('Please specify the location of python. [Default is '
183 '%s]: ') % default_python_bin_path
184 while True:
185 python_bin_path = get_from_env_or_user_or_default(
186 environ_cp, 'PYTHON_BIN_PATH', ask_python_bin_path,
187 default_python_bin_path)
188 # Check if the path is valid
Jonathan Hseu008910f2017-08-25 14:01:05 -0700189 if os.path.isfile(python_bin_path) and os.access(
190 python_bin_path, os.X_OK):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700191 break
192 elif not os.path.exists(python_bin_path):
193 print('Invalid python path: %s cannot be found.' % python_bin_path)
194 else:
195 print('%s is not executable. Is it the python binary?' % python_bin_path)
196 environ_cp['PYTHON_BIN_PATH'] = ''
197
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700198 # Convert python path to Windows style before checking lib and version
Martin Wicked57572e2017-09-02 19:21:45 -0700199 if is_windows() or is_cygwin():
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700200 python_bin_path = cygpath(python_bin_path)
201
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700202 # Get PYTHON_LIB_PATH
203 python_lib_path = environ_cp.get('PYTHON_LIB_PATH')
204 if not python_lib_path:
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700205 python_lib_paths = get_python_path(environ_cp, python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700206 if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1':
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700207 python_lib_path = python_lib_paths[0]
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700208 else:
Jonathan Hseu008910f2017-08-25 14:01:05 -0700209 print('Found possible Python library paths:\n %s' %
210 '\n '.join(python_lib_paths))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700211 default_python_lib_path = python_lib_paths[0]
212 python_lib_path = get_input(
Jonathan Hseu008910f2017-08-25 14:01:05 -0700213 'Please input the desired Python library path to use. '
214 'Default is [%s]\n' % python_lib_paths[0])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700215 if not python_lib_path:
216 python_lib_path = default_python_lib_path
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700217 environ_cp['PYTHON_LIB_PATH'] = python_lib_path
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700218
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700219 python_major_version = get_python_major_version(python_bin_path)
220
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700221 # Convert python path to Windows style before writing into bazel.rc
Martin Wicked57572e2017-09-02 19:21:45 -0700222 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700223 python_lib_path = cygpath(python_lib_path)
224
225 # Set-up env variables used by python_configure.bzl
226 write_action_env_to_bazelrc('PYTHON_BIN_PATH', python_bin_path)
227 write_action_env_to_bazelrc('PYTHON_LIB_PATH', python_lib_path)
228 write_to_bazelrc('build --define PYTHON_BIN_PATH="%s"' % python_bin_path)
229 write_to_bazelrc('build --define PYTHON_LIB_PATH="%s"' % python_lib_path)
230 write_to_bazelrc('build --force_python=py%s' % python_major_version)
231 write_to_bazelrc('build --host_force_python=py%s' % python_major_version)
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700232 write_to_bazelrc('build --python_path=\"%s"' % python_bin_path)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700233 write_to_bazelrc('test --force_python=py%s' % python_major_version)
234 write_to_bazelrc('test --host_force_python=py%s' % python_major_version)
235 write_to_bazelrc('test --define PYTHON_BIN_PATH="%s"' % python_bin_path)
236 write_to_bazelrc('test --define PYTHON_LIB_PATH="%s"' % python_lib_path)
237 write_to_bazelrc('run --define PYTHON_BIN_PATH="%s"' % python_bin_path)
238 write_to_bazelrc('run --define PYTHON_LIB_PATH="%s"' % python_lib_path)
239 environ_cp['PYTHON_BIN_PATH'] = python_bin_path
240
241 # Write tools/python_bin_path.sh
242 with open('tools/python_bin_path.sh', 'w') as f:
243 f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path)
244
245
246def reset_tf_configure_bazelrc():
247 """Reset file that contains customized config settings."""
248 open(_TF_BAZELRC, 'w').close()
249
250 home = os.path.expanduser('~')
251 if not os.path.exists('.bazelrc'):
252 if os.path.exists(os.path.join(home, '.bazelrc')):
253 with open('.bazelrc', 'a') as f:
Shanqing Caie2e3a942017-09-25 19:35:53 -0700254 f.write('import %s/.bazelrc\n' % home.replace('\\', '/'))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700255 else:
256 open('.bazelrc', 'w').close()
257
258 remove_line_with('.bazelrc', 'tf_configure')
259 with open('.bazelrc', 'a') as f:
260 f.write('import %workspace%/.tf_configure.bazelrc\n')
261
262
263def run_gen_git_source(environ_cp):
264 """Run the gen_git_source to create links.
265
266 The links are for bazel to track dependencies for git hash propagation.
267
268 Args:
269 environ_cp: copy of the os.environ.
270 """
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700271 cmd = '"%s" tensorflow/tools/git/gen_git_source.py --configure %s' % (
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700272 environ_cp.get('PYTHON_BIN_PATH'), os.getcwd())
273 os.system(cmd)
274
275
276def cleanup_makefile():
277 """Delete any leftover BUILD files from the Makefile build.
278
279 These files could interfere with Bazel parsing.
280 """
281 makefile_download_dir = 'tensorflow/contrib/makefile/downloads'
282 if os.path.isdir(makefile_download_dir):
283 for root, _, filenames in os.walk(makefile_download_dir):
284 for f in filenames:
285 if f.endswith('BUILD'):
286 os.remove(os.path.join(root, f))
287
288
289def get_var(environ_cp,
290 var_name,
291 query_item,
292 enabled_by_default,
293 question=None,
294 yes_reply=None,
295 no_reply=None):
296 """Get boolean input from user.
297
298 If var_name is not set in env, ask user to enable query_item or not. If the
299 response is empty, use the default.
300
301 Args:
302 environ_cp: copy of the os.environ.
303 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
304 query_item: string for feature related to the variable, e.g. "Hadoop File
305 System".
306 enabled_by_default: boolean for default behavior.
307 question: optional string for how to ask for user input.
308 yes_reply: optionanl string for reply when feature is enabled.
309 no_reply: optional string for reply when feature is disabled.
310
311 Returns:
312 boolean value of the variable.
313 """
314 if not question:
315 question = 'Do you wish to build TensorFlow with %s support?' % query_item
316 if not yes_reply:
317 yes_reply = '%s support will be enabled for TensorFlow.' % query_item
318 if not no_reply:
319 no_reply = 'No %s' % yes_reply
320
321 yes_reply += '\n'
322 no_reply += '\n'
323
324 if enabled_by_default:
325 question += ' [Y/n]: '
326 else:
327 question += ' [y/N]: '
328
329 var = environ_cp.get(var_name)
330 while var is None:
331 user_input_origin = get_input(question)
332 user_input = user_input_origin.strip().lower()
333 if user_input == 'y':
334 print(yes_reply)
335 var = True
336 elif user_input == 'n':
337 print(no_reply)
338 var = False
339 elif not user_input:
340 if enabled_by_default:
341 print(yes_reply)
342 var = True
343 else:
344 print(no_reply)
345 var = False
346 else:
347 print('Invalid selection: %s' % user_input_origin)
348 return var
349
350
351def set_build_var(environ_cp, var_name, query_item, option_name,
Michael Case98850a52017-09-14 13:35:57 -0700352 enabled_by_default, bazel_config_name=None):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700353 """Set if query_item will be enabled for the build.
354
355 Ask user if query_item will be enabled. Default is used if no input is given.
356 Set subprocess environment variable and write to .bazelrc if enabled.
357
358 Args:
359 environ_cp: copy of the os.environ.
360 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
361 query_item: string for feature related to the variable, e.g. "Hadoop File
362 System".
363 option_name: string for option to define in .bazelrc.
364 enabled_by_default: boolean for default behavior.
Michael Case98850a52017-09-14 13:35:57 -0700365 bazel_config_name: Name for Bazel --config argument to enable build feature.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700366 """
367
368 var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default)))
369 environ_cp[var_name] = var
370 if var == '1':
371 write_to_bazelrc('build --define %s=true' % option_name)
Michael Case98850a52017-09-14 13:35:57 -0700372 elif bazel_config_name is not None:
373 # TODO(mikecase): Migrate all users of configure.py to use --config Bazel
374 # options and not to set build configs through environment variables.
375 write_to_bazelrc('build:%s --define %s=true'
376 % (bazel_config_name, option_name))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700377
378
379def set_action_env_var(environ_cp,
380 var_name,
381 query_item,
382 enabled_by_default,
383 question=None,
384 yes_reply=None,
385 no_reply=None):
386 """Set boolean action_env variable.
387
388 Ask user if query_item will be enabled. Default is used if no input is given.
389 Set environment variable and write to .bazelrc.
390
391 Args:
392 environ_cp: copy of the os.environ.
393 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
394 query_item: string for feature related to the variable, e.g. "Hadoop File
395 System".
396 enabled_by_default: boolean for default behavior.
397 question: optional string for how to ask for user input.
398 yes_reply: optionanl string for reply when feature is enabled.
399 no_reply: optional string for reply when feature is disabled.
400 """
401 var = int(
402 get_var(environ_cp, var_name, query_item, enabled_by_default, question,
403 yes_reply, no_reply))
404
405 write_action_env_to_bazelrc(var_name, var)
406 environ_cp[var_name] = str(var)
407
408
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700409def convert_version_to_int(version):
410 """Convert a version number to a integer that can be used to compare.
411
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700412 Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The
413 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.
414
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700415 Args:
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700416 version: a version to be converted
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700417
418 Returns:
419 An integer if converted successfully, otherwise return None.
420 """
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700421 version = version.split('-')[0]
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700422 version_segments = version.split('.')
423 for seg in version_segments:
424 if not seg.isdigit():
425 return None
426
427 version_str = ''.join(['%03d' % int(seg) for seg in version_segments])
428 return int(version_str)
429
430
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700431def check_bazel_version(min_version):
432 """Check installed bezel version is at least min_version.
433
434 Args:
435 min_version: string for minimum bazel version.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700436
437 Returns:
438 The bazel version detected.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700439 """
Jonathan Hseu008910f2017-08-25 14:01:05 -0700440 if which('bazel') is None:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700441 print('Cannot find bazel. Please install bazel.')
442 sys.exit(0)
Jonathan Hseu008910f2017-08-25 14:01:05 -0700443 curr_version = run_shell(['bazel', '--batch', 'version'])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700444
445 for line in curr_version.split('\n'):
446 if 'Build label: ' in line:
447 curr_version = line.split('Build label: ')[1]
448 break
449
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700450 min_version_int = convert_version_to_int(min_version)
451 curr_version_int = convert_version_to_int(curr_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700452
453 # Check if current bazel version can be detected properly.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700454 if not curr_version_int:
455 print('WARNING: current bazel installation is not a release version.')
456 print('Make sure you are running at least bazel %s' % min_version)
457 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700458
Michael Cased94271a2017-08-22 17:26:52 -0700459 print('You have bazel %s installed.' % curr_version)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700460
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700461 if curr_version_int < min_version_int:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700462 print('Please upgrade your bazel installation to version %s or higher to '
463 'build TensorFlow!' % min_version)
464 sys.exit(0)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700465 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700466
467
468def set_cc_opt_flags(environ_cp):
469 """Set up architecture-dependent optimization flags.
470
471 Also append CC optimization flags to bazel.rc..
472
473 Args:
474 environ_cp: copy of the os.environ.
475 """
476 if is_ppc64le():
477 # gcc on ppc64le does not support -march, use mcpu instead
478 default_cc_opt_flags = '-mcpu=native'
479 else:
480 default_cc_opt_flags = '-march=native'
481 question = ('Please specify optimization flags to use during compilation when'
482 ' bazel option "--config=opt" is specified [Default is %s]: '
483 ) % default_cc_opt_flags
484 cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',
485 question, default_cc_opt_flags)
486 for opt in cc_opt_flags.split():
487 write_to_bazelrc('build:opt --cxxopt=%s --copt=%s' % (opt, opt))
488
489
490def set_tf_cuda_clang(environ_cp):
491 """set TF_CUDA_CLANG action_env.
492
493 Args:
494 environ_cp: copy of the os.environ.
495 """
496 question = 'Do you want to use clang as CUDA compiler?'
497 yes_reply = 'Clang will be used as CUDA compiler.'
498 no_reply = 'nvcc will be used as CUDA compiler.'
499 set_action_env_var(
500 environ_cp,
501 'TF_CUDA_CLANG',
502 None,
503 False,
504 question=question,
505 yes_reply=yes_reply,
506 no_reply=no_reply)
507
508
509def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
510 var_default):
511 """Get var_name either from env, or user or default.
512
513 If var_name has been set as environment variable, use the preset value, else
514 ask for user input. If no input is provided, the default is used.
515
516 Args:
517 environ_cp: copy of the os.environ.
518 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
519 ask_for_var: string for how to ask for user input.
520 var_default: default value string.
521
522 Returns:
523 string value for var_name
524 """
525 var = environ_cp.get(var_name)
526 if not var:
527 var = get_input(ask_for_var)
Michael Cased94271a2017-08-22 17:26:52 -0700528 print('\n')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700529 if not var:
530 var = var_default
531 return var
532
533
534def set_clang_cuda_compiler_path(environ_cp):
535 """Set CLANG_CUDA_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700536 default_clang_path = which('clang') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700537 ask_clang_path = ('Please specify which clang should be used as device and '
538 'host compiler. [Default is %s]: ') % default_clang_path
539
540 while True:
541 clang_cuda_compiler_path = get_from_env_or_user_or_default(
542 environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path,
543 default_clang_path)
544 if os.path.exists(clang_cuda_compiler_path):
545 break
546
547 # Reset and retry
548 print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path)
549 environ_cp['CLANG_CUDA_COMPILER_PATH'] = ''
550
551 # Set CLANG_CUDA_COMPILER_PATH
552 environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path
553 write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',
554 clang_cuda_compiler_path)
555
556
557def set_gcc_host_compiler_path(environ_cp):
558 """Set GCC_HOST_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700559 default_gcc_host_compiler_path = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700560 cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH')
561
562 if os.path.islink(cuda_bin_symlink):
563 # os.readlink is only available in linux
Jonathan Hseu008910f2017-08-25 14:01:05 -0700564 default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700565
566 ask_gcc_path = (
567 'Please specify which gcc should be used by nvcc as the '
568 'host compiler. [Default is %s]: ') % default_gcc_host_compiler_path
569 while True:
570 gcc_host_compiler_path = get_from_env_or_user_or_default(
571 environ_cp, 'GCC_HOST_COMPILER_PATH', ask_gcc_path,
572 default_gcc_host_compiler_path)
573
574 if os.path.exists(gcc_host_compiler_path):
575 break
576
577 # Reset and retry
578 print('Invalid gcc path. %s cannot be found' % gcc_host_compiler_path)
579 environ_cp['GCC_HOST_COMPILER_PATH'] = ''
580
581 # Set GCC_HOST_COMPILER_PATH
582 environ_cp['GCC_HOST_COMPILER_PATH'] = gcc_host_compiler_path
583 write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)
584
585
586def set_tf_cuda_version(environ_cp):
587 """Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION."""
588 ask_cuda_version = (
589 'Please specify the CUDA SDK version you want to use, '
590 'e.g. 7.0. [Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
591
592 while True:
593 # Configure the Cuda SDK version to use.
594 tf_cuda_version = get_from_env_or_user_or_default(
595 environ_cp, 'TF_CUDA_VERSION', ask_cuda_version, _DEFAULT_CUDA_VERSION)
596
597 # Find out where the CUDA toolkit is installed
598 default_cuda_path = _DEFAULT_CUDA_PATH
Martin Wicked57572e2017-09-02 19:21:45 -0700599 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700600 default_cuda_path = cygpath(
601 environ_cp.get('CUDA_PATH', _DEFAULT_CUDA_PATH_WIN))
602 elif is_linux():
603 # If the default doesn't exist, try an alternative default.
604 if (not os.path.exists(default_cuda_path)
605 ) and os.path.exists(_DEFAULT_CUDA_PATH_LINUX):
606 default_cuda_path = _DEFAULT_CUDA_PATH_LINUX
607 ask_cuda_path = ('Please specify the location where CUDA %s toolkit is'
608 ' installed. Refer to README.md for more details. '
609 '[Default is %s]: ') % (tf_cuda_version, default_cuda_path)
610 cuda_toolkit_path = get_from_env_or_user_or_default(
611 environ_cp, 'CUDA_TOOLKIT_PATH', ask_cuda_path, default_cuda_path)
612
613 if is_windows():
614 cuda_rt_lib_path = 'lib/x64/cudart.lib'
615 elif is_linux():
616 cuda_rt_lib_path = 'lib64/libcudart.so.%s' % tf_cuda_version
617 elif is_macos():
618 cuda_rt_lib_path = 'lib/libcudart.%s.dylib' % tf_cuda_version
619
620 cuda_toolkit_path_full = os.path.join(cuda_toolkit_path, cuda_rt_lib_path)
621 if os.path.exists(cuda_toolkit_path_full):
622 break
623
624 # Reset and retry
625 print('Invalid path to CUDA %s toolkit. %s cannot be found' %
626 (tf_cuda_version, cuda_toolkit_path_full))
627 environ_cp['TF_CUDA_VERSION'] = ''
628 environ_cp['CUDA_TOOLKIT_PATH'] = ''
629
630 # Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION
631 environ_cp['CUDA_TOOLKIT_PATH'] = cuda_toolkit_path
632 write_action_env_to_bazelrc('CUDA_TOOLKIT_PATH', cuda_toolkit_path)
633 environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
634 write_action_env_to_bazelrc('TF_CUDA_VERSION', tf_cuda_version)
635
636
637def set_tf_cunn_version(environ_cp):
638 """Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION."""
639 ask_cudnn_version = (
Jonathan Hseu008910f2017-08-25 14:01:05 -0700640 'Please specify the cuDNN version you want to use. '
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700641 '[Leave empty to default to cuDNN %s.0]: ') % _DEFAULT_CUDNN_VERSION
642
643 while True:
644 tf_cudnn_version = get_from_env_or_user_or_default(
645 environ_cp, 'TF_CUDNN_VERSION', ask_cudnn_version,
646 _DEFAULT_CUDNN_VERSION)
647
648 default_cudnn_path = environ_cp.get('CUDA_TOOLKIT_PATH')
649 ask_cudnn_path = (r'Please specify the location where cuDNN %s library is '
650 'installed. Refer to README.md for more details. [Default'
651 ' is %s]:') % (tf_cudnn_version, default_cudnn_path)
652 cudnn_install_path = get_from_env_or_user_or_default(
653 environ_cp, 'CUDNN_INSTALL_PATH', ask_cudnn_path, default_cudnn_path)
654
655 # Result returned from "read" will be used unexpanded. That make "~"
656 # unusable. Going through one more level of expansion to handle that.
657 cudnn_install_path = os.path.realpath(
658 os.path.expanduser(cudnn_install_path))
Martin Wicked57572e2017-09-02 19:21:45 -0700659 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700660 cudnn_install_path = cygpath(cudnn_install_path)
661
662 if is_windows():
663 cuda_dnn_lib_path = 'lib/x64/cudnn.lib'
664 cuda_dnn_lib_alt_path = 'lib/x64/cudnn.lib'
665 elif is_linux():
666 cuda_dnn_lib_path = 'lib64/libcudnn.so.%s' % tf_cudnn_version
667 cuda_dnn_lib_alt_path = 'libcudnn.so.%s' % tf_cudnn_version
668 elif is_macos():
669 cuda_dnn_lib_path = 'lib/libcudnn.%s.dylib' % tf_cudnn_version
670 cuda_dnn_lib_alt_path = 'libcudnn.%s.dylib' % tf_cudnn_version
671
672 cuda_dnn_lib_path_full = os.path.join(cudnn_install_path, cuda_dnn_lib_path)
673 cuda_dnn_lib_alt_path_full = os.path.join(cudnn_install_path,
674 cuda_dnn_lib_alt_path)
675 if os.path.exists(cuda_dnn_lib_path_full) or os.path.exists(
676 cuda_dnn_lib_alt_path_full):
677 break
678
679 # Try another alternative for Linux
680 if is_linux():
Jonathan Hseu008910f2017-08-25 14:01:05 -0700681 ldconfig_bin = which('ldconfig') or '/sbin/ldconfig'
682 cudnn_path_from_ldconfig = run_shell([ldconfig_bin, '-p'])
683 cudnn_path_from_ldconfig = re.search('.*libcudnn.so .* => (.*)',
A. Unique TensorFlowere7223582017-09-06 17:57:04 -0700684 cudnn_path_from_ldconfig)
685 if cudnn_path_from_ldconfig:
686 cudnn_path_from_ldconfig = cudnn_path_from_ldconfig.group(1)
687 if os.path.exists('%s.%s' % (cudnn_path_from_ldconfig,
688 tf_cudnn_version)):
689 cudnn_install_path = os.path.dirname(cudnn_path_from_ldconfig)
690 break
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700691
692 # Reset and Retry
693 print(
694 'Invalid path to cuDNN %s toolkit. None of the following files can be '
695 'found:' % tf_cudnn_version)
696 print(cuda_dnn_lib_path_full)
697 print(cuda_dnn_lib_alt_path_full)
698 if is_linux():
699 print('%s.%s' % (cudnn_path_from_ldconfig, tf_cudnn_version))
700
701 environ_cp['TF_CUDNN_VERSION'] = ''
702
703 # Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION
704 environ_cp['CUDNN_INSTALL_PATH'] = cudnn_install_path
705 write_action_env_to_bazelrc('CUDNN_INSTALL_PATH', cudnn_install_path)
706 environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
707 write_action_env_to_bazelrc('TF_CUDNN_VERSION', tf_cudnn_version)
708
709
710def get_native_cuda_compute_capabilities(environ_cp):
711 """Get native cuda compute capabilities.
712
713 Args:
714 environ_cp: copy of the os.environ.
715 Returns:
716 string of native cuda compute capabilities, separated by comma.
717 """
718 device_query_bin = os.path.join(
719 environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery')
Jonathan Hseu008910f2017-08-25 14:01:05 -0700720 if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK):
721 try:
722 output = run_shell(device_query_bin).split('\n')
723 pattern = re.compile('[0-9]*\\.[0-9]*')
724 output = [pattern.search(x) for x in output if 'Capability' in x]
725 output = ','.join(x.group() for x in output if x is not None)
726 except subprocess.CalledProcessError:
727 output = ''
728 else:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700729 output = ''
730 return output
731
732
733def set_tf_cuda_compute_capabilities(environ_cp):
734 """Set TF_CUDA_COMPUTE_CAPABILITIES."""
735 while True:
736 native_cuda_compute_capabilities = get_native_cuda_compute_capabilities(
737 environ_cp)
738 if not native_cuda_compute_capabilities:
739 default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES
740 else:
741 default_cuda_compute_capabilities = native_cuda_compute_capabilities
742
743 ask_cuda_compute_capabilities = (
744 'Please specify a list of comma-separated '
745 'Cuda compute capabilities you want to '
746 'build with.\nYou can find the compute '
747 'capability of your device at: '
748 'https://developer.nvidia.com/cuda-gpus.\nPlease'
749 ' note that each additional compute '
750 'capability significantly increases your '
751 'build time and binary size. [Default is: %s]' %
752 default_cuda_compute_capabilities)
753 tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
754 environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
755 ask_cuda_compute_capabilities, default_cuda_compute_capabilities)
756 # Check whether all capabilities from the input is valid
757 all_valid = True
758 for compute_capability in tf_cuda_compute_capabilities.split(','):
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700759 m = re.match('[0-9]+.[0-9]+', compute_capability)
760 if not m:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700761 print('Invalid compute capability: ' % compute_capability)
762 all_valid = False
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700763 else:
764 ver = int(m.group(0).split('.')[0])
765 if ver < 3:
766 print('Only compute capabilities 3.0 or higher are supported.')
767 all_valid = False
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700768
769 if all_valid:
770 break
771
772 # Reset and Retry
773 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = ''
774
775 # Set TF_CUDA_COMPUTE_CAPABILITIES
776 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities
777 write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES',
778 tf_cuda_compute_capabilities)
779
780
781def set_other_cuda_vars(environ_cp):
782 """Set other CUDA related variables."""
783 if is_windows():
784 # The following three variables are needed for MSVC toolchain configuration
785 # in Bazel
786 environ_cp['CUDA_PATH'] = environ_cp.get('CUDA_TOOLKIT_PATH')
787 environ_cp['CUDA_COMPUTE_CAPABILITIES'] = environ_cp.get(
788 'TF_CUDA_COMPUTE_CAPABILITIES')
789 environ_cp['NO_WHOLE_ARCHIVE_OPTION'] = 1
790 write_action_env_to_bazelrc('CUDA_PATH', environ_cp.get('CUDA_PATH'))
791 write_action_env_to_bazelrc('CUDA_COMPUTE_CAPABILITIE',
792 environ_cp.get('CUDA_COMPUTE_CAPABILITIE'))
793 write_action_env_to_bazelrc('NO_WHOLE_ARCHIVE_OPTION',
794 environ_cp.get('NO_WHOLE_ARCHIVE_OPTION'))
795 write_to_bazelrc('build --config=win-cuda')
796 write_to_bazelrc('test --config=win-cuda')
797 else:
798 # If CUDA is enabled, always use GPU during build and test.
799 if environ_cp.get('TF_CUDA_CLANG') == '1':
800 write_to_bazelrc('build --config=cuda_clang')
801 write_to_bazelrc('test --config=cuda_clang')
802 else:
803 write_to_bazelrc('build --config=cuda')
804 write_to_bazelrc('test --config=cuda')
805
806
807def set_host_cxx_compiler(environ_cp):
808 """Set HOST_CXX_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700809 default_cxx_host_compiler = which('g++') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700810 ask_cxx_host_compiler = (
811 'Please specify which C++ compiler should be used as'
812 ' the host C++ compiler. [Default is %s]: ') % default_cxx_host_compiler
813
814 while True:
815 host_cxx_compiler = get_from_env_or_user_or_default(
816 environ_cp, 'HOST_CXX_COMPILER', ask_cxx_host_compiler,
817 default_cxx_host_compiler)
818 if os.path.exists(host_cxx_compiler):
819 break
820
821 # Reset and retry
822 print('Invalid C++ compiler path. %s cannot be found' % host_cxx_compiler)
823 environ_cp['HOST_CXX_COMPILER'] = ''
824
825 # Set HOST_CXX_COMPILER
826 environ_cp['HOST_CXX_COMPILER'] = host_cxx_compiler
827 write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler)
828
829
830def set_host_c_compiler(environ_cp):
831 """Set HOST_C_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700832 default_c_host_compiler = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700833 ask_c_host_compiler = (
834 'Please specify which C compiler should be used as the'
835 ' host C compiler. [Default is %s]: ') % default_c_host_compiler
836
837 while True:
838 host_c_compiler = get_from_env_or_user_or_default(
839 environ_cp, 'HOST_C_COMPILER', ask_c_host_compiler,
840 default_c_host_compiler)
841 if os.path.exists(host_c_compiler):
842 break
843
844 # Reset and retry
845 print('Invalid C compiler path. %s cannot be found' % host_c_compiler)
846 environ_cp['HOST_C_COMPILER'] = ''
847
848 # Set HOST_C_COMPILER
849 environ_cp['HOST_C_COMPILER'] = host_c_compiler
850 write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler)
851
852
853def set_computecpp_toolkit_path(environ_cp):
854 """Set COMPUTECPP_TOOLKIT_PATH."""
855 ask_computecpp_toolkit_path = ('Please specify the location where ComputeCpp '
856 'for SYCL %s is installed. [Default is %s]: '
857 ) % (_TF_OPENCL_VERSION,
858 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
859
860 while True:
861 computecpp_toolkit_path = get_from_env_or_user_or_default(
862 environ_cp, 'COMPUTECPP_TOOLKIT_PATH', ask_computecpp_toolkit_path,
863 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
864 if is_linux():
865 sycl_rt_lib_path = 'lib/libComputeCpp.so'
866 else:
867 sycl_rt_lib_path = ''
868
869 sycl_rt_lib_path_full = os.path.join(computecpp_toolkit_path,
870 sycl_rt_lib_path)
871 if os.path.exists(sycl_rt_lib_path_full):
872 break
873
874 print('Invalid SYCL %s library path. %s cannot be found' %
875 (_TF_OPENCL_VERSION, sycl_rt_lib_path_full))
876 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = ''
877
878 # Set COMPUTECPP_TOOLKIT_PATH
879 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = computecpp_toolkit_path
880 write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH',
881 computecpp_toolkit_path)
882
883
884def set_mpi_home(environ_cp):
885 """Set MPI_HOME."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700886 default_mpi_home = which('mpirun') or which('mpiexec') or ''
887 default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home))
888
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700889 ask_mpi_home = ('Please specify the MPI toolkit folder. [Default is %s]: '
890 ) % default_mpi_home
891 while True:
892 mpi_home = get_from_env_or_user_or_default(environ_cp, 'MPI_HOME',
893 ask_mpi_home, default_mpi_home)
894
895 if os.path.exists(os.path.join(mpi_home, 'include')) and os.path.exists(
896 os.path.join(mpi_home, 'lib')):
897 break
898
899 print('Invalid path to the MPI Toolkit. %s or %s cannot be found' %
900 (os.path.join(mpi_home, 'include'),
901 os.path.exists(os.path.join(mpi_home, 'lib'))))
902 environ_cp['MPI_HOME'] = ''
903
904 # Set MPI_HOME
905 environ_cp['MPI_HOME'] = str(mpi_home)
906
907
908def set_other_mpi_vars(environ_cp):
909 """Set other MPI related variables."""
910 # Link the MPI header files
911 mpi_home = environ_cp.get('MPI_HOME')
912 symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h')
913
914 # Determine if we use OpenMPI or MVAPICH, these require different header files
915 # to be included here to make bazel dependency checker happy
916 if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')):
917 symlink_force(
918 os.path.join(mpi_home, 'include/mpi_portable_platform.h'),
919 'third_party/mpi/mpi_portable_platform.h')
920 # TODO(gunan): avoid editing files in configure
921 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False',
922 'MPI_LIB_IS_OPENMPI=True')
923 else:
924 # MVAPICH / MPICH
925 symlink_force(
926 os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h')
927 symlink_force(
928 os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h')
929 # TODO(gunan): avoid editing files in configure
930 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True',
931 'MPI_LIB_IS_OPENMPI=False')
932
933 if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')):
934 symlink_force(
935 os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so')
936 else:
937 raise ValueError('Cannot find the MPI library file in %s/lib' % mpi_home)
938
939
940def set_mkl():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700941 write_to_bazelrc('build:mkl --define using_mkl=true')
942 write_to_bazelrc('build:mkl -c opt')
943 write_to_bazelrc('build:mkl --copt="-DEIGEN_USE_VML"')
944 print(
945 'Add "--config=mkl" to your bazel command to build with MKL '
946 'support.\nPlease note that MKL on MacOS or windows is still not '
947 'supported.\nIf you would like to use a local MKL instead of '
948 'downloading, please set the environment variable \"TF_MKL_ROOT\" every '
949 'time before build.')
950
951
Allen Lavoie5c7f9e32017-09-21 11:29:45 -0700952def set_monolithic():
953 # Add --config=monolithic to your bazel command to use a mostly-static
954 # build and disable modular op registration support (this will revert to
955 # loading TensorFlow with RTLD_GLOBAL in Python). By default (without
956 # --config=monolithic), TensorFlow will build with a dependence on
957 # //tensorflow:libtensorflow_framework.so.
958 write_to_bazelrc('build:monolithic --define framework_shared_object=false')
959 # For projects which use TensorFlow as part of a Bazel build process, putting
960 # nothing in a bazelrc will default to a monolithic build. The following line
961 # opts in to modular op registration support by default:
962 write_to_bazelrc('build --define framework_shared_object=true')
963
964
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700965def main():
966 # Make a copy of os.environ to be clear when functions and getting and setting
967 # environment variables.
968 environ_cp = dict(os.environ)
969
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700970 check_bazel_version('0.5.4')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700971
972 reset_tf_configure_bazelrc()
973 cleanup_makefile()
Gunhan Gulsoyed89a2b2017-09-19 18:36:26 -0700974 setup_python(environ_cp)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700975 run_gen_git_source(environ_cp)
976
977 if is_windows():
978 environ_cp['TF_NEED_GCP'] = '0'
979 environ_cp['TF_NEED_HDFS'] = '0'
980 environ_cp['TF_NEED_JEMALLOC'] = '0'
981 environ_cp['TF_NEED_OPENCL'] = '0'
982 environ_cp['TF_CUDA_CLANG'] = '0'
983
984 if is_macos():
985 environ_cp['TF_NEED_JEMALLOC'] = '0'
986
987 set_build_var(environ_cp, 'TF_NEED_JEMALLOC', 'jemalloc as malloc',
988 'with_jemalloc', True)
989 set_build_var(environ_cp, 'TF_NEED_GCP', 'Google Cloud Platform',
Michael Case98850a52017-09-14 13:35:57 -0700990 'with_gcp_support', False, 'gcp')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700991 set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
Michael Case98850a52017-09-14 13:35:57 -0700992 'with_hdfs_support', False, 'hdfs')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700993 set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
Michael Case98850a52017-09-14 13:35:57 -0700994 False, 'xla')
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700995 set_build_var(environ_cp, 'TF_NEED_GDR', 'GDR', 'with_gdr_support',
Michael Case98850a52017-09-14 13:35:57 -0700996 False, 'gdr')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700997 set_build_var(environ_cp, 'TF_NEED_VERBS', 'VERBS', 'with_verbs_support',
Michael Case98850a52017-09-14 13:35:57 -0700998 False, 'verbs')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700999
1000 set_action_env_var(environ_cp, 'TF_NEED_OPENCL', 'OpenCL', False)
1001 if environ_cp.get('TF_NEED_OPENCL') == '1':
1002 set_host_cxx_compiler(environ_cp)
1003 set_host_c_compiler(environ_cp)
1004 set_computecpp_toolkit_path(environ_cp)
1005
1006 set_action_env_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)
A. Unique TensorFlower24cbb2a2017-09-08 07:45:44 -07001007 if (environ_cp.get('TF_NEED_CUDA') == '1' and
1008 'TF_CUDA_CONFIG_REPO' not in environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001009 set_tf_cuda_version(environ_cp)
1010 set_tf_cunn_version(environ_cp)
1011 set_tf_cuda_compute_capabilities(environ_cp)
1012
1013 set_tf_cuda_clang(environ_cp)
1014 if environ_cp.get('TF_CUDA_CLANG') == '1':
1015 # Set up which clang we should use as the cuda / host compiler.
1016 set_clang_cuda_compiler_path(environ_cp)
1017 else:
1018 # Set up which gcc nvcc should use as the host compiler
1019 # No need to set this on Windows
1020 if not is_windows():
1021 set_gcc_host_compiler_path(environ_cp)
1022 set_other_cuda_vars(environ_cp)
1023
1024 set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False)
1025 if environ_cp.get('TF_NEED_MPI') == '1':
1026 set_mpi_home(environ_cp)
1027 set_other_mpi_vars(environ_cp)
1028
1029 set_cc_opt_flags(environ_cp)
1030 set_mkl()
Allen Lavoie5c7f9e32017-09-21 11:29:45 -07001031 set_monolithic()
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001032
1033
1034if __name__ == '__main__':
1035 main()