Skip to content

Commit

Permalink
Merge pull request #2470 from devitocodes/tkns
Browse files Browse the repository at this point in the history
dsl: Move SubDimension thickness evaluation to the thicknesses themselves
  • Loading branch information
FabioLuporini authored Nov 13, 2024
2 parents 2f4f80f + 6e7c017 commit 2f18ab8
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 198 deletions.
2 changes: 1 addition & 1 deletion devito/data/decomposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def index_glb_to_loc(self, *args, rel=True):
if self.loc_empty:
return None
abs_ofs, side = args
if side is LEFT:
if side == LEFT:
rel_ofs = self.glb_min + abs_ofs - base
if abs_ofs >= base and abs_ofs <= top:
return rel_ofs
Expand Down
28 changes: 16 additions & 12 deletions devito/ir/equations/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ConditionalDimension)
from devito.types.array import Array
from devito.types.basic import AbstractFunction
from devito.types.dimension import MultiSubDimension
from devito.types.dimension import MultiSubDimension, Thickness
from devito.data.allocators import DataReference
from devito.logger import warning

Expand Down Expand Up @@ -213,18 +213,24 @@ def _(expr, mapper, rebuilt, sregistry):
_concretize_subdims(expr.implicit_dims, mapper, rebuilt, sregistry)


@_concretize_subdims.register(Thickness)
def _(tkn, mapper, rebuilt, sregistry):
if tkn in mapper:
# Already have a substitution for this thickness
return

mapper[tkn] = tkn._rebuild(name=sregistry.make_name(prefix=tkn.name))


@_concretize_subdims.register(SubDimension)
def _(d, mapper, rebuilt, sregistry):
if d in mapper:
# Already have a substitution for this dimension
return

tkns_subs = {tkn: tkn._rebuild(name=sregistry.make_name(prefix=tkn.name))
for tkn in d.tkns}
left, right = [mM.subs(tkns_subs) for mM in (d.symbolic_min, d.symbolic_max)]
thickness = tuple((v, d._thickness_map[k]) for k, v in tkns_subs.items())

mapper[d] = d._rebuild(symbolic_min=left, symbolic_max=right, thickness=thickness)
tkns = tuple(t._rebuild(name=sregistry.make_name(prefix=t.name)) for t in d.tkns)
mapper.update({tkn0: tkn1 for tkn0, tkn1 in zip(d.tkns, tkns)})
mapper[d] = d._rebuild(thickness=tkns)


@_concretize_subdims.register(ConditionalDimension)
Expand Down Expand Up @@ -261,11 +267,9 @@ def _(d, mapper, rebuilt, sregistry):
# Already have a substitution for this dimension
return

abstract_tkns = MultiSubDimension._symbolic_thickness(d.parent.name)
concrete_tkns = tuple(tkn._rebuild(name=sregistry.make_name(prefix=tkn.name))
for tkn in abstract_tkns)

kwargs = {'thickness': concrete_tkns}
tkns = tuple(tkn._rebuild(name=sregistry.make_name(prefix=tkn.name))
for tkn in d.thickness)
kwargs = {'thickness': tkns}
fkwargs = {}

idim0 = d.implicit_dimension
Expand Down
2 changes: 1 addition & 1 deletion devito/ir/support/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ def disjoint_test(e0, e1, d, it):
if d.is_Custom:
subs = {}
elif d.is_Sub and d.is_left:
subs = {d.root.symbolic_min: 0, **dict([d.thickness.left])}
subs = {d.root.symbolic_min: 0, d.ltkn: d.ltkn.value}
else:
return False

Expand Down
3 changes: 1 addition & 2 deletions devito/mpi/halo_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ def __init__(self, exprs, ispace):
if d._defines & self.dimensions])
subdims = [d for d in dims if d.is_Sub and not d.local]
for i in subdims:
ltk, _ = i.thickness.left
rtk, _ = i.thickness.right
ltk, rtk = i.tkns
self._honored[i.root] = frozenset([(ltk, rtk)])
self._honored = frozendict(self._honored)

Expand Down
7 changes: 7 additions & 0 deletions devito/operator/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
split, timed_pass, timed_region, contains_val)
from devito.types import (Buffer, Grid, Evaluable, host_layer, device_layer,
disk_layer)
from devito.types.dimension import Thickness


__all__ = ['Operator']

Expand Down Expand Up @@ -640,6 +642,11 @@ def _prepare_arguments(self, autotune=None, **kwargs):
for d in reversed(toposort):
args.update(d._arg_values(self._dspace[d], grid, **kwargs))

# Process Thicknesses
for p in self.parameters:
if isinstance(p, Thickness):
args.update(p._arg_values(grid=grid, **kwargs))

# Process Objects
for o in self.objects:
args.update(o._arg_values(grid=grid, **kwargs))
Expand Down
Loading

0 comments on commit 2f18ab8

Please sign in to comment.