Skip to content

Commit 18094bc

Browse files
committed
compiler: fix multi-cond for multi-layer
1 parent c27c742 commit 18094bc

5 files changed

Lines changed: 31 additions & 11 deletions

File tree

devito/ir/equations/equation.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
from devito.tools import (
1414
Pickable, Tag, as_hashable, filter_sorted, frozendict, reuse_if_unchanged
1515
)
16-
from devito.types import Eq, Inc, ReduceMax, ReduceMin, ReduceMinMax, relational_min
16+
from devito.symbolics import IntDiv, limits_mapper, uxreplace
17+
from devito.tools import Pickable, Tag, frozendict
18+
from devito.types import Eq, Inc, ReduceMax, ReduceMin, ReduceMinMax, relational_min, relational_shift
1719

1820
__all__ = [
1921
'ClusterizedEq',
@@ -308,13 +310,10 @@ def __new__(cls, *args, **kwargs):
308310
index = d.index
309311
if d.condition is not None and d in expr.free_symbols:
310312
index = index - relational_min(d.condition, d.parent)
311-
# If there is a condition we might access on a non-factor
312-
# index and need to make sure we don't overwrite the previous
313-
# index
314-
num = index + d.symbolic_factor - 1
313+
shift = relational_shift(d.condition, d.parent)
315314
else:
316-
num = index
317-
expr = uxreplace(expr, {d: IntDiv(num, d.symbolic_factor)})
315+
shift = 0
316+
expr = uxreplace(expr, {d: IntDiv(index, d.symbolic_factor) + shift})
318317

319318
conditionals = frozendict(conditionals)
320319

devito/passes/clusters/asynchrony.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def _actions_from_update_memcpy(c, d, clusters, actions, sregistry):
240240

241241
fetch = e.rhs.indices[d]
242242
fshift = {Forward: 1, Backward: -1}.get(direction, 0)
243-
findex = fetch._subs(pd, pd + fshift)
243+
findex = fetch + fshift if fetch.find(IntDiv) else fetch._subs(pd, pd + fshift)
244244

245245
# If fetching into e.g. `ub[t1]` we might need to prefetch into e.g. `ub[t0]`
246246
tindex0 = e.lhs.indices[d]

devito/passes/clusters/buffering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from itertools import chain
44

55
import numpy as np
6-
from sympy import S
6+
from sympy import S, simplify
77

88
from devito.exceptions import CompilationError
99
from devito.ir import (
@@ -774,7 +774,7 @@ def infer_buffer_size(f, dim, clusters):
774774
slots = [Vector(i) for i in slots]
775775
size = int((vmax(*slots) - vmin(*slots) + 1)[0])
776776

777-
return size
777+
return simplify(size)
778778

779779

780780
def offset_from_centre(d, indices):

devito/symbolics/extended_sympy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
)
2020
from devito.types import Symbol
2121
from devito.types.basic import Basic
22+
from devito.types.relational import Ge
2223

2324
__all__ = ['CondEq', 'CondNe', 'BitwiseNot', 'BitwiseXor', 'BitwiseAnd', # noqa
2425
'LeftShift', 'RightShift', 'IntDiv', 'Terminal', 'CallFromPointer',
@@ -48,6 +49,11 @@ def canonical(self):
4849
def negated(self):
4950
return CondNe(*self.args, evaluate=False)
5051

52+
@property
53+
def _as_min(self):
54+
from devito.symbolics.extended_dtypes import INT
55+
return INT(Ge(*self.args))
56+
5157

5258
class CondNe(sympy.Ne):
5359

devito/types/relational.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44
import sympy
55

6-
__all__ = ['Ge', 'Gt', 'Le', 'Lt', 'Ne', 'relational_max', 'relational_min']
6+
__all__ = ['Ge', 'Gt', 'Le', 'Lt', 'Ne', 'relational_max', 'relational_min',
7+
'relational_shift']
78

89

910
class AbstractRel:
@@ -291,3 +292,17 @@ def _(expr, s):
291292
return expr.gts
292293
else:
293294
return sympy.S.Infinity
295+
296+
297+
def relational_shift(expr, s):
298+
"""
299+
Infer shift incurred by the expression. Generally only
300+
applies when a CondEq is used as it adds a single value.
301+
"""
302+
if not expr.has(s):
303+
return 0
304+
305+
try:
306+
return expr._as_min
307+
except (TypeError, AttributeError):
308+
return 0

0 commit comments

Comments
 (0)