-
Notifications
You must be signed in to change notification settings - Fork 41
Fix two missing parents and check the DAG against feature sets #162
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
Open
haampie
wants to merge
3
commits into
archspec:master
Choose a base branch
from
haampie:fix/feature-dag-consistency
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright 2019-2020 Lawrence Livermore National Security, LLC and other | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| # Archspec Project Developers. See the top-level COPYRIGHT file for details. | ||
| # | ||
| # SPDX-License-Identifier: (Apache-2.0 OR MIT) | ||
| """Check that the explicit ``from`` DAG is consistent with feature set inclusion. | ||
|
|
||
| Every microarchitecture names a set of features, so feature inclusion defines a | ||
| partial order of its own. The ``from`` DAG must agree with it in two directions: | ||
|
|
||
| * A descendant must list every feature of its ancestors, up to ``feature_aliases``. | ||
| * Within a family, a microarchitecture whose feature set strictly contains | ||
| another's must descend from it when both share a vendor, or when the smaller | ||
| one is a generic level. Cross-vendor lineage is intentionally not required: | ||
| portability between vendors is expressed through the generic levels only. | ||
| """ | ||
| import itertools | ||
| import json | ||
| import pathlib | ||
| import sys | ||
|
|
||
| JSON_DIR = pathlib.Path(__file__).parent.parent / "cpu" | ||
|
|
||
|
|
||
| def main() -> int: | ||
| with open(JSON_DIR / "microarchitectures.json") as f: | ||
| data = json.load(f) | ||
|
|
||
| uarchs = data["microarchitectures"] | ||
| aliases = data.get("feature_aliases", {}) | ||
|
|
||
| ancestors = {} | ||
|
|
||
| def transitive_ancestors(name): | ||
| if name not in ancestors: | ||
| result = set() | ||
| for parent in uarchs[name]["from"]: | ||
| result.add(parent) | ||
| result |= transitive_ancestors(parent) | ||
| ancestors[name] = result | ||
| return ancestors[name] | ||
|
|
||
| def family(name): | ||
| roots = [a for a in transitive_ancestors(name) | {name} if not uarchs[a]["from"]] | ||
| assert len(roots) == 1, f"{name} has multiple family roots: {roots}" | ||
| return roots[0] | ||
|
|
||
| def closed_features(name): | ||
| """The declared features, closed under the alias rules.""" | ||
| result = set(uarchs[name]["features"]) | ||
| for feature, rule in aliases.items(): | ||
| if "any_of" in rule and result & set(rule["any_of"]): | ||
| result.add(feature) | ||
| if "families" in rule and family(name) in rule["families"]: | ||
| result.add(feature) | ||
| return result | ||
|
|
||
| features = {name: closed_features(name) for name in uarchs} | ||
| violations = [] | ||
|
|
||
| for ancestor in uarchs: | ||
| for descendant in uarchs: | ||
| if ancestor not in transitive_ancestors(descendant): | ||
| continue | ||
| missing = features[ancestor] - features[descendant] | ||
| if missing: | ||
| violations.append( | ||
| f"{descendant} descends from {ancestor} but lacks its features: " | ||
| f"{', '.join(sorted(missing))}" | ||
| ) | ||
|
|
||
| for smaller, larger in itertools.permutations(uarchs, 2): | ||
| if family(smaller) != family(larger): | ||
| continue | ||
| # an entry with no declared features asserts nothing, and alias closure may still | ||
| # give it synthetic ones, so it cannot imply an edge | ||
| if not uarchs[smaller]["features"]: | ||
| continue | ||
| if not features[smaller] < features[larger]: | ||
| continue | ||
| same_vendor = uarchs[smaller]["vendor"] == uarchs[larger]["vendor"] | ||
| if not same_vendor and uarchs[smaller]["vendor"] != "generic": | ||
| continue | ||
| if smaller not in transitive_ancestors(larger): | ||
| violations.append( | ||
| f"{larger} has every feature of {smaller} and more, but does not descend " | ||
| f"from it" | ||
| ) | ||
|
|
||
| for violation in violations: | ||
| print(f"ERROR: {violation}") | ||
| return 1 if violations else 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.