Skip to content

Commit 86dafc2

Browse files
committed
compiler: Prevent fusion if dep over shm functions
1 parent dcc0d78 commit 86dafc2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

devito/ir/clusters/cluster.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,23 @@ def from_clusters(cls, *clusters):
6969
"""
7070
assert len(clusters) > 0
7171
root = clusters[0]
72+
73+
if len(clusters) == 1:
74+
return root
75+
7276
if not all(root.ispace.is_compatible(c.ispace) for c in clusters):
7377
raise ValueError("Cannot build a Cluster from Clusters with "
7478
"incompatible IterationSpace")
7579
if not all(root.guards == c.guards for c in clusters):
7680
raise ValueError("Cannot build a Cluster from Clusters with "
7781
"non-homogeneous guards")
7882

83+
writes = set().union(*[c.scope.writes for c in clusters])
84+
reads = set().union(*[c.scope.reads for c in clusters])
85+
if any(f._mem_shared for f in writes & reads):
86+
raise ValueError("Cannot build a Cluster from Clusters with "
87+
"read-write conflicts on shared-memory Functions")
88+
7989
exprs = chain(*[c.exprs for c in clusters])
8090
ispace = IterationSpace.union(*[c.ispace for c in clusters])
8191

devito/passes/clusters/misc.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,13 @@ def callback(self, cgroups, prefix):
146146
g = list(group)
147147

148148
for maybe_fusible in self._apply_heuristics(g):
149-
if len(maybe_fusible) == 1:
149+
try:
150+
# Perform fusion
151+
processed.append(Cluster.from_clusters(*maybe_fusible))
152+
except ValueError:
153+
# We end up here if, for example, some Clusters have same
154+
# iteration Dimensions but different (partial) orderings
150155
processed.extend(maybe_fusible)
151-
else:
152-
try:
153-
# Perform fusion
154-
processed.append(Cluster.from_clusters(*maybe_fusible))
155-
except ValueError:
156-
# We end up here if, for example, some Clusters have same
157-
# iteration Dimensions but different (partial) orderings
158-
processed.extend(maybe_fusible)
159156

160157
# Maximize effectiveness of topo-sorting at next stage by only
161158
# grouping together Clusters characterized by data dependencies

0 commit comments

Comments
 (0)