Skip to content

Commit

Permalink
compiler: restructure tests and pass
Browse files Browse the repository at this point in the history
  • Loading branch information
georgebisbas committed Mar 17, 2021
1 parent b0581d2 commit b611b90
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 359 deletions.
10 changes: 5 additions & 5 deletions devito/core/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from devito.core.operator import CoreOperator, CustomOperator
from devito.exceptions import InvalidOperator
from devito.passes.equations import buffering, collect_derivatives
from devito.passes.clusters import (Blocking, Lift, cire, cse, eliminate_arrays, fuse,
extract_increments, factorize, optimize_pows, Skewing)
from devito.passes.clusters import (Blocking, Skewing, Lift, cire, cse, eliminate_arrays,
fuse, extract_increments, factorize, optimize_pows)
from devito.passes.iet import (CTarget, OmpTarget, avoid_denormals, mpiize,
optimize_halospots, hoist_prodders, relax_incr_dimensions)
from devito.tools import timed_pass
Expand Down Expand Up @@ -325,7 +325,7 @@ def _make_clusters_passes_mapper(cls, **kwargs):
'cire-divs': lambda i: cire(i, 'divs', sregistry, options, platform),
'cse': lambda i: cse(i, sregistry),
'opt-pows': optimize_pows,
'topofuse': lambda i: fuse(i, toposort=True),
'topofuse': lambda i: fuse(i, toposort=True)
}

@classmethod
Expand Down Expand Up @@ -354,8 +354,8 @@ def _make_iet_passes_mapper(cls, **kwargs):
# Expressions
'buffering',
# Clusters
'blocking', 'topofuse', 'fuse', 'factorize', 'cire-sops', 'cire-divs',
'cse', 'lift', 'opt-pows', 'skewing',
'blocking', 'skewing', 'topofuse', 'fuse', 'factorize', 'cire-sops', 'cire-divs',
'cse', 'lift', 'opt-pows'
# IET
'denormals', 'optcomms', 'openmp', 'mpi', 'simd', 'prodders',
)
Expand Down
4 changes: 2 additions & 2 deletions devito/core/gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def _make_iet_passes_mapper(cls, **kwargs):
# Expressions
'buffering',
# Clusters
'blocking', 'tasking', 'streaming', 'factorize', 'fuse', 'lift',
'cire-sops', 'cire-divs', 'cse', 'opt-pows', 'topofuse', 'skewing',
'blocking', 'skewing', 'tasking', 'streaming', 'factorize', 'fuse',
'lift', 'cire-sops', 'cire-divs', 'cse', 'opt-pows', 'topofuse',
# IET
'optcomms', 'orchestrate', 'parallel', 'mpi', 'prodders', 'gpu-direct'
)
Expand Down
29 changes: 1 addition & 28 deletions devito/mpi/halo_scheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,31 +429,4 @@ def classify(exprs, ispace):

mapper[f] = HaloSchemeEntry(frozendict(loc_indices), frozenset(halos))

def compute_local_indices(f, dims, ispace, scope):
"""
Map the Dimensions in ``dims`` to the local indices necessary
to perform a halo exchange, as described in HaloScheme.__doc__.
Examples
--------
1) u[t+1, x] = f(u[t, x]) => shift == 1
2) u[t-1, x] = f(u[t, x]) => shift == 1
3) u[t+1, x] = f(u[t+1, x]) => shift == 0
In the first and second cases, the x-halo should be inserted at `t`,
while in the last case it should be inserted at `t+1`.
"""
loc_indices = {}
for d in dims:
try:
func = Max if ispace.is_forward(d.root) else Min
except KeyError:
raise HaloSchemeException("Don't know how to build a HaloScheme as `%s` "
"doesn't appear in `%s`" % (d, ispace))
if d.is_Stepping:
candidates = {i[d].origin - d: i[d] for i in scope.getreads(f)
if not is_integer(i[d])}
else:
candidates = {i[d] - d: i[d] for i in scope.getreads(f)
if not is_integer(i[d])}
loc_indices[d] = candidates[func(*candidates.keys())]
return loc_indices
return mapper
6 changes: 1 addition & 5 deletions devito/passes/clusters/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,11 @@ class Skewing(Queue):

