devito.dse package

Submodules

devito.dse.aliases module

devito.dse.aliases.collect(exprs)[source]

Determine groups of aliasing expressions in exprs.

An expression A aliases an expression B if both A and B apply the same operations to the same input operands, with the possibility for indexed objects to index into locations at a fixed constant offset in each dimension.

For example:

exprs = (a[i+1] + b[i+1], a[i+1] + b[j+1], a[i] + c[i],
         a[i+2] - b[i+2], a[i+2] + b[i], a[i-1] + b[i-1])

The following expressions in exprs alias to a[i] + b[i]:

a[i+1] + b[i+1] : same operands and operations, distance along i = 1
a[i-1] + b[i-1] : same operands and operations, distance along i = -1

Whereas the following do not:

a[i+1] + b[j+1] : because at least one index differs
a[i] + c[i] : because at least one of the operands differs
a[i+2] - b[i+2] : because at least one operation differs
a[i+2] + b[i] : because distance along ``i`` differ (+2 and +0)

devito.dse.manipulation module

devito.dse.manipulation.collect_nested(expr, aggressive=False)[source]

Collect terms appearing in expr, checking all levels of the expression tree.

Parameters:expr – the expression to be factorized.
devito.dse.manipulation.common_subexprs_elimination(exprs, make, mode='default')[source]

Perform common subexpressions elimination.

Note: the output is not guranteed to be topologically sorted.

Parameters:
  • exprs – The target SymPy expression, or a collection of SymPy expressions.
  • make – A function to construct symbols used for replacement.
devito.dse.manipulation.compact_temporaries(temporaries, leaves)[source]

Drop temporaries consisting of single symbols.

devito.dse.manipulation.cross_cluster_cse(clusters)[source]

Perform common sub-expressions elimination across an iterable of Clusters.

devito.dse.transformer module

devito.dse.transformer.rewrite(clusters, mode='advanced')[source]

Transform N Cluster objects of SymPy expressions into M Cluster objects of SymPy expressions with reduced operation count, with M >= N.

Parameters:
  • clusters – The clusters to be transformed.
  • mode – drive the expression transformation

The mode parameter recognises the following values:

* 'noop': Do nothing.
* 'basic': Apply common sub-expressions elimination.
* 'advanced': Apply all transformations that will reduce the
              operation count w/ minimum increase to the memory pressure,
              namely 'basic', factorization, CIRE for time-invariants only.
* 'speculative': Like 'advanced', but apply CIRE also to time-varying
                 sub-expressions, which might further increase the memory
                 pressure.
* 'aggressive': Like 'speculative', but apply CIRE to any non-trivial
                sub-expression (i.e., anything that is at least in a
                sum-of-product form).
                Further, seek and drop cross-cluster redundancies (this
                is the only pass that attempts to optimize *across*
                clusters, rather than within a cluster).
                The 'aggressive' mode may substantially increase the
                symbolic processing time; it may or may not reduce the
                JIT-compilation time; it may or may not improve the
                overall runtime performance.

Module contents