Skip to content

Commit

Permalink
compiler: Drop redundant code
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Nov 14, 2024
1 parent ec2d13f commit d6ed1a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
7 changes: 2 additions & 5 deletions devito/ir/iet/visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,6 @@ def default_retval(cls):
the nodes of type ``child_types`` retrieved by the search. This behaviour
can be changed through this parameter. Accepted values are:
- 'immediate': only the closest matching ancestor is mapped.
- 'groupby': the matching ancestors are grouped together as a single key.
"""

def __init__(self, parent_type=None, child_types=None, mode=None):
Expand All @@ -886,7 +885,7 @@ def __init__(self, parent_type=None, child_types=None, mode=None):
assert issubclass(parent_type, Node)
self.parent_type = parent_type
self.child_types = as_tuple(child_types) or (Call, Expression)
assert mode in (None, 'immediate', 'groupby')
assert mode in (None, 'immediate')
self.mode = mode

def visit_object(self, o, ret=None, **kwargs):
Expand All @@ -903,9 +902,7 @@ def visit_Node(self, o, ret=None, parents=None, in_parent=False):
if parents is None:
parents = []
if isinstance(o, self.child_types):
if self.mode == 'groupby':
ret.setdefault(as_tuple(parents), []).append(o)
elif self.mode == 'immediate':
if self.mode == 'immediate':
if in_parent:
ret.setdefault(parents[-1], []).append(o)
else:
Expand Down
30 changes: 16 additions & 14 deletions devito/passes/iet/mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,7 @@ def _hoist_invariant(iet):
hsmapper = {}
imapper = defaultdict(list)

iter_mapper = MapNodes(Iteration, HaloSpot, 'immediate').visit(iet)

# Drop void `halo_scheme`s from the analysis
iter_mapper = {k: [hs for hs in v if not hs.halo_scheme.is_void]
for k, v in iter_mapper.items()}

iter_mapper = {k: v for k, v in iter_mapper.items() if k is not None}

iter_mapper = {k: v for k, v in iter_mapper.items() if len(v) > 1}
iter_mapper = filter_iter_mapper(iet)

for it, halo_spots in iter_mapper.items():
for hs0, hs1 in combinations(halo_spots, r=2):
Expand Down Expand Up @@ -168,11 +160,7 @@ def _merge_halospots(iet):

mapper = {}

iter_mapper = MapNodes(Iteration, HaloSpot, 'immediate').visit(iet)

iter_mapper = {k: v for k, v in iter_mapper.items() if k is not None}

iter_mapper = {k: v for k, v in iter_mapper.items() if len(v) > 1}
iter_mapper = filter_iter_mapper(iet)

for it, halo_spots in iter_mapper.items():
scope = Scope([e.expr for e in FindNodes(Expression).visit(it)])
Expand Down Expand Up @@ -366,6 +354,20 @@ def mpiize(graph, **kwargs):

# *** Utilities

def filter_iter_mapper(iet):
"""
Given an IET, return a mapper from Iterations to the HaloSpots.
Additionally, filter out Iterations that are not of interest.
"""
iter_mapper = MapNodes(Iteration, HaloSpot, 'immediate').visit(iet)
iter_mapper = {k: [hs for hs in v if not hs.halo_scheme.is_void]
for k, v in iter_mapper.items()}
iter_mapper = {k: v for k, v in iter_mapper.items() if k is not None}
iter_mapper = {k: v for k, v in iter_mapper.items() if len(v) > 1}

return iter_mapper


def _make_cond_mapper(iet):
cond_mapper = MapHaloSpots().visit(iet)
return {hs: {i for i in v if i.is_Conditional and
Expand Down

0 comments on commit d6ed1a7

Please sign in to comment.