Skip to content

Enable/Disable Propagation for Compiler Flags & Variants#29761

Merged
tgamblin merged 2 commits intospack:developfrom
RikkiButler20:feature/compiler_flag_and_variant_propagation
Nov 2, 2022
Merged

Enable/Disable Propagation for Compiler Flags & Variants#29761
tgamblin merged 2 commits intospack:developfrom
RikkiButler20:feature/compiler_flag_and_variant_propagation

Conversation

@RikkiButler20
Copy link
Copy Markdown
Contributor

@RikkiButler20 RikkiButler20 commented Mar 28, 2022

Fixes #29653.

Allow for inheritance to be enabled or disabled for both variants and compiler flags.

  • Add new (spec language) operators
  • Apply operators to variants and compiler flags
  • Resolve conflicts
  • Add tests
  • Add documentation

@RikkiButler20 RikkiButler20 added feature A feature is missing in Spack variants labels Mar 28, 2022
@RikkiButler20 RikkiButler20 self-assigned this Mar 28, 2022
@RikkiButler20 RikkiButler20 marked this pull request as draft March 28, 2022 21:22
@RikkiButler20 RikkiButler20 changed the title Compiler & Variant Propagation Compiler Flag & Variant Propagation Mar 28, 2022
@RikkiButler20 RikkiButler20 changed the title Compiler Flag & Variant Propagation Enable/Disable Inheritance for Compiler Flags & Variants Mar 28, 2022
@RikkiButler20 RikkiButler20 changed the title Enable/Disable Inheritance for Compiler Flags & Variants Enable/Disable Propagation for Compiler Flags & Variants Mar 28, 2022
@RikkiButler20 RikkiButler20 force-pushed the feature/compiler_flag_and_variant_propagation branch from 2de2807 to 8a0bdb0 Compare May 19, 2022 20:01
@spackbot-app spackbot-app bot added the tests General test capability(ies) label Jun 15, 2022
Copy link
Copy Markdown
Member

@becker33 becker33 left a comment

Choose a reason for hiding this comment

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

This mostly LGTM, a couple of concerns about potentially vestigial code and some legibility suggestions.

@RikkiButler20
Copy link
Copy Markdown
Contributor Author

@spackbot fix style

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Nov 2, 2022

@spackbot fix style

@spackbot-app
Copy link
Copy Markdown

spackbot-app bot commented Nov 2, 2022

Let me see if I can fix that for you!

@spackbot-app
Copy link
Copy Markdown

spackbot-app bot commented Nov 2, 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/__init__.py
  lib/spack/spack/cmd/deactivate.py
  lib/spack/spack/cmd/extensions.py
  lib/spack/spack/compiler.py
  lib/spack/spack/provider_index.py
  lib/spack/spack/solver/asp.py
  lib/spack/spack/spec.py
  lib/spack/spack/test/cmd/common/arguments.py
  lib/spack/spack/test/concretize.py
  lib/spack/spack/test/spec_semantics.py
  lib/spack/spack/variant.py
  var/spack/repos/builtin.mock/packages/hypre/package.py
  var/spack/repos/builtin.mock/packages/openblas/package.py
==> Running isort checks
  isort checks were clean
==> Running mypy checks
Success: no issues found in 564 source files
  mypy checks were clean
==> Running black checks
reformatted lib/spack/spack/solver/asp.py
reformatted lib/spack/spack/spec.py
All done! ✨ 🍰 ✨
2 files reformatted, 11 files left unchanged.
  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 style fixes.

RikkiButler20 and others added 2 commits November 1, 2022 23:45
Currently, compiler flags and variants are inconsistent: compiler flags set for a
package are inherited by its dependencies, while variants are not. We should have these
be consistent by allowing for inheritance to be enabled or disabled for both variants
and compiler flags.

