Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: cleanup SubDimension and SubDomain #2219

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions devito/passes/clusters/implicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,25 @@ def callback(self, clusters, prefix):
exprs, dims, sub_iterators = make_implicit_exprs(d.msd, c)

# The IterationSpace induced by the MultiSubDomain
intervals = [Interval(i, 0, 0) for i in dims]
relations = (ispace0.itdimensions + dims, dims + ispace1.itdimensions)
ispaceN = IterationSpace(
IntervalGroup(intervals, relations=relations), sub_iterators
)
if dims:
intervals = [Interval(i) for i in dims]
relations = (ispace0.itdimensions + dims, dims + ispace1.itdimensions)
ispaceN = IterationSpace(
IntervalGroup(intervals, relations=relations), sub_iterators
)
ispace = IterationSpace.union(ispace0, ispaceN)
else:
ispaceN = None
ispace = ispace0

ispace = IterationSpace.union(ispace0, ispaceN)
properties = {i.dim: {SEQUENTIAL} for i in ispace}
if len(ispaceN) == 0:

if not ispaceN:
# Special case: we can factorize the thickness assignments
# once and for all at the top of the current IterationInterval,
# and reuse them for one or more (potentially non-consecutive)
# `clusters`
if ispaceN not in seen:
if d not in seen:
# Retain the guards and the syncs along the outer Dimensions
retained = {None} | set(c.ispace[:n-1].dimensions)

Expand All @@ -143,8 +148,12 @@ def callback(self, clusters, prefix):
)
tip = nxt

ispace = IterationSpace.union(c.ispace, ispaceN)
processed.append(c.rebuild(ispace=ispace))
if ispaceN:
ispace = IterationSpace.union(c.ispace, ispaceN)
processed.append(c.rebuild(ispace=ispace))
else:
processed.append(c)
seen.add(d)

return processed

Expand Down
3 changes: 2 additions & 1 deletion devito/types/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,8 @@ def __subdomain_finalize__(self, grid, counter=0, **kwargs):

# Create the SubDomainSet SubDimensions
self._dimensions = tuple(
MultiSubDimension('%si' % d.name, d, self) for d in grid.dimensions
MultiSubDimension('%si%d' % (d.name, counter), d, self)
for d in grid.dimensions
)

# Compute the SubDomainSet shapes
Expand Down
23 changes: 12 additions & 11 deletions tests/test_subdomains.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class DummySubdomains(SubDomainSet):
# Make sure it jit-compiles
op.cfunction

assert_structure(op, ['x,y', 't,n0', 't,n0,xi,yi'], 'x,y,t,n0,xi,yi')
assert_structure(op, ['x,y', 't,n0', 't,n0,xi2,yi2'], 'x,y,t,n0,xi2,yi2')

def test_issue_1761_b(self):
"""
Expand Down Expand Up @@ -486,8 +486,8 @@ class DummySubdomains2(SubDomainSet):
op.cfunction

assert_structure(op,
['x,y', 't,n0', 't,n0,xi,yi', 't,n1', 't,n1,xi,yi'],
'x,y,t,n0,xi,yi,n1,xi,yi')
['x,y', 't,n0', 't,n0,xi2,yi2', 't,n1', 't,n1,xi3,yi3'],
'x,y,t,n0,xi2,yi2,n1,xi3,yi3')

def test_issue_1761_c(self):
"""
Expand Down Expand Up @@ -522,9 +522,9 @@ class DummySubdomains2(SubDomainSet):
# Make sure it jit-compiles
op.cfunction

assert_structure(op, ['x,y', 't,n0', 't,n0,xi,yi',
't,n1', 't,n1,xi,yi', 't,n0', 't,n0,xi,yi'],
'x,y,t,n0,xi,yi,n1,xi,yi,n0,xi,yi')
assert_structure(op, ['x,y', 't,n0', 't,n0,xi2,yi2',
't,n1', 't,n1,xi3,yi3', 't,n0', 't,n0,xi2,yi2'],
'x,y,t,n0,xi2,yi2,n1,xi3,yi3,n0,xi2,yi2')

def test_issue_1761_d(self):
"""
Expand All @@ -549,7 +549,8 @@ class Dummy(SubDomainSet):
# Make sure it jit-compiles
op.cfunction

assert_structure(op, ['t,n0', 't,n0,xi,yi', 't,n0,xi,yi'], 't,n0,xi,yi,xi,yi')
assert_structure(op, ['t,n0', 't,n0,xi2,yi2', 't,n0,xi2,yi2'],
't,n0,xi2,yi2,xi2,yi2')

def test_guarding(self):

Expand All @@ -576,8 +577,8 @@ class Dummy(SubDomainSet):
# Make sure it jit-compiles
op.cfunction

assert_structure(op, ['t', 't,n0', 't,n0,xi,yi', 't,n0', 't,n0,xi,yi'],
't,n0,xi,yi,n0,xi,yi')
assert_structure(op, ['t', 't,n0', 't,n0,xi2,yi2', 't,n0', 't,n0,xi2,yi2'],
't,n0,xi2,yi2,n0,xi2,yi2')

def test_3D(self):

Expand All @@ -597,8 +598,8 @@ class Dummy(SubDomainSet):
# Make sure it jit-compiles
op.cfunction

assert_structure(op, ['t,n0', 't,n0,xi0_blk0,yi0_blk0,xi,yi,zi'],
't,n0,xi0_blk0,yi0_blk0,xi,yi,zi')
assert_structure(op, ['t,n0', 't,n0,xi20_blk0,yi20_blk0,xi2,yi2,zi2'],
't,n0,xi20_blk0,yi20_blk0,xi2,yi2,zi2')

def test_sequential_implicit(self):
"""
Expand Down