Skip to main content

Ordered derivative extraction with cire-mode

cire-mode splits selected stencil expressions into separate stages. This can reduce register pressure and improve GPU occupancy, at the cost of temporary storage, memory traffic, and kernel launches.

Use commas to request stages in order:

op = Operator(equations, opt=('advanced', {
    'expand': False,
    'cire-mode': 'x|y|z:stag,y|z:center,x|y|z:interp'
}))

This example requests three stages:

  1. Select staggered derivatives along x, y, or z.
  2. Select centered derivatives along y or z in the remaining expressions.
  3. Select interpolations along x, y, or z in the remaining expressions.

These selectors require a three-dimensional computation and expand=False.

Selecting stencils

Use | for alternatives within one stage. Digits specify differential order, not discretization accuracy:

Selector Candidates
x First derivatives and interpolations along x
x2 Second derivatives along x
x\|y\|z Separate first derivatives and interpolations along any axis
xy A nested mixed stencil along x and y
xy2 A first derivative along x nested with a second derivative along y

xy and yx select the same mixed stencil. x|y requests one stage with two alternatives, whereas x,y requests two successive stages.

Append a kind after the complete selector to restrict its candidates:

Suffix Selects
:stag Staggered derivatives
:center Centered derivatives
:interp Interpolations

Here, centered and staggered refer to evaluation on the input lattice or halfway between its points. For a mixed selector, the suffix applies to every axis: xy:interp, for example, selects bilinear interpolation.

Ordering and per-computation settings

Stage order matters: extracting an inner stencil can make an outer stencil available to a later stage. Repeat a selector to apply it again, for example 'x|y|z:interp,x|y|z:interp'. A stage with no eligible expressions is skipped. The number of stages need not equal the number of generated GPU kernels.

A tuple assigns a mode to each successive computation:

'cire-mode': (
    '1pass',
    '1pass',
    'x|y|z:stag,y|z:center,x|y|z:interp'
)

The first two computations stay unsplit; the third uses the three-stage sequence. The final tuple entry is reused for any remaining computations. 1pass must be a complete mode, so it cannot be combined with other stages in one string.

Other presets include any and automatic:200. The latter is GPU-only and uses a register threshold of 200. Both can appear in comma-separated sequences.

Loop-invariant expressions with cire-hoist

cire-hoist=1 (the default) precomputes loop-invariant derivatives. Set it to 2 to also consider invariant arithmetic, such as sums and products:

op = Operator(equations, opt=('advanced', {
    'cire-hoist': 2,
    'cire-mode': '1pass'
}))

For example, if a, b, and c are unchanged within the loop over k, (a[x] + b[x])*c[x]*u[k, x] can become r[x]*u[k, x], with r[x] = (a[x] + b[x])*c[x] computed outside that loop. This applies to any loop, including spatial loops. The temporary is recomputed on each Operator invocation.

The compiler selects which expressions to precompute. Extra arrays can increase memory use and traffic, so compare performance with the default setting.

Use '2:80' to require at least 80 stencil points for derivative hoisting while also enabling arithmetic hoisting. The threshold applies only to derivatives.

Back to top