Skip to content

Commit

Permalink
tests: op.apply() for operators, plain subdomain tests
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Apr 6, 2021
1 parent 7ed79e6 commit 2a51ab1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
13 changes: 5 additions & 8 deletions devito/passes/clusters/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def blocking(clusters, options):
------
In case of skewing, if 'blockinner' is enabled, the innermost loop is also skewed.
"""
clusters = preprocess(clusters, options)
processed = Blocking(options).process(clusters)
processed = preprocess(clusters, options)

if options['blocklevels'] > 0:
processed = Blocking(options).process(processed)

if options['skewing']:
processed = Skewing(options).process(processed)
Expand All @@ -55,12 +57,6 @@ def __init__(self, options):
def _make_key_hook(self, cluster, level):
return (tuple(cluster.guards.get(i.dim) for i in cluster.itintervals[:level]),)

def process(self, clusters):
if self.levels < 1:
return clusters
else:
return super(Blocking, self).process(clusters)

def _process_fdta(self, clusters, level, prefix=None):
# Truncate recursion in case of TILABLE, non-perfect sub-nests, as
# it's an unsupported case
Expand Down Expand Up @@ -110,6 +106,7 @@ def callback(self, clusters, prefix):
properties.update({bd: c.properties[d] - {TILABLE} for bd in block_dims})
properties.update({bd: c.properties[d] - {SKEWABLE}
for bd in block_dims[:-1]})

processed.append(c.rebuild(exprs=exprs, ispace=ispace,
properties=properties))
else:
Expand Down
44 changes: 32 additions & 12 deletions tests/test_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def test_multi_buffer_long_time(self):

class TestSubDimension(object):

def test_interior(self):
@pytest.mark.parametrize('opt', ['advanced',
('advanced', {'skewing': True}),
('advanced', {'skewing': True, 'blockinner': True})])
def test_interior(self, opt):
"""
Tests application of an Operator consisting of a single equation
over the ``interior`` subdomain.
Expand All @@ -61,7 +64,7 @@ def test_interior(self):

eqn = [Eq(u.forward, u + 2, subdomain=interior)]

op = Operator(eqn)
op = Operator(eqn, opt=opt)
op.apply(time_M=2)
assert np.all(u.data[1, 1:-1, 1:-1, 1:-1] == 6.)
assert np.all(u.data[1, :, 0] == 0.)
Expand Down Expand Up @@ -97,7 +100,10 @@ def test_domain_vs_interior(self):
assert np.all(u.data[1, :, :, -1] == 1)
assert np.all(u.data[1, 1:3, 1:3, 1:3] == 3)

def test_subdim_middle(self):
@pytest.mark.parametrize('opt', ['advanced',
('advanced', {'skewing': True}),
('advanced', {'skewing': True, 'blockinner': True})])
def test_subdim_middle(self, opt):
"""
Tests that instantiating SubDimensions using the classmethod
constructors works correctly.
Expand All @@ -113,7 +119,7 @@ def test_subdim_middle(self):
eqs = [Eq(u.forward, u + 1)]
eqs = [e.subs(x, xi) for e in eqs]

op = Operator(eqs)
op = Operator(eqs, opt=opt)

u.data[:] = 1.0
op.apply(time_M=1)
Expand All @@ -138,7 +144,10 @@ def test_symbolic_size(self):
xright = SubDimension.right(name='xright', parent=x, thickness=thickness)
assert xright.symbolic_size == xright.thickness.right[0]

def test_bcs(self):
@pytest.mark.parametrize('opt', ['advanced',
('advanced', {'skewing': True}),
('advanced', {'skewing': True, 'blockinner': True})])
def test_bcs(self, opt):
"""
Tests application of an Operator consisting of multiple equations
defined over different sub-regions, explicitly created through the
Expand All @@ -163,7 +172,7 @@ def test_bcs(self):
leftbc = Eq(u[t+1, xleft, yi], u[t+1, xleft+1, yi] + 1)
rightbc = Eq(u[t+1, xright, yi], u[t+1, xright-1, yi] + 1)

op = Operator([t_in_centre, leftbc, rightbc])
op = Operator([t_in_centre, leftbc, rightbc], opt=opt)

op.apply(time_m=1, time_M=1)

Expand Down Expand Up @@ -287,7 +296,10 @@ def test_iteration_property_vector(self, exprs, expected):
vectorized = [i.dim.name for i in iterations if i.is_Vectorized]
assert set(vectorized) == set(expected)

