Skip to content

Commit fa07652

Browse files
committed
compiler: Fix and simplify lower_aliases
1 parent f3c20e8 commit fa07652

3 files changed

Lines changed: 49 additions & 23 deletions

File tree

devito/passes/clusters/aliases.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -722,16 +722,20 @@ def lower_aliases(aliases, meta, opt_maxpar, opt_block_temps):
722722
# which is what appears in `ispace`
723723
interval = interval.lift(i.stamp)
724724

725-
if opt_block_temps:
726-
sub_iterators.update(dmapper)
727-
writeto.append(interval)
728-
intervals[d] = interval
729-
elif d.is_Block:
730-
pd = d.parent
731-
writeto.append(interval.relaxed)
732-
# The lower/upper bounds belong to the parent BlockDimension
733-
intervals[d] = interval.zero()
734-
intervals[pd] = interval.switch(pd)
725+
# Construct the write-to space, which will define the shape of the
726+
# temporary, and the iteration intervals in which it will be
727+
# populated
728+
if d.is_Block:
729+
if opt_block_temps:
730+
sub_iterators.update(dmapper)
731+
writeto.append(interval)
732+
intervals[d] = interval
733+
else:
734+
pd = d.parent
735+
writeto.append(interval.relaxed)
736+
# The lower/upper bounds belong to the parent BlockDimension
737+
intervals[d] = interval.zero()
738+
intervals[pd] = interval.switch(pd)
735739
else:
736740
writeto.append(interval.relaxed)
737741
intervals[d] = interval
@@ -1505,24 +1509,22 @@ def __repr__(self):
15051509

15061510
@property
15071511
def dimensions(self):
1508-
# Legacy: with SubDimensions, we may have the following situation:
1509-
#
1510-
# for zi = z_m + zi_ltkn; zi <= z_M - zi_rtkn; ...
1511-
# r[zi] = ...
1512-
#
1513-
# Instead of `r[zi - z_m - zi_ltkn]` we have just `r[zi]`, so we'll
1514-
# need as much room as in `zi`'s parent to avoid going out-of-bounds.
1515-
# Aside from ugly generated code, the reason we do not rather shift the
1516-
# indices is that it prevents future passes to transform the loop
1517-
# bounds (e.g., MPI's comp/comm overlap does that)
1518-
return tuple(d.parent if d.is_AbstractSub else d
1519-
for d in self.writeto.itdims)
1512+
return self.writeto.itdims
15201513

15211514
@property
15221515
def indices(self):
1516+
"""
1517+
The indices used to populate the temporary.
1518+
1519+
The write-to space may be relaxed for storage sizing, while the
1520+
temporary still has to be indexed with the active iteration Dimension.
1521+
"""
15231522
bdims = [d for d in self.ispace.itdims if d.is_Block]
15241523
depth = max([d._depth for d in bdims], default=0)
15251524
mapper = {d.root: d for d in bdims if d._depth == depth}
1525+
1526+
mapper.update({d.root: d for d in self.ispace.itdims if d.is_AbstractSub})
1527+
15261528
return tuple(mapper.get(d.root, d) for d in self.writeto.itdims)
15271529

15281530

devito/passes/iet/parpragma.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def _make_parregion(self, partree, parrays):
326326
i = n.write
327327
if not (i.is_Array or i.is_TempFunction):
328328
continue
329-
elif partree.dim in i.dimensions:
329+
elif partree.dim._defines.intersection(i.dimensions):
330330
# Non-local Array (full iteration space): no need to vector-expand
331331
continue
332332
elif i in parrays:

tests/test_dse.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,30 @@ def test_block_temps_false(self):
28902890
'tx0_blk0y0_blk0xyzx1_blk0y1_blk0xyz'
28912891
)
28922892

2893+
def test_subdims_wo_block_temps(self):
2894+
grid = Grid(shape=(16, 17, 18))
2895+
2896+
damp = Function(name='damp', grid=grid)
2897+
vp = Function(name='vp', grid=grid)
2898+
vp.data_with_halo[:] = np.linspace(
2899+
0.1, 1.1, vp.data_with_halo.size
2900+
).reshape(vp.shape_with_halo)
2901+
2902+
x, y, z = grid.dimensions
2903+
2904+
eqns = [Eq(damp, 0.0)]
2905+
for d in (x, y, z):
2906+
dl = SubDimension.left(name=f'{d.name}l', parent=d, thickness=4)
2907+
pos = Abs((4 - (dl - d.symbolic_min))/4.0)
2908+
eqns.append(Inc(damp.subs(d, dl),
2909+
sin(pos)/(vp.subs(d, dl) + 1.0)))
2910+
2911+
op = Operator(eqns, opt=('advanced', {'openmp': True,
2912+
'cire-mingain': 0,
2913+
'cire-block-temps': False}))
2914+
2915+
op.apply()
2916+
28932917

28942918
class TestIsoAcoustic:
28952919

0 commit comments

Comments
 (0)