def __init__(self, options):

self.nskewed = Counter()

super(Skewing, self).__init__()

@timed_pass(name='skewing')
def process(self, clusters):
processed = super(Skewing, self).process(clusters)

return processed
return super(Skewing, self).process(clusters)

def _process_fdta(self, clusters, level, prefix=None):

Expand Down
18 changes: 11 additions & 7 deletions tests/test_autotuner.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,10 @@ def test_mixed_blocking_w_skewing(openmp, expected):
assert 'nthreads' not in op._state['autotuning'][0]['tuned']


def test_tti_aggressive():
@pytest.mark.parametrize('opt', ['advanced', ('blocking', 'skewing')])
def test_tti_aggressive(opt):
from test_dse import TestTTI
wave_solver = TestTTI().tti_operator(opt='advanced')
wave_solver = TestTTI().tti_operator(opt=opt)
op = wave_solver.op_fwd(kernel='centered')
op.apply(time=0, autotune='aggressive', dt=0.1)
assert op._state['autotuning'][0]['runs'] == 30
Expand Down Expand Up @@ -262,13 +263,14 @@ def test_multiple_blocking():
assert len(op._state['autotuning'][0]['tuned']) == 5


def test_hierarchical_blocking():
@pytest.mark.parametrize('opt', ['blocking', ('blocking', 'skewing')])
def test_hierarchical_blocking(opt):
grid = Grid(shape=(64, 64, 64))

u = TimeFunction(name='u', grid=grid, space_order=2)

op = Operator(Eq(u.forward, u + 1), opt=('blocking', {'openmp': False,
'blocklevels': 2}))
op = Operator(Eq(u.forward, u + 1), opt=(opt, {'openmp': False,
'blocklevels': 2}))

# 'basic' mode
op.apply(time_M=0, autotune='basic')
Expand All @@ -284,7 +286,8 @@ def test_hierarchical_blocking():


@switchconfig(platform='cpu64-dummy') # To fix the core count
def test_multiple_threads():
@pytest.mark.parametrize('opt', ['blocking', ('blocking', 'skewing')])
def test_multiple_threads(opt):
"""
Test autotuning when different ``num_threads`` for a given OpenMP parallel
region are attempted.
Expand All @@ -293,7 +296,8 @@ def test_multiple_threads():

v = TimeFunction(name='v', grid=grid)

op = Operator(Eq(v.forward, v + 1), opt=('blocking', {'openmp': True}))
op = Operator(Eq(v.forward, v + 1), opt=(opt, {'openmp': True}))

op.apply(time_M=0, autotune='max')
assert op._state['autotuning'][0]['runs'] == 60 # Would be 30 with `aggressive`
assert op._state['autotuning'][0]['tpr'] == options['squeezer'] + 1
Expand Down
2 changes: 0 additions & 2 deletions tests/test_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ def fa(self, grid):
('u[x + z,x + y,z*z]', (IRREGULAR, IRREGULAR, REGULAR)),
('u[x+1,u[2,2,2],z-1]', (AFFINE, IRREGULAR, AFFINE)),
('u[y,x,z]', (IRREGULAR, IRREGULAR, AFFINE)),
('u[x-time, y-time, z]', (IRREGULAR, IRREGULAR, AFFINE)),
])
def test_index_mode_detection(self, indexed, expected):
"""
Expand All @@ -550,7 +549,6 @@ def test_index_mode_detection(self, indexed, expected):
"""
grid = Grid(shape=(4, 4, 4))
x, y, z = grid.dimensions # noqa
time = grid.time_dim # noqa

sx = SubDimension.middle('sx', x, 1, 1) # noqa

Expand Down
Loading

0 comments on commit b611b90

Please sign in to comment.