def test_subdimmiddle_parallel(self):
@pytest.mark.parametrize('opt', ['advanced',
('advanced', {'skewing': True}),
('advanced', {'skewing': True, 'blockinner': True})])
def test_subdimmiddle_parallel(self, opt):
"""
Tests application of an Operator consisting of a subdimension
defined over different sub-regions, explicitly created through the
Expand All @@ -312,7 +324,8 @@ def test_subdimmiddle_parallel(self):

u.data[0, 10, 10] = 1.0

op = Operator([centre])
op = Operator([centre], opt=opt)
print(op.ccode)

iterations = FindNodes(Iteration).visit(op)
assert all(i.is_Affine and i.is_Parallel for i in iterations if i.dim in [xi, yi])
Expand Down Expand Up @@ -484,7 +497,10 @@ def test_arrays_defined_over_subdims(self):
# "ValueError: No value found for parameter xi_size"
op()

def test_expandingbox_like(self):
@pytest.mark.parametrize('opt', ['advanced',
('advanced', {'skewing': True}),
('advanced', {'skewing': True, 'blockinner': True})])
def test_expandingbox_like(self, opt):
"""
Make sure SubDimensions aren't an obstacle to expanding boxes.
"""
Expand All @@ -498,7 +514,7 @@ def test_expandingbox_like(self):
eqn = Eq(u.forward, u + 1)
eqn = eqn.subs({x: xi, y: yi})

op = Operator(eqn)
op = Operator(eqn, opt=opt)

op.apply(time=3, x_m=2, x_M=5, y_m=2, y_M=5,
xi_ltkn=0, xi_rtkn=0, yi_ltkn=0, yi_rtkn=0)
Expand Down Expand Up @@ -582,7 +598,10 @@ def test_basic_shuffles(self):
assert np.all([np.allclose(usave.data[i], i*factor)
for i in range((nt+factor-1)//factor)])

def test_spacial_subsampling(self):
@pytest.mark.parametrize('opt', ['advanced',
('advanced', {'skewing': True}),
('advanced', {'skewing': True, 'blockinner': True})])
def test_spacial_subsampling(self, opt):
"""
Test conditional dimension for the spatial ones.
This test saves u every two grid points :
Expand All @@ -603,7 +622,8 @@ def test_spacial_subsampling(self):
assert(time in u2.indices)

eqns = [Eq(u.forward, u + 1.), Eq(u2, u)]
op = Operator(eqns)
op = Operator(eqns, opt=opt)
import pdb;pdb.set_trace()
op.apply(time_M=nt-2)
# Verify that u2[x,y]= u[2*x, 2*y]
assert np.allclose(u.data[:-1, 0::2, 0::2], u2.data[:-1, :, :])
Expand Down
11 changes: 5 additions & 6 deletions tests/test_skewing.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import pytest

from sympy import Add, cos, sin, sqrt # noqa

from devito.core.autotuning import options # noqa
from devito import Function, TimeFunction, Grid, Operator, Eq # noqa
from devito import Grid, Dimension, Eq, Function, TimeFunction, Operator # noqa
from devito.ir import Expression, Iteration, FindNodes


class TestCodeGenSkew(object):
class TestCodeGenSkewing(object):

'''
Test code generation with blocking+skewing, tests adapted from test_operator.py
Expand All @@ -31,6 +28,7 @@ def test_skewed_bounds(self, expr, expected):
eqn = eval(expr)
# List comprehension would need explicit locals/globals mappings to eval
op = Operator(eqn, opt=('blocking', {'skewing': True}))
op.apply(time_M=5)
iters = FindNodes(Iteration).visit(op)
time_iter = [i for i in iters if i.dim.is_Time]
assert len(time_iter) == 1
Expand Down Expand Up @@ -78,7 +76,7 @@ def test_no_sequential(self, expr, expected):
eqn = eval(expr)
# List comprehension would need explicit locals/globals mappings to eval
op = Operator(eqn, opt=('blocking', {'skewing': True}))

op.apply()
iters = FindNodes(Iteration).visit(op)
time_iter = [i for i in iters if i.dim.is_Time]
assert len(time_iter) == 0
Expand Down Expand Up @@ -121,6 +119,7 @@ def test_skewing_codegen(self, expr, expected, skewing, blockinner):
# List comprehension would need explicit locals/globals mappings to eval
op = Operator(eqn, opt=('blocking', {'blocklevels': 0, 'skewing': skewing,
'blockinner': blockinner}))
op.apply(time_M=5)

iters = FindNodes(Iteration).visit(op)

Expand Down
7 changes: 2 additions & 5 deletions tests/test_subdomains.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ class Inner(SubDomainSet):

assert((np.array(result) == np.array(fex.data[:])).all())

@pytest.mark.parametrize('opt', ['advanced',
('advanced', {'skewing': True}),
('advanced', {'skewing': True, 'blockinner': True})])
def test_multi_sets_eq(self, opt):
def test_multi_sets_eq(self):
"""
Check functionality for when multiple subdomain sets are present, each
with multiple equations.
Expand Down Expand Up @@ -416,7 +413,7 @@ class MySubdomains2(SubDomainSet):
eq3 = Eq(f, f-1, subdomain=grid.subdomains['mydomains1'])
eq4 = Eq(g, g+1, subdomain=grid.subdomains['mydomains2'])

op = Operator([eq1, eq2, eq3, eq4], opt=opt)
op = Operator([eq1, eq2, eq3, eq4])
op.apply()

expected = np.array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
Expand Down

0 comments on commit 2a51ab1

Please sign in to comment.