Skip to content

Commit

Permalink
compiler: fix dimension sort determinism
Browse files Browse the repository at this point in the history
  • Loading branch information
mloubout committed Sep 6, 2023
1 parent 92a60b8 commit ab03930
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
12 changes: 10 additions & 2 deletions devito/ir/equations/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 7 additions & 4 deletions devito/operations/interpolators.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,22 +176,25 @@ 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)
ub = sympy.And(rd + p <= d.symbolic_max + self.r, evaluate=False)
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

Expand Down
4 changes: 0 additions & 4 deletions devito/symbolics/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ def _print_Mod(self, expr):
args = ['(%s)' % self._print(a) for a in expr.args]
return '%'.join(args)

def _print_Mul(self, expr):
term = super()._print_Mul(expr)
return term.replace("(-1)*", "-")

def _print_Min(self, expr):
if has_integer_args(*expr.args) and len(expr.args) == 2:
return "MIN(%s)" % self._print(expr.args)[1:-1]
Expand Down
10 changes: 5 additions & 5 deletions devito/types/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ab03930

Please sign in to comment.