-
Notifications
You must be signed in to change notification settings - Fork 257
api: Fix staggered sum indices #3012
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
mloubout
wants to merge
5
commits into
main
Choose a base branch
from
fix-staggered-sum-indices
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.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
598061a
dsl: Look a DimensionTuple up by the Dimension asked for
mloubout 8e805ab
dsl: Differentiate a mixed-staggering sum term by term
mloubout 254136a
compiler: Search a Definition for applied functions
mloubout e9db68d
compiler: Let an Array vouch for a reduction over its whole allocation
mloubout 09c6005
compiler: Zero an Array whose out-of-DOMAIN entries are data
mloubout 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
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 |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| VOID, Byref, DefFunction, FieldFromPointer, IndexedPointer, ListInitializer, SizeOf, | ||
| as_long, pow_to_mul, unevaluate | ||
| ) | ||
| from devito.tools import as_list, as_mapper, as_tuple, filter_sorted, flatten | ||
| from devito.tools import as_list, as_mapper, as_tuple, filter_sorted, flatten, is_integer | ||
| from devito.types import ( | ||
| Array, ComponentAccess, CustomDimension, DeviceMap, DeviceRM, Dimension, Eq, Symbol, | ||
| size_t | ||
|
|
@@ -91,6 +91,27 @@ def __init__(self, rcompile=None, sregistry=None, platform=None, | |
| self.sregistry = sregistry | ||
| self.platform = platform | ||
|
|
||
| # Off inside the recursive compilation of a zero-init itself, which | ||
| # would otherwise ask for a zero-init of its own, ad infinitum | ||
| self.zero_init = (options or {}).get('zero-init', True) | ||
|
|
||
| def _zero_init(self, obj, storage): | ||
| """ | ||
| The nodes zeroing `obj` upfront, if it asks for it, plus the efuncs | ||
| they call, if any. | ||
| """ | ||
| if not (obj._is_zero_init and self.zero_init): | ||
| return (), () | ||
|
|
||
| return self._make_zero_init(obj, storage) | ||
|
|
||
| def _make_zero_init(self, obj, storage): | ||
| """How to zero `obj`'s whole allocation, padding included.""" | ||
| storage.include(self.langbb['header-memcpy']) | ||
| nbytes = SizeOf(obj._C_typedata)*as_long(obj.size) | ||
|
|
||
| return (self.langbb['host-memset'](obj._C_symbol, 0, nbytes),), () | ||
|
|
||
| def _alloc_object_on_low_lat_mem(self, site, obj, storage): | ||
| """ | ||
| Allocate a LocalObject in the low latency memory. | ||
|
|
@@ -172,11 +193,13 @@ def _alloc_host_array_on_high_bw_mem(self, site, obj, storage, *args): | |
| memptr = VOID(Byref(obj._C_symbol), '**') | ||
| alignment = obj._data_alignment | ||
| nbytes = SizeOf(obj._C_typedata)*as_long(obj.size) | ||
| alloc = self.langbb['host-alloc'](memptr, alignment, nbytes) | ||
| zeroing, efuncs = self._zero_init(obj, storage) | ||
| allocs = [decl, self.langbb['host-alloc'](memptr, alignment, nbytes), | ||
| *zeroing] | ||
|
|
||
| free = self.langbb['host-free'](obj._C_symbol) | ||
|
|
||
| storage.update(obj, site, allocs=(decl, alloc), frees=free) | ||
| storage.update(obj, site, allocs=tuple(allocs), frees=free, efuncs=efuncs) | ||
|
|
||
| def _alloc_local_array_on_high_bw_mem(self, site, obj, storage, *args): | ||
| """ | ||
|
|
@@ -568,7 +591,7 @@ def __init__(self, options=None, **kwargs): | |
| self.gpu_create = options['gpu-create'] | ||
| self.gpu_place_transfers = options.get('place-transfers') | ||
|
|
||
| super().__init__(**kwargs) | ||
| super().__init__(options=options, **kwargs) | ||
|
|
||
| def _alloc_local_array_on_high_bw_mem(self, site, obj, storage): | ||
| """ | ||
|
|
@@ -579,11 +602,22 @@ def _alloc_local_array_on_high_bw_mem(self, site, obj, storage): | |
| dofree = self.langbb['device-free'] | ||
|
|
||
| nbytes = SizeOf(obj._C_typedata)*obj.size | ||
| init = doalloc(nbytes, deviceid, retobj=obj) | ||
|
|
||
| zeroing, efuncs = self._zero_init(obj, storage) | ||
| allocs = [doalloc(nbytes, deviceid, retobj=obj), *zeroing] | ||
|
|
||
| free = dofree(obj._C_name, deviceid) | ||
|
|
||
| storage.update(obj, site, allocs=init, frees=free) | ||
| storage.update(obj, site, allocs=tuple(allocs), frees=free, efuncs=efuncs) | ||
|
|
||
| def _make_zero_init(self, obj, storage): | ||
| # No language here has a device-side memset, so use a kernel. It gains | ||
| # nothing from tiling, and nvc++ trips over the padded loop bounds | ||
| # when it is asked to tile them | ||
| efuncs, init = make_zero_init(obj, self.rcompile, self.sregistry, | ||
| options={'par-tile': False}) | ||
|
|
||
| return (init,), efuncs | ||
|
|
||
| def _map_array_on_high_bw_mem(self, site, obj, storage): | ||
| """ | ||
|
|
@@ -702,18 +736,19 @@ def process(self, graph): | |
| self.place_casts(graph) | ||
|
|
||
|
|
||
| def make_zero_init(obj, rcompile, sregistry): | ||
| def make_zero_init(obj, rcompile, sregistry, options=None): | ||
| cdims = [] | ||
| for d, (h0, h1), s in zip( | ||
| obj.dimensions, obj._size_halo, obj.symbolic_shape, strict=True | ||
| for d, (h0, h1), (p0, p1), s in zip( | ||
| obj.dimensions, obj._size_halo, obj._size_padding, obj.symbolic_shape, | ||
|
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. it must be a symbolic padding or it's wrong (an operator override would kill it) |
||
| strict=True | ||
| ): | ||
| if d.is_NonlinearDerived: | ||
| assert h0 == h1 == 0 | ||
| assert h0 == h1 == p0 == p1 == 0 | ||
| m = 0 | ||
| M = s - 1 | ||
| else: | ||
| m = d.symbolic_min - h0 | ||
| M = d.symbolic_max + h1 | ||
| M = d.symbolic_max + h1 + (0 if is_integer(p1) else p1) | ||
| cdims.append(CustomDimension(name=d.name, parent=d, | ||
| symbolic_min=m, symbolic_max=M)) | ||
|
|
||
|
|
@@ -722,7 +757,8 @@ def make_zero_init(obj, rcompile, sregistry): | |
| else: | ||
| eqns = [Eq(obj[cdims], 0)] | ||
|
|
||
| irs, byproduct = rcompile(eqns) | ||
| irs, byproduct = rcompile(eqns, options={'zero-init': False, | ||
| **(options or {})}) | ||
|
|
||
| init = irs.iet.body.body[0] | ||
|
|
||
|
|
||
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
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.
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.
not sure we actually need an extra method like this, why not putting everything in
_make_zero_init?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.
Makes it easier for subclass to only have to implement the init and not have to put back the check