-
Notifications
You must be signed in to change notification settings - Fork 73
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
Dependency finding #704
Draft
a-alveyblanc
wants to merge
55
commits into
inducer:main
Choose a base branch
from
a-alveyblanc:dependencies-wip
base: main
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.
Draft
Dependency finding #704
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
9f097a3
Sketch out where precise dependencies might go in the IR
inducer 779c2f0
New branch
a-alveyblanc 365781d
Merge branch 'inducer:main' into dependencies-wip
a-alveyblanc 6a58e1d
Added draft of new version of dependency finding
a-alveyblanc ba3fbf5
Added some documentation
a-alveyblanc 990624b
Started implementation of add_lexicographic_...
a-alveyblanc 93b4126
Update gitignore to ignore DS_STORE
a-alveyblanc 01d3688
Sketch out add_lexicographic_happens_after
inducer 51c460d
Add relation to HappensAfter data structure
a-alveyblanc f6b75dd
New version of data dependency finding, still WIP
a-alveyblanc 8327c70
added read-after-write, write-after-read, write-after-write dep findi…
a-alveyblanc 999446f
update documentation
a-alveyblanc f110b30
Added first implementation of dependency finding for non-successive i…
a-alveyblanc a671762
Minor fixes for some failing tests
a-alveyblanc 34f5b90
Slight refactor to improve readability and remove repeated code
a-alveyblanc adb924c
Merge branch 'main' into dependencies-wip
a-alveyblanc a7eb364
More changes to fix failing CI
a-alveyblanc c23eff4
Some slight changes to fix failing CI and improve readability
a-alveyblanc 1647d5a
More fixes for CI
a-alveyblanc 055d7e3
Add knl.id_to_insn to find instructions from ids instead of looping t…
a-alveyblanc 888291f
Change the way the new happens_after is updated when finding dependen…
a-alveyblanc b785738
Temporary changes for how to handle cases in which happens_after and …
a-alveyblanc 457cb6f
Revert a change to a test that was not supposed to be changed
a-alveyblanc 096e68b
pushing
a-alveyblanc 1b9f186
Revert "pushing"
a-alveyblanc 5f3a249
Refactor dependency finding code to eliminate bugs.
a-alveyblanc 169e808
Attempt at fixing CI failures due to replacing happens_after with dep…
a-alveyblanc faa5f23
Remove HappensAfter import from where it never should have been
a-alveyblanc d3224d1
Minor tweaks. Add a function to print dependency info of a knl
a-alveyblanc a215511
Refactored code. Much shorter with better access map finding.
a-alveyblanc 72ab7e7
Remove giant todo list from top of file, change printing code
a-alveyblanc 590a8cf
Minor grammatical fix
a-alveyblanc 5208fb6
Minor print function change
a-alveyblanc cf4b9bd
Implement map_sub_array_ref in AccessMapFinder
a-alveyblanc faff25c
Read-after-read dependency finding avoided
a-alveyblanc d967949
Change back to long version of dependency finding. Switch to using pmap
a-alveyblanc 307aa83
Nested array access finding
a-alveyblanc 808cef6
Allow depends_on to be passed as an argument for legacy purposes
a-alveyblanc 8a28e7f
Fix issues found by mypy and pylint
a-alveyblanc 5731025
Fix documentation issues, handle cases where depends_on and happens_a…
a-alveyblanc e745336
Fix dependency cylce introduced by interaction between add_lexicograp…
a-alveyblanc b9cc691
Add a possible solution for supporting scalars in dependency finding …
a-alveyblanc d361167
Pushing [skip ci]
a-alveyblanc 16be472
Precompute coarse-grained dependencies, add traces of transitive depe…
a-alveyblanc 8e0e384
Use fine-grain dependency information that exists in the kernel when …
a-alveyblanc 69265b2
Fix failing pylint
a-alveyblanc 8c42f69
Remove file that was accidentally created
a-alveyblanc 970feb0
Some unimportant changes
a-alveyblanc 5b98c84
Remove unnecessary tests
a-alveyblanc 2043233
Fix failing doctests
a-alveyblanc 1cea1b3
Remove some (currently) unnecessary changes
a-alveyblanc 9131461
Remove accidentally added files
a-alveyblanc 290c91e
Remove more (temporarily) unnecessary code to prep for compatibility …
a-alveyblanc 7cd7ea0
Fix failing doctest
a-alveyblanc c1a553a
Merge branch 'inducer:main' into dependencies-wip
a-alveyblanc 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 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 |
---|---|---|
|
@@ -20,6 +20,7 @@ htmlcov | |
lextab.py | ||
yacctab.py | ||
.pytest_cache/* | ||
.DS_STORE | ||
|
||
loopy/_git_rev.py | ||
|
||
|
This file contains 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 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 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 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 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 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,122 @@ | ||
""" | ||
.. autofunction:: add_lexicographic_happens_after | ||
""" | ||
|
||
__copyright__ = "Copyright (C) 2023 Addison Alvey-Blanco" | ||
|
||
__license__ = """ | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
""" | ||
|
||
import islpy as isl | ||
from islpy import dim_type | ||
|
||
from loopy import LoopKernel | ||
from loopy.kernel.instruction import HappensAfter | ||
from loopy.translation_unit import for_each_kernel | ||
|
||
|
||
@for_each_kernel | ||
def add_lexicographic_happens_after(knl: LoopKernel) -> LoopKernel: | ||
"""Construct a sequential dependency specification between each instruction | ||
and the instruction immediately before it. This dependency information | ||
contains a lexicographic map which acts as a description of the precise, | ||
statement-instance level dependencies between statements. | ||
""" | ||
|
||
new_insns = [] | ||
|
||
for iafter, insn_after in enumerate(knl.instructions): | ||
|
||
if iafter == 0: | ||
new_insns.append(insn_after) | ||
|
||
else: | ||
|
||
insn_before = knl.instructions[iafter - 1] | ||
shared_inames = insn_after.within_inames & insn_before.within_inames | ||
|
||
domain_before = knl.get_inames_domain(insn_before.within_inames) | ||
domain_after = knl.get_inames_domain(insn_after.within_inames) | ||
happens_before = isl.Map.from_domain_and_range( | ||
domain_before, domain_after | ||
) | ||
|
||
for idim in range(happens_before.dim(dim_type.out)): | ||
happens_before = happens_before.set_dim_name( | ||
dim_type.out, idim, | ||
happens_before.get_dim_name(dim_type.out, idim) + "'" | ||
) | ||
|
||
n_inames_before = happens_before.dim(dim_type.in_) | ||
happens_before_set = happens_before.move_dims( | ||
dim_type.out, 0, | ||
dim_type.in_, 0, | ||
n_inames_before).range() | ||
|
||
shared_inames_order_before = [ | ||
domain_before.get_dim_name(dim_type.out, idim) | ||
for idim in range(domain_before.dim(dim_type.out)) | ||
if domain_before.get_dim_name(dim_type.out, idim) | ||
in shared_inames | ||
] | ||
shared_inames_order_after = [ | ||
domain_after.get_dim_name(dim_type.out, idim) | ||
for idim in range(domain_after.dim(dim_type.out)) | ||
if domain_after.get_dim_name(dim_type.out, idim) | ||
in shared_inames | ||
] | ||
assert shared_inames_order_after == shared_inames_order_before | ||
shared_inames_order = shared_inames_order_after | ||
|
||
affs = isl.affs_from_space(happens_before_set.space) | ||
|
||
lex_set = isl.Set.empty(happens_before_set.space) | ||
for iinnermost, innermost_iname in enumerate(shared_inames_order): | ||
|
||
innermost_set = affs[innermost_iname].lt_set( | ||
affs[innermost_iname+"'"] | ||
) | ||
|
||
for outer_iname in shared_inames_order[:iinnermost]: | ||
innermost_set = innermost_set & ( | ||
affs[outer_iname].eq_set(affs[outer_iname + "'"]) | ||
) | ||
|
||
lex_set = lex_set | innermost_set | ||
|
||
lex_map = isl.Map.from_range(lex_set).move_dims( | ||
dim_type.in_, 0, | ||
dim_type.out, 0, | ||
n_inames_before) | ||
|
||
happens_before = happens_before & lex_map | ||
|
||
new_happens_after = { | ||
insn_before.id: HappensAfter(None, happens_before) | ||
} | ||
|
||
insn_after = insn_after.copy(happens_after=new_happens_after) | ||
|
||
new_insns.append(insn_after) | ||
|
||
return knl.copy(instructions=new_insns) | ||
|
||
|
||
# vim: foldmethod=marker |
Oops, something went wrong.
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.
There's a big unresolved question here, in terms of what nesting order we should use for the shared inames. Right now, this uses the axis order in the domains, however we also already do have
LoopKernel.loop_priority
to indicate nesting order during code generation). If nothing else, this should make sure that the order produced is consistent with that. But there's also the option of using/introducing a different mechanism entirely for this.@kaushikcfd, got an opinion?