From 4d9abed4238b4ddf196a8efe68776b8679fa9480 Mon Sep 17 00:00:00 2001 From: Mathias Louboutin Date: Tue, 5 Sep 2023 09:57:27 -0400 Subject: [PATCH] compiler: fix dimension sort determinism --- devito/ir/equations/algorithms.py | 12 ++++++++++-- devito/ir/support/utils.py | 1 + devito/operations/interpolators.py | 11 +++++++---- devito/types/sparse.py | 10 +++++----- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/devito/ir/equations/algorithms.py b/devito/ir/equations/algorithms.py index 2606d2dd2d..0c0185055e 100644 --- a/devito/ir/equations/algorithms.py +++ b/devito/ir/equations/algorithms.py @@ -74,10 +74,18 @@ def handle_indexed(indexed): # obtain the desired ordering `(time, x, xi)`. W/o `(time, x)`, the ordering # `(x, time, xi)` might be returned instead, which would be non-sense for i in relations: - dims = [di for d in i for di in (d.index, d)] + dims = [] + for d in i: + # Only add index if a different Dimension name to avoid dropping conditionals + # with the same name as the parent + if d.index.name == d.name: + dims.append(d) + else: + dims.extend([d.index, d]) + implicit_relations.update({tuple(filter_ordered(dims))}) - ordering = PartialOrderTuple(extra, relations=(relations | implicit_relations)) + ordering = PartialOrderTuple(extra, relations=implicit_relations) return ordering diff --git a/devito/ir/support/utils.py b/devito/ir/support/utils.py index 5f08f48020..3750b08a0e 100644 --- a/devito/ir/support/utils.py +++ b/devito/ir/support/utils.py @@ -183,6 +183,7 @@ def detect_accesses(exprs): for e in as_tuple(exprs): other_dims.update(i for i in e.free_symbols if isinstance(i, Dimension)) other_dims.update(e.implicit_dims) + other_dims = filter_sorted(other_dims) mapper[None] = Stencil([(i, 0) for i in other_dims]) return mapper diff --git a/devito/operations/interpolators.py b/devito/operations/interpolators.py index e082848ffc..3f1ad5e3b6 100644 --- a/devito/operations/interpolators.py +++ b/devito/operations/interpolators.py @@ -176,11 +176,7 @@ def _interp_idx(self, variables, implicit_dims=None): """ mapper = {} pos = self.sfunction._position_map.values() - # Temporaries for the position - temps = self._positions(implicit_dims) - # Coefficient symbol expression - temps.extend(self._coeff_temps(implicit_dims)) for ((di, d), rd, p) in zip(enumerate(self._gdims), self._rdim, pos): # Add conditional to avoid OOB lb = sympy.And(rd + p >= d.symbolic_min - self.r, evaluate=False) @@ -188,10 +184,17 @@ def _interp_idx(self, variables, implicit_dims=None): cond = sympy.And(lb, ub, evaluate=False) mapper[d] = ConditionalDimension(rd.name, rd, condition=cond, indirect=True) + # Temporaries for the position + temps = self._positions(implicit_dims) + + # Coefficient symbol expression + temps.extend(self._coeff_temps(implicit_dims)) + # Substitution mapper for variables idx_subs = {v: v.subs({k: c - v.origin.get(k, 0) + p for ((k, c), p) in zip(mapper.items(), pos)}) for v in variables} + idx_subs.update(dict(zip(self._rdim, mapper.values()))) return idx_subs, temps diff --git a/devito/types/sparse.py b/devito/types/sparse.py index d2eb1047b9..a1aef68f5f 100644 --- a/devito/types/sparse.py +++ b/devito/types/sparse.py @@ -84,7 +84,7 @@ def func(self, *args, **kwargs): # Rebuild subfunctions first to avoid new data creation as we have to use `_data` # as a reconstruction kwargs to avoid the circular dependency # with the parent in SubFunction - # This is also necessary to avoid shaoe issue in the SubFunction with mpi + # This is also necessary to avoid shape issue in the SubFunction with mpi for s in self._sub_functions: if getattr(self, s) is not None: kwargs.update({s: getattr(self, s).func(*args, **kwargs)}) @@ -724,7 +724,7 @@ class SparseFunction(AbstractSparseFunction): Discretisation order for space derivatives. Defaults to 0. shape : tuple of ints, optional Shape of the object. Defaults to ``(npoint,)``. - Dimensions : tuple of Dimension, optional + dimensions : tuple of Dimension, optional Dimensions associated with the object. Only necessary if the SparseFunction defines a multi-dimensional tensor. dtype : data-type, optional @@ -845,7 +845,7 @@ class SparseTimeFunction(AbstractSparseTimeFunction, SparseFunction): Discretisation order for time derivatives. Defaults to 1. shape : tuple of ints, optional Shape of the object. Defaults to ``(nt, npoint)``. - Dimensions : tuple of Dimension, optional + dimensions : tuple of Dimension, optional Dimensions associated with the object. Only necessary if the SparseFunction defines a multi-dimensional tensor. dtype : data-type, optional @@ -992,7 +992,7 @@ class PrecomputedSparseFunction(AbstractSparseFunction): Discretisation order for space derivatives. Defaults to 0. shape : tuple of ints, optional Shape of the object. Defaults to `(npoint,)`. - Dimensions : tuple of Dimension, optional + dimensions : tuple of Dimension, optional Dimensions associated with the object. Only necessary if the SparseFunction defines a multi-dimensional tensor. dtype : data-type, optional @@ -1156,7 +1156,7 @@ class PrecomputedSparseTimeFunction(AbstractSparseTimeFunction, Discretisation order for time derivatives. Default to 1. shape : tuple of ints, optional Shape of the object. Defaults to `(npoint,)`. - Dimensions : tuple of Dimension, optional + dimensions : tuple of Dimension, optional Dimensions associated with the object. Only necessary if the SparseFunction defines a multi-dimensional tensor. dtype : data-type, optional