-
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
base: main
Are you sure you want to change the base?
Changes from all commits
598061a
8e805ab
254136a
e9db68d
2a3e49a
e68a40c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
|
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.
|
||
|
|
||
| def _zero_init(self, obj, storage): | ||
|
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. not sure we actually need an extra method like this, why not putting everything in
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. Makes it easier for subclass to only have to implement the init and not have to put back the check |
||
| """ | ||
| 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,20 @@ 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), (_, 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)
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. prod |
||
| strict=True | ||
| ): | ||
| if d.is_NonlinearDerived: | ||
| assert h0 == h1 == 0 | ||
| assert h0 == h1 | ||
| m = 0 | ||
| M = s - 1 | ||
| else: | ||
| m = d.symbolic_min - h0 | ||
| M = d.symbolic_max + h1 | ||
| # Object needing padding zeroing need symbolic padding | ||
| 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 +758,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] | ||
|
|
||
|
|
||
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.
this is a bit hacky, there should be a different way of doing it...