Skip to content

depfile: reduce dag with --use-buildcache flag.#33315

Merged
trws merged 1 commit intospack:developfrom
haampie:depfile/shallow-install
Oct 19, 2022
Merged

depfile: reduce dag with --use-buildcache flag.#33315
trws merged 1 commit intospack:developfrom
haampie:depfile/shallow-install

Conversation

@haampie
Copy link
Copy Markdown
Member

@haampie haampie commented Oct 14, 2022

When installing some/all specs from a buildcache, build edges are pruned
from those specs. This can result in a much smaller effective DAG. Until
now, spack env depfile would always generate a full DAG.

Ths PR adds the spack env depfile --use-buildcache flag that was
introduced for spack install before. This way, not only can we drop
build edges, but also we can automatically set the right buildcache
related flags on the specific specs that are gonna get installed.

On top of that, this PR introduces spack env depfile [spec 1] [spec 2]...
that reduces the dag to particular specs of interest in the environment.

This way we get parallel installs of binary deps of a particular spec
that's built from sources, without redundancy, which is useful for
Gitlab CI.

Example use:

# install from buildcache w/o build deps
spack env depfile -o Makefile --use-buildcache only && make -j8

# drop build deps of deps
spack env depfile -o Makefile --use-buildcache dependencies:only && make -j8

# restrict environment install to pkg-a and pkg-b + deps
# build those two from sources
# dependencies are pulled from a buildcache, their build deps dropped
spack env depfile -o Makefile --use-buildcache package:never,dependencies:only pkg-a pkg-b && make -j8 

@spackbot-app spackbot-app bot added commands core PR affects Spack core functionality labels Oct 14, 2022
@haampie haampie marked this pull request as draft October 14, 2022 16:55
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 16, 2022

@spackbot fix style

@spackbot-app
Copy link
Copy Markdown

spackbot-app bot commented Oct 16, 2022

Let me see if I can fix that for you!

@spackbot-app
Copy link
Copy Markdown

spackbot-app bot commented Oct 16, 2022

I was able to run spack style --fix for you!

spack style --fix
==> Running style checks on spack
  selected: isort, mypy, black, flake8
==> Modified files
  lib/spack/spack/cmd/env.py
==> Running isort checks
  isort checks were clean
==> Running mypy checks
Success: no issues found in 556 source files
  mypy checks were clean
==> Running black checks
reformatted lib/spack/spack/cmd/env.py
All done! ✨ 🍰 ✨
1 file reformatted.
  black checks were clean
==> Running flake8 checks
  flake8 checks were clean
==> spack style checks were clean
Keep in mind that I cannot fix your flake8 or mypy errors, so if you have any you'll need to fix them and update the pull request. If I was able to push to your branch, if you make further changes you will need to pull from your updated branch before pushing again.

I've updated the branch with isort fixes.

@haampie haampie marked this pull request as ready for review October 17, 2022 08:22
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 17, 2022

@trws do you have opinions here?

So, --shallow now corresponds with dropping non-direct build deps. This is quite... specific. Only useful for CI type of situations where you wanna build one (or more) specific packages from sources, and require their dependencies to be installed from a binary cache.

But maybe shallow is not a great name, cause you might as well expect a DAG where all build type deps are pruned.

--prune-build-deps=all/package/dependencies or so is also an option...

@haampie haampie changed the title depfile: shallow dag depfile: allow reduced dag (shallow -- dropping build deps, and restricted to selected specs) Oct 17, 2022
@haampie haampie changed the title depfile: allow reduced dag (shallow -- dropping build deps, and restricted to selected specs) depfile: allow reduced dag (dropping build deps, and restricted to selected specs) Oct 17, 2022
@haampie haampie changed the title depfile: allow reduced dag (dropping build deps, and restricted to selected specs) depfile: allow reduced dag (drop build deps, restrict to selected specs) Oct 17, 2022
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 17, 2022

@alalazo mentioned:

spack env depfile --[build-|install-]from-sources=all/root/none

If we do that, we can immediately add the right --cache-only type of flags too.

But actually it's kinda similar to the amazing --use-buildcache=... flag 🤔 then maybe that should be used for consistency.

@scheibelp scheibelp self-assigned this Oct 17, 2022
pass


def traverse_breadth_first(visitor, specs=[]):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec.traverse(order='pre') should match this in all the desired ways and might avoid some corner cases like:

1____
| \  \
2  3  4
|  |  |
|  5  6
|_/__/
|
7

i.e., we want something more-sophisticated than breadth first or we may end up visiting 7 before [5, 6] (if your implementation avoids this, we should probably call it something like "topological" rather than "breadth-first").

Copy link
Copy Markdown
Member Author

@haampie haampie Oct 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, the point is I have multiple root specs, and need to handle the roots differently from the dependencies. Given that the second root may appear as a dependency of the first root, I don't want depth-first search. Breadth-first search initialized with all root specs guarantees that roots are found at depth 0 and that all connected nodes are visited once. I don't see the need for topological sort, for make targets all I need is the adjacency list.

See the bit

    def neighbors(self, node):
        # At depth zero we return build / test deps too
        if node.depth == 0:
            return node.spec.dependencies(deptype="all")
        # Otherwise we just return link/run type deps
        return node.spec.dependencies(deptype=("link", "run"))

@haampie haampie force-pushed the depfile/shallow-install branch from d91d94b to c92bde9 Compare October 18, 2022 12:05
@spackbot-app spackbot-app bot added the tests General test capability(ies) label Oct 18, 2022
@haampie haampie changed the title depfile: allow reduced dag (drop build deps, restrict to selected specs) depfile: reduce dag with --use-buildcache flag. Oct 18, 2022
@haampie haampie force-pushed the depfile/shallow-install branch 2 times, most recently from 94f3c45 to 5e031ba Compare October 18, 2022 16:29
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 18, 2022

This is ready for review, again. Includes tests now.

When installing some/all specs from a buildcache, build edges are pruned
from those specs. This can result in a much smaller effective DAG. Until
now, `spack env depfile` would always generate a full DAG.

Ths PR adds the `spack env depfile --use-buildcache` flag that was
introduced for `spack install` before. This way, not only can we drop
build edges, but also we can automatically set the right buildcache
related flags on the specific specs that are gonna get installed.

This way we get parallel installs of binary deps without redundancy,
which is useful for Gitlab CI.
@haampie haampie force-pushed the depfile/shallow-install branch from 5e031ba to 0760894 Compare October 18, 2022 22:02
@haampie
Copy link
Copy Markdown
Member Author

haampie commented Oct 19, 2022

@scheibelp I've moved the breadth-first traversal bits to #33406 so that this PR doesn't introduce its own "custom" traversal.

@trws trws merged commit e134406 into spack:develop Oct 19, 2022
@haampie haampie deleted the depfile/shallow-install branch October 19, 2022 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands core PR affects Spack core functionality tests General test capability(ies)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants