Skip to content

Commit abd7893

Browse files
committed
compiler: Refactor fusion.py
1 parent d2cc887 commit abd7893

1 file changed

Lines changed: 29 additions & 28 deletions

File tree

devito/passes/clusters/fusion.py

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,34 @@ def _fusion_hazards(scope0, scope1, prefix):
5050
return NO_HAZARD
5151

5252

53+
class Key(tuple):
54+
55+
"""
56+
A "fusion Key" for a Cluster (ClusterGroup) is a hashable tuple such that
57+
two Clusters (ClusterGroups) are topo-fusible if and only if their Key is
58+
identical.
59+
60+
A Key contains elements that can logically be split into two groups -- the
61+
`strict` and the `weak` components of the Key. Two Clusters (ClusterGroups)
62+
having same `strict` but different `weak` parts are, by definition, not
63+
fusible; however, since at least their `strict` parts match, they can at
64+
least be topologically reordered.
65+
"""
66+
67+
def __new__(cls, itintervals, guards, syncs, weak):
68+
strict = [itintervals, guards, syncs]
69+
obj = super().__new__(cls, strict + weak)
70+
71+
obj.itintervals = itintervals
72+
obj.guards = guards
73+
obj.syncs = syncs
74+
75+
obj.strict = tuple(strict)
76+
obj.weak = tuple(weak)
77+
78+
return obj
79+
80+
5381
class Fusion(Queue):
5482

5583
"""
@@ -106,33 +134,6 @@ def callback(self, cgroups, prefix):
106134
else:
107135
return [ClusterGroup(processed, prefix)]
108136

109-
class Key(tuple):
110-
111-
"""
112-
A fusion Key for a Cluster (ClusterGroup) is a hashable tuple such that
113-
two Clusters (ClusterGroups) are topo-fusible if and only if their Key is
114-
identical.
115-
116-
A Key contains elements that can logically be split into two groups -- the
117-
`strict` and the `weak` components of the Key. Two Clusters (ClusterGroups)
118-
having same `strict` but different `weak` parts are, by definition, not
119-
fusible; however, since at least their `strict` parts match, they can at
120-
least be topologically reordered.
121-
"""
122-
123-
def __new__(cls, itintervals, guards, syncs, weak):
124-
strict = [itintervals, guards, syncs]
125-
obj = super().__new__(cls, strict + weak)
126-
127-
obj.itintervals = itintervals
128-
obj.guards = guards
129-
obj.syncs = syncs
130-
131-
obj.strict = tuple(strict)
132-
obj.weak = tuple(weak)
133-
134-
return obj
135-
136137
@memoized_meth
137138
def _key(self, c):
138139
itintervals = frozenset(c.ispace.itintervals)
@@ -184,7 +185,7 @@ def _key(self, c):
184185
# Promote adjacency of Clusters with same guard
185186
weak.append(c.guards)
186187

187-
key = self.Key(itintervals, guards, syncs, weak)
188+
key = Key(itintervals, guards, syncs, weak)
188189

189190
return key
190191

0 commit comments

Comments
 (0)