Skip to content

create less temporary directories for TensorFlow by (only) using --output_user_root #2293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions easybuild/easyblocks/t/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,10 @@ def get_system_libs(self):

def setup_build_dirs(self):
"""Setup temporary build directories"""
# Tensorflow/Bazel needs a couple of directories where it stores build cache and artefacts
tmpdir = tempfile.mkdtemp(suffix='-bazel-tf', dir=self.builddir)
self.output_root_dir = os.path.join(tmpdir, 'output_root')
self.output_base_dir = os.path.join(tmpdir, 'output_base')
self.output_user_root_dir = os.path.join(tmpdir, 'output_user_root')
self.wrapper_dir = os.path.join(tmpdir, 'wrapper_bin')
# This (likely) needs to be a subdir of output_base
self.install_base_dir = os.path.join(self.output_base_dir, 'inst_base')
# Path where Bazel will store its output, build artefacts etc.
self.output_user_root_dir = tempfile.mkdtemp(suffix='-bazel-tf', dir=self.builddir)
# Folder where wrapper binaries can be placed, where required. TODO: Replace by --action_env cmds
self.wrapper_dir = tempfile.mkdtemp(suffix='-wrapper_bin', dir=self.builddir)

def configure_step(self):
"""Custom configuration procedure for TensorFlow."""
Expand Down Expand Up @@ -640,17 +636,14 @@ def configure_step(self):
for (key, val) in sorted(config_env_vars.items()):
env.setvar(key, val)

# Does no longer apply (and might not be required at all) since 1.12.0
if LooseVersion(self.version) < LooseVersion('1.12.0'):
# patch configure.py (called by configure script) to avoid that Bazel abuses $HOME/.cache/bazel
regex_subs = [(r"(run_shell\(\['bazel')",
r"\1, '--output_base=%s', '--install_base=%s'" % (self.output_base_dir,
self.install_base_dir))]
# configure.py (called by configure script) already calls bazel to determine the bazel version
# Since 2.3.0 `bazel --version` is used which doesn't extract bazel, prior it did
# Hence make sure it doesn't extract into $HOME/.cache/bazel
if LooseVersion(self.version) < LooseVersion('2.3.0'):
regex_subs = [(r"('bazel', '--batch')",
r"\1, '--output_user_root=%s'" % self.output_user_root_dir)]
apply_regex_substitutions('configure.py', regex_subs)

# Tell Bazel to not use $HOME/.cache/bazel at all
# See https://docs.bazel.build/versions/master/output_directories.html
env.setvar('TEST_TMPDIR', self.output_root_dir)
cmd = self.cfg['preconfigopts'] + './configure ' + self.cfg['configopts']
run_cmd(cmd, log_all=True, simple=True)

Expand Down Expand Up @@ -733,8 +726,6 @@ def build_step(self):

# Options passed to the bazel command
self.bazel_opts = [
'--output_base=%s' % self.output_base_dir,
'--install_base=%s' % self.install_base_dir,
'--output_user_root=%s' % self.output_user_root_dir,
]
jvm_max_memory = self.cfg['jvm_max_memory']
Expand Down