Skip to content

Commit 767950b

Browse files
authored
Merge pull request #2704 from devitocodes/fix-inf-dir
compiler: prevent directions from non indexed
2 parents 3c93647 + 5125201 commit 767950b

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

devito/ir/support/basic.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class IterationInstance(LabeledVector):
6161
x, y, z : findices
6262
w : a generic Dimension
6363
64-
| x+1 | | x | | x | | w | | x+y |
65-
obj1 = | y+2 | , obj2 = | 4 | , obj3 = | x | , obj4 = | y | , obj5 = | y |
66-
| z-3 | | z+1 | | y | | z | | z |
64+
| x+1 | | x | | x | | w | | x+y |
65+
obj1 | y+2 |, obj2 = | 4 |, obj3 = | x |, obj4 = | y |, obj5 = | y |
66+
| z-3 | | z+1 | | y | | z | | z |
6767
6868
We have that:
6969
@@ -371,7 +371,8 @@ def distance(self, other):
371371
# symbolic Lt or Gt operations,
372372
# Note: Boolean is split to make the conditional short
373373
# circuit more frequently for mild speedup.
374-
if smart_lt(v, sit.symbolic_min) or smart_gt(v, sit.symbolic_max):
374+
if smart_lt(v, sit.symbolic_min) or \
375+
smart_gt(v, sit.symbolic_max):
375376
return Vector(S.ImaginaryUnit)
376377

377378
# Case 2: `sit` is an IterationInterval over a local SubDimension
@@ -403,19 +404,24 @@ def distance(self, other):
403404
ret.append(other[n] - self[n])
404405
else:
405406
ret.append(self[n] - other[n])
407+
elif sai in self.ispace and oai in other.ispace:
408+
# E.g., `self=R<f,[x, y]>`, `sai=time`,
409+
# `self.itintervals=(time, x, y)`, `n=0`
410+
continue
406411
elif not sai and not oai:
407-
# E.g., `self=R<a,[3]>` and `other=W<a,[4]>`
408412
if self[n] - other[n] == 0:
413+
# E.g., `self=R<a,[4]>` and `other=W<a,[4]>`
409414
ret.append(S.Zero)
410415
else:
416+
# E.g., `self=R<a,[3]>` and `other=W<a,[4]>`
411417
break
412-
elif sai in self.ispace and oai in other.ispace:
413-
# E.g., `self=R<f,[x, y]>`, `sai=time`,
414-
# `self.itintervals=(time, x, y)`, `n=0`
415-
continue
418+
elif any(i is S.Infinity for i in (self[n], other[n])):
419+
# E.g., `self=R<f,[oo, oo]>` (due to `self.access=f_vec->size[1]`)
420+
# and `other=W<f,[t - 1, x + 1]>`
421+
ret.append(S.Zero)
416422
else:
417-
# E.g., `self=R<u,[t+1, ii_src_0+1, ii_src_1+2]>`, `fi=p_src`,
418-
# and `n=1`
423+
# E.g., `self=R<u,[t+1, ii_src_0+1]>`, `fi=p_src`, `n=1`
424+
# E.g., `self=R<a,[time,x]>`, `other=W<a,[time,4]>`, `n=1`
419425
return vinf(ret)
420426

421427
n = len(ret)

devito/passes/iet/mpi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,11 @@ def _semantical_eq_loc_indices(hsf0, hsf1):
530530

531531
# Special case: they might be syntactically different, but semantically
532532
# equivalent, e.g., `t0` and `t1` with same modulus
533-
if v0.modulo == v1.modulo == 1:
534-
continue
533+
try:
534+
if v0.modulo == v1.modulo == 1:
535+
continue
536+
except AttributeError:
537+
return False
535538

536539
return False
537540

devito/types/dense.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from devito.logger import debug, warning
1717
from devito.mpi import MPI
1818
from devito.parameters import configuration
19-
from devito.symbolics import FieldFromPointer, normalize_args
19+
from devito.symbolics import FieldFromPointer, normalize_args, IndexedPointer
2020
from devito.finite_differences import Differentiable, generate_fd_shortcuts
2121
from devito.finite_differences.tools import fd_weights_registry
2222
from devito.tools import (ReducerMap, as_tuple, c_restrict_void_p, flatten,
@@ -719,7 +719,7 @@ def _C_make_index(self, dim, side=None):
719719
@memoized_meth
720720
def _C_get_field(self, region, dim, side=None):
721721
"""Symbolic representation of a given data region."""
722-
ffp = lambda f, i: FieldFromPointer("%s[%d]" % (f, i), self._C_symbol)
722+
ffp = lambda f, i: IndexedPointer(FieldFromPointer(f"{f}", self._C_symbol), i)
723723
if region is DOMAIN:
724724
offset = ffp(self._C_field_owned_ofs, self._C_make_index(dim, LEFT))
725725
size = ffp(self._C_field_domain_size, self._C_make_index(dim))

tests/test_operator.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
from devito.passes.iet.languages.C import CDataManager
3636
from devito.symbolics import ListInitializer, indexify, retrieve_indexed
3737
from devito.tools import flatten, powerset, timed_region
38-
from devito.types import Array, Barrier, CustomDimension, Indirection, Scalar, Symbol
38+
from devito.types import (
39+
Array, Barrier, CustomDimension, Indirection, Scalar, Symbol, ConditionalDimension
40+
)
3941

4042

4143
def dimify(dimensions):
@@ -2034,6 +2036,23 @@ def test_2194_v2(self, eqns, expected, exp_trees, exp_iters):
20342036
op.apply()
20352037
assert(np.all(u.data[:] == expected[:]))
20362038

2039+
def test_pseudo_time_dep(self):
2040+
"""
2041+
Test that a data dependency through a field is correctly
2042+
ignored when not direction dependent
2043+
"""
2044+
grid = Grid((11, 11))
2045+
ct = ConditionalDimension(name='ct', parent=grid.time_dim, factor=2)
2046+
f = TimeFunction(name='f', grid=grid, time_order=1)
2047+
g = Function(name='g', grid=grid)
2048+
2049+
eq = [Eq(f.backward, div(f) + 1),
2050+
Eq(g, g + f.symbolic_shape[1], implicit_dims=ct),
2051+
Eq(g, g + 1, implicit_dims=ct)]
2052+
op = Operator(eq)
2053+
2054+
assert_structure(op, ['t,x,y', 't', 't,x,y'], 't,x,y,x,y')
2055+
20372056

20382057
class TestInternals:
20392058

0 commit comments

Comments
 (0)