blob: ef5051d275e5b1a7c1d06e6cfec3dc00fc1305e2 [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,
362 enabled_by_default):
363 """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.
375 """
376
377 var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default)))
378 environ_cp[var_name] = var
379 if var == '1':
380 write_to_bazelrc('build --define %s=true' % option_name)
381
382
383def set_action_env_var(environ_cp,
384 var_name,
385 query_item,
386 enabled_by_default,
387 question=None,
388 yes_reply=None,
389 no_reply=None):
390 """Set boolean action_env variable.
391
392 Ask user if query_item will be enabled. Default is used if no input is given.
393 Set environment variable and write to .bazelrc.
394
395 Args:
396 environ_cp: copy of the os.environ.
397 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
398 query_item: string for feature related to the variable, e.g. "Hadoop File
399 System".
400 enabled_by_default: boolean for default behavior.
401 question: optional string for how to ask for user input.
402 yes_reply: optionanl string for reply when feature is enabled.
403 no_reply: optional string for reply when feature is disabled.
404 """
405 var = int(
406 get_var(environ_cp, var_name, query_item, enabled_by_default, question,
407 yes_reply, no_reply))
408
409 write_action_env_to_bazelrc(var_name, var)
410 environ_cp[var_name] = str(var)
411
412
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700413def convert_version_to_int(version):
414 """Convert a version number to a integer that can be used to compare.
415
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700416 Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The
417 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored.
418
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700419 Args:
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700420 version: a version to be converted
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700421
422 Returns:
423 An integer if converted successfully, otherwise return None.
424 """
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700425 version = version.split('-')[0]
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700426 version_segments = version.split('.')
427 for seg in version_segments:
428 if not seg.isdigit():
429 return None
430
431 version_str = ''.join(['%03d' % int(seg) for seg in version_segments])
432 return int(version_str)
433
434
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700435def check_bazel_version(min_version):
436 """Check installed bezel version is at least min_version.
437
438 Args:
439 min_version: string for minimum bazel version.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700440
441 Returns:
442 The bazel version detected.
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700443 """
Jonathan Hseu008910f2017-08-25 14:01:05 -0700444 if which('bazel') is None:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700445 print('Cannot find bazel. Please install bazel.')
446 sys.exit(0)
Jonathan Hseu008910f2017-08-25 14:01:05 -0700447 curr_version = run_shell(['bazel', '--batch', 'version'])
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700448
449 for line in curr_version.split('\n'):
450 if 'Build label: ' in line:
451 curr_version = line.split('Build label: ')[1]
452 break
453
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700454 min_version_int = convert_version_to_int(min_version)
455 curr_version_int = convert_version_to_int(curr_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700456
457 # Check if current bazel version can be detected properly.
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700458 if not curr_version_int:
459 print('WARNING: current bazel installation is not a release version.')
460 print('Make sure you are running at least bazel %s' % min_version)
461 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700462
Michael Cased94271a2017-08-22 17:26:52 -0700463 print('You have bazel %s installed.' % curr_version)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700464
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700465 if curr_version_int < min_version_int:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700466 print('Please upgrade your bazel installation to version %s or higher to '
467 'build TensorFlow!' % min_version)
468 sys.exit(0)
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700469 return curr_version
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700470
471
472def set_cc_opt_flags(environ_cp):
473 """Set up architecture-dependent optimization flags.
474
475 Also append CC optimization flags to bazel.rc..
476
477 Args:
478 environ_cp: copy of the os.environ.
479 """
480 if is_ppc64le():
481 # gcc on ppc64le does not support -march, use mcpu instead
482 default_cc_opt_flags = '-mcpu=native'
483 else:
484 default_cc_opt_flags = '-march=native'
485 question = ('Please specify optimization flags to use during compilation when'
486 ' bazel option "--config=opt" is specified [Default is %s]: '
487 ) % default_cc_opt_flags
488 cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS',
489 question, default_cc_opt_flags)
490 for opt in cc_opt_flags.split():
491 write_to_bazelrc('build:opt --cxxopt=%s --copt=%s' % (opt, opt))
492
493
494def set_tf_cuda_clang(environ_cp):
495 """set TF_CUDA_CLANG action_env.
496
497 Args:
498 environ_cp: copy of the os.environ.
499 """
500 question = 'Do you want to use clang as CUDA compiler?'
501 yes_reply = 'Clang will be used as CUDA compiler.'
502 no_reply = 'nvcc will be used as CUDA compiler.'
503 set_action_env_var(
504 environ_cp,
505 'TF_CUDA_CLANG',
506 None,
507 False,
508 question=question,
509 yes_reply=yes_reply,
510 no_reply=no_reply)
511
512
513def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var,
514 var_default):
515 """Get var_name either from env, or user or default.
516
517 If var_name has been set as environment variable, use the preset value, else
518 ask for user input. If no input is provided, the default is used.
519
520 Args:
521 environ_cp: copy of the os.environ.
522 var_name: string for name of environment variable, e.g. "TF_NEED_HDFS".
523 ask_for_var: string for how to ask for user input.
524 var_default: default value string.
525
526 Returns:
527 string value for var_name
528 """
529 var = environ_cp.get(var_name)
530 if not var:
531 var = get_input(ask_for_var)
Michael Cased94271a2017-08-22 17:26:52 -0700532 print('\n')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700533 if not var:
534 var = var_default
535 return var
536
537
538def set_clang_cuda_compiler_path(environ_cp):
539 """Set CLANG_CUDA_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700540 default_clang_path = which('clang') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700541 ask_clang_path = ('Please specify which clang should be used as device and '
542 'host compiler. [Default is %s]: ') % default_clang_path
543
544 while True:
545 clang_cuda_compiler_path = get_from_env_or_user_or_default(
546 environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path,
547 default_clang_path)
548 if os.path.exists(clang_cuda_compiler_path):
549 break
550
551 # Reset and retry
552 print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path)
553 environ_cp['CLANG_CUDA_COMPILER_PATH'] = ''
554
555 # Set CLANG_CUDA_COMPILER_PATH
556 environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path
557 write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH',
558 clang_cuda_compiler_path)
559
560
561def set_gcc_host_compiler_path(environ_cp):
562 """Set GCC_HOST_COMPILER_PATH."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700563 default_gcc_host_compiler_path = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700564 cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH')
565
566 if os.path.islink(cuda_bin_symlink):
567 # os.readlink is only available in linux
Jonathan Hseu008910f2017-08-25 14:01:05 -0700568 default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700569
570 ask_gcc_path = (
571 'Please specify which gcc should be used by nvcc as the '
572 'host compiler. [Default is %s]: ') % default_gcc_host_compiler_path
573 while True:
574 gcc_host_compiler_path = get_from_env_or_user_or_default(
575 environ_cp, 'GCC_HOST_COMPILER_PATH', ask_gcc_path,
576 default_gcc_host_compiler_path)
577
578 if os.path.exists(gcc_host_compiler_path):
579 break
580
581 # Reset and retry
582 print('Invalid gcc path. %s cannot be found' % gcc_host_compiler_path)
583 environ_cp['GCC_HOST_COMPILER_PATH'] = ''
584
585 # Set GCC_HOST_COMPILER_PATH
586 environ_cp['GCC_HOST_COMPILER_PATH'] = gcc_host_compiler_path
587 write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path)
588
589
590def set_tf_cuda_version(environ_cp):
591 """Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION."""
592 ask_cuda_version = (
593 'Please specify the CUDA SDK version you want to use, '
594 'e.g. 7.0. [Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION
595
596 while True:
597 # Configure the Cuda SDK version to use.
598 tf_cuda_version = get_from_env_or_user_or_default(
599 environ_cp, 'TF_CUDA_VERSION', ask_cuda_version, _DEFAULT_CUDA_VERSION)
600
601 # Find out where the CUDA toolkit is installed
602 default_cuda_path = _DEFAULT_CUDA_PATH
Martin Wicked57572e2017-09-02 19:21:45 -0700603 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700604 default_cuda_path = cygpath(
605 environ_cp.get('CUDA_PATH', _DEFAULT_CUDA_PATH_WIN))
606 elif is_linux():
607 # If the default doesn't exist, try an alternative default.
608 if (not os.path.exists(default_cuda_path)
609 ) and os.path.exists(_DEFAULT_CUDA_PATH_LINUX):
610 default_cuda_path = _DEFAULT_CUDA_PATH_LINUX
611 ask_cuda_path = ('Please specify the location where CUDA %s toolkit is'
612 ' installed. Refer to README.md for more details. '
613 '[Default is %s]: ') % (tf_cuda_version, default_cuda_path)
614 cuda_toolkit_path = get_from_env_or_user_or_default(
615 environ_cp, 'CUDA_TOOLKIT_PATH', ask_cuda_path, default_cuda_path)
616
617 if is_windows():
618 cuda_rt_lib_path = 'lib/x64/cudart.lib'
619 elif is_linux():
620 cuda_rt_lib_path = 'lib64/libcudart.so.%s' % tf_cuda_version
621 elif is_macos():
622 cuda_rt_lib_path = 'lib/libcudart.%s.dylib' % tf_cuda_version
623
624 cuda_toolkit_path_full = os.path.join(cuda_toolkit_path, cuda_rt_lib_path)
625 if os.path.exists(cuda_toolkit_path_full):
626 break
627
628 # Reset and retry
629 print('Invalid path to CUDA %s toolkit. %s cannot be found' %
630 (tf_cuda_version, cuda_toolkit_path_full))
631 environ_cp['TF_CUDA_VERSION'] = ''
632 environ_cp['CUDA_TOOLKIT_PATH'] = ''
633
634 # Set CUDA_TOOLKIT_PATH and TF_CUDA_VERSION
635 environ_cp['CUDA_TOOLKIT_PATH'] = cuda_toolkit_path
636 write_action_env_to_bazelrc('CUDA_TOOLKIT_PATH', cuda_toolkit_path)
637 environ_cp['TF_CUDA_VERSION'] = tf_cuda_version
638 write_action_env_to_bazelrc('TF_CUDA_VERSION', tf_cuda_version)
639
640
641def set_tf_cunn_version(environ_cp):
642 """Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION."""
643 ask_cudnn_version = (
Jonathan Hseu008910f2017-08-25 14:01:05 -0700644 'Please specify the cuDNN version you want to use. '
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700645 '[Leave empty to default to cuDNN %s.0]: ') % _DEFAULT_CUDNN_VERSION
646
647 while True:
648 tf_cudnn_version = get_from_env_or_user_or_default(
649 environ_cp, 'TF_CUDNN_VERSION', ask_cudnn_version,
650 _DEFAULT_CUDNN_VERSION)
651
652 default_cudnn_path = environ_cp.get('CUDA_TOOLKIT_PATH')
653 ask_cudnn_path = (r'Please specify the location where cuDNN %s library is '
654 'installed. Refer to README.md for more details. [Default'
655 ' is %s]:') % (tf_cudnn_version, default_cudnn_path)
656 cudnn_install_path = get_from_env_or_user_or_default(
657 environ_cp, 'CUDNN_INSTALL_PATH', ask_cudnn_path, default_cudnn_path)
658
659 # Result returned from "read" will be used unexpanded. That make "~"
660 # unusable. Going through one more level of expansion to handle that.
661 cudnn_install_path = os.path.realpath(
662 os.path.expanduser(cudnn_install_path))
Martin Wicked57572e2017-09-02 19:21:45 -0700663 if is_windows() or is_cygwin():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700664 cudnn_install_path = cygpath(cudnn_install_path)
665
666 if is_windows():
667 cuda_dnn_lib_path = 'lib/x64/cudnn.lib'
668 cuda_dnn_lib_alt_path = 'lib/x64/cudnn.lib'
669 elif is_linux():
670 cuda_dnn_lib_path = 'lib64/libcudnn.so.%s' % tf_cudnn_version
671 cuda_dnn_lib_alt_path = 'libcudnn.so.%s' % tf_cudnn_version
672 elif is_macos():
673 cuda_dnn_lib_path = 'lib/libcudnn.%s.dylib' % tf_cudnn_version
674 cuda_dnn_lib_alt_path = 'libcudnn.%s.dylib' % tf_cudnn_version
675
676 cuda_dnn_lib_path_full = os.path.join(cudnn_install_path, cuda_dnn_lib_path)
677 cuda_dnn_lib_alt_path_full = os.path.join(cudnn_install_path,
678 cuda_dnn_lib_alt_path)
679 if os.path.exists(cuda_dnn_lib_path_full) or os.path.exists(
680 cuda_dnn_lib_alt_path_full):
681 break
682
683 # Try another alternative for Linux
684 if is_linux():
Jonathan Hseu008910f2017-08-25 14:01:05 -0700685 ldconfig_bin = which('ldconfig') or '/sbin/ldconfig'
686 cudnn_path_from_ldconfig = run_shell([ldconfig_bin, '-p'])
687 cudnn_path_from_ldconfig = re.search('.*libcudnn.so .* => (.*)',
A. Unique TensorFlowere7223582017-09-06 17:57:04 -0700688 cudnn_path_from_ldconfig)
689 if cudnn_path_from_ldconfig:
690 cudnn_path_from_ldconfig = cudnn_path_from_ldconfig.group(1)
691 if os.path.exists('%s.%s' % (cudnn_path_from_ldconfig,
692 tf_cudnn_version)):
693 cudnn_install_path = os.path.dirname(cudnn_path_from_ldconfig)
694 break
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700695
696 # Reset and Retry
697 print(
698 'Invalid path to cuDNN %s toolkit. None of the following files can be '
699 'found:' % tf_cudnn_version)
700 print(cuda_dnn_lib_path_full)
701 print(cuda_dnn_lib_alt_path_full)
702 if is_linux():
703 print('%s.%s' % (cudnn_path_from_ldconfig, tf_cudnn_version))
704
705 environ_cp['TF_CUDNN_VERSION'] = ''
706
707 # Set CUDNN_INSTALL_PATH and TF_CUDNN_VERSION
708 environ_cp['CUDNN_INSTALL_PATH'] = cudnn_install_path
709 write_action_env_to_bazelrc('CUDNN_INSTALL_PATH', cudnn_install_path)
710 environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version
711 write_action_env_to_bazelrc('TF_CUDNN_VERSION', tf_cudnn_version)
712
713
714def get_native_cuda_compute_capabilities(environ_cp):
715 """Get native cuda compute capabilities.
716
717 Args:
718 environ_cp: copy of the os.environ.
719 Returns:
720 string of native cuda compute capabilities, separated by comma.
721 """
722 device_query_bin = os.path.join(
723 environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery')
Jonathan Hseu008910f2017-08-25 14:01:05 -0700724 if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK):
725 try:
726 output = run_shell(device_query_bin).split('\n')
727 pattern = re.compile('[0-9]*\\.[0-9]*')
728 output = [pattern.search(x) for x in output if 'Capability' in x]
729 output = ','.join(x.group() for x in output if x is not None)
730 except subprocess.CalledProcessError:
731 output = ''
732 else:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700733 output = ''
734 return output
735
736
737def set_tf_cuda_compute_capabilities(environ_cp):
738 """Set TF_CUDA_COMPUTE_CAPABILITIES."""
739 while True:
740 native_cuda_compute_capabilities = get_native_cuda_compute_capabilities(
741 environ_cp)
742 if not native_cuda_compute_capabilities:
743 default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES
744 else:
745 default_cuda_compute_capabilities = native_cuda_compute_capabilities
746
747 ask_cuda_compute_capabilities = (
748 'Please specify a list of comma-separated '
749 'Cuda compute capabilities you want to '
750 'build with.\nYou can find the compute '
751 'capability of your device at: '
752 'https://developer.nvidia.com/cuda-gpus.\nPlease'
753 ' note that each additional compute '
754 'capability significantly increases your '
755 'build time and binary size. [Default is: %s]' %
756 default_cuda_compute_capabilities)
757 tf_cuda_compute_capabilities = get_from_env_or_user_or_default(
758 environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES',
759 ask_cuda_compute_capabilities, default_cuda_compute_capabilities)
760 # Check whether all capabilities from the input is valid
761 all_valid = True
762 for compute_capability in tf_cuda_compute_capabilities.split(','):
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700763 m = re.match('[0-9]+.[0-9]+', compute_capability)
764 if not m:
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700765 print('Invalid compute capability: ' % compute_capability)
766 all_valid = False
Andrew Harp6e3e7d12017-08-21 12:10:44 -0700767 else:
768 ver = int(m.group(0).split('.')[0])
769 if ver < 3:
770 print('Only compute capabilities 3.0 or higher are supported.')
771 all_valid = False
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700772
773 if all_valid:
774 break
775
776 # Reset and Retry
777 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = ''
778
779 # Set TF_CUDA_COMPUTE_CAPABILITIES
780 environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities
781 write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES',
782 tf_cuda_compute_capabilities)
783
784
785def set_other_cuda_vars(environ_cp):
786 """Set other CUDA related variables."""
787 if is_windows():
788 # The following three variables are needed for MSVC toolchain configuration
789 # in Bazel
790 environ_cp['CUDA_PATH'] = environ_cp.get('CUDA_TOOLKIT_PATH')
791 environ_cp['CUDA_COMPUTE_CAPABILITIES'] = environ_cp.get(
792 'TF_CUDA_COMPUTE_CAPABILITIES')
793 environ_cp['NO_WHOLE_ARCHIVE_OPTION'] = 1
794 write_action_env_to_bazelrc('CUDA_PATH', environ_cp.get('CUDA_PATH'))
795 write_action_env_to_bazelrc('CUDA_COMPUTE_CAPABILITIE',
796 environ_cp.get('CUDA_COMPUTE_CAPABILITIE'))
797 write_action_env_to_bazelrc('NO_WHOLE_ARCHIVE_OPTION',
798 environ_cp.get('NO_WHOLE_ARCHIVE_OPTION'))
799 write_to_bazelrc('build --config=win-cuda')
800 write_to_bazelrc('test --config=win-cuda')
801 else:
802 # If CUDA is enabled, always use GPU during build and test.
803 if environ_cp.get('TF_CUDA_CLANG') == '1':
804 write_to_bazelrc('build --config=cuda_clang')
805 write_to_bazelrc('test --config=cuda_clang')
806 else:
807 write_to_bazelrc('build --config=cuda')
808 write_to_bazelrc('test --config=cuda')
809
810
811def set_host_cxx_compiler(environ_cp):
812 """Set HOST_CXX_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700813 default_cxx_host_compiler = which('g++') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700814 ask_cxx_host_compiler = (
815 'Please specify which C++ compiler should be used as'
816 ' the host C++ compiler. [Default is %s]: ') % default_cxx_host_compiler
817
818 while True:
819 host_cxx_compiler = get_from_env_or_user_or_default(
820 environ_cp, 'HOST_CXX_COMPILER', ask_cxx_host_compiler,
821 default_cxx_host_compiler)
822 if os.path.exists(host_cxx_compiler):
823 break
824
825 # Reset and retry
826 print('Invalid C++ compiler path. %s cannot be found' % host_cxx_compiler)
827 environ_cp['HOST_CXX_COMPILER'] = ''
828
829 # Set HOST_CXX_COMPILER
830 environ_cp['HOST_CXX_COMPILER'] = host_cxx_compiler
831 write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler)
832
833
834def set_host_c_compiler(environ_cp):
835 """Set HOST_C_COMPILER."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700836 default_c_host_compiler = which('gcc') or ''
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700837 ask_c_host_compiler = (
838 'Please specify which C compiler should be used as the'
839 ' host C compiler. [Default is %s]: ') % default_c_host_compiler
840
841 while True:
842 host_c_compiler = get_from_env_or_user_or_default(
843 environ_cp, 'HOST_C_COMPILER', ask_c_host_compiler,
844 default_c_host_compiler)
845 if os.path.exists(host_c_compiler):
846 break
847
848 # Reset and retry
849 print('Invalid C compiler path. %s cannot be found' % host_c_compiler)
850 environ_cp['HOST_C_COMPILER'] = ''
851
852 # Set HOST_C_COMPILER
853 environ_cp['HOST_C_COMPILER'] = host_c_compiler
854 write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler)
855
856
857def set_computecpp_toolkit_path(environ_cp):
858 """Set COMPUTECPP_TOOLKIT_PATH."""
859 ask_computecpp_toolkit_path = ('Please specify the location where ComputeCpp '
860 'for SYCL %s is installed. [Default is %s]: '
861 ) % (_TF_OPENCL_VERSION,
862 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
863
864 while True:
865 computecpp_toolkit_path = get_from_env_or_user_or_default(
866 environ_cp, 'COMPUTECPP_TOOLKIT_PATH', ask_computecpp_toolkit_path,
867 _DEFAULT_COMPUTECPP_TOOLKIT_PATH)
868 if is_linux():
869 sycl_rt_lib_path = 'lib/libComputeCpp.so'
870 else:
871 sycl_rt_lib_path = ''
872
873 sycl_rt_lib_path_full = os.path.join(computecpp_toolkit_path,
874 sycl_rt_lib_path)
875 if os.path.exists(sycl_rt_lib_path_full):
876 break
877
878 print('Invalid SYCL %s library path. %s cannot be found' %
879 (_TF_OPENCL_VERSION, sycl_rt_lib_path_full))
880 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = ''
881
882 # Set COMPUTECPP_TOOLKIT_PATH
883 environ_cp['COMPUTECPP_TOOLKIT_PATH'] = computecpp_toolkit_path
884 write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH',
885 computecpp_toolkit_path)
886
887
888def set_mpi_home(environ_cp):
889 """Set MPI_HOME."""
Jonathan Hseu008910f2017-08-25 14:01:05 -0700890 default_mpi_home = which('mpirun') or which('mpiexec') or ''
891 default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home))
892
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700893 ask_mpi_home = ('Please specify the MPI toolkit folder. [Default is %s]: '
894 ) % default_mpi_home
895 while True:
896 mpi_home = get_from_env_or_user_or_default(environ_cp, 'MPI_HOME',
897 ask_mpi_home, default_mpi_home)
898
899 if os.path.exists(os.path.join(mpi_home, 'include')) and os.path.exists(
900 os.path.join(mpi_home, 'lib')):
901 break
902
903 print('Invalid path to the MPI Toolkit. %s or %s cannot be found' %
904 (os.path.join(mpi_home, 'include'),
905 os.path.exists(os.path.join(mpi_home, 'lib'))))
906 environ_cp['MPI_HOME'] = ''
907
908 # Set MPI_HOME
909 environ_cp['MPI_HOME'] = str(mpi_home)
910
911
912def set_other_mpi_vars(environ_cp):
913 """Set other MPI related variables."""
914 # Link the MPI header files
915 mpi_home = environ_cp.get('MPI_HOME')
916 symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h')
917
918 # Determine if we use OpenMPI or MVAPICH, these require different header files
919 # to be included here to make bazel dependency checker happy
920 if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')):
921 symlink_force(
922 os.path.join(mpi_home, 'include/mpi_portable_platform.h'),
923 'third_party/mpi/mpi_portable_platform.h')
924 # TODO(gunan): avoid editing files in configure
925 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False',
926 'MPI_LIB_IS_OPENMPI=True')
927 else:
928 # MVAPICH / MPICH
929 symlink_force(
930 os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h')
931 symlink_force(
932 os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h')
933 # TODO(gunan): avoid editing files in configure
934 sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True',
935 'MPI_LIB_IS_OPENMPI=False')
936
937 if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')):
938 symlink_force(
939 os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so')
940 else:
941 raise ValueError('Cannot find the MPI library file in %s/lib' % mpi_home)
942
943
944def set_mkl():
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700945 write_to_bazelrc('build:mkl --define using_mkl=true')
946 write_to_bazelrc('build:mkl -c opt')
947 write_to_bazelrc('build:mkl --copt="-DEIGEN_USE_VML"')
948 print(
949 'Add "--config=mkl" to your bazel command to build with MKL '
950 'support.\nPlease note that MKL on MacOS or windows is still not '
951 'supported.\nIf you would like to use a local MKL instead of '
952 'downloading, please set the environment variable \"TF_MKL_ROOT\" every '
953 'time before build.')
954
955
956def main():
957 # Make a copy of os.environ to be clear when functions and getting and setting
958 # environment variables.
959 environ_cp = dict(os.environ)
960
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700961 bazel_version = check_bazel_version('0.4.5')
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700962
963 reset_tf_configure_bazelrc()
964 cleanup_makefile()
A. Unique TensorFlower6252d292017-08-04 00:52:34 -0700965 setup_python(environ_cp, bazel_version)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700966 run_gen_git_source(environ_cp)
967
968 if is_windows():
969 environ_cp['TF_NEED_GCP'] = '0'
970 environ_cp['TF_NEED_HDFS'] = '0'
971 environ_cp['TF_NEED_JEMALLOC'] = '0'
972 environ_cp['TF_NEED_OPENCL'] = '0'
973 environ_cp['TF_CUDA_CLANG'] = '0'
974
975 if is_macos():
976 environ_cp['TF_NEED_JEMALLOC'] = '0'
977
978 set_build_var(environ_cp, 'TF_NEED_JEMALLOC', 'jemalloc as malloc',
979 'with_jemalloc', True)
980 set_build_var(environ_cp, 'TF_NEED_GCP', 'Google Cloud Platform',
981 'with_gcp_support', False)
982 set_build_var(environ_cp, 'TF_NEED_HDFS', 'Hadoop File System',
983 'with_hdfs_support', False)
984 set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support',
985 False)
A. Unique TensorFlower28ce1d12017-08-15 12:08:29 -0700986 set_build_var(environ_cp, 'TF_NEED_GDR', 'GDR', 'with_gdr_support',
987 False)
A. Unique TensorFlower73ea2872017-07-25 13:30:03 -0700988 set_build_var(environ_cp, 'TF_NEED_VERBS', 'VERBS', 'with_verbs_support',
989 False)
990
991 set_action_env_var(environ_cp, 'TF_NEED_OPENCL', 'OpenCL', False)
992 if environ_cp.get('TF_NEED_OPENCL') == '1':
993 set_host_cxx_compiler(environ_cp)
994 set_host_c_compiler(environ_cp)
995 set_computecpp_toolkit_path(environ_cp)
996
997 set_action_env_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False)
998 if environ_cp.get('TF_NEED_CUDA') == '1':
999 set_tf_cuda_version(environ_cp)
1000 set_tf_cunn_version(environ_cp)
1001 set_tf_cuda_compute_capabilities(environ_cp)
1002
1003 set_tf_cuda_clang(environ_cp)
1004 if environ_cp.get('TF_CUDA_CLANG') == '1':
1005 # Set up which clang we should use as the cuda / host compiler.
1006 set_clang_cuda_compiler_path(environ_cp)
1007 else:
1008 # Set up which gcc nvcc should use as the host compiler
1009 # No need to set this on Windows
1010 if not is_windows():
1011 set_gcc_host_compiler_path(environ_cp)
1012 set_other_cuda_vars(environ_cp)
1013
1014 set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False)
1015 if environ_cp.get('TF_NEED_MPI') == '1':
1016 set_mpi_home(environ_cp)
1017 set_other_mpi_vars(environ_cp)
1018
1019 set_cc_opt_flags(environ_cp)
1020 set_mkl()
1021
1022
1023if __name__ == '__main__':
1024 main()