Skip to content

Commit

Permalink
tests: improve tests, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Jul 26, 2021
1 parent 9cbad5f commit 4d25407
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 51 deletions.
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def assert_structure(operator, exp_trees=None, exp_iters=None):
.. code-block:: python
for time
for t
for x
for y
for f
Expand All @@ -241,7 +241,7 @@ def assert_structure(operator, exp_trees=None, exp_iters=None):
if exp_trees is not None:
exp_trees = [i.replace(',', '') for i in exp_trees] # 't,x,y' -> 'txy'
tree_struc = (["".join(mapper.get(i.dim.name, i.dim.name) for i in j)
for j in trees])
for j in trees]) # Flatten every tree's dims as a string
assert tree_struc == exp_trees

if exp_iters is not None:
Expand All @@ -263,7 +263,7 @@ def assert_blocking(operator, exp_nests):
.. code-block:: python
for time
for t
for x0_blk0
for x
for x1_blk0
Expand All @@ -290,11 +290,11 @@ def assert_blocking(operator, exp_nests):
trees = retrieve_iteration_tree(operator)
for tree in trees:
iterations = [i for i in tree if i.dim.is_Incr] # Collect Incr dimensions
parallel_blocks = FindNodes(ParallelBlock).visit(tree)
if iterations:
# If Incr dimensions exist map the first one to its name in the dict
bns[iterations[0].dim.name] = iterations[0]
try:
parallel_blocks = FindNodes(ParallelBlock).visit(tree)
pbs[iterations[0].dim.name] = parallel_blocks[0]
except IndexError:
pbs[iterations[0].dim.name] = tree[0]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_autotuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def test_multiple_blocking():
opt=('blocking', {'openmp': False}))

# First of all, make sure there are indeed two different loop nests
_, _ = assert_blocking(op, {'x0_blk0', 'x1_blk0'})
assert_blocking(op, {'x0_blk0', 'x1_blk0'})

# 'basic' mode
op.apply(time_M=0, autotune='basic')
Expand Down
3 changes: 0 additions & 3 deletions tests/test_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,6 @@ def test_topofusion_w_subdims_conddims(self):
# Check generated code -- expect the gsave equation to be scheduled together
# in the same loop nest with the fsave equation
bns, _ = assert_blocking(op, {'x0_blk0', 'x1_blk0', 'i0x0_blk0'})

exprs = FindNodes(Expression).visit(bns['x0_blk0'])
assert len(exprs) == 2
assert exprs[0].write is f
Expand Down Expand Up @@ -1222,7 +1221,6 @@ def test_topofusion_w_subdims_conddims_v2(self):
# Check generated code -- expect the gsave equation to be scheduled together
# in the same loop nest with the fsave equation
bns, _ = assert_blocking(op, {'i0x0_blk0', 'x0_blk0'})

assert len(FindNodes(Expression).visit(bns['i0x0_blk0'])) == 3
exprs = FindNodes(Expression).visit(bns['x0_blk0'])
assert len(exprs) == 2
Expand Down Expand Up @@ -1256,7 +1254,6 @@ def test_topofusion_w_subdims_conddims_v3(self):
# Check generated code -- expect the gsave equation to be scheduled together
# in the same loop nest with the fsave equation
bns, _ = assert_blocking(op, {'i0x0_blk0', 'x0_blk0', 'i0x1_blk0'})

exprs = FindNodes(Expression).visit(bns['i0x0_blk0'])
assert len(exprs) == 2
assert exprs[0].write is f
Expand Down
8 changes: 3 additions & 5 deletions tests/test_dle.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def test_cache_blocking_structure(blockinner, openmp):
opt=('blocking', {'openmp': True, 'blockinner': blockinner,
'par-collapse-ncores': 1}))
if blockinner:
_, _ = assert_structure(op, ['t,x0_blk0,y0_blk0,z0_blk0,x,y,z'])
assert_structure(op, ['t,x0_blk0,y0_blk0,z0_blk0,x,y,z'])
else:
_, _ = assert_structure(op, ['t,x0_blk0,y0_blk0,x,y,z'])
assert_structure(op, ['t,x0_blk0,y0_blk0,x,y,z'])

# Check presence of openmp pragmas at the right place
trees = retrieve_iteration_tree(op)
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_cache_blocking_structure_subdims():
# Local SubDimension -> no blocking expected
op = Operator(Eq(f[t+1, xl, y, z], f[t, xl, y, z] + 1))

_, _ = assert_blocking(op, {})
assert_blocking(op, {})

