Skip to content

Commit 753a6ac

Browse files
committed
compiler: Fix for upstream custom_multi_partile
1 parent 1edb9ff commit 753a6ac

2 files changed

Lines changed: 40 additions & 3 deletions

File tree

‎devito/passes/clusters/blocking.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,16 @@ def _process_fatd(self, clusters, level, prefix=None):
101101

102102
return super()._process_fatd(clusters, level, prefix)
103103

104-
def _has_data_reuse(self, cluster):
104+
def _has_data_reuse(self, cluster, dims=None):
105105
# A sufficient condition for the existence of data reuse in `cluster`
106106
# is that the same Function is accessed twice at the same memory location,
107107
# which translates into the existence of any Relation across Indexeds
108-
if any(r.function.is_AbstractFunction for r in cluster.scope.r_gen()):
108+
for r in cluster.scope.r_gen():
109+
if not r.function.is_AbstractFunction:
110+
continue
111+
# E.g., `u.forward = u + 1` has no reuse along parallel Dimensions
112+
if dims is not None and all(r.distance_mapper.get(d) == 0 for d in dims):
113+
continue
109114
return True
110115
if search(cluster.exprs, IndexSum):
111116
return True
@@ -208,9 +213,11 @@ def callback(self, clusters, prefix):
208213
return clusters
209214

210215
properties = c.properties.block(d)
216+
dims = [i for i in c.ispace.itdims
217+
if c.properties.is_parallel_relaxed(i)]
211218

212219
if any(self._has_short_trip_count(i) for i in c.ispace.itdims) or \
213-
not self._has_data_reuse(c):
220+
not self._has_data_reuse(c, dims):
214221
properties = properties.notune(d)
215222

216223
elif self._has_data_reuse(c):

‎tests/test_gpu_openacc.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,36 @@ def test_short_multi_tile_keeps_outer_dim_on_device(self):
189189
assert len(iters) == len(v)
190190
assert all(i.step == j for i, j in zip(iters, v, strict=True))
191191

192+
@pytest.mark.parametrize('shifted', [False, True])
193+
def test_short_multi_tile_time_update(self, shifted):
194+
grid = Grid(shape=(8, 8, 8))
195+
t = grid.stepping_dim
196+
x, y, z = grid.dimensions
197+
u = TimeFunction(name='u', grid=grid)
198+
199+
source = u[t, x + 1, y, z] if shifted else u
200+
op = Operator(Eq(u.forward, source + 1), name='short_tile_time_update',
201+
platform='nvidiaX', language='openacc',
202+
opt=('advanced', {'par-tile': ((16, 4), (8, 8)),
203+
'blocklevels': 1, 'blockinner': True,
204+
'blockrelax': 'device-aware'}))
205+
206+
root = 'y0_blk0' if shifted else 'x0_blk0'
207+
bns, _ = assert_blocking(op, {root})
208+
iters = FindNodes(Iteration).visit(bns[root])
209+
steps = [i.step for i in iters if i.dim.is_Block and i.dim._depth == 1]
210+
assert steps == ([4, 16] if shifted else [4, 4, 16])
211+
212+
tree, = retrieve_iteration_tree(op)
213+
assert tree[0].dim is grid.time_dim
214+
if shifted:
215+
assert tree[1].dim is x
216+
assert tree[1].limits == (x.symbolic_min, x.symbolic_max, 1)
217+
else:
218+
assert all(i.dim.is_Block for i in tree[1:])
219+
assert tree[1].pragmas[0].ccode.value ==\
220+
'acc parallel loop tile(16,4,4) present(u)'
221+
192222
def test_multi_tile_blocking_structure(self):
193223
grid = Grid(shape=(8, 8, 8))
194224

0 commit comments

Comments
 (0)