Skip to content

Commit ce27131

Browse files
committed
compiler: Split up Cluster.used_dimensions to fix Lift
1 parent 142d1a4 commit ce27131

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

devito/ir/clusters/cluster.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,34 @@ def dimensions(self):
172172
return set().union(*[i._defines for i in self.ispace.dimensions])
173173

174174
@cached_property
175-
def used_dimensions(self):
175+
def exprs_dimensions(self):
176176
"""
177-
The Dimensions that *actually* appear among the expressions in ``self``.
178-
These do not necessarily coincide the IterationSpace Dimensions; for
179-
example, reduction or redundant (i.e., invariant) Dimensions won't
180-
appear in an expression.
177+
The Dimensions that appear explicitly in the Cluster expressions.
181178
"""
182-
dims_exprs = {i for i in self.free_symbols if i.is_Dimension}
183-
179+
dims_explicit = {i for i in self.free_symbols if i.is_Dimension}
184180
dims_implicit = set().union(*[set(e.implicit_dims) for e in self.exprs])
181+
return dims_explicit | dims_implicit
185182

183+
@cached_property
184+
def guards_dimensions(self):
185+
"""
186+
The Dimensions that appear explicitly in the Cluster guards.
187+
"""
186188
syms_guards = set().union(*[e.free_symbols for e in self.guards.values()])
187189
dims_guards = {i for i in syms_guards if i.is_Dimension}
190+
return dims_guards
188191

189-
return dims_exprs | dims_implicit | dims_guards
192+
@cached_property
193+
def used_dimensions(self):
194+
"""
195+
All the Dimensions that appear explicitly either within the expressions
196+
or the guards.
197+
198+
Note that, in some cases, some of the IterationSpace Dimensions might
199+
not appear here among the used Dimensions -- for example, reduction or
200+
redundant (i.e., invariant) Dimensions.
201+
"""
202+
return self.exprs_dimensions | self.guards_dimensions
190203

191204
@cached_property
192205
def dist_dimensions(self):

devito/passes/clusters/misc.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def callback(self, clusters, prefix):
5555
continue
5656

5757
# Is `c` a real candidate -- is there at least one invariant Dimension?
58-
if any(d._defines & hope_invariant for d in c.used_dimensions):
58+
if any(d._defines & hope_invariant for d in c.exprs_dimensions):
5959
processed.append(c)
6060
continue
6161

@@ -69,16 +69,16 @@ def callback(self, clusters, prefix):
6969
# All of the inner Dimensions must appear in the write-to region
7070
# otherwise we would violate data dependencies. Consider
7171
#
72-
# 1) 2) 3)
73-
# for i for i for i
74-
# for x for x for x
75-
# r = f(a[x]) for y for y
76-
# r[x] = f(a[x, y]) r[x, y] = f(a[x, y])
72+
# 1) 2) 3)
73+
# for i for i for i
74+
# for x for x for x
75+
# r = f(a[x]) for y for y
76+
# r[x] = f(a[x, y]) r[x, y] = f(a[x, y])
7777
#
7878
# In 1) and 2) lifting is infeasible; in 3) the statement can
7979
# be lifted outside the `i` loop as `r`'s write-to region contains
8080
# both `x` and `y`
81-
xed = {d._defines for d in c.used_dimensions if d not in outer}
81+
xed = {d._defines for d in c.exprs_dimensions if d not in outer}
8282
if not all(i & set(w.dimensions) for i, w in product(xed, c.scope.writes)):
8383
processed.append(c)
8484
continue

0 commit comments

Comments
 (0)