# Non-local SubDimension -> blocking expected
op = Operator(Eq(f.forward, f + 1, subdomain=grid.interior))
Expand Down Expand Up @@ -272,7 +272,6 @@ def test_cache_blocking_imperfect_nest(blockinner):

# First, check the generated code
bns, _ = assert_blocking(op1, {'x0_blk0'})

trees = retrieve_iteration_tree(bns['x0_blk0'])
assert len(trees) == 2
assert len(trees[0]) == len(trees[1])
Expand Down Expand Up @@ -319,7 +318,6 @@ def test_cache_blocking_imperfect_nest_v2(blockinner):

# First, check the generated code
bns, _ = assert_blocking(op2, {'x0_blk0'})

trees = retrieve_iteration_tree(bns['x0_blk0'])
assert len(trees) == 2
assert len(trees[0]) == len(trees[1])
Expand Down
30 changes: 2 additions & 28 deletions tests/test_dse.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ def test_full_shape(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 1
Expand Down Expand Up @@ -526,7 +525,6 @@ def test_contracted_shape(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

ys, zs = self.get_params(op1, 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 1
Expand Down Expand Up @@ -565,7 +563,6 @@ def test_uncontracted_shape(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 1
Expand Down Expand Up @@ -640,7 +637,6 @@ def test_full_shape_w_subdims(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'i0x0_blk0'})

xs, ys, zs = self.get_params(op1, 'i0x0_blk0_size', 'i0y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['i0x0_blk0']) if i.is_Array]
assert len(arrays) == 1
Expand Down Expand Up @@ -686,7 +682,6 @@ def test_mixed_shapes(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 2
Expand Down Expand Up @@ -809,7 +804,6 @@ def test_mixed_shapes_v2_w_subdims(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'i0x0_blk0'})

xs, ys, zs = self.get_params(op1, 'i0x0_blk0_size', 'i0y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['i0x0_blk0']) if i.is_Array]
assert len(arrays) == 2
Expand Down Expand Up @@ -854,7 +848,6 @@ def test_in_bounds_w_shift(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 2
Expand Down Expand Up @@ -902,7 +895,6 @@ def test_constant_symbolic_distance(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 3
Expand Down Expand Up @@ -1186,7 +1178,6 @@ def test_from_different_nests(self, rotate):

# Check code generation
bns, _ = assert_blocking(op1, {'x0_blk0', 'x1_blk0'})

trees = retrieve_iteration_tree(bns['x0_blk0'])
assert len(trees) == 2
assert trees[0][-1].nodes[0].body[0].write.is_Array
Expand Down Expand Up @@ -1230,7 +1221,6 @@ def test_minimize_remainders_due_to_autopadding(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 1
Expand Down Expand Up @@ -1377,8 +1367,8 @@ def test_space_invariant(self):
op = Operator([pde, df])

# Check code generation
_, _ = assert_structure(op, ['t,x,y', 't,f', 't,f0_blk0,f,x,y'],
't,x,y,f,f0_blk0,f,x,y')
assert_structure(op, ['t,x,y', 't,f', 't,f0_blk0,f,x,y'],
't,x,y,f,f0_blk0,f,x,y')

def test_space_invariant_v2(self):
"""
Expand Down Expand Up @@ -1634,7 +1624,6 @@ def test_full_shape_big_temporaries(self):

# Check code generation
bns, _ = assert_blocking(op1, {'x0_blk0', 'x1_blk0'})

xs, ys, zs = self.get_params(op1, 'x_size', 'y_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 1
Expand Down Expand Up @@ -1724,7 +1713,6 @@ def g1_tilde(field, phi):

# Check code generation
bns, pbs = assert_blocking(op, {'x0_blk0'})

assert op._profiler._sections['section1'].sops == exp_ops
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 5
Expand Down Expand Up @@ -1771,9 +1759,7 @@ def g3_tilde(field, phi):

# Check code generation
assert op._profiler._sections['section1'].sops == exp_ops

bns, pbs = assert_blocking(op, {'x0_blk0'})

assert len([i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]) == 6
assert len(FindNodes(VExpanded).visit(pbs['x0_blk0'])) == 3

Expand Down Expand Up @@ -1817,9 +1803,7 @@ def g2_tilde(field, phi, theta):

# Check code generation
assert op._profiler._sections['section1'].sops == exp_ops

bns, pbs = assert_blocking(op, {'x0_blk0'})

assert len([i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]) == 7
assert len(FindNodes(VExpanded).visit(pbs['x0_blk0'])) == 3

Expand Down Expand Up @@ -1886,9 +1870,7 @@ def g3_tilde(field, phi, theta):

# Check code generation
assert op._profiler._sections['section1'].sops == exp_ops

bns, pbs = assert_blocking(op, {'x0_blk0'})

arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 10
assert len(FindNodes(VExpanded).visit(pbs['x0_blk0'])) == 6
Expand Down Expand Up @@ -1952,9 +1934,7 @@ def test_tti_adjoint_akin(self, so_ops, rotate):

# Check code generation
assert summary[('section1', None)].ops == exp_ops

bns, pbs = assert_blocking(op1, {'x0_blk0'})

assert len([i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]) == 5
assert len(FindNodes(VExpanded).visit(pbs['x0_blk0'])) == 1

Expand Down Expand Up @@ -1997,7 +1977,6 @@ def test_tti_adjoint_akin_v2(self):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 4
Expand Down Expand Up @@ -2039,7 +2018,6 @@ def test_nested_first_derivatives(self, rotate):

# Check code generation
bns, pbs = assert_blocking(op1, {'x0_blk0'})

assert len([i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]) == 1
assert len(FindNodes(VExpanded).visit(pbs['x0_blk0'])) == 1

Expand Down Expand Up @@ -2192,7 +2170,6 @@ def test_maxpar_option(self, rotate):

# Check code generation
bns, _ = assert_blocking(op1, {'x0_blk0'})

trees = retrieve_iteration_tree(bns['x0_blk0'])
assert len(trees) == 2
assert trees[0][1] is trees[1][1]
Expand Down Expand Up @@ -2224,7 +2201,6 @@ def test_maxpar_option_v2(self):

# Check code generation
bns, _ = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 1
Expand Down Expand Up @@ -2369,7 +2345,6 @@ def test_grouping_fallback(self, rotate):
# Check code generation
# `min-storage` leads to one 2D and one 3D Arrays
bns, pbs = assert_blocking(op1, {'x0_blk0'})

xs, ys, zs = self.get_params(op1, 'x0_blk0_size', 'y0_blk0_size', 'z_size')
arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 3
Expand Down Expand Up @@ -2681,7 +2656,6 @@ def test_opcounts(self, space_order, expected):

# Check code generation
_, pbs = assert_blocking(op, {'x0_blk0'})

arrays = FindNodes(VExpanded).visit(pbs['x0_blk0'])
assert len(arrays) == 4
assert all(len(i.pointee.shape) == 2 for i in arrays) # Expected 2D arrays
Expand Down
14 changes: 7 additions & 7 deletions tests/test_gpu_openacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ def test_blocking_customop(self, opt):

trees = retrieve_iteration_tree(op)
assert len(trees) == 1
assert len(trees[0]) == 7
tree = trees[0]
assert len(tree) == 7
assert all(i.dim.is_Incr for i in tree[1:7])

assert all(i.dim.is_Incr for i in trees[0][1:7])
assert op.parameters[3] is tree[1].step
assert op.parameters[6] is tree[2].step
assert op.parameters[9] is tree[3].step

assert op.parameters[3] is trees[0][1].step
assert op.parameters[6] is trees[0][2].step
assert op.parameters[9] is trees[0][3].step

assert trees[0][1].pragmas[0].value ==\
assert tree[1].pragmas[0].value ==\
'acc parallel loop collapse(3) present(u)'

def test_streaming_postponed_deletion(self):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_mpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ def test_hoist_haloupdate_with_subdims(self):

# ... and none in the created efuncs
bns, _ = assert_blocking(op, {'i0x0_blk0', 'x0_blk0'})

calls = FindNodes(Call).visit(bns['i0x0_blk0'])
assert len(calls) == 0
calls = FindNodes(Call).visit(bns['x0_blk0'])
Expand Down Expand Up @@ -1898,7 +1897,6 @@ def test_cire_options(self, opt_options):

# Check generated code
bns, _ = assert_blocking(op1, {'x0_blk0'})

arrays = [i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]
assert len(arrays) == 3
assert 'haloupdate0' in op1._func_table
Expand Down
2 changes: 1 addition & 1 deletion tests/test_skewing.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_no_sequential(self, expr, expected):
iters = FindNodes(Iteration).visit(op)
assert len([i for i in iters if i.dim.is_Time]) == 0

_, _ = assert_blocking(op, {}) # no blocking is expected in the absence of time
assert_blocking(op, {}) # no blocking is expected in the absence of time

iters = FindNodes(Iteration).visit(op)
assert len(iters) == 3
Expand Down

0 comments on commit 4d25407

Please sign in to comment.