- [x] Make new (spec language) operators
- [x] Apply operators to variants and compiler flags
- [x] Conflicts currently result in an unsatisfiable spec
      (i.e., you can't propagate two conflicting values)

What I propose is using two of the currently used sigils to symbolized that the variant
or compiler flag will be inherited:

Example syntax:
- `package ++variant`
      enabled variant that will be propagated to dependencies
- `package +variant`
      enabled variant that will NOT be propagated to dependencies
- `package ~~variant`
      disabled variant that will be propagated to dependencies
- `package ~variant`
      disabled variant that will NOT be propagated to dependencies
- `package cflags==True`
      `cflags` will be propagated to dependencies
- `package cflags=True`
      `cflags` will NOT be propagated to dependencies

Syntax for string-valued variants is similar to compiler flags.
This updates the propagation logic used in `concretize.lp` to avoid rules with `path()`
in the body and instead base propagation around `depends_on()`.
@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Nov 2, 2022

I've cleaned up the commits here and squashed into the original implementation + @becker33's performance fix. With the fix, I see negligible overhead for this feature, other than that setup seems to take a little longer:

develop:

(spackbook):spack> spack solve --timers trilinos
Time:
    setup:         5.9787
    load:          0.0143
    ground:        1.8304
    solve:         3.0472
Total: 10.9299

This PR:

(spackbook):spack> spack solve --timers trilinos
Time:
    setup:         6.3022
    load:          0.0138
    ground:        1.9173
    solve:         3.0648
Total: 11.3539

Setup is going to get optimized away soon, so I'm fine with this as-is.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Nov 2, 2022

Leaving a few notes to anticipate comments we might get after this is merged:

Propagating non-default variants might change the virtual provider

This is due to the fact that we don't change/transform the weight of propagated variant. So if we propagate a non-default Spack might try to minimize nodes in a certain subDAG. For instance:

$ spack spec hdf5++shared

selects openmpi on linux, while:

$ spack spec hdf5~~shared

selects mpich. This is solvable by constraining the second spec.

Knowledge on the final DAG topology is needed to propagate the same variant

For instance we can currently do:

$ spack solve hdf5++shared ^zlib~~shared

but we can't:

$ spack solve hdf5++shared ^perl~~shared
==> Error: 'zlib' required multiple values for single-valued variant 'shared'
    Requested '~shared' and '+shared'

This might be fine on the command line, since the error is informative. If people start to use propagation in directives though this might lead to some confusion when things don't concretize anymore.

For the error message part:

$ spack solve hdf5 cflags=="-foptimize-loops" ^perl cflags=="-g"
==> Error: No valid compiler version found for 'hdf5'

while clearly in this case the issue is conflicting cflags.

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Nov 2, 2022

RHEL8 issue here is fixed on develop; all PR-relevant tests are passing.

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Nov 2, 2022

@alalazo i think a follow on PR that doesn’t count propagated variants as non-default would address the biggest issue you list here.

@haampie
Copy link
Copy Markdown
Member

haampie commented Nov 7, 2022

This PR (also with follow up PRs) slows down unit tests very significantly.

The slowest test on ae99829

86.64s call     lib/spack/spack/test/concretize_preferences.py::TestConcretizePreferences::test_preferred_compilers

now (on bc209c4) takes

182.03s call     lib/spack/spack/test/concretize_preferences.py::TestConcretizePreferences::test_preferred_compilers

This individual test now runs slower than all 3500 other tests combined when run with xdist, which is quite annoying for development (2 mins of waiting -> 3+ minutes)

@tgamblin
Copy link
Copy Markdown
Member

tgamblin commented Nov 7, 2022

If we can’t make a general fix for this, we can separate the propagation logic introduced here from concretize.lp and only include it if we see propagation used. Then we would at least only pay when using this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands compilers core PR affects Spack core functionality dependencies documentation Improvements or additions to documentation feature A feature is missing in Spack new-variant tests General test capability(ies) variants

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler & Variant Propagation

7 participants