From 6ed397928de76b1f106f16a58d27c2f9aad82f4e Mon Sep 17 00:00:00 2001 From: Edward Caunt Date: Tue, 24 Sep 2024 16:47:00 +0100 Subject: [PATCH] compiler: Tweak renaming to operate after first encountered and warn user --- devito/ir/equations/algorithms.py | 25 ++++++++++++++++--------- devito/ir/support/symregistry.py | 6 +++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/devito/ir/equations/algorithms.py b/devito/ir/equations/algorithms.py index ab7f9745e8..c8f207855b 100644 --- a/devito/ir/equations/algorithms.py +++ b/devito/ir/equations/algorithms.py @@ -10,6 +10,7 @@ from devito.types.basic import AbstractFunction from devito.types.dimension import MultiSubDimension from devito.data.allocators import DataReference +from devito.logger import warning __all__ = ['dimension_sort', 'lower_exprs', 'concretize_subdims'] @@ -184,7 +185,7 @@ def concretize_subdims(exprs, **kwargs): dimensions = tuple(mapper.get(d, d) for d in f.dimensions) if dimensions != f.dimensions: # A dimension has been rebuilt, so build a mapper for Indexed - mapper[f.indexed] = f._rebuild(dimensions=dimensions, function=None).indexed + mapper[f.indexed] = f._rebuild(dimensions=dimensions).indexed processed = [uxreplace(e, mapper) for e in exprs] @@ -218,9 +219,8 @@ def _(d, mapper, rebuilt, sregistry): # Already have a substitution for this dimension return - tkns = [tkn._rebuild(name=sregistry.make_name(prefix=tkn.name)) - for tkn in d.tkns] - tkns_subs = {tkn0: tkn1 for tkn0, tkn1 in zip(d.tkns, tkns)} + 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()) @@ -277,15 +277,22 @@ def _(d, mapper, rebuilt, sregistry): rebuilt[idim0] = idim1 = idim0._rebuild(name=iname) kwargs['implicit_dimension'] = idim1 - fkwargs.update({'dimensions': (idim1,) + d.functions.dimensions[1:], - 'halo': None, - 'padding': None}) + fkwargs['dimensions'] = (idim1,) + d.functions.dimensions[1:] if d.functions in rebuilt: functions = rebuilt[d.functions] else: - fkwargs.update({'name': sregistry.make_name(prefix=d.functions.name), - 'function': None}) + # Increment every instance of this name after the first encountered + fname = sregistry.make_name(prefix=d.functions.name, increment_first=False) + # Warn the user if name has been changed, since this will affect overrides + if fname != d.functions.name: + fkwargs['name'] = fname + warning("%s <%s> renamed as '%s'. Consider assigning a unique name to %s." % + (str(d.functions), id(d.functions), fname, d.functions.name)) + + fkwargs.update({'function': None, + 'halo': None, + 'padding': None}) # Data in MultiSubDimension function may not have been touched at this point, # in which case do not use an allocator, as there is nothing to allocate, and diff --git a/devito/ir/support/symregistry.py b/devito/ir/support/symregistry.py index f5233d8143..8149ab22d5 100644 --- a/devito/ir/support/symregistry.py +++ b/devito/ir/support/symregistry.py @@ -30,7 +30,7 @@ def __init__(self): # passes, to maximize symbol (especially Dimension) reuse self.caches = {} - def make_name(self, prefix=None): + def make_name(self, prefix=None, increment_first=True): # By default we're creating a new symbol if prefix is None: prefix = self._symbol_prefix @@ -40,6 +40,10 @@ def make_name(self, prefix=None): except KeyError: counter = self.counters.setdefault(prefix, generator()) + # Only increment symbol names after the first encountered + if not increment_first: + return prefix + return "%s%d" % (prefix, counter()) def make_npthreads(self, size):