A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1 | # 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 | |
| 17 | from __future__ import absolute_import |
| 18 | from __future__ import division |
| 19 | from __future__ import print_function |
| 20 | |
Shanqing Cai | 7144571 | 2018-03-12 19:33:52 -0700 | [diff] [blame] | 21 | import argparse |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 22 | import errno |
| 23 | import os |
| 24 | import platform |
| 25 | import re |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 26 | import subprocess |
| 27 | import sys |
| 28 | |
Andrew Selle | c9885ea | 2017-11-06 09:37:03 -0800 | [diff] [blame] | 29 | # pylint: disable=g-import-not-at-top |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 30 | try: |
| 31 | from shutil import which |
| 32 | except ImportError: |
| 33 | from distutils.spawn import find_executable as which |
Andrew Selle | c9885ea | 2017-11-06 09:37:03 -0800 | [diff] [blame] | 34 | # pylint: enable=g-import-not-at-top |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 35 | |
A. Unique TensorFlower | 0cb8a07 | 2019-04-16 08:16:39 -0700 | [diff] [blame] | 36 | _DEFAULT_CUDA_VERSION = '10' |
| 37 | _DEFAULT_CUDNN_VERSION = '7' |
| 38 | _DEFAULT_TENSORRT_VERSION = '5' |
Smit Hinsu | fe7d1d9 | 2018-07-14 13:16:58 -0700 | [diff] [blame] | 39 | _DEFAULT_CUDA_COMPUTE_CAPABILITIES = '3.5,7.0' |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 40 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 41 | _TF_OPENCL_VERSION = '1.2' |
| 42 | _DEFAULT_COMPUTECPP_TOOLKIT_PATH = '/usr/local/computecpp' |
Yifei Feng | b1d8c59 | 2017-11-22 13:42:21 -0800 | [diff] [blame] | 43 | _DEFAULT_TRISYCL_INCLUDE_DIR = '/usr/local/triSYCL/include' |
A. Unique TensorFlower | 82820ef | 2018-11-12 13:22:13 -0800 | [diff] [blame] | 44 | _SUPPORTED_ANDROID_NDK_VERSIONS = [10, 11, 12, 13, 14, 15, 16, 17, 18] |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 45 | |
| 46 | _DEFAULT_PROMPT_ASK_ATTEMPTS = 10 |
| 47 | |
Shanqing Cai | 7144571 | 2018-03-12 19:33:52 -0700 | [diff] [blame] | 48 | _TF_BAZELRC_FILENAME = '.tf_configure.bazelrc' |
A. Unique TensorFlower | 7c5eb35 | 2018-10-01 07:15:23 -0700 | [diff] [blame] | 49 | _TF_WORKSPACE_ROOT = '' |
| 50 | _TF_BAZELRC = '' |
A. Unique TensorFlower | ed29734 | 2019-03-15 11:25:28 -0700 | [diff] [blame] | 51 | _TF_CURRENT_BAZEL_VERSION = None |
Shanqing Cai | 7144571 | 2018-03-12 19:33:52 -0700 | [diff] [blame] | 52 | |
Jason Furmanek | 7c23415 | 2018-09-26 04:44:12 +0000 | [diff] [blame] | 53 | NCCL_LIB_PATHS = [ |
TensorFlower Gardener | ea5c529 | 2018-10-01 17:28:26 -0700 | [diff] [blame] | 54 | 'lib64/', 'lib/powerpc64le-linux-gnu/', 'lib/x86_64-linux-gnu/', '' |
Jason Furmanek | 7c23415 | 2018-09-26 04:44:12 +0000 | [diff] [blame] | 55 | ] |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 56 | |
A. Unique TensorFlower | 76e879d | 2019-03-22 00:25:36 -0700 | [diff] [blame] | 57 | # List of files to configure when building Bazel on Apple platforms. |
A. Unique TensorFlower | 93e7073 | 2019-02-14 16:45:32 -0800 | [diff] [blame] | 58 | APPLE_BAZEL_FILES = [ |
A. Unique TensorFlower | 6a059c0 | 2019-04-05 14:28:27 -0700 | [diff] [blame] | 59 | 'tensorflow/lite/experimental/ios/BUILD', |
A. Unique TensorFlower | 93e7073 | 2019-02-14 16:45:32 -0800 | [diff] [blame] | 60 | 'tensorflow/lite/experimental/objc/BUILD', |
| 61 | 'tensorflow/lite/experimental/swift/BUILD' |
| 62 | ] |
| 63 | |
A. Unique TensorFlower | 76e879d | 2019-03-22 00:25:36 -0700 | [diff] [blame] | 64 | # List of files to move when building for iOS. |
| 65 | IOS_FILES = [ |
| 66 | 'tensorflow/lite/experimental/objc/TensorFlowLiteObjC.podspec', |
| 67 | 'tensorflow/lite/experimental/swift/TensorFlowLiteSwift.podspec', |
| 68 | ] |
| 69 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 70 | |
| 71 | class UserInputError(Exception): |
| 72 | pass |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 73 | |
| 74 | |
| 75 | def is_windows(): |
| 76 | return platform.system() == 'Windows' |
| 77 | |
| 78 | |
| 79 | def is_linux(): |
| 80 | return platform.system() == 'Linux' |
| 81 | |
| 82 | |
| 83 | def is_macos(): |
| 84 | return platform.system() == 'Darwin' |
| 85 | |
| 86 | |
| 87 | def is_ppc64le(): |
| 88 | return platform.machine() == 'ppc64le' |
| 89 | |
| 90 | |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 91 | def is_cygwin(): |
| 92 | return platform.system().startswith('CYGWIN_NT') |
| 93 | |
| 94 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 95 | def get_input(question): |
| 96 | try: |
| 97 | try: |
| 98 | answer = raw_input(question) |
| 99 | except NameError: |
| 100 | answer = input(question) # pylint: disable=bad-builtin |
| 101 | except EOFError: |
| 102 | answer = '' |
| 103 | return answer |
| 104 | |
| 105 | |
| 106 | def symlink_force(target, link_name): |
| 107 | """Force symlink, equivalent of 'ln -sf'. |
| 108 | |
| 109 | Args: |
| 110 | target: items to link to. |
| 111 | link_name: name of the link. |
| 112 | """ |
| 113 | try: |
| 114 | os.symlink(target, link_name) |
| 115 | except OSError as e: |
| 116 | if e.errno == errno.EEXIST: |
| 117 | os.remove(link_name) |
| 118 | os.symlink(target, link_name) |
| 119 | else: |
| 120 | raise e |
| 121 | |
| 122 | |
| 123 | def sed_in_place(filename, old, new): |
| 124 | """Replace old string with new string in file. |
| 125 | |
| 126 | Args: |
| 127 | filename: string for filename. |
| 128 | old: string to replace. |
| 129 | new: new string to replace to. |
| 130 | """ |
| 131 | with open(filename, 'r') as f: |
| 132 | filedata = f.read() |
| 133 | newdata = filedata.replace(old, new) |
| 134 | with open(filename, 'w') as f: |
| 135 | f.write(newdata) |
| 136 | |
| 137 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 138 | def write_to_bazelrc(line): |
| 139 | with open(_TF_BAZELRC, 'a') as f: |
| 140 | f.write(line + '\n') |
| 141 | |
| 142 | |
| 143 | def write_action_env_to_bazelrc(var_name, var): |
| 144 | write_to_bazelrc('build --action_env %s="%s"' % (var_name, str(var))) |
| 145 | |
| 146 | |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 147 | def run_shell(cmd, allow_non_zero=False): |
| 148 | if allow_non_zero: |
| 149 | try: |
| 150 | output = subprocess.check_output(cmd) |
| 151 | except subprocess.CalledProcessError as e: |
| 152 | output = e.output |
| 153 | else: |
| 154 | output = subprocess.check_output(cmd) |
| 155 | return output.decode('UTF-8').strip() |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 156 | |
| 157 | |
| 158 | def cygpath(path): |
| 159 | """Convert path from posix to windows.""" |
Martin Wicke | d57572e | 2017-09-02 19:21:45 -0700 | [diff] [blame] | 160 | return os.path.abspath(path).replace('\\', '/') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 161 | |
| 162 | |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 163 | def get_python_path(environ_cp, python_bin_path): |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 164 | """Get the python site package paths.""" |
| 165 | python_paths = [] |
| 166 | if environ_cp.get('PYTHONPATH'): |
| 167 | python_paths = environ_cp.get('PYTHONPATH').split(':') |
| 168 | try: |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 169 | library_paths = run_shell([ |
| 170 | python_bin_path, '-c', |
| 171 | 'import site; print("\\n".join(site.getsitepackages()))' |
| 172 | ]).split('\n') |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 173 | except subprocess.CalledProcessError: |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 174 | library_paths = [ |
| 175 | run_shell([ |
| 176 | python_bin_path, '-c', |
| 177 | 'from distutils.sysconfig import get_python_lib;' |
| 178 | 'print(get_python_lib())' |
| 179 | ]) |
| 180 | ] |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 181 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 182 | all_paths = set(python_paths + library_paths) |
| 183 | |
| 184 | paths = [] |
| 185 | for path in all_paths: |
| 186 | if os.path.isdir(path): |
| 187 | paths.append(path) |
| 188 | return paths |
| 189 | |
| 190 | |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 191 | def get_python_major_version(python_bin_path): |
| 192 | """Get the python major version.""" |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 193 | return run_shell([python_bin_path, '-c', 'import sys; print(sys.version[0])']) |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 194 | |
| 195 | |
Gunhan Gulsoy | ed89a2b | 2017-09-19 18:36:26 -0700 | [diff] [blame] | 196 | def setup_python(environ_cp): |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 197 | """Setup python related env variables.""" |
| 198 | # Get PYTHON_BIN_PATH, default is the current running python. |
| 199 | default_python_bin_path = sys.executable |
| 200 | ask_python_bin_path = ('Please specify the location of python. [Default is ' |
| 201 | '%s]: ') % default_python_bin_path |
| 202 | while True: |
A. Unique TensorFlower | 5001ac0 | 2019-04-03 11:59:08 -0700 | [diff] [blame] | 203 | python_bin_path = get_from_env_or_user_or_default(environ_cp, |
| 204 | 'PYTHON_BIN_PATH', |
| 205 | ask_python_bin_path, |
| 206 | default_python_bin_path) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 207 | # Check if the path is valid |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 208 | if os.path.isfile(python_bin_path) and os.access(python_bin_path, os.X_OK): |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 209 | break |
| 210 | elif not os.path.exists(python_bin_path): |
| 211 | print('Invalid python path: %s cannot be found.' % python_bin_path) |
| 212 | else: |
| 213 | print('%s is not executable. Is it the python binary?' % python_bin_path) |
| 214 | environ_cp['PYTHON_BIN_PATH'] = '' |
| 215 | |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 216 | # Convert python path to Windows style before checking lib and version |
Martin Wicke | d57572e | 2017-09-02 19:21:45 -0700 | [diff] [blame] | 217 | if is_windows() or is_cygwin(): |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 218 | python_bin_path = cygpath(python_bin_path) |
| 219 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 220 | # Get PYTHON_LIB_PATH |
| 221 | python_lib_path = environ_cp.get('PYTHON_LIB_PATH') |
| 222 | if not python_lib_path: |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 223 | python_lib_paths = get_python_path(environ_cp, python_bin_path) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 224 | if environ_cp.get('USE_DEFAULT_PYTHON_LIB_PATH') == '1': |
Vijay Vasudevan | a1fba7f | 2017-07-28 10:58:56 -0700 | [diff] [blame] | 225 | python_lib_path = python_lib_paths[0] |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 226 | else: |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 227 | print('Found possible Python library paths:\n %s' % |
| 228 | '\n '.join(python_lib_paths)) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 229 | default_python_lib_path = python_lib_paths[0] |
| 230 | python_lib_path = get_input( |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 231 | 'Please input the desired Python library path to use. ' |
| 232 | 'Default is [%s]\n' % python_lib_paths[0]) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 233 | if not python_lib_path: |
| 234 | python_lib_path = default_python_lib_path |
Vijay Vasudevan | a1fba7f | 2017-07-28 10:58:56 -0700 | [diff] [blame] | 235 | environ_cp['PYTHON_LIB_PATH'] = python_lib_path |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 236 | |
TensorFlower Gardener | 61a8720 | 2018-10-01 12:25:39 -0700 | [diff] [blame] | 237 | _ = get_python_major_version(python_bin_path) |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 238 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 239 | # Convert python path to Windows style before writing into bazel.rc |
Martin Wicke | d57572e | 2017-09-02 19:21:45 -0700 | [diff] [blame] | 240 | if is_windows() or is_cygwin(): |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 241 | python_lib_path = cygpath(python_lib_path) |
| 242 | |
| 243 | # Set-up env variables used by python_configure.bzl |
| 244 | write_action_env_to_bazelrc('PYTHON_BIN_PATH', python_bin_path) |
| 245 | write_action_env_to_bazelrc('PYTHON_LIB_PATH', python_lib_path) |
Gunhan Gulsoy | ed89a2b | 2017-09-19 18:36:26 -0700 | [diff] [blame] | 246 | write_to_bazelrc('build --python_path=\"%s"' % python_bin_path) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 247 | environ_cp['PYTHON_BIN_PATH'] = python_bin_path |
| 248 | |
William D. Irons | dcc76a5 | 2018-11-20 10:35:18 -0600 | [diff] [blame] | 249 | # If choosen python_lib_path is from a path specified in the PYTHONPATH |
| 250 | # variable, need to tell bazel to include PYTHONPATH |
| 251 | if environ_cp.get('PYTHONPATH'): |
| 252 | python_paths = environ_cp.get('PYTHONPATH').split(':') |
| 253 | if python_lib_path in python_paths: |
TensorFlower Gardener | 968cd18 | 2018-11-28 11:33:16 -0800 | [diff] [blame] | 254 | write_action_env_to_bazelrc('PYTHONPATH', environ_cp.get('PYTHONPATH')) |
William D. Irons | dcc76a5 | 2018-11-20 10:35:18 -0600 | [diff] [blame] | 255 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 256 | # Write tools/python_bin_path.sh |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 257 | with open( |
| 258 | os.path.join(_TF_WORKSPACE_ROOT, 'tools', 'python_bin_path.sh'), |
| 259 | 'w') as f: |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 260 | f.write('export PYTHON_BIN_PATH="%s"' % python_bin_path) |
| 261 | |
| 262 | |
A. Unique TensorFlower | 7c5eb35 | 2018-10-01 07:15:23 -0700 | [diff] [blame] | 263 | def reset_tf_configure_bazelrc(): |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 264 | """Reset file that contains customized config settings.""" |
| 265 | open(_TF_BAZELRC, 'w').close() |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 266 | |
TensorFlower Gardener | abb763b | 2019-02-06 16:23:03 -0800 | [diff] [blame] | 267 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 268 | def cleanup_makefile(): |
| 269 | """Delete any leftover BUILD files from the Makefile build. |
| 270 | |
| 271 | These files could interfere with Bazel parsing. |
| 272 | """ |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 273 | makefile_download_dir = os.path.join(_TF_WORKSPACE_ROOT, 'tensorflow', |
| 274 | 'contrib', 'makefile', 'downloads') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 275 | if os.path.isdir(makefile_download_dir): |
| 276 | for root, _, filenames in os.walk(makefile_download_dir): |
| 277 | for f in filenames: |
| 278 | if f.endswith('BUILD'): |
| 279 | os.remove(os.path.join(root, f)) |
| 280 | |
| 281 | |
| 282 | def get_var(environ_cp, |
| 283 | var_name, |
| 284 | query_item, |
| 285 | enabled_by_default, |
| 286 | question=None, |
| 287 | yes_reply=None, |
| 288 | no_reply=None): |
| 289 | """Get boolean input from user. |
| 290 | |
| 291 | If var_name is not set in env, ask user to enable query_item or not. If the |
| 292 | response is empty, use the default. |
| 293 | |
| 294 | Args: |
| 295 | environ_cp: copy of the os.environ. |
R S Nikhil Krishna | 05e348b | 2019-04-18 15:58:12 +0530 | [diff] [blame] | 296 | var_name: string for name of environment variable, e.g. "TF_NEED_CUDA". |
| 297 | query_item: string for feature related to the variable, e.g. "CUDA for |
| 298 | Nvidia GPUs". |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 299 | enabled_by_default: boolean for default behavior. |
| 300 | question: optional string for how to ask for user input. |
Michael Case | d90054e | 2018-02-07 14:36:00 -0800 | [diff] [blame] | 301 | yes_reply: optional string for reply when feature is enabled. |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 302 | no_reply: optional string for reply when feature is disabled. |
| 303 | |
| 304 | Returns: |
| 305 | boolean value of the variable. |
Frank Chen | c4ef927 | 2018-01-10 11:36:52 -0800 | [diff] [blame] | 306 | |
| 307 | Raises: |
| 308 | UserInputError: if an environment variable is set, but it cannot be |
| 309 | interpreted as a boolean indicator, assume that the user has made a |
| 310 | scripting error, and will continue to provide invalid input. |
| 311 | Raise the error to avoid infinitely looping. |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 312 | """ |
| 313 | if not question: |
| 314 | question = 'Do you wish to build TensorFlow with %s support?' % query_item |
| 315 | if not yes_reply: |
| 316 | yes_reply = '%s support will be enabled for TensorFlow.' % query_item |
| 317 | if not no_reply: |
| 318 | no_reply = 'No %s' % yes_reply |
| 319 | |
| 320 | yes_reply += '\n' |
| 321 | no_reply += '\n' |
| 322 | |
| 323 | if enabled_by_default: |
| 324 | question += ' [Y/n]: ' |
| 325 | else: |
| 326 | question += ' [y/N]: ' |
| 327 | |
| 328 | var = environ_cp.get(var_name) |
Frank Chen | c4ef927 | 2018-01-10 11:36:52 -0800 | [diff] [blame] | 329 | if var is not None: |
| 330 | var_content = var.strip().lower() |
| 331 | true_strings = ('1', 't', 'true', 'y', 'yes') |
| 332 | false_strings = ('0', 'f', 'false', 'n', 'no') |
| 333 | if var_content in true_strings: |
| 334 | var = True |
| 335 | elif var_content in false_strings: |
| 336 | var = False |
| 337 | else: |
| 338 | raise UserInputError( |
| 339 | 'Environment variable %s must be set as a boolean indicator.\n' |
| 340 | 'The following are accepted as TRUE : %s.\n' |
| 341 | 'The following are accepted as FALSE: %s.\n' |
A. Unique TensorFlower | ed29734 | 2019-03-15 11:25:28 -0700 | [diff] [blame] | 342 | 'Current value is %s.' % |
| 343 | (var_name, ', '.join(true_strings), ', '.join(false_strings), var)) |
Frank Chen | c4ef927 | 2018-01-10 11:36:52 -0800 | [diff] [blame] | 344 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 345 | while var is None: |
| 346 | user_input_origin = get_input(question) |
| 347 | user_input = user_input_origin.strip().lower() |
| 348 | if user_input == 'y': |
| 349 | print(yes_reply) |
| 350 | var = True |
| 351 | elif user_input == 'n': |
| 352 | print(no_reply) |
| 353 | var = False |
| 354 | elif not user_input: |
| 355 | if enabled_by_default: |
| 356 | print(yes_reply) |
| 357 | var = True |
| 358 | else: |
| 359 | print(no_reply) |
| 360 | var = False |
| 361 | else: |
| 362 | print('Invalid selection: %s' % user_input_origin) |
| 363 | return var |
| 364 | |
| 365 | |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 366 | def set_build_var(environ_cp, |
| 367 | var_name, |
| 368 | query_item, |
| 369 | option_name, |
| 370 | enabled_by_default, |
| 371 | bazel_config_name=None): |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 372 | """Set if query_item will be enabled for the build. |
| 373 | |
| 374 | Ask user if query_item will be enabled. Default is used if no input is given. |
| 375 | Set subprocess environment variable and write to .bazelrc if enabled. |
| 376 | |
| 377 | Args: |
| 378 | environ_cp: copy of the os.environ. |
R S Nikhil Krishna | 05e348b | 2019-04-18 15:58:12 +0530 | [diff] [blame] | 379 | var_name: string for name of environment variable, e.g. "TF_NEED_CUDA". |
| 380 | query_item: string for feature related to the variable, e.g. "CUDA for |
| 381 | Nvidia GPUs". |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 382 | option_name: string for option to define in .bazelrc. |
| 383 | enabled_by_default: boolean for default behavior. |
Michael Case | 98850a5 | 2017-09-14 13:35:57 -0700 | [diff] [blame] | 384 | bazel_config_name: Name for Bazel --config argument to enable build feature. |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 385 | """ |
| 386 | |
| 387 | var = str(int(get_var(environ_cp, var_name, query_item, enabled_by_default))) |
| 388 | environ_cp[var_name] = var |
| 389 | if var == '1': |
A. Unique TensorFlower | 5001ac0 | 2019-04-03 11:59:08 -0700 | [diff] [blame] | 390 | write_to_bazelrc('build:%s --define %s=true' % |
| 391 | (bazel_config_name, option_name)) |
Yifei Feng | ec451f5 | 2018-10-05 12:53:50 -0700 | [diff] [blame] | 392 | write_to_bazelrc('build --config=%s' % bazel_config_name) |
Michael Case | 98850a5 | 2017-09-14 13:35:57 -0700 | [diff] [blame] | 393 | elif bazel_config_name is not None: |
| 394 | # TODO(mikecase): Migrate all users of configure.py to use --config Bazel |
| 395 | # options and not to set build configs through environment variables. |
A. Unique TensorFlower | 5001ac0 | 2019-04-03 11:59:08 -0700 | [diff] [blame] | 396 | write_to_bazelrc('build:%s --define %s=true' % |
| 397 | (bazel_config_name, option_name)) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 398 | |
| 399 | |
| 400 | def set_action_env_var(environ_cp, |
| 401 | var_name, |
| 402 | query_item, |
| 403 | enabled_by_default, |
| 404 | question=None, |
| 405 | yes_reply=None, |
| 406 | no_reply=None): |
| 407 | """Set boolean action_env variable. |
| 408 | |
| 409 | Ask user if query_item will be enabled. Default is used if no input is given. |
| 410 | Set environment variable and write to .bazelrc. |
| 411 | |
| 412 | Args: |
| 413 | environ_cp: copy of the os.environ. |
R S Nikhil Krishna | 05e348b | 2019-04-18 15:58:12 +0530 | [diff] [blame] | 414 | var_name: string for name of environment variable, e.g. "TF_NEED_CUDA". |
| 415 | query_item: string for feature related to the variable, e.g. "CUDA for |
| 416 | Nvidia GPUs". |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 417 | enabled_by_default: boolean for default behavior. |
| 418 | question: optional string for how to ask for user input. |
Michael Case | d90054e | 2018-02-07 14:36:00 -0800 | [diff] [blame] | 419 | yes_reply: optional string for reply when feature is enabled. |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 420 | no_reply: optional string for reply when feature is disabled. |
| 421 | """ |
| 422 | var = int( |
| 423 | get_var(environ_cp, var_name, query_item, enabled_by_default, question, |
| 424 | yes_reply, no_reply)) |
| 425 | |
| 426 | write_action_env_to_bazelrc(var_name, var) |
| 427 | environ_cp[var_name] = str(var) |
| 428 | |
| 429 | |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 430 | def convert_version_to_int(version): |
| 431 | """Convert a version number to a integer that can be used to compare. |
| 432 | |
A. Unique TensorFlower | 28ce1d1 | 2017-08-15 12:08:29 -0700 | [diff] [blame] | 433 | Version strings of the form X.YZ and X.Y.Z-xxxxx are supported. The |
| 434 | 'xxxxx' part, for instance 'homebrew' on OS/X, is ignored. |
| 435 | |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 436 | Args: |
A. Unique TensorFlower | 28ce1d1 | 2017-08-15 12:08:29 -0700 | [diff] [blame] | 437 | version: a version to be converted |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 438 | |
| 439 | Returns: |
| 440 | An integer if converted successfully, otherwise return None. |
| 441 | """ |
A. Unique TensorFlower | 28ce1d1 | 2017-08-15 12:08:29 -0700 | [diff] [blame] | 442 | version = version.split('-')[0] |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 443 | version_segments = version.split('.') |
Austin Anderson | 87ea41d | 2019-04-04 10:03:50 -0700 | [diff] [blame] | 444 | # Treat "0.24" as "0.24.0" |
| 445 | if len(version_segments) == 2: |
| 446 | version_segments.append('0') |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 447 | for seg in version_segments: |
| 448 | if not seg.isdigit(): |
| 449 | return None |
| 450 | |
| 451 | version_str = ''.join(['%03d' % int(seg) for seg in version_segments]) |
| 452 | return int(version_str) |
| 453 | |
| 454 | |
Mihai Maruseac | e7a123f | 2018-11-30 13:33:25 -0800 | [diff] [blame] | 455 | def check_bazel_version(min_version, max_version): |
| 456 | """Check installed bazel version is between min_version and max_version. |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 457 | |
| 458 | Args: |
Mihai Maruseac | 4db860f | 2019-04-19 08:52:10 -0700 | [diff] [blame^] | 459 | min_version: string for minimum bazel version (must exist!). |
| 460 | max_version: string for maximum bazel version (must exist!). |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 461 | |
| 462 | Returns: |
| 463 | The bazel version detected. |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 464 | """ |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 465 | if which('bazel') is None: |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 466 | print('Cannot find bazel. Please install bazel.') |
| 467 | sys.exit(0) |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 468 | curr_version = run_shell( |
| 469 | ['bazel', '--batch', '--bazelrc=/dev/null', 'version']) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 470 | |
| 471 | for line in curr_version.split('\n'): |
| 472 | if 'Build label: ' in line: |
| 473 | curr_version = line.split('Build label: ')[1] |
| 474 | break |
| 475 | |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 476 | min_version_int = convert_version_to_int(min_version) |
| 477 | curr_version_int = convert_version_to_int(curr_version) |
Mihai Maruseac | e7a123f | 2018-11-30 13:33:25 -0800 | [diff] [blame] | 478 | max_version_int = convert_version_to_int(max_version) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 479 | |
| 480 | # Check if current bazel version can be detected properly. |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 481 | if not curr_version_int: |
| 482 | print('WARNING: current bazel installation is not a release version.') |
| 483 | print('Make sure you are running at least bazel %s' % min_version) |
| 484 | return curr_version |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 485 | |
Michael Case | d94271a | 2017-08-22 17:26:52 -0700 | [diff] [blame] | 486 | print('You have bazel %s installed.' % curr_version) |
A. Unique TensorFlower | 28ce1d1 | 2017-08-15 12:08:29 -0700 | [diff] [blame] | 487 | |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 488 | if curr_version_int < min_version_int: |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 489 | print('Please upgrade your bazel installation to version %s or higher to ' |
| 490 | 'build TensorFlow!' % min_version) |
Jason Zaman | b41761c | 2018-10-14 11:28:53 +0800 | [diff] [blame] | 491 | sys.exit(1) |
TensorFlower Gardener | 78c246b | 2018-12-13 12:37:42 -0800 | [diff] [blame] | 492 | if (curr_version_int > max_version_int and |
| 493 | 'TF_IGNORE_MAX_BAZEL_VERSION' not in os.environ): |
Mihai Maruseac | e7a123f | 2018-11-30 13:33:25 -0800 | [diff] [blame] | 494 | print('Please downgrade your bazel installation to version %s or lower to ' |
Mihai Maruseac | e0963c4 | 2018-12-20 14:27:40 -0800 | [diff] [blame] | 495 | 'build TensorFlow! To downgrade: download the installer for the old ' |
| 496 | 'version (from https://github.com/bazelbuild/bazel/releases) then ' |
| 497 | 'run the installer.' % max_version) |
Jason Zaman | b41761c | 2018-10-14 11:28:53 +0800 | [diff] [blame] | 498 | sys.exit(1) |
A. Unique TensorFlower | 6252d29 | 2017-08-04 00:52:34 -0700 | [diff] [blame] | 499 | return curr_version |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 500 | |
| 501 | |
| 502 | def set_cc_opt_flags(environ_cp): |
| 503 | """Set up architecture-dependent optimization flags. |
| 504 | |
| 505 | Also append CC optimization flags to bazel.rc.. |
| 506 | |
| 507 | Args: |
| 508 | environ_cp: copy of the os.environ. |
| 509 | """ |
| 510 | if is_ppc64le(): |
| 511 | # gcc on ppc64le does not support -march, use mcpu instead |
| 512 | default_cc_opt_flags = '-mcpu=native' |
A. Unique TensorFlower | 1bba94a | 2018-04-04 15:45:20 -0700 | [diff] [blame] | 513 | elif is_windows(): |
| 514 | default_cc_opt_flags = '/arch:AVX' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 515 | else: |
Justin Lebar | 9ef04f5 | 2018-10-10 18:52:45 -0700 | [diff] [blame] | 516 | default_cc_opt_flags = '-march=native -Wno-sign-compare' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 517 | question = ('Please specify optimization flags to use during compilation when' |
| 518 | ' bazel option "--config=opt" is specified [Default is %s]: ' |
| 519 | ) % default_cc_opt_flags |
| 520 | cc_opt_flags = get_from_env_or_user_or_default(environ_cp, 'CC_OPT_FLAGS', |
| 521 | question, default_cc_opt_flags) |
| 522 | for opt in cc_opt_flags.split(): |
Michael Case | 0017742 | 2017-11-10 13:14:03 -0800 | [diff] [blame] | 523 | write_to_bazelrc('build:opt --copt=%s' % opt) |
| 524 | # It should be safe on the same build host. |
A. Unique TensorFlower | 1bba94a | 2018-04-04 15:45:20 -0700 | [diff] [blame] | 525 | if not is_ppc64le() and not is_windows(): |
Shanqing Cai | 7144571 | 2018-03-12 19:33:52 -0700 | [diff] [blame] | 526 | write_to_bazelrc('build:opt --host_copt=-march=native') |
Michael Case | bb3355d | 2017-11-09 08:46:31 -0800 | [diff] [blame] | 527 | write_to_bazelrc('build:opt --define with_default_optimizations=true') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 528 | |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 529 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 530 | def set_tf_cuda_clang(environ_cp): |
| 531 | """set TF_CUDA_CLANG action_env. |
| 532 | |
| 533 | Args: |
| 534 | environ_cp: copy of the os.environ. |
| 535 | """ |
| 536 | question = 'Do you want to use clang as CUDA compiler?' |
| 537 | yes_reply = 'Clang will be used as CUDA compiler.' |
| 538 | no_reply = 'nvcc will be used as CUDA compiler.' |
| 539 | set_action_env_var( |
| 540 | environ_cp, |
| 541 | 'TF_CUDA_CLANG', |
| 542 | None, |
| 543 | False, |
| 544 | question=question, |
| 545 | yes_reply=yes_reply, |
| 546 | no_reply=no_reply) |
| 547 | |
| 548 | |
A. Unique TensorFlower | fd29e95 | 2017-12-22 03:07:51 -0800 | [diff] [blame] | 549 | def set_tf_download_clang(environ_cp): |
| 550 | """Set TF_DOWNLOAD_CLANG action_env.""" |
Ilya Biryukov | 9e651e4 | 2018-03-22 05:33:42 -0700 | [diff] [blame] | 551 | question = 'Do you wish to download a fresh release of clang? (Experimental)' |
A. Unique TensorFlower | fd29e95 | 2017-12-22 03:07:51 -0800 | [diff] [blame] | 552 | yes_reply = 'Clang will be downloaded and used to compile tensorflow.' |
| 553 | no_reply = 'Clang will not be downloaded.' |
| 554 | set_action_env_var( |
| 555 | environ_cp, |
| 556 | 'TF_DOWNLOAD_CLANG', |
| 557 | None, |
| 558 | False, |
| 559 | question=question, |
| 560 | yes_reply=yes_reply, |
| 561 | no_reply=no_reply) |
| 562 | |
| 563 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 564 | def get_from_env_or_user_or_default(environ_cp, var_name, ask_for_var, |
| 565 | var_default): |
| 566 | """Get var_name either from env, or user or default. |
| 567 | |
| 568 | If var_name has been set as environment variable, use the preset value, else |
| 569 | ask for user input. If no input is provided, the default is used. |
| 570 | |
| 571 | Args: |
| 572 | environ_cp: copy of the os.environ. |
R S Nikhil Krishna | 05e348b | 2019-04-18 15:58:12 +0530 | [diff] [blame] | 573 | var_name: string for name of environment variable, e.g. "TF_NEED_CUDA". |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 574 | ask_for_var: string for how to ask for user input. |
| 575 | var_default: default value string. |
| 576 | |
| 577 | Returns: |
| 578 | string value for var_name |
| 579 | """ |
| 580 | var = environ_cp.get(var_name) |
| 581 | if not var: |
| 582 | var = get_input(ask_for_var) |
Michael Case | d94271a | 2017-08-22 17:26:52 -0700 | [diff] [blame] | 583 | print('\n') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 584 | if not var: |
| 585 | var = var_default |
| 586 | return var |
| 587 | |
| 588 | |
| 589 | def set_clang_cuda_compiler_path(environ_cp): |
| 590 | """Set CLANG_CUDA_COMPILER_PATH.""" |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 591 | default_clang_path = which('clang') or '' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 592 | ask_clang_path = ('Please specify which clang should be used as device and ' |
| 593 | 'host compiler. [Default is %s]: ') % default_clang_path |
| 594 | |
| 595 | while True: |
| 596 | clang_cuda_compiler_path = get_from_env_or_user_or_default( |
| 597 | environ_cp, 'CLANG_CUDA_COMPILER_PATH', ask_clang_path, |
| 598 | default_clang_path) |
| 599 | if os.path.exists(clang_cuda_compiler_path): |
| 600 | break |
| 601 | |
| 602 | # Reset and retry |
| 603 | print('Invalid clang path: %s cannot be found.' % clang_cuda_compiler_path) |
| 604 | environ_cp['CLANG_CUDA_COMPILER_PATH'] = '' |
| 605 | |
| 606 | # Set CLANG_CUDA_COMPILER_PATH |
| 607 | environ_cp['CLANG_CUDA_COMPILER_PATH'] = clang_cuda_compiler_path |
| 608 | write_action_env_to_bazelrc('CLANG_CUDA_COMPILER_PATH', |
| 609 | clang_cuda_compiler_path) |
| 610 | |
| 611 | |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 612 | def prompt_loop_or_load_from_env(environ_cp, |
| 613 | var_name, |
| 614 | var_default, |
| 615 | ask_for_var, |
| 616 | check_success, |
| 617 | error_msg, |
| 618 | suppress_default_error=False, |
| 619 | n_ask_attempts=_DEFAULT_PROMPT_ASK_ATTEMPTS): |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 620 | """Loop over user prompts for an ENV param until receiving a valid response. |
| 621 | |
| 622 | For the env param var_name, read from the environment or verify user input |
| 623 | until receiving valid input. When done, set var_name in the environ_cp to its |
| 624 | new value. |
| 625 | |
| 626 | Args: |
| 627 | environ_cp: (Dict) copy of the os.environ. |
| 628 | var_name: (String) string for name of environment variable, e.g. "TF_MYVAR". |
| 629 | var_default: (String) default value string. |
| 630 | ask_for_var: (String) string for how to ask for user input. |
| 631 | check_success: (Function) function that takes one argument and returns a |
| 632 | boolean. Should return True if the value provided is considered valid. May |
| 633 | contain a complex error message if error_msg does not provide enough |
| 634 | information. In that case, set suppress_default_error to True. |
| 635 | error_msg: (String) String with one and only one '%s'. Formatted with each |
| 636 | invalid response upon check_success(input) failure. |
| 637 | suppress_default_error: (Bool) Suppress the above error message in favor of |
| 638 | one from the check_success function. |
| 639 | n_ask_attempts: (Integer) Number of times to query for valid input before |
| 640 | raising an error and quitting. |
| 641 | |
| 642 | Returns: |
| 643 | [String] The value of var_name after querying for input. |
| 644 | |
| 645 | Raises: |
| 646 | UserInputError: if a query has been attempted n_ask_attempts times without |
Frank Chen | c4ef927 | 2018-01-10 11:36:52 -0800 | [diff] [blame] | 647 | success, assume that the user has made a scripting error, and will |
| 648 | continue to provide invalid input. Raise the error to avoid infinitely |
| 649 | looping. |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 650 | """ |
| 651 | default = environ_cp.get(var_name) or var_default |
| 652 | full_query = '%s [Default is %s]: ' % ( |
| 653 | ask_for_var, |
| 654 | default, |
| 655 | ) |
| 656 | |
| 657 | for _ in range(n_ask_attempts): |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 658 | val = get_from_env_or_user_or_default(environ_cp, var_name, full_query, |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 659 | default) |
| 660 | if check_success(val): |
| 661 | break |
| 662 | if not suppress_default_error: |
| 663 | print(error_msg % val) |
| 664 | environ_cp[var_name] = '' |
| 665 | else: |
A. Unique TensorFlower | 5001ac0 | 2019-04-03 11:59:08 -0700 | [diff] [blame] | 666 | raise UserInputError('Invalid %s setting was provided %d times in a row. ' |
| 667 | 'Assuming to be a scripting mistake.' % |
| 668 | (var_name, n_ask_attempts)) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 669 | |
| 670 | environ_cp[var_name] = val |
| 671 | return val |
| 672 | |
| 673 | |
| 674 | def create_android_ndk_rule(environ_cp): |
| 675 | """Set ANDROID_NDK_HOME and write Android NDK WORKSPACE rule.""" |
| 676 | if is_windows() or is_cygwin(): |
A. Unique TensorFlower | 5001ac0 | 2019-04-03 11:59:08 -0700 | [diff] [blame] | 677 | default_ndk_path = cygpath('%s/Android/Sdk/ndk-bundle' % |
| 678 | environ_cp['APPDATA']) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 679 | elif is_macos(): |
| 680 | default_ndk_path = '%s/library/Android/Sdk/ndk-bundle' % environ_cp['HOME'] |
| 681 | else: |
| 682 | default_ndk_path = '%s/Android/Sdk/ndk-bundle' % environ_cp['HOME'] |
| 683 | |
| 684 | def valid_ndk_path(path): |
| 685 | return (os.path.exists(path) and |
| 686 | os.path.exists(os.path.join(path, 'source.properties'))) |
| 687 | |
| 688 | android_ndk_home_path = prompt_loop_or_load_from_env( |
| 689 | environ_cp, |
| 690 | var_name='ANDROID_NDK_HOME', |
| 691 | var_default=default_ndk_path, |
| 692 | ask_for_var='Please specify the home path of the Android NDK to use.', |
| 693 | check_success=valid_ndk_path, |
| 694 | error_msg=('The path %s or its child file "source.properties" ' |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 695 | 'does not exist.')) |
Michael Case | 5105350 | 2018-06-05 17:47:19 -0700 | [diff] [blame] | 696 | write_action_env_to_bazelrc('ANDROID_NDK_HOME', android_ndk_home_path) |
Jared Duke | a0104b7 | 2019-04-04 12:23:58 -0700 | [diff] [blame] | 697 | write_action_env_to_bazelrc( |
| 698 | 'ANDROID_NDK_API_LEVEL', |
| 699 | get_ndk_api_level(environ_cp, android_ndk_home_path)) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 700 | |
| 701 | |
| 702 | def create_android_sdk_rule(environ_cp): |
| 703 | """Set Android variables and write Android SDK WORKSPACE rule.""" |
| 704 | if is_windows() or is_cygwin(): |
| 705 | default_sdk_path = cygpath('%s/Android/Sdk' % environ_cp['APPDATA']) |
| 706 | elif is_macos(): |
Shashi Shekhar | c0ff0cc | 2018-07-17 09:00:24 -0700 | [diff] [blame] | 707 | default_sdk_path = '%s/library/Android/Sdk' % environ_cp['HOME'] |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 708 | else: |
| 709 | default_sdk_path = '%s/Android/Sdk' % environ_cp['HOME'] |
| 710 | |
| 711 | def valid_sdk_path(path): |
| 712 | return (os.path.exists(path) and |
| 713 | os.path.exists(os.path.join(path, 'platforms')) and |
| 714 | os.path.exists(os.path.join(path, 'build-tools'))) |
| 715 | |
| 716 | android_sdk_home_path = prompt_loop_or_load_from_env( |
| 717 | environ_cp, |
| 718 | var_name='ANDROID_SDK_HOME', |
| 719 | var_default=default_sdk_path, |
| 720 | ask_for_var='Please specify the home path of the Android SDK to use.', |
| 721 | check_success=valid_sdk_path, |
| 722 | error_msg=('Either %s does not exist, or it does not contain the ' |
| 723 | 'subdirectories "platforms" and "build-tools".')) |
| 724 | |
| 725 | platforms = os.path.join(android_sdk_home_path, 'platforms') |
| 726 | api_levels = sorted(os.listdir(platforms)) |
| 727 | api_levels = [x.replace('android-', '') for x in api_levels] |
| 728 | |
| 729 | def valid_api_level(api_level): |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 730 | return os.path.exists( |
| 731 | os.path.join(android_sdk_home_path, 'platforms', |
| 732 | 'android-' + api_level)) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 733 | |
| 734 | android_api_level = prompt_loop_or_load_from_env( |
| 735 | environ_cp, |
| 736 | var_name='ANDROID_API_LEVEL', |
| 737 | var_default=api_levels[-1], |
| 738 | ask_for_var=('Please specify the Android SDK API level to use. ' |
| 739 | '[Available levels: %s]') % api_levels, |
| 740 | check_success=valid_api_level, |
| 741 | error_msg='Android-%s is not present in the SDK path.') |
| 742 | |
| 743 | build_tools = os.path.join(android_sdk_home_path, 'build-tools') |
| 744 | versions = sorted(os.listdir(build_tools)) |
| 745 | |
| 746 | def valid_build_tools(version): |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 747 | return os.path.exists( |
| 748 | os.path.join(android_sdk_home_path, 'build-tools', version)) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 749 | |
| 750 | android_build_tools_version = prompt_loop_or_load_from_env( |
| 751 | environ_cp, |
| 752 | var_name='ANDROID_BUILD_TOOLS_VERSION', |
| 753 | var_default=versions[-1], |
| 754 | ask_for_var=('Please specify an Android build tools version to use. ' |
| 755 | '[Available versions: %s]') % versions, |
| 756 | check_success=valid_build_tools, |
| 757 | error_msg=('The selected SDK does not have build-tools version %s ' |
| 758 | 'available.')) |
| 759 | |
Michael Case | 5105350 | 2018-06-05 17:47:19 -0700 | [diff] [blame] | 760 | write_action_env_to_bazelrc('ANDROID_BUILD_TOOLS_VERSION', |
| 761 | android_build_tools_version) |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 762 | write_action_env_to_bazelrc('ANDROID_SDK_API_LEVEL', android_api_level) |
| 763 | write_action_env_to_bazelrc('ANDROID_SDK_HOME', android_sdk_home_path) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 764 | |
| 765 | |
Jared Duke | a0104b7 | 2019-04-04 12:23:58 -0700 | [diff] [blame] | 766 | def get_ndk_api_level(environ_cp, android_ndk_home_path): |
| 767 | """Gets the appropriate NDK API level to use for the provided Android NDK path.""" |
| 768 | |
| 769 | # First check to see if we're using a blessed version of the NDK. |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 770 | properties_path = '%s/source.properties' % android_ndk_home_path |
| 771 | if is_windows() or is_cygwin(): |
| 772 | properties_path = cygpath(properties_path) |
| 773 | with open(properties_path, 'r') as f: |
| 774 | filedata = f.read() |
| 775 | |
| 776 | revision = re.search(r'Pkg.Revision = (\d+)', filedata) |
| 777 | if revision: |
Jared Duke | a0104b7 | 2019-04-04 12:23:58 -0700 | [diff] [blame] | 778 | ndk_version = revision.group(1) |
Michael Case | 5105350 | 2018-06-05 17:47:19 -0700 | [diff] [blame] | 779 | else: |
| 780 | raise Exception('Unable to parse NDK revision.') |
Jared Duke | a0104b7 | 2019-04-04 12:23:58 -0700 | [diff] [blame] | 781 | if int(ndk_version) not in _SUPPORTED_ANDROID_NDK_VERSIONS: |
| 782 | print('WARNING: The NDK version in %s is %s, which is not ' |
| 783 | 'supported by Bazel (officially supported versions: %s). Please use ' |
| 784 | 'another version. Compiling Android targets may result in confusing ' |
| 785 | 'errors.\n' % (android_ndk_home_path, ndk_version, |
| 786 | _SUPPORTED_ANDROID_NDK_VERSIONS)) |
| 787 | |
| 788 | # Now grab the NDK API level to use. Note that this is different from the |
| 789 | # SDK API level, as the NDK API level is effectively the *min* target SDK |
| 790 | # version. |
| 791 | platforms = os.path.join(android_ndk_home_path, 'platforms') |
| 792 | api_levels = sorted(os.listdir(platforms)) |
| 793 | api_levels = [ |
| 794 | x.replace('android-', '') for x in api_levels if 'android-' in x |
| 795 | ] |
| 796 | |
| 797 | def valid_api_level(api_level): |
| 798 | return os.path.exists( |
| 799 | os.path.join(android_ndk_home_path, 'platforms', |
| 800 | 'android-' + api_level)) |
| 801 | |
| 802 | android_ndk_api_level = prompt_loop_or_load_from_env( |
| 803 | environ_cp, |
| 804 | var_name='ANDROID_NDK_API_LEVEL', |
| 805 | var_default='18', # 18 is required for GPU acceleration. |
| 806 | ask_for_var=('Please specify the (min) Android NDK API level to use. ' |
| 807 | '[Available levels: %s]') % api_levels, |
| 808 | check_success=valid_api_level, |
| 809 | error_msg='Android-%s is not present in the NDK path.') |
| 810 | |
| 811 | return android_ndk_api_level |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 812 | |
| 813 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 814 | def set_gcc_host_compiler_path(environ_cp): |
| 815 | """Set GCC_HOST_COMPILER_PATH.""" |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 816 | default_gcc_host_compiler_path = which('gcc') or '' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 817 | cuda_bin_symlink = '%s/bin/gcc' % environ_cp.get('CUDA_TOOLKIT_PATH') |
| 818 | |
| 819 | if os.path.islink(cuda_bin_symlink): |
| 820 | # os.readlink is only available in linux |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 821 | default_gcc_host_compiler_path = os.path.realpath(cuda_bin_symlink) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 822 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 823 | gcc_host_compiler_path = prompt_loop_or_load_from_env( |
| 824 | environ_cp, |
| 825 | var_name='GCC_HOST_COMPILER_PATH', |
| 826 | var_default=default_gcc_host_compiler_path, |
TensorFlower Gardener | abb763b | 2019-02-06 16:23:03 -0800 | [diff] [blame] | 827 | ask_for_var='Please specify which gcc should be used by nvcc as the host compiler.', |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 828 | check_success=os.path.exists, |
| 829 | error_msg='Invalid gcc path. %s cannot be found.', |
| 830 | ) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 831 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 832 | write_action_env_to_bazelrc('GCC_HOST_COMPILER_PATH', gcc_host_compiler_path) |
| 833 | |
| 834 | |
Ankur Taly | 0e6f39d | 2018-02-16 18:22:55 -0800 | [diff] [blame] | 835 | def reformat_version_sequence(version_str, sequence_count): |
| 836 | """Reformat the version string to have the given number of sequences. |
| 837 | |
| 838 | For example: |
| 839 | Given (7, 2) -> 7.0 |
| 840 | (7.0.1, 2) -> 7.0 |
| 841 | (5, 1) -> 5 |
| 842 | (5.0.3.2, 1) -> 5 |
| 843 | |
| 844 | Args: |
| 845 | version_str: String, the version string. |
| 846 | sequence_count: int, an integer. |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 847 | |
Ankur Taly | 0e6f39d | 2018-02-16 18:22:55 -0800 | [diff] [blame] | 848 | Returns: |
| 849 | string, reformatted version string. |
| 850 | """ |
| 851 | v = version_str.split('.') |
| 852 | if len(v) < sequence_count: |
| 853 | v = v + (['0'] * (sequence_count - len(v))) |
| 854 | |
| 855 | return '.'.join(v[:sequence_count]) |
| 856 | |
| 857 | |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 858 | def set_tf_cuda_paths(environ_cp): |
| 859 | """Set TF_CUDA_PATHS.""" |
| 860 | ask_cuda_paths = ( |
| 861 | 'Please specify the comma-separated list of base paths to look for CUDA ' |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 862 | 'libraries and headers. [Leave empty to use the default]: ') |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 863 | tf_cuda_paths = get_from_env_or_user_or_default(environ_cp, 'TF_CUDA_PATHS', |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 864 | ask_cuda_paths, '') |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 865 | if tf_cuda_paths: |
| 866 | environ_cp['TF_CUDA_PATHS'] = tf_cuda_paths |
| 867 | |
| 868 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 869 | def set_tf_cuda_version(environ_cp): |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 870 | """Set TF_CUDA_VERSION.""" |
A. Unique TensorFlower | 0cb8a07 | 2019-04-16 08:16:39 -0700 | [diff] [blame] | 871 | ask_cuda_version = ( |
| 872 | 'Please specify the CUDA SDK version you want to use. ' |
| 873 | '[Leave empty to default to CUDA %s]: ') % _DEFAULT_CUDA_VERSION |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 874 | tf_cuda_version = get_from_env_or_user_or_default(environ_cp, |
| 875 | 'TF_CUDA_VERSION', |
A. Unique TensorFlower | 0cb8a07 | 2019-04-16 08:16:39 -0700 | [diff] [blame] | 876 | ask_cuda_version, |
| 877 | _DEFAULT_CUDA_VERSION) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 878 | environ_cp['TF_CUDA_VERSION'] = tf_cuda_version |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 879 | |
| 880 | |
Yifei Feng | b1d8c59 | 2017-11-22 13:42:21 -0800 | [diff] [blame] | 881 | def set_tf_cudnn_version(environ_cp): |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 882 | """Set TF_CUDNN_VERSION.""" |
A. Unique TensorFlower | 0cb8a07 | 2019-04-16 08:16:39 -0700 | [diff] [blame] | 883 | ask_cudnn_version = ( |
| 884 | 'Please specify the cuDNN version you want to use. ' |
| 885 | '[Leave empty to default to cuDNN %s]: ') % _DEFAULT_CUDNN_VERSION |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 886 | tf_cudnn_version = get_from_env_or_user_or_default(environ_cp, |
| 887 | 'TF_CUDNN_VERSION', |
A. Unique TensorFlower | 0cb8a07 | 2019-04-16 08:16:39 -0700 | [diff] [blame] | 888 | ask_cudnn_version, |
| 889 | _DEFAULT_CUDNN_VERSION) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 890 | environ_cp['TF_CUDNN_VERSION'] = tf_cudnn_version |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 891 | |
| 892 | |
Mingxing Tan | 1e7b0e4 | 2018-06-28 19:13:20 -0700 | [diff] [blame] | 893 | def is_cuda_compatible(lib, cuda_ver, cudnn_ver): |
| 894 | """Check compatibility between given library and cudnn/cudart libraries.""" |
| 895 | ldd_bin = which('ldd') or '/usr/bin/ldd' |
| 896 | ldd_out = run_shell([ldd_bin, lib], True) |
| 897 | ldd_out = ldd_out.split(os.linesep) |
| 898 | cudnn_pattern = re.compile('.*libcudnn.so\\.?(.*) =>.*$') |
| 899 | cuda_pattern = re.compile('.*libcudart.so\\.?(.*) =>.*$') |
| 900 | cudnn = None |
| 901 | cudart = None |
| 902 | cudnn_ok = True # assume no cudnn dependency by default |
| 903 | cuda_ok = True # assume no cuda dependency by default |
| 904 | for line in ldd_out: |
| 905 | if 'libcudnn.so' in line: |
| 906 | cudnn = cudnn_pattern.search(line) |
| 907 | cudnn_ok = False |
| 908 | elif 'libcudart.so' in line: |
| 909 | cudart = cuda_pattern.search(line) |
| 910 | cuda_ok = False |
| 911 | if cudnn and len(cudnn.group(1)): |
| 912 | cudnn = convert_version_to_int(cudnn.group(1)) |
| 913 | if cudart and len(cudart.group(1)): |
| 914 | cudart = convert_version_to_int(cudart.group(1)) |
| 915 | if cudnn is not None: |
| 916 | cudnn_ok = (cudnn == cudnn_ver) |
| 917 | if cudart is not None: |
| 918 | cuda_ok = (cudart == cuda_ver) |
| 919 | return cudnn_ok and cuda_ok |
| 920 | |
| 921 | |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 922 | def set_tf_tensorrt_version(environ_cp): |
| 923 | """Set TF_TENSORRT_VERSION.""" |
Guangda Lai | 76f6938 | 2018-01-25 23:59:19 -0800 | [diff] [blame] | 924 | if not is_linux(): |
| 925 | raise ValueError('Currently TensorRT is only supported on Linux platform.') |
| 926 | |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 927 | if not int(environ_cp.get('TF_NEED_TENSORRT', False)): |
Guangda Lai | 76f6938 | 2018-01-25 23:59:19 -0800 | [diff] [blame] | 928 | return |
| 929 | |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 930 | ask_tensorrt_version = ( |
| 931 | 'Please specify the TensorRT version you want to use. ' |
A. Unique TensorFlower | 0cb8a07 | 2019-04-16 08:16:39 -0700 | [diff] [blame] | 932 | '[Leave empty to default to TensorRT %s]: ') % _DEFAULT_TENSORRT_VERSION |
| 933 | tf_tensorrt_version = get_from_env_or_user_or_default( |
| 934 | environ_cp, 'TF_TENSORRT_VERSION', ask_tensorrt_version, |
| 935 | _DEFAULT_TENSORRT_VERSION) |
Guangda Lai | 76f6938 | 2018-01-25 23:59:19 -0800 | [diff] [blame] | 936 | environ_cp['TF_TENSORRT_VERSION'] = tf_tensorrt_version |
Guangda Lai | 76f6938 | 2018-01-25 23:59:19 -0800 | [diff] [blame] | 937 | |
| 938 | |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 939 | def set_tf_nccl_version(environ_cp): |
| 940 | """Set TF_NCCL_VERSION.""" |
A. Unique TensorFlower | 1fda764 | 2018-04-05 03:09:27 -0700 | [diff] [blame] | 941 | if not is_linux(): |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 942 | raise ValueError('Currently NCCL is only supported on Linux platform.') |
A. Unique TensorFlower | 1fda764 | 2018-04-05 03:09:27 -0700 | [diff] [blame] | 943 | |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 944 | if 'TF_NCCL_VERSION' in environ_cp: |
| 945 | return |
| 946 | |
A. Unique TensorFlower | 1fda764 | 2018-04-05 03:09:27 -0700 | [diff] [blame] | 947 | ask_nccl_version = ( |
A. Unique TensorFlower | 53faa31 | 2018-10-05 08:46:54 -0700 | [diff] [blame] | 948 | 'Please specify the locally installed NCCL version you want to use. ' |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 949 | '[Leave empty to use http://github.com/nvidia/nccl]: ') |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 950 | tf_nccl_version = get_from_env_or_user_or_default(environ_cp, |
| 951 | 'TF_NCCL_VERSION', |
| 952 | ask_nccl_version, '') |
A. Unique TensorFlower | 1fda764 | 2018-04-05 03:09:27 -0700 | [diff] [blame] | 953 | environ_cp['TF_NCCL_VERSION'] = tf_nccl_version |
TensorFlower Gardener | abb763b | 2019-02-06 16:23:03 -0800 | [diff] [blame] | 954 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 955 | def get_native_cuda_compute_capabilities(environ_cp): |
| 956 | """Get native cuda compute capabilities. |
| 957 | |
| 958 | Args: |
| 959 | environ_cp: copy of the os.environ. |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 960 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 961 | Returns: |
| 962 | string of native cuda compute capabilities, separated by comma. |
| 963 | """ |
| 964 | device_query_bin = os.path.join( |
| 965 | environ_cp.get('CUDA_TOOLKIT_PATH'), 'extras/demo_suite/deviceQuery') |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 966 | if os.path.isfile(device_query_bin) and os.access(device_query_bin, os.X_OK): |
| 967 | try: |
| 968 | output = run_shell(device_query_bin).split('\n') |
| 969 | pattern = re.compile('[0-9]*\\.[0-9]*') |
| 970 | output = [pattern.search(x) for x in output if 'Capability' in x] |
| 971 | output = ','.join(x.group() for x in output if x is not None) |
| 972 | except subprocess.CalledProcessError: |
| 973 | output = '' |
| 974 | else: |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 975 | output = '' |
| 976 | return output |
| 977 | |
| 978 | |
| 979 | def set_tf_cuda_compute_capabilities(environ_cp): |
| 980 | """Set TF_CUDA_COMPUTE_CAPABILITIES.""" |
| 981 | while True: |
| 982 | native_cuda_compute_capabilities = get_native_cuda_compute_capabilities( |
| 983 | environ_cp) |
| 984 | if not native_cuda_compute_capabilities: |
| 985 | default_cuda_compute_capabilities = _DEFAULT_CUDA_COMPUTE_CAPABILITIES |
| 986 | else: |
| 987 | default_cuda_compute_capabilities = native_cuda_compute_capabilities |
| 988 | |
| 989 | ask_cuda_compute_capabilities = ( |
| 990 | 'Please specify a list of comma-separated ' |
P Sudeepam | 5209356 | 2019-02-17 17:34:01 +0530 | [diff] [blame] | 991 | 'CUDA compute capabilities you want to ' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 992 | 'build with.\nYou can find the compute ' |
| 993 | 'capability of your device at: ' |
| 994 | 'https://developer.nvidia.com/cuda-gpus.\nPlease' |
| 995 | ' note that each additional compute ' |
| 996 | 'capability significantly increases your ' |
P Sudeepam | 5209356 | 2019-02-17 17:34:01 +0530 | [diff] [blame] | 997 | 'build time and binary size, and that ' |
| 998 | 'TensorFlow only supports compute ' |
P Sudeepam | 765ceda | 2019-02-17 17:39:08 +0530 | [diff] [blame] | 999 | 'capabilities >= 3.5 [Default is: %s]: ' % |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1000 | default_cuda_compute_capabilities) |
| 1001 | tf_cuda_compute_capabilities = get_from_env_or_user_or_default( |
| 1002 | environ_cp, 'TF_CUDA_COMPUTE_CAPABILITIES', |
| 1003 | ask_cuda_compute_capabilities, default_cuda_compute_capabilities) |
| 1004 | # Check whether all capabilities from the input is valid |
| 1005 | all_valid = True |
Maciej | d0f5bc1 | 2018-04-30 22:30:58 -0500 | [diff] [blame] | 1006 | # Remove all whitespace characters before splitting the string |
Michael Case | 5105350 | 2018-06-05 17:47:19 -0700 | [diff] [blame] | 1007 | # that users may insert by accident, as this will result in error |
Maciej | d0f5bc1 | 2018-04-30 22:30:58 -0500 | [diff] [blame] | 1008 | tf_cuda_compute_capabilities = ''.join(tf_cuda_compute_capabilities.split()) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1009 | for compute_capability in tf_cuda_compute_capabilities.split(','): |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 1010 | m = re.match('[0-9]+.[0-9]+', compute_capability) |
| 1011 | if not m: |
Austin Anderson | 32202dc | 2019-02-19 10:46:27 -0800 | [diff] [blame] | 1012 | print('Invalid compute capability: %s' % compute_capability) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1013 | all_valid = False |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 1014 | else: |
P Sudeepam | 5209356 | 2019-02-17 17:34:01 +0530 | [diff] [blame] | 1015 | ver = float(m.group(0)) |
A. Unique TensorFlower | 8dc2d0e | 2019-03-12 01:41:05 -0700 | [diff] [blame] | 1016 | if ver < 3.0: |
| 1017 | print('ERROR: TensorFlow only supports CUDA compute capabilities 3.0 ' |
Austin Anderson | 32202dc | 2019-02-19 10:46:27 -0800 | [diff] [blame] | 1018 | 'and higher. Please re-specify the list of compute ' |
| 1019 | 'capabilities excluding version %s.' % ver) |
Andrew Harp | 6e3e7d1 | 2017-08-21 12:10:44 -0700 | [diff] [blame] | 1020 | all_valid = False |
A. Unique TensorFlower | 8dc2d0e | 2019-03-12 01:41:05 -0700 | [diff] [blame] | 1021 | if ver < 3.5: |
| 1022 | print('WARNING: XLA does not support CUDA compute capabilities ' |
| 1023 | 'lower than 3.5. Disable XLA when running on older GPUs.') |
P Sudeepam | 765ceda | 2019-02-17 17:39:08 +0530 | [diff] [blame] | 1024 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1025 | if all_valid: |
| 1026 | break |
| 1027 | |
| 1028 | # Reset and Retry |
| 1029 | environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = '' |
| 1030 | |
| 1031 | # Set TF_CUDA_COMPUTE_CAPABILITIES |
| 1032 | environ_cp['TF_CUDA_COMPUTE_CAPABILITIES'] = tf_cuda_compute_capabilities |
| 1033 | write_action_env_to_bazelrc('TF_CUDA_COMPUTE_CAPABILITIES', |
| 1034 | tf_cuda_compute_capabilities) |
| 1035 | |
| 1036 | |
| 1037 | def set_other_cuda_vars(environ_cp): |
| 1038 | """Set other CUDA related variables.""" |
A. Unique TensorFlower | ab39198 | 2018-07-11 04:52:49 -0700 | [diff] [blame] | 1039 | # If CUDA is enabled, always use GPU during build and test. |
| 1040 | if environ_cp.get('TF_CUDA_CLANG') == '1': |
| 1041 | write_to_bazelrc('build --config=cuda_clang') |
| 1042 | write_to_bazelrc('test --config=cuda_clang') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1043 | else: |
A. Unique TensorFlower | ab39198 | 2018-07-11 04:52:49 -0700 | [diff] [blame] | 1044 | write_to_bazelrc('build --config=cuda') |
| 1045 | write_to_bazelrc('test --config=cuda') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1046 | |
| 1047 | |
| 1048 | def set_host_cxx_compiler(environ_cp): |
| 1049 | """Set HOST_CXX_COMPILER.""" |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 1050 | default_cxx_host_compiler = which('g++') or '' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1051 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1052 | host_cxx_compiler = prompt_loop_or_load_from_env( |
| 1053 | environ_cp, |
| 1054 | var_name='HOST_CXX_COMPILER', |
| 1055 | var_default=default_cxx_host_compiler, |
| 1056 | ask_for_var=('Please specify which C++ compiler should be used as the ' |
| 1057 | 'host C++ compiler.'), |
| 1058 | check_success=os.path.exists, |
| 1059 | error_msg='Invalid C++ compiler path. %s cannot be found.', |
| 1060 | ) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1061 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1062 | write_action_env_to_bazelrc('HOST_CXX_COMPILER', host_cxx_compiler) |
| 1063 | |
| 1064 | |
| 1065 | def set_host_c_compiler(environ_cp): |
| 1066 | """Set HOST_C_COMPILER.""" |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 1067 | default_c_host_compiler = which('gcc') or '' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1068 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1069 | host_c_compiler = prompt_loop_or_load_from_env( |
| 1070 | environ_cp, |
| 1071 | var_name='HOST_C_COMPILER', |
| 1072 | var_default=default_c_host_compiler, |
Shanqing Cai | 7144571 | 2018-03-12 19:33:52 -0700 | [diff] [blame] | 1073 | ask_for_var=('Please specify which C compiler should be used as the host ' |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1074 | 'C compiler.'), |
| 1075 | check_success=os.path.exists, |
| 1076 | error_msg='Invalid C compiler path. %s cannot be found.', |
| 1077 | ) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1078 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1079 | write_action_env_to_bazelrc('HOST_C_COMPILER', host_c_compiler) |
| 1080 | |
| 1081 | |
| 1082 | def set_computecpp_toolkit_path(environ_cp): |
| 1083 | """Set COMPUTECPP_TOOLKIT_PATH.""" |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1084 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1085 | def toolkit_exists(toolkit_path): |
| 1086 | """Check if a computecpp toolkit path is valid.""" |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1087 | if is_linux(): |
| 1088 | sycl_rt_lib_path = 'lib/libComputeCpp.so' |
| 1089 | else: |
| 1090 | sycl_rt_lib_path = '' |
| 1091 | |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1092 | sycl_rt_lib_path_full = os.path.join(toolkit_path, sycl_rt_lib_path) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1093 | exists = os.path.exists(sycl_rt_lib_path_full) |
| 1094 | if not exists: |
| 1095 | print('Invalid SYCL %s library path. %s cannot be found' % |
| 1096 | (_TF_OPENCL_VERSION, sycl_rt_lib_path_full)) |
| 1097 | return exists |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1098 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1099 | computecpp_toolkit_path = prompt_loop_or_load_from_env( |
| 1100 | environ_cp, |
| 1101 | var_name='COMPUTECPP_TOOLKIT_PATH', |
| 1102 | var_default=_DEFAULT_COMPUTECPP_TOOLKIT_PATH, |
| 1103 | ask_for_var=( |
| 1104 | 'Please specify the location where ComputeCpp for SYCL %s is ' |
| 1105 | 'installed.' % _TF_OPENCL_VERSION), |
| 1106 | check_success=toolkit_exists, |
| 1107 | error_msg='Invalid SYCL compiler path. %s cannot be found.', |
| 1108 | suppress_default_error=True) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1109 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1110 | write_action_env_to_bazelrc('COMPUTECPP_TOOLKIT_PATH', |
| 1111 | computecpp_toolkit_path) |
| 1112 | |
Michael Case | d31531a | 2018-01-05 14:09:41 -0800 | [diff] [blame] | 1113 | |
Dandelion Man? | 90e42f3 | 2017-12-15 18:15:07 -0800 | [diff] [blame] | 1114 | def set_trisycl_include_dir(environ_cp): |
Michael Case | d31531a | 2018-01-05 14:09:41 -0800 | [diff] [blame] | 1115 | """Set TRISYCL_INCLUDE_DIR.""" |
Frank Chen | c4ef927 | 2018-01-10 11:36:52 -0800 | [diff] [blame] | 1116 | |
Dandelion Man? | 90e42f3 | 2017-12-15 18:15:07 -0800 | [diff] [blame] | 1117 | ask_trisycl_include_dir = ('Please specify the location of the triSYCL ' |
| 1118 | 'include directory. (Use --config=sycl_trisycl ' |
| 1119 | 'when building with Bazel) ' |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1120 | '[Default is %s]: ') % ( |
| 1121 | _DEFAULT_TRISYCL_INCLUDE_DIR) |
Frank Chen | c4ef927 | 2018-01-10 11:36:52 -0800 | [diff] [blame] | 1122 | |
Dandelion Man? | 90e42f3 | 2017-12-15 18:15:07 -0800 | [diff] [blame] | 1123 | while True: |
| 1124 | trisycl_include_dir = get_from_env_or_user_or_default( |
Michael Case | d31531a | 2018-01-05 14:09:41 -0800 | [diff] [blame] | 1125 | environ_cp, 'TRISYCL_INCLUDE_DIR', ask_trisycl_include_dir, |
| 1126 | _DEFAULT_TRISYCL_INCLUDE_DIR) |
Dandelion Man? | 90e42f3 | 2017-12-15 18:15:07 -0800 | [diff] [blame] | 1127 | if os.path.exists(trisycl_include_dir): |
| 1128 | break |
| 1129 | |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1130 | print('Invalid triSYCL include directory, %s cannot be found' % |
| 1131 | (trisycl_include_dir)) |
Dandelion Man? | 90e42f3 | 2017-12-15 18:15:07 -0800 | [diff] [blame] | 1132 | |
| 1133 | # Set TRISYCL_INCLUDE_DIR |
| 1134 | environ_cp['TRISYCL_INCLUDE_DIR'] = trisycl_include_dir |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1135 | write_action_env_to_bazelrc('TRISYCL_INCLUDE_DIR', trisycl_include_dir) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1136 | |
Yifei Feng | b1d8c59 | 2017-11-22 13:42:21 -0800 | [diff] [blame] | 1137 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1138 | def set_mpi_home(environ_cp): |
| 1139 | """Set MPI_HOME.""" |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1140 | |
Jonathan Hseu | 008910f | 2017-08-25 14:01:05 -0700 | [diff] [blame] | 1141 | default_mpi_home = which('mpirun') or which('mpiexec') or '' |
| 1142 | default_mpi_home = os.path.dirname(os.path.dirname(default_mpi_home)) |
| 1143 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1144 | def valid_mpi_path(mpi_home): |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1145 | exists = ( |
| 1146 | os.path.exists(os.path.join(mpi_home, 'include')) and |
TensorFlower Gardener | f7c861f | 2018-11-01 11:29:40 -0700 | [diff] [blame] | 1147 | (os.path.exists(os.path.join(mpi_home, 'lib')) or |
| 1148 | os.path.exists(os.path.join(mpi_home, 'lib64')) or |
| 1149 | os.path.exists(os.path.join(mpi_home, 'lib32')))) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1150 | if not exists: |
TensorFlower Gardener | f7c861f | 2018-11-01 11:29:40 -0700 | [diff] [blame] | 1151 | print( |
| 1152 | 'Invalid path to the MPI Toolkit. %s or %s or %s or %s cannot be found' |
| 1153 | % (os.path.join(mpi_home, 'include'), |
Christian Goll | ba95d09 | 2018-10-04 17:06:23 +0200 | [diff] [blame] | 1154 | os.path.exists(os.path.join(mpi_home, 'lib')), |
| 1155 | os.path.exists(os.path.join(mpi_home, 'lib64')), |
| 1156 | os.path.exists(os.path.join(mpi_home, 'lib32')))) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1157 | return exists |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1158 | |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1159 | _ = prompt_loop_or_load_from_env( |
| 1160 | environ_cp, |
| 1161 | var_name='MPI_HOME', |
| 1162 | var_default=default_mpi_home, |
| 1163 | ask_for_var='Please specify the MPI toolkit folder.', |
| 1164 | check_success=valid_mpi_path, |
| 1165 | error_msg='', |
| 1166 | suppress_default_error=True) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1167 | |
| 1168 | |
| 1169 | def set_other_mpi_vars(environ_cp): |
| 1170 | """Set other MPI related variables.""" |
| 1171 | # Link the MPI header files |
| 1172 | mpi_home = environ_cp.get('MPI_HOME') |
| 1173 | symlink_force('%s/include/mpi.h' % mpi_home, 'third_party/mpi/mpi.h') |
| 1174 | |
| 1175 | # Determine if we use OpenMPI or MVAPICH, these require different header files |
| 1176 | # to be included here to make bazel dependency checker happy |
| 1177 | if os.path.exists(os.path.join(mpi_home, 'include/mpi_portable_platform.h')): |
| 1178 | symlink_force( |
| 1179 | os.path.join(mpi_home, 'include/mpi_portable_platform.h'), |
| 1180 | 'third_party/mpi/mpi_portable_platform.h') |
| 1181 | # TODO(gunan): avoid editing files in configure |
| 1182 | sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=False', |
| 1183 | 'MPI_LIB_IS_OPENMPI=True') |
| 1184 | else: |
| 1185 | # MVAPICH / MPICH |
| 1186 | symlink_force( |
| 1187 | os.path.join(mpi_home, 'include/mpio.h'), 'third_party/mpi/mpio.h') |
| 1188 | symlink_force( |
| 1189 | os.path.join(mpi_home, 'include/mpicxx.h'), 'third_party/mpi/mpicxx.h') |
| 1190 | # TODO(gunan): avoid editing files in configure |
| 1191 | sed_in_place('third_party/mpi/mpi.bzl', 'MPI_LIB_IS_OPENMPI=True', |
| 1192 | 'MPI_LIB_IS_OPENMPI=False') |
| 1193 | |
| 1194 | if os.path.exists(os.path.join(mpi_home, 'lib/libmpi.so')): |
| 1195 | symlink_force( |
| 1196 | os.path.join(mpi_home, 'lib/libmpi.so'), 'third_party/mpi/libmpi.so') |
Christian Goll | ba95d09 | 2018-10-04 17:06:23 +0200 | [diff] [blame] | 1197 | elif os.path.exists(os.path.join(mpi_home, 'lib64/libmpi.so')): |
| 1198 | symlink_force( |
| 1199 | os.path.join(mpi_home, 'lib64/libmpi.so'), 'third_party/mpi/libmpi.so') |
| 1200 | elif os.path.exists(os.path.join(mpi_home, 'lib32/libmpi.so')): |
| 1201 | symlink_force( |
| 1202 | os.path.join(mpi_home, 'lib32/libmpi.so'), 'third_party/mpi/libmpi.so') |
| 1203 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1204 | else: |
TensorFlower Gardener | f7c861f | 2018-11-01 11:29:40 -0700 | [diff] [blame] | 1205 | raise ValueError( |
| 1206 | 'Cannot find the MPI library file in %s/lib or %s/lib64 or %s/lib32' % |
Mihai Maruseac | 91ebeec | 2019-01-29 17:07:38 -0800 | [diff] [blame] | 1207 | (mpi_home, mpi_home, mpi_home)) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1208 | |
A. Unique TensorFlower | ed29734 | 2019-03-15 11:25:28 -0700 | [diff] [blame] | 1209 | |
A. Unique TensorFlower | e9797fd | 2019-03-22 11:02:40 -0700 | [diff] [blame] | 1210 | def system_specific_test_config(env): |
A. Unique TensorFlower | 7bd8637 | 2019-03-21 15:19:30 -0700 | [diff] [blame] | 1211 | """Add default build and test flags required for TF tests to bazelrc.""" |
Gunhan Gulsoy | fff6696 | 2019-02-20 15:28:43 -0800 | [diff] [blame] | 1212 | write_to_bazelrc('test --flaky_test_attempts=3') |
| 1213 | write_to_bazelrc('test --test_size_filters=small,medium') |
| 1214 | write_to_bazelrc( |
| 1215 | 'test --test_tag_filters=-benchmark-test,-no_oss,-oss_serial') |
| 1216 | write_to_bazelrc('test --build_tag_filters=-benchmark-test,-no_oss') |
| 1217 | if is_windows(): |
Guangda Lai | bcd701a | 2019-03-12 21:04:51 -0700 | [diff] [blame] | 1218 | if env.get('TF_NEED_CUDA', None) == '1': |
Gunhan Gulsoy | fff6696 | 2019-02-20 15:28:43 -0800 | [diff] [blame] | 1219 | write_to_bazelrc( |
| 1220 | 'test --test_tag_filters=-no_windows,-no_windows_gpu,-no_gpu') |
| 1221 | write_to_bazelrc( |
| 1222 | 'test --build_tag_filters=-no_windows,-no_windows_gpu,-no_gpu') |
| 1223 | else: |
| 1224 | write_to_bazelrc('test --test_tag_filters=-no_windows,-gpu') |
| 1225 | write_to_bazelrc('test --build_tag_filters=-no_windows,-gpu') |
| 1226 | elif is_macos(): |
| 1227 | write_to_bazelrc('test --test_tag_filters=-gpu,-nomac,-no_mac') |
| 1228 | write_to_bazelrc('test --build_tag_filters=-gpu,-nomac,-no_mac') |
| 1229 | elif is_linux(): |
Guangda Lai | bcd701a | 2019-03-12 21:04:51 -0700 | [diff] [blame] | 1230 | if env.get('TF_NEED_CUDA', None) == '1': |
Gunhan Gulsoy | fff6696 | 2019-02-20 15:28:43 -0800 | [diff] [blame] | 1231 | write_to_bazelrc('test --test_tag_filters=-no_gpu') |
| 1232 | write_to_bazelrc('test --build_tag_filters=-no_gpu') |
| 1233 | write_to_bazelrc('test --test_env=LD_LIBRARY_PATH') |
| 1234 | else: |
| 1235 | write_to_bazelrc('test --test_tag_filters=-gpu') |
| 1236 | write_to_bazelrc('test --build_tag_filters=-gpu') |
| 1237 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1238 | |
Yifei Feng | 5198cb8 | 2018-08-17 13:53:06 -0700 | [diff] [blame] | 1239 | def set_system_libs_flag(environ_cp): |
| 1240 | syslibs = environ_cp.get('TF_SYSTEM_LIBS', '') |
TensorFlower Gardener | 61a8720 | 2018-10-01 12:25:39 -0700 | [diff] [blame] | 1241 | if syslibs: |
Jason Zaman | 5fc39bd | 2018-09-16 01:38:55 +0800 | [diff] [blame] | 1242 | if ',' in syslibs: |
| 1243 | syslibs = ','.join(sorted(syslibs.split(','))) |
| 1244 | else: |
| 1245 | syslibs = ','.join(sorted(syslibs.split())) |
Yifei Feng | 5198cb8 | 2018-08-17 13:53:06 -0700 | [diff] [blame] | 1246 | write_action_env_to_bazelrc('TF_SYSTEM_LIBS', syslibs) |
| 1247 | |
Jason Zaman | 5fc39bd | 2018-09-16 01:38:55 +0800 | [diff] [blame] | 1248 | if 'PREFIX' in environ_cp: |
| 1249 | write_to_bazelrc('build --define=PREFIX=%s' % environ_cp['PREFIX']) |
| 1250 | if 'LIBDIR' in environ_cp: |
| 1251 | write_to_bazelrc('build --define=LIBDIR=%s' % environ_cp['LIBDIR']) |
| 1252 | if 'INCLUDEDIR' in environ_cp: |
| 1253 | write_to_bazelrc('build --define=INCLUDEDIR=%s' % environ_cp['INCLUDEDIR']) |
| 1254 | |
Yifei Feng | 5198cb8 | 2018-08-17 13:53:06 -0700 | [diff] [blame] | 1255 | |
A. Unique TensorFlower | 1b21235 | 2018-07-19 13:48:50 -0700 | [diff] [blame] | 1256 | def set_windows_build_flags(environ_cp): |
| 1257 | """Set Windows specific build options.""" |
| 1258 | # The non-monolithic build is not supported yet |
| 1259 | write_to_bazelrc('build --config monolithic') |
| 1260 | # Suppress warning messages |
| 1261 | write_to_bazelrc('build --copt=-w --host_copt=-w') |
Loo Rong Jie | 31f10d2 | 2019-02-02 10:03:20 +0800 | [diff] [blame] | 1262 | # Fix winsock2.h conflicts |
TensorFlower Gardener | 345cccf | 2019-02-28 15:22:59 -0800 | [diff] [blame] | 1263 | write_to_bazelrc( |
| 1264 | 'build --copt=-DWIN32_LEAN_AND_MEAN --host_copt=-DWIN32_LEAN_AND_MEAN') |
A. Unique TensorFlower | 1b21235 | 2018-07-19 13:48:50 -0700 | [diff] [blame] | 1265 | # Output more verbose information when something goes wrong |
| 1266 | write_to_bazelrc('build --verbose_failures') |
| 1267 | # The host and target platforms are the same in Windows build. So we don't |
| 1268 | # have to distinct them. This avoids building the same targets twice. |
| 1269 | write_to_bazelrc('build --distinct_host_configuration=false') |
A. Unique TensorFlower | 1b21235 | 2018-07-19 13:48:50 -0700 | [diff] [blame] | 1270 | |
| 1271 | if get_var( |
| 1272 | environ_cp, 'TF_OVERRIDE_EIGEN_STRONG_INLINE', 'Eigen strong inline', |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1273 | True, ('Would you like to override eigen strong inline for some C++ ' |
| 1274 | 'compilation to reduce the compilation time?'), |
| 1275 | 'Eigen strong inline overridden.', 'Not overriding eigen strong inline, ' |
A. Unique TensorFlower | 1b21235 | 2018-07-19 13:48:50 -0700 | [diff] [blame] | 1276 | 'some compilations could take more than 20 mins.'): |
| 1277 | # Due to a known MSVC compiler issue |
| 1278 | # https://github.com/tensorflow/tensorflow/issues/10521 |
| 1279 | # Overriding eigen strong inline speeds up the compiling of |
| 1280 | # conv_grad_ops_3d.cc and conv_ops_3d.cc by 20 minutes, |
| 1281 | # but this also hurts the performance. Let users decide what they want. |
| 1282 | write_to_bazelrc('build --define=override_eigen_strong_inline=true') |
Dandelion Man? | 90e42f3 | 2017-12-15 18:15:07 -0800 | [diff] [blame] | 1283 | |
A. Unique TensorFlower | 061c359 | 2017-11-13 14:21:04 -0800 | [diff] [blame] | 1284 | |
Michael Case | d31531a | 2018-01-05 14:09:41 -0800 | [diff] [blame] | 1285 | def config_info_line(name, help_text): |
| 1286 | """Helper function to print formatted help text for Bazel config options.""" |
| 1287 | print('\t--config=%-12s\t# %s' % (name, help_text)) |
| 1288 | |
| 1289 | |
A. Unique TensorFlower | 76e879d | 2019-03-22 00:25:36 -0700 | [diff] [blame] | 1290 | def configure_ios(): |
| 1291 | """Configures TensorFlow for iOS builds. |
A. Unique TensorFlower | 93e7073 | 2019-02-14 16:45:32 -0800 | [diff] [blame] | 1292 | |
A. Unique TensorFlower | 76e879d | 2019-03-22 00:25:36 -0700 | [diff] [blame] | 1293 | This function will only be executed if `is_macos()` is true. |
A. Unique TensorFlower | 93e7073 | 2019-02-14 16:45:32 -0800 | [diff] [blame] | 1294 | """ |
| 1295 | if not is_macos(): |
| 1296 | return |
A. Unique TensorFlower | ed29734 | 2019-03-15 11:25:28 -0700 | [diff] [blame] | 1297 | if _TF_CURRENT_BAZEL_VERSION is None or _TF_CURRENT_BAZEL_VERSION < 23000: |
| 1298 | print( |
| 1299 | 'Building Bazel rules on Apple platforms requires Bazel 0.23 or later.') |
A. Unique TensorFlower | 76e879d | 2019-03-22 00:25:36 -0700 | [diff] [blame] | 1300 | for filepath in APPLE_BAZEL_FILES: |
| 1301 | existing_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath + '.apple') |
| 1302 | renamed_filepath = os.path.join(_TF_WORKSPACE_ROOT, filepath) |
| 1303 | symlink_force(existing_filepath, renamed_filepath) |
| 1304 | for filepath in IOS_FILES: |
| 1305 | filename = os.path.basename(filepath) |
| 1306 | new_filepath = os.path.join(_TF_WORKSPACE_ROOT, filename) |
| 1307 | symlink_force(filepath, new_filepath) |
A. Unique TensorFlower | 93e7073 | 2019-02-14 16:45:32 -0800 | [diff] [blame] | 1308 | |
| 1309 | |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 1310 | def validate_cuda_config(environ_cp): |
| 1311 | """Run find_cuda_config.py and return cuda_toolkit_path, or None.""" |
| 1312 | |
| 1313 | def maybe_encode_env(env): |
| 1314 | """Encodes unicode in env to str on Windows python 2.x.""" |
| 1315 | if not is_windows() or sys.version_info[0] != 2: |
| 1316 | return env |
| 1317 | for k, v in env.items(): |
| 1318 | if isinstance(k, unicode): |
| 1319 | k = k.encode('ascii') |
| 1320 | if isinstance(v, unicode): |
| 1321 | v = v.encode('ascii') |
| 1322 | env[k] = v |
| 1323 | return env |
| 1324 | |
| 1325 | cuda_libraries = ['cuda', 'cudnn'] |
| 1326 | if is_linux(): |
| 1327 | if 'TF_TENSORRT_VERSION' in environ_cp: # if env variable exists |
| 1328 | cuda_libraries.append('tensorrt') |
| 1329 | if environ_cp.get('TF_NCCL_VERSION', None): # if env variable not empty |
| 1330 | cuda_libraries.append('nccl') |
| 1331 | |
| 1332 | proc = subprocess.Popen( |
| 1333 | [environ_cp['PYTHON_BIN_PATH'], 'third_party/gpus/find_cuda_config.py'] + |
| 1334 | cuda_libraries, |
| 1335 | stdout=subprocess.PIPE, |
| 1336 | env=maybe_encode_env(environ_cp)) |
| 1337 | |
| 1338 | if proc.wait(): |
| 1339 | # Errors from find_cuda_config.py were sent to stderr. |
A. Unique TensorFlower | 0cb8a07 | 2019-04-16 08:16:39 -0700 | [diff] [blame] | 1340 | print('Asking for detailed CUDA configuration...\n') |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 1341 | return False |
| 1342 | |
| 1343 | config = dict( |
| 1344 | tuple(line.decode('ascii').rstrip().split(': ')) for line in proc.stdout) |
| 1345 | |
| 1346 | print('Found CUDA %s in:' % config['cuda_version']) |
| 1347 | print(' %s' % config['cuda_library_dir']) |
| 1348 | print(' %s' % config['cuda_include_dir']) |
| 1349 | |
| 1350 | print('Found cuDNN %s in:' % config['cudnn_version']) |
| 1351 | print(' %s' % config['cudnn_library_dir']) |
| 1352 | print(' %s' % config['cudnn_include_dir']) |
| 1353 | |
| 1354 | if 'tensorrt_version' in config: |
| 1355 | print('Found TensorRT %s in:' % config['tensorrt_version']) |
| 1356 | print(' %s' % config['tensorrt_library_dir']) |
| 1357 | print(' %s' % config['tensorrt_include_dir']) |
| 1358 | |
| 1359 | if config.get('nccl_version', None): |
| 1360 | print('Found NCCL %s in:' % config['nccl_version']) |
| 1361 | print(' %s' % config['nccl_library_dir']) |
| 1362 | print(' %s' % config['nccl_include_dir']) |
| 1363 | |
| 1364 | print('\n') |
| 1365 | |
| 1366 | environ_cp['CUDA_TOOLKIT_PATH'] = config['cuda_toolkit_path'] |
| 1367 | return True |
| 1368 | |
| 1369 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1370 | def main(): |
A. Unique TensorFlower | 7c5eb35 | 2018-10-01 07:15:23 -0700 | [diff] [blame] | 1371 | global _TF_WORKSPACE_ROOT |
| 1372 | global _TF_BAZELRC |
A. Unique TensorFlower | ed29734 | 2019-03-15 11:25:28 -0700 | [diff] [blame] | 1373 | global _TF_CURRENT_BAZEL_VERSION |
A. Unique TensorFlower | 7c5eb35 | 2018-10-01 07:15:23 -0700 | [diff] [blame] | 1374 | |
Shanqing Cai | 7144571 | 2018-03-12 19:33:52 -0700 | [diff] [blame] | 1375 | parser = argparse.ArgumentParser() |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1376 | parser.add_argument( |
| 1377 | '--workspace', |
| 1378 | type=str, |
A. Unique TensorFlower | 7c5eb35 | 2018-10-01 07:15:23 -0700 | [diff] [blame] | 1379 | default=os.path.abspath(os.path.dirname(__file__)), |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1380 | help='The absolute path to your active Bazel workspace.') |
Shanqing Cai | 7144571 | 2018-03-12 19:33:52 -0700 | [diff] [blame] | 1381 | args = parser.parse_args() |
| 1382 | |
A. Unique TensorFlower | 7c5eb35 | 2018-10-01 07:15:23 -0700 | [diff] [blame] | 1383 | _TF_WORKSPACE_ROOT = args.workspace |
| 1384 | _TF_BAZELRC = os.path.join(_TF_WORKSPACE_ROOT, _TF_BAZELRC_FILENAME) |
| 1385 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1386 | # Make a copy of os.environ to be clear when functions and getting and setting |
| 1387 | # environment variables. |
| 1388 | environ_cp = dict(os.environ) |
| 1389 | |
Mihai Maruseac | 4db860f | 2019-04-19 08:52:10 -0700 | [diff] [blame^] | 1390 | current_bazel_version = check_bazel_version('0.24.1', '0.24.1') |
A. Unique TensorFlower | ed29734 | 2019-03-15 11:25:28 -0700 | [diff] [blame] | 1391 | _TF_CURRENT_BAZEL_VERSION = convert_version_to_int(current_bazel_version) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1392 | |
A. Unique TensorFlower | 7c5eb35 | 2018-10-01 07:15:23 -0700 | [diff] [blame] | 1393 | reset_tf_configure_bazelrc() |
Yun Peng | 03e63a2 | 2018-11-07 11:18:53 +0100 | [diff] [blame] | 1394 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1395 | cleanup_makefile() |
Gunhan Gulsoy | ed89a2b | 2017-09-19 18:36:26 -0700 | [diff] [blame] | 1396 | setup_python(environ_cp) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1397 | |
| 1398 | if is_windows(): |
Yifei Feng | b1d8c59 | 2017-11-22 13:42:21 -0800 | [diff] [blame] | 1399 | environ_cp['TF_NEED_OPENCL_SYCL'] = '0' |
| 1400 | environ_cp['TF_NEED_COMPUTECPP'] = '0' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1401 | environ_cp['TF_NEED_OPENCL'] = '0' |
| 1402 | environ_cp['TF_CUDA_CLANG'] = '0' |
Guangda Lai | 76f6938 | 2018-01-25 23:59:19 -0800 | [diff] [blame] | 1403 | environ_cp['TF_NEED_TENSORRT'] = '0' |
Ilya Biryukov | 9e651e4 | 2018-03-22 05:33:42 -0700 | [diff] [blame] | 1404 | # TODO(ibiryukov): Investigate using clang as a cpu or cuda compiler on |
| 1405 | # Windows. |
| 1406 | environ_cp['TF_DOWNLOAD_CLANG'] = '0' |
A. Unique TensorFlower | 6e97fb3 | 2018-07-16 14:07:29 -0700 | [diff] [blame] | 1407 | environ_cp['TF_NEED_MPI'] = '0' |
| 1408 | environ_cp['TF_SET_ANDROID_WORKSPACE'] = '0' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1409 | |
| 1410 | if is_macos(): |
Guangda Lai | 76f6938 | 2018-01-25 23:59:19 -0800 | [diff] [blame] | 1411 | environ_cp['TF_NEED_TENSORRT'] = '0' |
A. Unique TensorFlower | 93e7073 | 2019-02-14 16:45:32 -0800 | [diff] [blame] | 1412 | else: |
A. Unique TensorFlower | 76e879d | 2019-03-22 00:25:36 -0700 | [diff] [blame] | 1413 | environ_cp['TF_CONFIGURE_IOS'] = '0' |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1414 | |
Jon Triebenbach | 6896a74 | 2018-06-27 13:29:53 -0500 | [diff] [blame] | 1415 | # The numpy package on ppc64le uses OpenBLAS which has multi-threading |
| 1416 | # issues that lead to incorrect answers. Set OMP_NUM_THREADS=1 at |
| 1417 | # runtime to allow the Tensorflow testcases which compare numpy |
| 1418 | # results to Tensorflow results to succeed. |
| 1419 | if is_ppc64le(): |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1420 | write_action_env_to_bazelrc('OMP_NUM_THREADS', 1) |
Jon Triebenbach | 6896a74 | 2018-06-27 13:29:53 -0500 | [diff] [blame] | 1421 | |
Grzegorz Pawelczak | ec82efd | 2018-10-09 15:03:46 +0100 | [diff] [blame] | 1422 | xla_enabled_by_default = is_linux() |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1423 | set_build_var(environ_cp, 'TF_ENABLE_XLA', 'XLA JIT', 'with_xla_support', |
Grzegorz Pawelczak | ec82efd | 2018-10-09 15:03:46 +0100 | [diff] [blame] | 1424 | xla_enabled_by_default, 'xla') |
Gunhan Gulsoy | 3da0dff | 2018-09-26 11:55:50 -0700 | [diff] [blame] | 1425 | |
Yifei Feng | b1d8c59 | 2017-11-22 13:42:21 -0800 | [diff] [blame] | 1426 | set_action_env_var(environ_cp, 'TF_NEED_OPENCL_SYCL', 'OpenCL SYCL', False) |
| 1427 | if environ_cp.get('TF_NEED_OPENCL_SYCL') == '1': |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1428 | set_host_cxx_compiler(environ_cp) |
| 1429 | set_host_c_compiler(environ_cp) |
Yifei Feng | b1d8c59 | 2017-11-22 13:42:21 -0800 | [diff] [blame] | 1430 | set_action_env_var(environ_cp, 'TF_NEED_COMPUTECPP', 'ComputeCPP', True) |
| 1431 | if environ_cp.get('TF_NEED_COMPUTECPP') == '1': |
| 1432 | set_computecpp_toolkit_path(environ_cp) |
| 1433 | else: |
| 1434 | set_trisycl_include_dir(environ_cp) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1435 | |
Wen-Heng (Jack) Chung | 69d3b8f | 2018-06-22 23:09:43 -0500 | [diff] [blame] | 1436 | set_action_env_var(environ_cp, 'TF_NEED_ROCM', 'ROCm', False) |
| 1437 | if (environ_cp.get('TF_NEED_ROCM') == '1' and |
TensorFlower Gardener | 62e6016 | 2018-09-27 10:22:55 -0700 | [diff] [blame] | 1438 | 'LD_LIBRARY_PATH' in environ_cp and |
| 1439 | environ_cp.get('LD_LIBRARY_PATH') != '1'): |
| 1440 | write_action_env_to_bazelrc('LD_LIBRARY_PATH', |
| 1441 | environ_cp.get('LD_LIBRARY_PATH')) |
Wen-Heng (Jack) Chung | 69d3b8f | 2018-06-22 23:09:43 -0500 | [diff] [blame] | 1442 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1443 | set_action_env_var(environ_cp, 'TF_NEED_CUDA', 'CUDA', False) |
A. Unique TensorFlower | 24cbb2a | 2017-09-08 07:45:44 -0700 | [diff] [blame] | 1444 | if (environ_cp.get('TF_NEED_CUDA') == '1' and |
| 1445 | 'TF_CUDA_CONFIG_REPO' not in environ_cp): |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 1446 | |
| 1447 | set_action_env_var(environ_cp, 'TF_NEED_TENSORRT', 'TensorRT', False) |
| 1448 | |
| 1449 | environ_save = dict(environ_cp) |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 1450 | for _ in range(_DEFAULT_PROMPT_ASK_ATTEMPTS): |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 1451 | |
| 1452 | if validate_cuda_config(environ_cp): |
| 1453 | cuda_env_names = [ |
| 1454 | 'TF_CUDA_VERSION', 'TF_CUBLAS_VERSION', 'TF_CUDNN_VERSION', |
| 1455 | 'TF_TENSORRT_VERSION', 'TF_NCCL_VERSION', 'TF_CUDA_PATHS', |
| 1456 | 'CUDA_TOOLKIT_PATH' |
| 1457 | ] |
| 1458 | for name in cuda_env_names: |
| 1459 | if name in environ_cp: |
| 1460 | write_action_env_to_bazelrc(name, environ_cp[name]) |
| 1461 | break |
| 1462 | |
| 1463 | # Restore settings changed below if CUDA config could not be validated. |
| 1464 | environ_cp = dict(environ_save) |
| 1465 | |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 1466 | set_tf_cuda_version(environ_cp) |
| 1467 | set_tf_cudnn_version(environ_cp) |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 1468 | if is_linux(): |
| 1469 | set_tf_tensorrt_version(environ_cp) |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 1470 | set_tf_nccl_version(environ_cp) |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 1471 | |
A. Unique TensorFlower | 651b0bc | 2019-04-16 06:13:43 -0700 | [diff] [blame] | 1472 | set_tf_cuda_paths(environ_cp) |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 1473 | |
A. Unique TensorFlower | 8e9ca66 | 2019-04-15 12:47:11 -0700 | [diff] [blame] | 1474 | else: |
| 1475 | raise UserInputError( |
| 1476 | 'Invalid CUDA setting were provided %d ' |
| 1477 | 'times in a row. Assuming to be a scripting mistake.' % |
| 1478 | _DEFAULT_PROMPT_ASK_ATTEMPTS) |
| 1479 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1480 | set_tf_cuda_compute_capabilities(environ_cp) |
Ankur Taly | 0e6f39d | 2018-02-16 18:22:55 -0800 | [diff] [blame] | 1481 | if 'LD_LIBRARY_PATH' in environ_cp and environ_cp.get( |
| 1482 | 'LD_LIBRARY_PATH') != '1': |
| 1483 | write_action_env_to_bazelrc('LD_LIBRARY_PATH', |
| 1484 | environ_cp.get('LD_LIBRARY_PATH')) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1485 | |
| 1486 | set_tf_cuda_clang(environ_cp) |
| 1487 | if environ_cp.get('TF_CUDA_CLANG') == '1': |
Ilya Biryukov | 9e651e4 | 2018-03-22 05:33:42 -0700 | [diff] [blame] | 1488 | # Ask whether we should download the clang toolchain. |
| 1489 | set_tf_download_clang(environ_cp) |
A. Unique TensorFlower | fd29e95 | 2017-12-22 03:07:51 -0800 | [diff] [blame] | 1490 | if environ_cp.get('TF_DOWNLOAD_CLANG') != '1': |
| 1491 | # Set up which clang we should use as the cuda / host compiler. |
| 1492 | set_clang_cuda_compiler_path(environ_cp) |
Ilya Biryukov | 1c3d02e | 2018-09-04 03:09:52 -0700 | [diff] [blame] | 1493 | else: |
| 1494 | # Use downloaded LLD for linking. |
| 1495 | write_to_bazelrc('build:cuda_clang --config=download_clang_use_lld') |
| 1496 | write_to_bazelrc('test:cuda_clang --config=download_clang_use_lld') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1497 | else: |
| 1498 | # Set up which gcc nvcc should use as the host compiler |
| 1499 | # No need to set this on Windows |
| 1500 | if not is_windows(): |
| 1501 | set_gcc_host_compiler_path(environ_cp) |
| 1502 | set_other_cuda_vars(environ_cp) |
Ilya Biryukov | 9e651e4 | 2018-03-22 05:33:42 -0700 | [diff] [blame] | 1503 | else: |
| 1504 | # CUDA not required. Ask whether we should download the clang toolchain and |
| 1505 | # use it for the CPU build. |
| 1506 | set_tf_download_clang(environ_cp) |
| 1507 | if environ_cp.get('TF_DOWNLOAD_CLANG') == '1': |
| 1508 | write_to_bazelrc('build --config=download_clang') |
| 1509 | write_to_bazelrc('test --config=download_clang') |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1510 | |
Wen-Heng (Jack) Chung | 69d3b8f | 2018-06-22 23:09:43 -0500 | [diff] [blame] | 1511 | # SYCL / ROCm / CUDA are mutually exclusive. |
| 1512 | # At most 1 GPU platform can be configured. |
| 1513 | gpu_platform_count = 0 |
| 1514 | if environ_cp.get('TF_NEED_OPENCL_SYCL') == '1': |
| 1515 | gpu_platform_count += 1 |
| 1516 | if environ_cp.get('TF_NEED_ROCM') == '1': |
| 1517 | gpu_platform_count += 1 |
| 1518 | if environ_cp.get('TF_NEED_CUDA') == '1': |
| 1519 | gpu_platform_count += 1 |
| 1520 | if gpu_platform_count >= 2: |
| 1521 | raise UserInputError('SYCL / CUDA / ROCm are mututally exclusive. ' |
| 1522 | 'At most 1 GPU platform can be configured.') |
| 1523 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1524 | set_build_var(environ_cp, 'TF_NEED_MPI', 'MPI', 'with_mpi_support', False) |
| 1525 | if environ_cp.get('TF_NEED_MPI') == '1': |
| 1526 | set_mpi_home(environ_cp) |
| 1527 | set_other_mpi_vars(environ_cp) |
| 1528 | |
| 1529 | set_cc_opt_flags(environ_cp) |
Yifei Feng | 5198cb8 | 2018-08-17 13:53:06 -0700 | [diff] [blame] | 1530 | set_system_libs_flag(environ_cp) |
A. Unique TensorFlower | 1b21235 | 2018-07-19 13:48:50 -0700 | [diff] [blame] | 1531 | if is_windows(): |
| 1532 | set_windows_build_flags(environ_cp) |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1533 | |
Anna R | a9a1d5a | 2018-09-14 12:44:31 -0700 | [diff] [blame] | 1534 | # Add a config option to build TensorFlow 2.0 API. |
| 1535 | write_to_bazelrc('build:v2 --define=tf_api_version=2') |
| 1536 | |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1537 | if get_var(environ_cp, 'TF_SET_ANDROID_WORKSPACE', 'android workspace', False, |
| 1538 | ('Would you like to interactively configure ./WORKSPACE for ' |
| 1539 | 'Android builds?'), 'Searching for NDK and SDK installations.', |
| 1540 | 'Not configuring the WORKSPACE for Android builds.'): |
Michael Case | 5105350 | 2018-06-05 17:47:19 -0700 | [diff] [blame] | 1541 | create_android_ndk_rule(environ_cp) |
| 1542 | create_android_sdk_rule(environ_cp) |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1543 | |
A. Unique TensorFlower | e9797fd | 2019-03-22 11:02:40 -0700 | [diff] [blame] | 1544 | system_specific_test_config(os.environ) |
Gunhan Gulsoy | fff6696 | 2019-02-20 15:28:43 -0800 | [diff] [blame] | 1545 | |
A. Unique TensorFlower | 5001ac0 | 2019-04-03 11:59:08 -0700 | [diff] [blame] | 1546 | set_action_env_var(environ_cp, 'TF_CONFIGURE_IOS', 'iOS', False) |
| 1547 | if environ_cp.get('TF_CONFIGURE_IOS') == '1': |
A. Unique TensorFlower | 76e879d | 2019-03-22 00:25:36 -0700 | [diff] [blame] | 1548 | configure_ios() |
A. Unique TensorFlower | e9797fd | 2019-03-22 11:02:40 -0700 | [diff] [blame] | 1549 | else: |
| 1550 | # TODO(pcloudy): Remove BAZEL_USE_CPP_ONLY_TOOLCHAIN after Bazel is upgraded |
| 1551 | # to 0.24.0. |
| 1552 | # For working around https://github.com/bazelbuild/bazel/issues/7607 |
| 1553 | if is_macos(): |
| 1554 | write_to_bazelrc('build --action_env=BAZEL_USE_CPP_ONLY_TOOLCHAIN=1') |
A. Unique TensorFlower | 93e7073 | 2019-02-14 16:45:32 -0800 | [diff] [blame] | 1555 | |
Gunhan Gulsoy | 3437098 | 2018-10-12 15:26:01 -0700 | [diff] [blame] | 1556 | print('Preconfigured Bazel build configs. You can use any of the below by ' |
| 1557 | 'adding "--config=<>" to your build command. See .bazelrc for more ' |
| 1558 | 'details.') |
| 1559 | config_info_line('mkl', 'Build with MKL support.') |
| 1560 | config_info_line('monolithic', 'Config for mostly static monolithic build.') |
| 1561 | config_info_line('gdr', 'Build with GDR support.') |
| 1562 | config_info_line('verbs', 'Build with libverbs support.') |
| 1563 | config_info_line('ngraph', 'Build with Intel nGraph support.') |
A. Unique TensorFlower | a6bf9c8 | 2019-02-26 10:08:35 -0800 | [diff] [blame] | 1564 | config_info_line('numa', 'Build with NUMA support.') |
TensorFlower Gardener | abb763b | 2019-02-06 16:23:03 -0800 | [diff] [blame] | 1565 | config_info_line( |
| 1566 | 'dynamic_kernels', |
| 1567 | '(Experimental) Build kernels into separate shared objects.') |
Gunhan Gulsoy | 3437098 | 2018-10-12 15:26:01 -0700 | [diff] [blame] | 1568 | |
| 1569 | print('Preconfigured Bazel build configs to DISABLE default on features:') |
| 1570 | config_info_line('noaws', 'Disable AWS S3 filesystem support.') |
| 1571 | config_info_line('nogcp', 'Disable GCP support.') |
| 1572 | config_info_line('nohdfs', 'Disable HDFS support.') |
Penporn Koanantakool | 489f1dc | 2019-01-10 22:07:22 -0800 | [diff] [blame] | 1573 | config_info_line('noignite', 'Disable Apache Ignite support.') |
Gunhan Gulsoy | 3437098 | 2018-10-12 15:26:01 -0700 | [diff] [blame] | 1574 | config_info_line('nokafka', 'Disable Apache Kafka support.') |
Gunhan Gulsoy | eea8168 | 2018-11-26 16:51:23 -0800 | [diff] [blame] | 1575 | config_info_line('nonccl', 'Disable NVIDIA NCCL support.') |
Austin Anderson | 6afface | 2017-12-05 11:59:17 -0800 | [diff] [blame] | 1576 | |
Gunhan Gulsoy | ffa90fc | 2018-09-26 01:38:55 -0700 | [diff] [blame] | 1577 | |
A. Unique TensorFlower | 73ea287 | 2017-07-25 13:30:03 -0700 | [diff] [blame] | 1578 | if __name__ == '__main__': |
| 1579 | main() |