blob: 986e7b0e2ae4bf8dbfd659ecfc47ec07259cd9c3 [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
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700178def setup_python(environ_cp, bazel_version):
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)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700232 bazel_version_int = convert_version_to_int(bazel_version)
233 version_0_5_3_int = convert_version_to_int('0.5.3')
234 # If bazel_version_int is None, we are testing a release Bazel, then the
235 # version should be higher than 0.5.3
236 # TODO(pcloudy): remove this after required min bazel version is higher
237 # than 0.5.3
238 if not bazel_version_int or bazel_version_int >= version_0_5_3_int:
239 write_to_bazelrc('build --python_path=\"%s"' % python_bin_path)
240 else:
241 write_to_bazelrc('build --python%s_path=\"%s"' % (python_major_version,
242 python_bin_path))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700243 write_to_bazelrc('test --force_python=py%s' % python_major_version)
244 write_to_bazelrc('test --host_force_python=py%s' % python_major_version)
245 write_to_bazelrc('test --define PYTHON_BIN_PATH="%s"' % python_bin_path)
246 write_to_bazelrc('test --define PYTHON_LIB_PATH="%s"' % python_lib_path)
247 write_to_bazelrc('run --define PYTHON_BIN_PATH="%s"' % python_bin_path)
248 write_to_bazelrc('run --define PYTHON_LIB_PATH="%s"' % python_lib_path)
249 environ_cp['PYTHON_BIN_PATH'] = python_bin_path
250
251 # Write tools/python_bin_path.sh
252 with open('tools/python_bin_path.sh', 'w') as f:
253 f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path)
254
255
256def reset_tf_configure_bazelrc():
257 """Reset file that contains customized config settings."""
258 open(_TF_BAZELRC, 'w').close()
259
260 home = os.path.expanduser('~')
261 if not os.path.exists('.bazelrc'):
262 if os.path.exists(os.path.join(home, '.bazelrc')):
263 with open('.bazelrc', 'a') as f:
264 f.write('import %s/.bazelrc\n' % home)
265 else:
266 open('.bazelrc', 'w').close()
267
268 remove_line_with('.bazelrc', 'tf_configure')
269 with open('.bazelrc', 'a') as f:
270 f.write('import %workspace%/.tf_configure.bazelrc\n')
271
272
273def run_gen_git_source(environ_cp):
274 """Run the gen_git_source to create links.
275
276 The links are for bazel to track dependencies for git hash propagation.
277
278 Args:
279 environ_cp: copy of the os.environ.
280 """
Vijay Vasudevana1fba7f2017-07-28 10:58:56 -0700281 cmd = '"%s" tensorflow/tools/git/gen_git_source.py --configure %s' % (
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700282 environ_cp.get('PYTHON_BIN_PATH'), os.getcwd())
283 os.system(cmd)
284
285
286def cleanup_makefile():
287 """Delete any leftover BUILD files from the Makefile build.
288
289 These files could interfere with Bazel parsing.
290 """
291 makefile_download_dir = 'tensorflow/contrib/makefile/downloads'
292 if os.path.isdir(makefile_download_dir):
293 for root, _, filenames in os.walk(makefile_download_dir):
294 for f in filenames:
295 if f.endswith('BUILD'):
296 os.remove(os.path.join(root, f))
297
298
299def get_var(environ_cp,
300 var_name,
301 query_item,
302 enabled_by_default,
303 question=None,
304 yes_reply=None,
305 no_reply=None):
306 """Get boolean input from user.
307
308 If var_name is not set in env, ask user to enable query_item or not. If the
309 response is empty, use the default.
310
311 Args:
312 environ_cp: copy of the os.environ.
313 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
314 query_item: string for feature related to the variable, e.g. "Hadoop File
315 System".
316 enabled_by_default: boolean for default behavior.
317 question: optional string for how to ask for user input.
318 yes_reply: optionanl string for reply when feature is enabled.
319 no_reply: optional string for reply when feature is disabled.
320
321 Returns:
322 boolean value of the variable.
323 """
324 if not question:
325 question = 'Do you wish to build TensorFlow with %s support?' % query_item
326 if not yes_reply:
327 yes_reply = '%s support will be enabled for TensorFlow.' % query_item
328 if not no_reply:
329 no_reply = 'No %s' % yes_reply
330
331 yes_reply += '\n'
332 no_reply += '\n'
333
334 if enabled_by_default:
335 question += ' [Y/n]: '
336 else:
337 question += ' [y/N]: '
338
339 var = environ_cp.get(var_name)
340 while var is None:
341 user_input_origin = get_input(question)
342 user_input = user_input_origin.strip().lower()
343 if user_input == 'y':
344 print(yes_reply)
345 var = True
346 elif user_input == 'n':
347 print(no_reply)
348 var = False
349 elif not user_input:
350 if enabled_by_default:
351 print(yes_reply)
352 var = True
353 else:
354 print(no_reply)
355 var = False
356 else:
357 print('Invalid selection: %s' % user_input_origin)
358 return var
359
360
361def set_build_var(environ_cp, var_name, query_item, option_name,
Michael Case98850a52017-09-14 13:35:57 -0700362 enabled_by_default, bazel_config_name=None):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700363 """Set if query_item will be enabled for the build.
364
365 Ask user if query_item will be enabled. Default is used if no input is given.
366 Set subprocess environment variable and write to .bazelrc if enabled.
367
368 Args:
369 environ_cp: copy of the os.environ.
370 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
371 query_item: string for feature related to the variable, e.g. "Hadoop File
372 System".
373 option_name: string for option to define in .bazelrc.
374 enabled_by_default: boolean for default behavior.
Michael Case98850a52017-09-14 13:35:57 -0700375 bazel_config_name: Name for Bazel --config argument to enable build feature.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700376 """
377
378 var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default)))
379 environ_cp[var_name] = var
380 if var == '1':
381 write_to_bazelrc('build --define %s=true' % option_name)
Michael Case98850a52017-09-14 13:35:57 -0700382 elif bazel_config_name is not None:
383 # TODO(mikecase): Migrate all users of configure.py to use --config Bazel
384 # options and not to set build configs through environment variables.
385 write_to_bazelrc('build:%s --define %s=true'
386 % (bazel_config_name, option_name))
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700387
388
389def set_action_env_var(environ_cp,
390 var_name,
391 query_item,
392 enabled_by_default,
393 question=None,
394 yes_reply=None,
395 no_reply=None):
396 """Set boolean action_env variable.
397
398 Ask user if query_item will be enabled. Default is used if no input is given.
399 Set environment variable and write to .bazelrc.
400
401 Args:
402 environ_cp: copy of the os.environ.
403 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
404 query_item: string for feature related to the variable, e.g. "Hadoop File
405 System".
406 enabled_by_default: boolean for default behavior.
407 question: optional string for how to ask for user input.
408 yes_reply: optionanl string for reply when feature is enabled.
409 no_reply: optional string for reply when feature is disabled.
410 """
411 var = int(
412 get_var(environ_cp, var_name, query_item, enabled_by_default, question,
413 yes_reply, no_reply))
414
415 write_action_env_to_bazelrc(var_name, var)
416 environ_cp[var_name] = str(var)
417
418
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700419def convert_version_to_int(version):
420 """Convert a version number to a integer that can be used to compare.
421
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700422 Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The
423 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.
424
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700425 Args:
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700426 version: a version to be converted
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700427
428 Returns:
429 An integer if converted successfully, otherwise return None.
430 """
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700431 version = version.split('-')[0]
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700432 version_segments = version.split('.')
433 for seg in version_segments:
434 if not seg.isdigit():
435 return None
436
437 version_str = ''.join(['%03d' % int(seg) for seg in version_segments])
438 return int(version_str)
439
440
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700441def check_bazel_version(min_version):
442 """Check installed bezel version is at least min_version.
443
444 Args:
445 min_version: string for minimum bazel version.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700446
447 Returns:
448 The bazel version detected.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700449 """
Jonathan Hseu008910f2017-08-25 14:01:05 -0700450 if which('bazel') is None:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700451 print('Cannot find bazel. Please install bazel.')
452 sys.exit(0)
Jonathan Hseu008910f2017-08-25 14:01:05 -0700453 curr_version = run_shell(['bazel', '--batch', 'version'])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700454
455 for line in curr_version.split('\n'):
456 if 'Build label: ' in line:
457 curr_version = line.split('Build label: ')[1]
458 break
459
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700460 min_version_int = convert_version_to_int(min_version)
461 curr_version_int = convert_version_to_int(curr_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700462
463 # Check if current bazel version can be detected properly.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700464 if not curr_version_int:
465 print('WARNING: current bazel installation is not a release version.')
466 print('Make sure you are running at least bazel %s' % min_version)
467 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700468
Michael Cased94271a2017-08-22 17:26:52 -0700469 print('You have bazel %s installed.' % curr_version)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700470
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700471 if curr_version_int < min_version_int:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700472 print('Please upgrade your bazel installation to version %s or higher to '
473 'build TensorFlow!' % min_version)
474 sys.exit(0)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700475 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700476
477
478def set_cc_opt_flags(environ_cp):
479 """Set up architecture-dependent optimization flags.
480
481 Also append CC optimization flags to bazel.rc..
482
483 Args:
484 environ_cp: copy of the os.environ.
485 """
486 if is_ppc64le():
487 # gcc on ppc64le does not support -march, use mcpu instead
488 default_cc_opt_flags = '-mcpu=native'
489 else:
490 default_cc_opt_flags = '-march=native'
491 question = ('Please specify optimization flags to use during compilation when'
492 ' bazel option "--config=opt" is specified [Default is %s]: '
493 ) % default_cc_opt_flags
494 cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',
495 question, default_cc_opt_flags)
496 for opt in cc_opt_flags.split():
497 write_to_bazelrc('build:opt --cxxopt=%s --copt=%s' % (opt, opt))
498
499
500def set_tf_cuda_clang(environ_cp):
501 """set TF_CUDA_CLANG action_env.
502
503 Args:
504 environ_cp: copy of the os.environ.
505 """
506 question = 'Do you want to use clang as CUDA compiler?'
507 yes_reply = 'Clang will be used as CUDA compiler.'
508 no_reply = 'nvcc will be used as CUDA compiler.'
509 set_action_env_var(
510 environ_cp,
511 'TF_CUDA_CLANG',
512 None,
513 False,
514 question=question,
515 yes_reply=yes_reply,
516 no_reply=no_reply)
517
518
519def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
520 var_default):
521 """Get var_name either from env, or user or default.
522
523 If var_name has been set as environment variable, use the preset value, else
524 ask for user input. If no input is provided, the default is used.
525
526 Args:
527 environ_cp: copy of the os.environ.
528 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
529 ask_for_var: string for how to ask for user input.
530 var_default: default value string.
531
532 Returns:
533 string value for var_name
534 """
535 var = environ_cp.get(var_name)
536 if not var:
537 var = get_input(ask_for_var)
Michael Cased94271a2017-08-22 17:26:52 -0700538 print('\n')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700539 if not var:
540 var = var_default
541 return var
542
543
544def set_clang_cuda_compiler_path(environ_cp):
545 """Set CLANG_CUDA_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700546 default_clang_path = which('clang') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700547 ask_clang_path = ('Please specify which clang should be used as device and '
548 'host compiler. [Default is %s]: ') % default_clang_path
549
550 while True:
551 clang_cuda_compiler_path = get_from_env_or_user_or_default(
552 environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path,
553 default_clang_path)
554 if os.path.exists(clang_cuda_compiler_path):
555 break
556
557 # Reset and retry
558 print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path)
559 environ_cp['CLANG_CUDA_COMPILER_PATH'] = ''
560
561 # Set CLANG_CUDA_COMPILER_PATH
562 environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path
563 write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',
564 clang_cuda_compiler_path)
565
566
567def set_gcc_host_compiler_path(environ_cp):
568 """Set GCC_HOST_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700569 default_gcc_host_compiler_path = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700570 cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH')
571
572 if os.path.islink(cuda_bin_symlink):
573 # os.readlink is only available in linux
Jonathan Hseu008910f2017-08-25 14:01:05 -0700574 default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700575
576 ask_gcc_path = (
577 'Please specify which gcc should be used by nvcc as the '
578 'host compiler. [Default is %s]: ') % default_gcc_host_compiler_path
579 while True:
580 gcc_host_compiler_path = get_from_env_or_user_or_default(
581 environ_cp, 'GCC_HOST_COMPILER_PATH', ask_gcc_path,
582 default_gcc_host_compiler_path)
583
584 if os.path.exists(gcc_host_compiler_path):
585 break
586
587 # Reset and retry
588 print('Invalid gcc path. %s cannot be found' % gcc_host_compiler_path)
589 environ_cp['GCC_HOST_COMPILER_PATH'] = ''
590
591 # Set GCC_HOST_COMPILER_PATH
592 environ_cp['GCC_HOST_COMPILER_PATH'] = gcc_host_compiler_path
593 write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)
594
595
596def set_tf_cuda_version(environ_cp):
597 """Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION."""
598 ask_cuda_version = (
599 'Please specify the CUDA SDK version you want to use, '
600 'e.g. 7.0. [Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
601
602 while True:
603 # Configure the Cuda SDK version to use.
604 tf_cuda_version = get_from_env_or_user_or_default(
605 environ_cp, 'TF_CUDA_VERSION', ask_cuda_version, _DEFAULT_CUDA_VERSION)
606
607 # Find out where the CUDA toolkit is installed
608 default_cuda_path = _DEFAULT_CUDA_PATH
Martin Wicked57572e2017-09-02 19:21:45 -0700609 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700610 default_cuda_path = cygpath(
611 environ_cp.get('CUDA_PATH', _DEFAULT_CUDA_PATH_WIN))
612 elif is_linux():
613 # If the default doesn't exist, try an alternative default.
614 if (not os.path.exists(default_cuda_path)
615 ) and os.path.exists(_DEFAULT_CUDA_PATH_LINUX):
616 default_cuda_path = _DEFAULT_CUDA_PATH_LINUX
617 ask_cuda_path = ('Please specify the location where CUDA %s toolkit is'
618 ' installed. Refer to README.md for more details. '
619 '[Default is %s]: ') % (tf_cuda_version, default_cuda_path)
620 cuda_toolkit_path = get_from_env_or_user_or_default(
621 environ_cp, 'CUDA_TOOLKIT_PATH', ask_cuda_path, default_cuda_path)
622
623 if is_windows():
624 cuda_rt_lib_path = 'lib/x64/cudart.lib'
625 elif is_linux():
626 cuda_rt_lib_path = 'lib64/libcudart.so.%s' % tf_cuda_version
627 elif is_macos():
628 cuda_rt_lib_path = 'lib/libcudart.%s.dylib' % tf_cuda_version
629
630 cuda_toolkit_path_full = os.path.join(cuda_toolkit_path, cuda_rt_lib_path)
631 if os.path.exists(cuda_toolkit_path_full):
632 break
633
634 # Reset and retry
635 print('Invalid path to CUDA %s toolkit. %s cannot be found' %
636 (tf_cuda_version, cuda_toolkit_path_full))
637 environ_cp['TF_CUDA_VERSION'] = ''
638 environ_cp['CUDA_TOOLKIT_PATH'] = ''
639
640 # Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION
641 environ_cp['CUDA_TOOLKIT_PATH'] = cuda_toolkit_path
642 write_action_env_to_bazelrc('CUDA_TOOLKIT_PATH', cuda_toolkit_path)
643 environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
644 write_action_env_to_bazelrc('TF_CUDA_VERSION', tf_cuda_version)
645
646
647def set_tf_cunn_version(environ_cp):
648 """Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION."""
649 ask_cudnn_version = (
Jonathan Hseu008910f2017-08-25 14:01:05 -0700650 'Please specify the cuDNN version you want to use. '
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700651 '[Leave empty to default to cuDNN %s.0]: ') % _DEFAULT_CUDNN_VERSION
652
653 while True:
654 tf_cudnn_version = get_from_env_or_user_or_default(
655 environ_cp, 'TF_CUDNN_VERSION', ask_cudnn_version,
656 _DEFAULT_CUDNN_VERSION)
657
658 default_cudnn_path = environ_cp.get('CUDA_TOOLKIT_PATH')
659 ask_cudnn_path = (r'Please specify the location where cuDNN %s library is '
660 'installed. Refer to README.md for more details. [Default'
661 ' is %s]:') % (tf_cudnn_version, default_cudnn_path)
662 cudnn_install_path = get_from_env_or_user_or_default(
663 environ_cp, 'CUDNN_INSTALL_PATH', ask_cudnn_path, default_cudnn_path)
664
665 # Result returned from "read" will be used unexpanded. That make "~"
666 # unusable. Going through one more level of expansion to handle that.
667 cudnn_install_path = os.path.realpath(
668 os.path.expanduser(cudnn_install_path))
Martin Wicked57572e2017-09-02 19:21:45 -0700669 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700670 cudnn_install_path = cygpath(cudnn_install_path)
671
672 if is_windows():
673 cuda_dnn_lib_path = 'lib/x64/cudnn.lib'
674 cuda_dnn_lib_alt_path = 'lib/x64/cudnn.lib'
675 elif is_linux():
676 cuda_dnn_lib_path = 'lib64/libcudnn.so.%s' % tf_cudnn_version
677 cuda_dnn_lib_alt_path = 'libcudnn.so.%s' % tf_cudnn_version
678 elif is_macos():
679 cuda_dnn_lib_path = 'lib/libcudnn.%s.dylib' % tf_cudnn_version
680 cuda_dnn_lib_alt_path = 'libcudnn.%s.dylib' % tf_cudnn_version
681
682 cuda_dnn_lib_path_full = os.path.join(cudnn_install_path, cuda_dnn_lib_path)
683 cuda_dnn_lib_alt_path_full = os.path.join(cudnn_install_path,
684 cuda_dnn_lib_alt_path)
685 if os.path.exists(cuda_dnn_lib_path_full) or os.path.exists(
686 cuda_dnn_lib_alt_path_full):
687 break
688
689 # Try another alternative for Linux
690 if is_linux():
Jonathan Hseu008910f2017-08-25 14:01:05 -0700691 ldconfig_bin = which('ldconfig') or '/sbin/ldconfig'
692 cudnn_path_from_ldconfig = run_shell([ldconfig_bin, '-p'])
693 cudnn_path_from_ldconfig = re.search('.*libcudnn.so .* => (.*)',
A. Unique TensorFlowere7223582017-09-06 17:57:04 -0700694 cudnn_path_from_ldconfig)
695 if cudnn_path_from_ldconfig:
696 cudnn_path_from_ldconfig = cudnn_path_from_ldconfig.group(1)
697 if os.path.exists('%s.%s' % (cudnn_path_from_ldconfig,
698 tf_cudnn_version)):
699 cudnn_install_path = os.path.dirname(cudnn_path_from_ldconfig)
700 break
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700701
702 # Reset and Retry
703 print(
704 'Invalid path to cuDNN %s toolkit. None of the following files can be '
705 'found:' % tf_cudnn_version)
706 print(cuda_dnn_lib_path_full)
707 print(cuda_dnn_lib_alt_path_full)
708 if is_linux():
709 print('%s.%s' % (cudnn_path_from_ldconfig, tf_cudnn_version))
710
711 environ_cp['TF_CUDNN_VERSION'] = ''
712
713 # Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION
714 environ_cp['CUDNN_INSTALL_PATH'] = cudnn_install_path
715 write_action_env_to_bazelrc('CUDNN_INSTALL_PATH', cudnn_install_path)
716 environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
717 write_action_env_to_bazelrc('TF_CUDNN_VERSION', tf_cudnn_version)
718
719
720def get_native_cuda_compute_capabilities(environ_cp):
721 """Get native cuda compute capabilities.
722
723 Args:
724 environ_cp: copy of the os.environ.
725 Returns:
726 string of native cuda compute capabilities, separated by comma.
727 """
728 device_query_bin = os.path.join(
729 environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery')
Jonathan Hseu008910f2017-08-25 14:01:05 -0700730 if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK):
731 try:
732 output = run_shell(device_query_bin).split('\n')
733 pattern = re.compile('[0-9]*\\.[0-9]*')
734 output = [pattern.search(x) for x in output if 'Capability' in x]
735 output = ','.join(x.group() for x in output if x is not None)
736 except subprocess.CalledProcessError:
737 output = ''
738 else:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700739 output = ''
740 return output
741
742
743def set_tf_cuda_compute_capabilities(environ_cp):
744 """Set TF_CUDA_COMPUTE_CAPABILITIES."""
745 while True:
746 native_cuda_compute_capabilities = get_native_cuda_compute_capabilities(
747 environ_cp)
748 if not native_cuda_compute_capabilities:
749 default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES
750 else:
751 default_cuda_compute_capabilities = native_cuda_compute_capabilities
752
753 ask_cuda_compute_capabilities = (
754 'Please specify a list of comma-separated '
755 'Cuda compute capabilities you want to '
756 'build with.\nYou can find the compute '
757 'capability of your device at: '
758 'https://developer.nvidia.com/cuda-gpus.\nPlease'
759 ' note that each additional compute '
760 'capability significantly increases your '
761 'build time and binary size. [Default is: %s]' %
762 default_cuda_compute_capabilities)
763 tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
764 environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
765 ask_cuda_compute_capabilities, default_cuda_compute_capabilities)
766 # Check whether all capabilities from the input is valid
767 all_valid = True
768 for compute_capability in tf_cuda_compute_capabilities.split(','):
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700769 m = re.match('[0-9]+.[0-9]+', compute_capability)
770 if not m:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700771 print('Invalid compute capability: ' % compute_capability)
772 all_valid = False
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700773 else:
774 ver = int(m.group(0).split('.')[0])
775 if ver < 3:
776 print('Only compute capabilities 3.0 or higher are supported.')
777 all_valid = False
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700778
779 if all_valid:
780 break
781
782 # Reset and Retry
783 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = ''
784
785 # Set TF_CUDA_COMPUTE_CAPABILITIES
786 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities
787 write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES',
788 tf_cuda_compute_capabilities)
789
790
791def set_other_cuda_vars(environ_cp):
792 """Set other CUDA related variables."""
793 if is_windows():
794 # The following three variables are needed for MSVC toolchain configuration
795 # in Bazel
796 environ_cp['CUDA_PATH'] = environ_cp.get('CUDA_TOOLKIT_PATH')
797 environ_cp['CUDA_COMPUTE_CAPABILITIES'] = environ_cp.get(
798 'TF_CUDA_COMPUTE_CAPABILITIES')
799 environ_cp['NO_WHOLE_ARCHIVE_OPTION'] = 1
800 write_action_env_to_bazelrc('CUDA_PATH', environ_cp.get('CUDA_PATH'))
801 write_action_env_to_bazelrc('CUDA_COMPUTE_CAPABILITIE',
802 environ_cp.get('CUDA_COMPUTE_CAPABILITIE'))
803 write_action_env_to_bazelrc('NO_WHOLE_ARCHIVE_OPTION',
804 environ_cp.get('NO_WHOLE_ARCHIVE_OPTION'))
805 write_to_bazelrc('build --config=win-cuda')
806 write_to_bazelrc('test --config=win-cuda')
807 else:
808 # If CUDA is enabled, always use GPU during build and test.
809 if environ_cp.get('TF_CUDA_CLANG') == '1':
810 write_to_bazelrc('build --config=cuda_clang')
811 write_to_bazelrc('test --config=cuda_clang')
812 else:
813 write_to_bazelrc('build --config=cuda')
814 write_to_bazelrc('test --config=cuda')
815
816
817def set_host_cxx_compiler(environ_cp):
818 """Set HOST_CXX_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700819 default_cxx_host_compiler = which('g++') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700820 ask_cxx_host_compiler = (
821 'Please specify which C++ compiler should be used as'
822 ' the host C++ compiler. [Default is %s]: ') % default_cxx_host_compiler
823
824 while True:
825 host_cxx_compiler = get_from_env_or_user_or_default(
826 environ_cp, 'HOST_CXX_COMPILER', ask_cxx_host_compiler,
827 default_cxx_host_compiler)
828 if os.path.exists(host_cxx_compiler):
829 break
830
831 # Reset and retry
832 print('Invalid C++ compiler path. %s cannot be found' % host_cxx_compiler)
833 environ_cp['HOST_CXX_COMPILER'] = ''
834
835 # Set HOST_CXX_COMPILER
836 environ_cp['HOST_CXX_COMPILER'] = host_cxx_compiler
837 write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler)
838
839
840def set_host_c_compiler(environ_cp):
841 """Set HOST_C_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700842 default_c_host_compiler = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700843 ask_c_host_compiler = (
844 'Please specify which C compiler should be used as the'
845 ' host C compiler. [Default is %s]: ') % default_c_host_compiler
846
847 while True:
848 host_c_compiler = get_from_env_or_user_or_default(
849 environ_cp, 'HOST_C_COMPILER', ask_c_host_compiler,
850 default_c_host_compiler)
851 if os.path.exists(host_c_compiler):
852 break
853
854 # Reset and retry
855 print('Invalid C compiler path. %s cannot be found' % host_c_compiler)
856 environ_cp['HOST_C_COMPILER'] = ''
857
858 # Set HOST_C_COMPILER
859 environ_cp['HOST_C_COMPILER'] = host_c_compiler
860 write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler)
861
862
863def set_computecpp_toolkit_path(environ_cp):
864 """Set COMPUTECPP_TOOLKIT_PATH."""
865 ask_computecpp_toolkit_path = ('Please specify the location where ComputeCpp '
866 'for SYCL %s is installed. [Default is %s]: '
867 ) % (_TF_OPENCL_VERSION,
868 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
869
870 while True:
871 computecpp_toolkit_path = get_from_env_or_user_or_default(
872 environ_cp, 'COMPUTECPP_TOOLKIT_PATH', ask_computecpp_toolkit_path,
873 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
874 if is_linux():
875 sycl_rt_lib_path = 'lib/libComputeCpp.so'
876 else:
877 sycl_rt_lib_path = ''
878
879 sycl_rt_lib_path_full = os.path.join(computecpp_toolkit_path,
880 sycl_rt_lib_path)
881 if os.path.exists(sycl_rt_lib_path_full):
882 break
883
884 print('Invalid SYCL %s library path. %s cannot be found' %
885 (_TF_OPENCL_VERSION, sycl_rt_lib_path_full))
886 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = ''
887
888 # Set COMPUTECPP_TOOLKIT_PATH
889 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = computecpp_toolkit_path
890 write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH',
891 computecpp_toolkit_path)
892
893
894def set_mpi_home(environ_cp):
895 """Set MPI_HOME."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700896 default_mpi_home = which('mpirun') or which('mpiexec') or ''
897 default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home))
898
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700899 ask_mpi_home = ('Please specify the MPI toolkit folder. [Default is %s]: '
900 ) % default_mpi_home
901 while True:
902 mpi_home = get_from_env_or_user_or_default(environ_cp, 'MPI_HOME',
903 ask_mpi_home, default_mpi_home)
904
905 if os.path.exists(os.path.join(mpi_home, 'include')) and os.path.exists(
906 os.path.join(mpi_home, 'lib')):
907 break
908
909 print('Invalid path to the MPI Toolkit. %s or %s cannot be found' %
910 (os.path.join(mpi_home, 'include'),
911 os.path.exists(os.path.join(mpi_home, 'lib'))))
912 environ_cp['MPI_HOME'] = ''
913
914 # Set MPI_HOME
915 environ_cp['MPI_HOME'] = str(mpi_home)
916
917
918def set_other_mpi_vars(environ_cp):
919 """Set other MPI related variables."""
920 # Link the MPI header files
921 mpi_home = environ_cp.get('MPI_HOME')
922 symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h')
923
924 # Determine if we use OpenMPI or MVAPICH, these require different header files
925 # to be included here to make bazel dependency checker happy
926 if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')):
927 symlink_force(
928 os.path.join(mpi_home, 'include/mpi_portable_platform.h'),
929 'third_party/mpi/mpi_portable_platform.h')
930 # TODO(gunan): avoid editing files in configure
931 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False',
932 'MPI_LIB_IS_OPENMPI=True')
933 else:
934 # MVAPICH / MPICH
935 symlink_force(
936 os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h')
937 symlink_force(
938 os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h')
939 # TODO(gunan): avoid editing files in configure
940 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True',
941 'MPI_LIB_IS_OPENMPI=False')
942
943 if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')):
944 symlink_force(
945 os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so')
946 else:
947 raise ValueError('Cannot find the MPI library file in %s/lib' % mpi_home)
948
949
950def set_mkl():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700951 write_to_bazelrc('build:mkl --define using_mkl=true')
952 write_to_bazelrc('build:mkl -c opt')
953 write_to_bazelrc('build:mkl --copt="-DEIGEN_USE_VML"')
954 print(
955 'Add "--config=mkl" to your bazel command to build with MKL '
956 'support.\nPlease note that MKL on MacOS or windows is still not '
957 'supported.\nIf you would like to use a local MKL instead of '
958 'downloading, please set the environment variable \"TF_MKL_ROOT\" every '
959 'time before build.')
960
961
962def main():
963 # Make a copy of os.environ to be clear when functions and getting and setting
964 # environment variables.
965 environ_cp = dict(os.environ)
966
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700967 bazel_version = check_bazel_version('0.4.5')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700968
969 reset_tf_configure_bazelrc()
970 cleanup_makefile()
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700971 setup_python(environ_cp, bazel_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700972 run_gen_git_source(environ_cp)
973
974 if is_windows():
975 environ_cp['TF_NEED_GCP'] = '0'
976 environ_cp['TF_NEED_HDFS'] = '0'
977 environ_cp['TF_NEED_JEMALLOC'] = '0'
978 environ_cp['TF_NEED_OPENCL'] = '0'
979 environ_cp['TF_CUDA_CLANG'] = '0'
980
981 if is_macos():
982 environ_cp['TF_NEED_JEMALLOC'] = '0'
983
984 set_build_var(environ_cp, 'TF_NEED_JEMALLOC', 'jemalloc as malloc',
985 'with_jemalloc', True)
986 set_build_var(environ_cp, 'TF_NEED_GCP', 'Google Cloud Platform',
Michael Case98850a52017-09-14 13:35:57 -0700987 'with_gcp_support', False, 'gcp')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700988 set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
Michael Case98850a52017-09-14 13:35:57 -0700989 'with_hdfs_support', False, 'hdfs')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700990 set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
Michael Case98850a52017-09-14 13:35:57 -0700991 False, 'xla')
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700992 set_build_var(environ_cp, 'TF_NEED_GDR', 'GDR', 'with_gdr_support',
Michael Case98850a52017-09-14 13:35:57 -0700993 False, 'gdr')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700994 set_build_var(environ_cp, 'TF_NEED_VERBS', 'VERBS', 'with_verbs_support',
Michael Case98850a52017-09-14 13:35:57 -0700995 False, 'verbs')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700996
997 set_action_env_var(environ_cp, 'TF_NEED_OPENCL', 'OpenCL', False)
998 if environ_cp.get('TF_NEED_OPENCL') == '1':
999 set_host_cxx_compiler(environ_cp)
1000 set_host_c_compiler(environ_cp)
1001 set_computecpp_toolkit_path(environ_cp)
1002
1003 set_action_env_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)
A. Unique TensorFlower24cbb2a2017-09-08 07:45:44 -07001004 if (environ_cp.get('TF_NEED_CUDA') == '1' and
1005 'TF_CUDA_CONFIG_REPO' not in environ_cp):
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -07001006 set_tf_cuda_version(environ_cp)
1007 set_tf_cunn_version(environ_cp)
1008 set_tf_cuda_compute_capabilities(environ_cp)
1009
1010 set_tf_cuda_clang(environ_cp)
1011 if environ_cp.get('TF_CUDA_CLANG') == '1':
1012 # Set up which clang we should use as the cuda / host compiler.
1013 set_clang_cuda_compiler_path(environ_cp)
1014 else:
1015 # Set up which gcc nvcc should use as the host compiler
1016 # No need to set this on Windows
1017 if not is_windows():
1018 set_gcc_host_compiler_path(environ_cp)
1019 set_other_cuda_vars(environ_cp)
1020
1021 set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False)
1022 if environ_cp.get('TF_NEED_MPI') == '1':
1023 set_mpi_home(environ_cp)
1024 set_other_mpi_vars(environ_cp)
1025
1026 set_cc_opt_flags(environ_cp)
1027 set_mkl()
1028
1029
1030if __name__ == '__main__':
1031 main()