-
Notifications
You must be signed in to change notification settings - Fork 263
compiler: Fix buffering in presence of written HALO regions #3030
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
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
411d6c7
compiler: Add TimedAccess.touched_nodomain
FabioLuporini 759fa77
compiler: Fix buffering with written HALOs
FabioLuporini 6adba1a
compiler: Throw exception if writing to HALO of a dist dimension
FabioLuporini 327c61f
compiler: Simplify HALO-write handling
FabioLuporini 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
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 |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ | |
| from devito.exceptions import CompilationError | ||
| from devito.ir import ( | ||
| Backward, Cluster, Forward, GuardBound, GuardFactor, InitArray, Interval, | ||
| IntervalGroup, IterationSpace, Properties, Queue, Vector, lower_exprs, vmax, vmin | ||
| IterationSpace, Properties, Queue, Vector, detect_halo_writes, lower_exprs, vmax, vmin | ||
| ) | ||
| from devito.logger import warning | ||
| from devito.passes.clusters.utils import is_memcpy | ||
|
|
@@ -118,6 +118,10 @@ def key(f): | |
| # First we generate all the necessary buffers | ||
| mapper = generate_buffers(clusters, key, sregistry, options) | ||
|
|
||
| # Take into account writes into the HALO regions so that the buffered | ||
| # Functions can be populated accordingly | ||
| clusters = expand_halo_transfers(clusters, mapper) | ||
|
|
||
| # Then we inject them into the Clusters. This involves creating the | ||
| # initializing Clusters, and replacing the buffered Functions with the buffers | ||
| clusters = InjectBuffers(mapper, sregistry, options).process(clusters) | ||
|
|
@@ -485,6 +489,86 @@ def generate_buffers(clusters, key, sregistry, options, **kwargs): | |
| return mapper | ||
|
|
||
|
|
||
| def expand_halo_transfers(clusters, mapper): | ||
| """ | ||
| Include the halo in buffered writes reading Functions with explicit HALO | ||
| writes. For example, `usave` in `Eq(usave, u)` must eventually receive `u`'s | ||
| populated HALO if a preceding `Eq` writes into `u`'s HALO. | ||
| """ | ||
| if not mapper: | ||
| return clusters | ||
|
|
||
| # Get HALO writes along the buffered dimensions | ||
| bdims = set() | ||
| for b in mapper.values(): | ||
| bdims.update(d for d in b.dimensions if not isinstance(d, BufferDimension)) | ||
|
|
||
| halo_writes = set() | ||
| for c in clusters: | ||
| for w in detect_halo_writes(c, bdims.__contains__): | ||
| halo_writes.add(w.function) | ||
| if not halo_writes: | ||
| return clusters | ||
|
|
||
| # Expand the IterationSpace over the necessary amount of HALO; in doing so, | ||
|
Contributor
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. why not just call memcpy in that case since it just copies the whole buffer (the langbb['memcpy'])
Contributor
Author
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. padding |
||
| # check the expanded footprint of every access, including shifted reads. | ||
| # Writes must be pointwise so that the whole destination halo is filled | ||
| buffered = {f for f, _ in mapper} | ||
| processed = [] | ||
| for c in clusters: | ||
| writes = c.scope.writes_tensor | ||
|
|
||
| if c.is_wild or \ | ||
| writes.isdisjoint(buffered) or \ | ||
| halo_writes.isdisjoint(c.scope.reads): | ||
| processed.append(c) | ||
| continue | ||
|
|
||
| if not writes <= buffered: | ||
| raise CompilationError( | ||
| "Cannot expand a mixed Cluster over the halo while buffering" | ||
| ) | ||
|
|
||
| ispace = c.ispace | ||
| for f in writes: | ||
| ispace = _include_halo(ispace, f) | ||
|
|
||
| for a in c.scope.accesses: | ||
| f = a.function | ||
|
|
||
| for d in bdims.intersection(a.findices): | ||
| size = f._size_nodomain[d] | ||
| offset = simplify(a[d] - d - size.left) | ||
|
|
||
| if d not in ispace.dimensions or \ | ||
| not is_integer(offset) or \ | ||
| (a.is_write and offset != 0): | ||
| raise CompilationError( | ||
| f"Cannot expand access to `{f.name}` over the halo" | ||
| ) | ||
|
|
||
| i = ispace[d] | ||
| if i.lower + offset < -size.left or \ | ||
| i.upper + offset > size.right: | ||
| raise CompilationError( | ||
| f"Insufficient halo for `{f.name}` in buffered write" | ||
| ) | ||
|
|
||
| processed.append(c.rebuild(ispace=ispace)) | ||
|
|
||
| return processed | ||
|
|
||
|
|
||
| def _include_halo(ispace, f): | ||
| """Extend `ispace` to include `f`'s HALO.""" | ||
| ihalo = [ | ||
| Interval(i.dim, -f._size_halo[i.dim].left, f._size_halo[i.dim].right, i.stamp) | ||
| for i in ispace if i.dim in f.dimensions | ||
| ] | ||
|
|
||
| return IterationSpace.union(ispace, IterationSpace(ihalo)) | ||
|
|
||
|
|
||
| def map_buffered_functions(clusters, key): | ||
| """ | ||
| Map each candidate Function to the Clusters that access it. | ||
|
|
@@ -641,12 +725,7 @@ def write_to(self): | |
| ispace = ispace.promote(lambda d: d.is_AbstractSub, mode='total') | ||
|
|
||
| # Analogous to the above, we need to include the halo region as well | ||
| ihalo = IntervalGroup([ | ||
| Interval(i.dim, -h.left, h.right, i.stamp) | ||
| for i, h in zip(ispace, self.b._size_halo, strict=False) | ||
| ]) | ||
|
|
||
| ispace = IterationSpace.union(ispace, IterationSpace(ihalo)) | ||
| ispace = _include_halo(ispace, self.b) | ||
|
|
||
| return ispace | ||
|
|
||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.