Skip to content

Commit 189a3af

Browse files
committed
compiler: Move opt_pows/fact next to unevaluation
1 parent ad447a3 commit 189a3af

5 files changed

Lines changed: 13 additions & 10 deletions

File tree

devito/core/cpu.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ def _specialize_clusters(cls, clusters, **kwargs):
177177
# Reduce flops
178178
clusters = cire(clusters, 'sops', sregistry, options, platform)
179179
clusters = factorize(clusters, **kwargs)
180-
clusters = optimize_pows(clusters)
181180

182181
# The previous passes may have created fusion opportunities
183182
clusters = fuse(clusters)

devito/core/gpu.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ def _specialize_clusters(cls, clusters, **kwargs):
218218
# Reduce flops
219219
clusters = cire(clusters, 'sops', sregistry, options, platform)
220220
clusters = factorize(clusters, **kwargs)
221-
clusters = optimize_pows(clusters)
222221

223222
# The previous passes may have created fusion opportunities
224223
clusters = fuse(clusters)

devito/operator/operator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
from devito.parameters import configuration
3030
from devito.passes import (
3131
Graph, lower_index_derivatives, generate_implicit, generate_macros,
32-
minimize_symbols, unevaluate, error_mapper, is_on_device, lower_dtypes
32+
minimize_symbols, optimize_pows, unevaluate, error_mapper, is_on_device,
33+
lower_dtypes
3334
)
3435
from devito.symbolics import estimate_cost, subs_op_args
3536
from devito.tools import (DAG, OrderedSet, Signer, ReducerMap, as_mapper, as_tuple,
@@ -409,6 +410,10 @@ def _lower_clusters(cls, expressions, profiler=None, **kwargs):
409410
# Lower all remaining high order symbolic objects
410411
clusters = lower_index_derivatives(clusters, **kwargs)
411412

413+
# Turn pows into multiplications. This must happen as late as possible
414+
# in the compilation process to maximize the optimization potential
415+
clusters = optimize_pows(clusters)
416+
412417
# Make sure no reconstructions can unpick any of the symbolic
413418
# optimizations performed so far
414419
clusters = unevaluate(clusters)

tests/test_dse.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ def g2_tilde(field, phi, theta):
17451745
assert len([i for i in FindSymbols().visit(bns['x0_blk0']) if i.is_Array]) == 7
17461746
assert len(FindNodes(VExpanded).visit(pbs['x0_blk0'])) == 3
17471747

1748-
@pytest.mark.parametrize('so_ops', [(4, 147), (8, 211)])
1748+
@pytest.mark.parametrize('so_ops', [(4, 146), (8, 210)])
17491749
@switchconfig(profiling='advanced')
17501750
def test_tti_J_akin_complete(self, so_ops):
17511751
grid = Grid(shape=(16, 16, 16))
@@ -2725,9 +2725,9 @@ def test_fullopt(self):
27252725
bns, _ = assert_blocking(op0, {})
27262726
bns, _ = assert_blocking(op1, {'x0_blk0'}) # due to loop blocking
27272727

2728-
assert summary0[('section0', None)].ops == 50
2728+
assert summary0[('section0', None)].ops == 55
27292729
assert summary0[('section1', None)].ops == 44
2730-
assert np.isclose(summary0[('section0', None)].oi, 2.851, atol=0.001)
2730+
assert np.isclose(summary0[('section0', None)].oi, 3.136, atol=0.001)
27312731

27322732
assert summary1[('section0', None)].ops == 31
27332733
assert summary1[('section1', None)].ops == 88
@@ -2779,7 +2779,7 @@ def tti_noopt(self):
27792779
# Make sure no opts were applied
27802780
op = wavesolver.op_fwd(False)
27812781
assert len(op._func_table) == 0
2782-
assert summary[('section0', None)].ops == 743
2782+
assert summary[('section0', None)].ops == 753
27832783

27842784
return v, rec
27852785

@@ -2865,7 +2865,7 @@ class TestTTIv2:
28652865

28662866
@switchconfig(profiling='advanced')
28672867
@pytest.mark.parametrize('space_order,expected', [
2868-
(4, 200), (12, 392)
2868+
(4, 190), (12, 382)
28692869
])
28702870
def test_opcounts(self, space_order, expected):
28712871
grid = Grid(shape=(3, 3, 3))

tests/test_unexpansion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_v4(self):
260260
'cire-mingain': 400}))
261261

262262
# Check code generation
263-
assert op._profiler._sections['section1'].sops == 1443
263+
assert op._profiler._sections['section1'].sops == 1442
264264
assert_structure(op, ['x,y,z',
265265
't,x0_blk0,y0_blk0,x,y,z',
266266
't,x0_blk0,y0_blk0,x,y,z,i1',
@@ -431,7 +431,7 @@ def test_v1(self):
431431
'openmp': False}))
432432

433433
# Check code generation
434-
assert op._profiler._sections['section1'].sops == 191
434+
assert op._profiler._sections['section1'].sops == 190
435435
assert_structure(op, ['x,y,z',
436436
't,x0_blk0,y0_blk0,x,y,z',
437437
't,x0_blk0,y0_blk0,x,y,z,i0',

0 commit comments

Comments
 (0)