-
Notifications
You must be signed in to change notification settings - Fork 256
mpi: Fixup code generation for Bundles #2581
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
Changes from all commits
4ebd337
6e7466e
184fdaf
f22aa87
95a0957
a41120f
478e1fd
4c9e5c2
f3d7aca
48a18cf
23eabda
a50a1d4
3e80acf
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 |
|---|---|---|
|
|
@@ -8,7 +8,8 @@ | |
| from devito.ir.support.utils import AccessMode, extrema | ||
| from devito.ir.support.vector import LabeledVector, Vector | ||
| from devito.symbolics import (compare_ops, retrieve_indexed, retrieve_terminals, | ||
| q_constant, q_affine, q_routine, search, uxreplace) | ||
| q_constant, q_comp_acc, q_affine, q_routine, search, | ||
| uxreplace) | ||
| from devito.tools import (Tag, as_mapper, as_tuple, is_integer, filter_sorted, | ||
| flatten, memoized_meth, memoized_generator) | ||
| from devito.types import (ComponentAccess, Dimension, DimensionTuple, Fence, | ||
|
|
@@ -529,9 +530,16 @@ def __hash__(self): | |
| (self.source, self.sink, self.source.timestamp == self.sink.timestamp) | ||
| ) | ||
|
|
||
| @property | ||
| @cached_property | ||
|
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. What is the motivation for this?
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 went from simply being an alias for an attribute of an attribute, to having internal logic etc |
||
| def function(self): | ||
| return self.source.function | ||
| if q_comp_acc(self.source.access) and not q_comp_acc(self.sink.access): | ||
| # E.g., `source=ab[x].x` and `sink=ab[x]` -> `a(x)` | ||
| return self.source.access.function_access | ||
| elif q_comp_acc(self.sink.access) and not q_comp_acc(self.source.access): | ||
| # E.g., `source=ab[x]` and `sink=ab[x].y` -> `b(x)` | ||
| return self.sink.access.function_access | ||
| else: | ||
| return self.source.function | ||
|
|
||
| @property | ||
| def findices(self): | ||
|
|
@@ -955,7 +963,7 @@ def reads_gen(self): | |
| @memoized_generator | ||
| def reads_smart_gen(self, f): | ||
| """ | ||
| Generate all read access to a given function. | ||
| Generate all read accesses to a given function. | ||
|
|
||
| StencilDimensions, if any, are replaced with their extrema. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,9 @@ | |
| from devito.symbolics import (Byref, CondNe, FieldFromPointer, FieldFromComposite, | ||
| IndexedPointer, Macro, cast, subs_op_args) | ||
| from devito.tools import (as_mapper, dtype_to_mpitype, dtype_len, infer_datasize, | ||
| flatten, generator, is_integer, split) | ||
| from devito.types import (Array, Bag, Dimension, Eq, Symbol, LocalObject, | ||
| CompositeObject, CustomDimension) | ||
| flatten, generator, is_integer) | ||
| from devito.types import (Array, Bag, BundleView, Dimension, Eq, Symbol, | ||
| LocalObject, CompositeObject, CustomDimension) | ||
|
|
||
| __all__ = ['HaloExchangeBuilder', 'ReductionBuilder', 'mpi_registry'] | ||
|
|
||
|
|
@@ -292,19 +292,28 @@ def _make_bundles(self, hs): | |
|
|
||
| mapper = as_mapper(halo_scheme.fmapper, lambda i: halo_scheme.fmapper[i]) | ||
| for hse, components in mapper.items(): | ||
| # We recast everything as Bags for simplicity -- worst case scenario | ||
| # all Bags only have one component. Existing Bundles are preserved | ||
| halo_scheme = halo_scheme.drop(components) | ||
| bundles, candidates = split(tuple(components), lambda i: i.is_Bundle) | ||
| for b in bundles: | ||
| halo_scheme = halo_scheme.add(b, hse) | ||
|
|
||
| # Existing Bundles are preserved | ||
| if hse.bundle: | ||
| if set(components) == set(hse.bundle.components): | ||
| halo_scheme = halo_scheme.add(hse.bundle, hse) | ||
| else: | ||
| name = f'bundleview_{hse.bundle.name}' | ||
| bundle_view = BundleView( | ||
| name=name, components=components, parent=hse.bundle | ||
| ) | ||
| halo_scheme = halo_scheme.add(bundle_view, hse) | ||
| continue | ||
|
|
||
| # We recast everything else as Bags for simplicity -- worst case | ||
| # scenario all Bags only have one component. | ||
| try: | ||
| name = "bag_%s" % "".join(f.name for f in candidates) | ||
| bag = Bag(name=name, components=candidates) | ||
| name = "bag_%s" % "".join(f.name for f in components) | ||
|
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. Fstring? Might be a rare occasion where it's less neat tbh |
||
| bag = Bag(name=name, components=components) | ||
| halo_scheme = halo_scheme.add(bag, hse) | ||
| except ValueError: | ||
| for i in candidates: | ||
| for i in components: | ||
| name = "bag_%s" % i.name | ||
|
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. Fstring |
||
| bag = Bag(name=name, components=i) | ||
| halo_scheme = halo_scheme.add(bag, hse) | ||
|
|
@@ -363,10 +372,17 @@ def _make_copy(self, f, hse, key, swap=False): | |
| else: | ||
| swap = lambda i, j: (j, i) | ||
| name = 'scatter%s' % key | ||
|
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. Ditto |
||
|
|
||
| if isinstance(f, Bag): | ||
| for i, c in enumerate(f.components): | ||
| eqns.append(Eq(*swap(buf[[i] + bdims], c[findices]))) | ||
| elif isinstance(f, BundleView): | ||
| assert f.parent is hse.bundle | ||
| for i, c in enumerate(f.components): | ||
| indices = [f.parent.components.index(c), *findices] | ||
| eqns.append(Eq(*swap(buf[[i] + bdims], f.parent[indices]))) | ||
| else: | ||
| assert f.is_Bundle | ||
| for i in range(f.ncomp): | ||
| eqns.append(Eq(*swap(buf[[i] + bdims], f[[i] + findices]))) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,9 +123,7 @@ class InjectBuffers(Queue): | |
| def __init__(self, mapper, sregistry, options): | ||
| super().__init__() | ||
|
|
||
| # Sort the mapper so that we always process the same Function in the | ||
| # same order, hence we get deterministic code generation | ||
| self.mapper = {i: mapper[i] for i in sorted(mapper, key=lambda i: i.name)} | ||
| self.mapper = mapper | ||
|
|
||
| self.sregistry = sregistry | ||
| self.options = options | ||
|
|
@@ -302,6 +300,9 @@ def generate_buffers(clusters, key, sregistry, options, **kwargs): | |
| # {candidate buffered Function -> [Clusters that access it]} | ||
| bfmap = map_buffered_functions(clusters, key) | ||
|
|
||
| # Sort for deterministic code generation | ||
| bfmap = {i: bfmap[i] for i in sorted(bfmap, key=lambda i: i.name)} | ||
|
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. Should this sorting go into |
||
|
|
||
| # {buffered Function -> Buffer} | ||
| xds = {} | ||
| mapper = {} | ||
|
|
@@ -718,7 +719,7 @@ def offset_from_centre(d, indices): | |
| # `time/factor` -- the starting pointing at time_m or time_M | ||
| v = indices[0] | ||
| try: | ||
| p = sum(v.args[1:]) | ||
| p = v.func(*[i for i in v.args if not is_integer(i)]) | ||
| if not ((p - v).is_Integer or (p - v).is_Symbol): | ||
| raise ValueError | ||
| except (IndexError, ValueError): | ||
|
|
||
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 like a prettier print I guess