Skip to content

Commit

Permalink
Merge pull request #2232 from devitocodes/patch-cluster-sparse
Browse files Browse the repository at this point in the history
compiler: Patch cluster.is_sparse
  • Loading branch information
FabioLuporini committed Oct 12, 2023
2 parents 7b5332a + 2ec2de6 commit e452a64
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
13 changes: 3 additions & 10 deletions devito/ir/clusters/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,10 @@ def is_dense(self):
@cached_property
def is_sparse(self):
"""
A cluster is sparse if it represent a sparse operation i.e if both
* The cluster contains sparse functions
* The cluster uses dense functions
If only the first case is true, the cluster only contains operation on the sparse
function itself without indirection and therefore only contains dense operations.
A Cluster is sparse if it represents a sparse operation, i.e iff
There's at least one irregular access.
"""
return (any(f.is_SparseFunction for f in self.functions) and
len([f for f in self.functions
if (f.is_Function and not f.is_SparseFunction)]) > 0)
return any(a.is_irregular for a in self.scope.accesses)

@property
def is_halo_touch(self):
Expand Down
18 changes: 18 additions & 0 deletions tests/test_lower_clusters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from devito import Grid, SparseTimeFunction, TimeFunction, Operator
from devito.ir.iet import FindSymbols


class TestLowerReductions(object):

def test_no_temp_upon_reduce_expansion(self):
grid = Grid(shape=(10, 10, 10))

u = TimeFunction(name='u', grid=grid)
sf = SparseTimeFunction(name='sf', grid=grid, npoint=1, nt=5)

rec_term = sf.interpolate(expr=u)

op = Operator(rec_term, opt=('advanced', {'mapify-reduce': True}))

arrays = [i for i in FindSymbols().visit(op) if i.is_Array]
assert len([i for i in arrays if i.ndim == grid.dim]) == 0

0 comments on commit e452a64

Please sign in to comment.