Skip to content

Commit 0aa772b

Browse files
Merge pull request #2974 from devitocodes/fix-cire-subdomain-parallelism
compiler: Fix regressed OpenMP parallelism with CIRE and subdomains
2 parents 85e7304 + 7610edb commit 0aa772b

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

devito/passes/clusters/aliases.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ def optimize_schedule_maxpar_compact(schedule):
939939
guards = sa.guards
940940

941941
# Do we need to introduce guards to preserve the original semantics?
942-
for i in sa.indices:
942+
for i in sa.active_dims:
943943
for d in i._defines:
944944
try:
945945
int0, int1 = sa.ispace[d], ispace_union[d]
@@ -973,6 +973,7 @@ def lower_schedule(schedule, meta, sregistry, opt_ftemps, opt_min_dtype, opt_min
973973
subs = {}
974974
for sa in schedule:
975975
pivot, writeto, ispace, aliaseds, indicess, guards = sa
976+
active_dims = sa.active_dims
976977

977978
name = sregistry.make_name()
978979

@@ -1003,7 +1004,7 @@ def lower_schedule(schedule, meta, sregistry, opt_ftemps, opt_min_dtype, opt_min
10031004

10041005
# The indices used to populate the Array
10051006
indices = []
1006-
for interval, i, s in zip(writeto, sa.indices, shift, strict=True):
1007+
for interval, i, s in zip(writeto, active_dims, shift, strict=True):
10071008
try:
10081009
# E.g., `xs`
10091010
di, = writeto.sub_iterators[i]
@@ -1043,15 +1044,15 @@ def lower_schedule(schedule, meta, sregistry, opt_ftemps, opt_min_dtype, opt_min
10431044
try:
10441045
if any(i.is_Modulo for i in ispace.sub_iterators[d]):
10451046
properties[d] = normalize_properties(v, {SEQUENTIAL})
1046-
elif d not in writeto.itdims:
1047+
elif d not in active_dims:
10471048
properties[d] = normalize_properties(v, {PARALLEL_IF_PVT})
10481049
except KeyError:
10491050
# Non-dimension key such as (x, y) for diagonal stencil u(x+i hx, y+i hy)
10501051
pass
10511052

10521053
# Track star-shaped stencils for potential future optimization
10531054
if len(writeto) > 1 and schedule.is_frame:
1054-
properties[Hyperplane(writeto.itdims)] = {SEPARABLE}
1055+
properties[Hyperplane(active_dims)] = {SEPARABLE}
10551056

10561057
# Finally, build the alias Cluster
10571058
clusters.append(Cluster(expression, ispace, guards, properties))
@@ -1516,9 +1517,9 @@ def dimensions(self):
15161517
return self.writeto.itdims
15171518

15181519
@property
1519-
def indices(self):
1520+
def active_dims(self):
15201521
"""
1521-
The indices used to populate the temporary.
1522+
The active Dimensions used to populate the temporary.
15221523
15231524
The write-to space may be relaxed for storage sizing, while the
15241525
temporary still has to be indexed with the active iteration Dimension.

tests/test_dle.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,37 @@ def test_collapsing_v2(self):
765765
assert iterations[2].is_Sequential
766766
assert iterations[3].is_Sequential
767767

768+
def test_collapsing_cire_subdomain(self):
769+
"""
770+
Test that CIRE temporaries over a SubDomain retain SIMD parallelism.
771+
"""
772+
grid = Grid(shape=(16, 16, 16))
773+
774+
u = Function(name='u', grid=grid, space_order=8)
775+
out = TimeFunction(name='out', grid=grid, space_order=8)
776+
a = Function(name='a', grid=grid)
777+
b = Function(name='b', grid=grid)
778+
c = Function(name='c', grid=grid)
779+
780+
eq = Eq(out.forward,
781+
a*u.dx.dx + b*u.dy.dy + c*u.dz.dz,
782+
subdomain=grid.interior)
783+
op = Operator(eq, opt=('advanced', {'blockeager': False,
784+
'blocklazy': False,
785+
'cire-mingain': 0,
786+
'openmp': True,
787+
'par-collapse-ncores': 1,
788+
'par-collapse-work': 0}))
789+
790+
iterations = FindNodes(Iteration).visit(op)
791+
assert len(iterations) == 7
792+
793+
# The CIRE producer should collapse x and y, then vectorize z
794+
assert iterations[1].ncollapsed == 2
795+
assert iterations[3].is_Vectorized
796+
797+
assert op.cfunction
798+
768799
def test_scheduling(self):
769800
"""
770801
Affine iterations -> #pragma omp ... schedule(dynamic,1) ...

0 commit comments

Comments
 (0)