Skip to content

Commit e452a64

Browse files
Merge pull request #2232 from devitocodes/patch-cluster-sparse
compiler: Patch cluster.is_sparse
2 parents 7b5332a + 2ec2de6 commit e452a64

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

devito/ir/clusters/cluster.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,10 @@ def is_dense(self):
231231
@cached_property
232232
def is_sparse(self):
233233
"""
234-
A cluster is sparse if it represent a sparse operation i.e if both
235-
236-
* The cluster contains sparse functions
237-
* The cluster uses dense functions
238-
239-
If only the first case is true, the cluster only contains operation on the sparse
240-
function itself without indirection and therefore only contains dense operations.
234+
A Cluster is sparse if it represents a sparse operation, i.e iff
235+
There's at least one irregular access.
241236
"""
242-
return (any(f.is_SparseFunction for f in self.functions) and
243-
len([f for f in self.functions
244-
if (f.is_Function and not f.is_SparseFunction)]) > 0)
237+
return any(a.is_irregular for a in self.scope.accesses)
245238

246239
@property
247240
def is_halo_touch(self):

tests/test_lower_clusters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from devito import Grid, SparseTimeFunction, TimeFunction, Operator
2+
from devito.ir.iet import FindSymbols
3+
4+
5+
class TestLowerReductions(object):
6+
7+
def test_no_temp_upon_reduce_expansion(self):
8+
grid = Grid(shape=(10, 10, 10))
9+
10+
u = TimeFunction(name='u', grid=grid)
11+
sf = SparseTimeFunction(name='sf', grid=grid, npoint=1, nt=5)
12+
13+
rec_term = sf.interpolate(expr=u)
14+
15+
op = Operator(rec_term, opt=('advanced', {'mapify-reduce': True}))
16+
17+
arrays = [i for i in FindSymbols().visit(op) if i.is_Array]
18+
assert len([i for i in arrays if i.ndim == grid.dim]) == 0

0 commit comments

Comments
 (0)