Skip to content

stencil

CompareToNumpyStencil

A wrapper over FrozenStencil which executes a numpy version of the stencil as well, and compares the results.

FrozenStencil

Bases: SDFGConvertible

Wrapper for gt4py stencils which stores origin and domain at compile time, and uses their stored values at call time.

This is useful when the stencil itself is meant to be used on a certain grid, for example if a compile-time external variable is tied to the values of origin and domain.

__init__(func, origin, domain, stencil_config, externals=None, skip_passes=(), timing_collector=None, comm=None)

Parameters:

Name Type Description Default
func Callable[..., None]

stencil definition function

required
origin tuple[int, ...] | Mapping[str, tuple[int, ...]]

gt4py origin to use at call time

required
domain tuple[int, ...]

gt4py domain to use at call time

required
stencil_config StencilConfig

container for stencil configuration

required
externals Mapping[str, Any] | None

compile-time external variables required by stencil

None
skip_passes tuple[str, ...]

compiler passes to skip when building stencil

()
timing_collector TimingCollector | None

Optional object that accumulates timings

None
comm Comm | None

if given, inputs and outputs will be compared to the "twin" rank of this rank

None

__sdfg__(*args, **kwargs)

Implemented SDFG generation

__sdfg_closure__(*args, **kwargs)

Implemented SDFG closure build

__sdfg_signature__()

Implemented SDFG signature lookup

closure_resolver(constant_args, given_args, parent_closure=None)

Implemented SDFG closure resolver build

GridIndexing

Provides indices for cell-centered variables with halos.

These indices can be used with horizontal interface variables by adding 1 to the domain shape along any interface axis.

iec property

Last index of the compute domain along the x-axis

ied property

Index of the last data point along the x-axis

isc property

Start of the compute domain along the x-axis

isd property

Start of the full domain including halos along the x-axis

jec property

Last index of the compute domain along the y-axis

jed property

Index of the last data point along the y-axis

jsc property

Start of the compute domain along the y-axis

jsd property

Start of the full domain including halos along the y-axis

max_shape property

Maximum required storage shape, corresponding to the shape of a cell-corner variable with maximum halo points.

This should rarely be required, consider using appropriate calls to helper methods that get the correct shape for your particular variable.

__init__(domain, n_halo, south_edge, north_edge, west_edge, east_edge, *, k_start=0)

Initialize a grid indexing object.

Parameters:

Name Type Description Default
domain Index3D

size of the compute domain for cell-centered variables

required
n_halo int

number of halo points

required
south_edge bool

whether the current rank is on the south edge of a tile

required
north_edge bool

whether the current rank is on the north edge of a tile

required
west_edge bool

whether the current rank is on the west edge of a tile

required
east_edge bool

whether the current rank is on the east edge of a tile

required

domain_compute(add=(0, 0, 0))

Returns the shape of the compute domain, plus an optional offset.

domain_full(add=(0, 0, 0))

Returns the shape of the full domain including halos, plus an optional offset.

get_2d_compute_origin_domain(klevel=0)

Get the origin and domain for a computation that occurs on the lowest klevel over a certain grid configuration (given by dims) and a certain number of halo points.

Parameters:

Name Type Description Default
klevel int

the vertical level of the domain, defaults to zero

0

Returns:

Name Type Description
origin tuple[int, ...]

origin of the computation

domain tuple[int, ...]

shape of the computation

get_origin_domain(dims, halos=tuple())

Get the origin and domain for a computation that occurs over a certain grid configuration (given by dims) and a certain number of halo points.

Parameters:

Name Type Description Default
dims Sequence[str]

dimension names, using dimension constants from ndsl.constants

required
halos Sequence[int]

number of halo points for each dimension, defaults to zero

tuple()

Returns:

Name Type Description
origin tuple[int, ...]

origin of the computation

domain tuple[int, ...]

shape of the computation

get_shape(dims, halos=tuple())

Get the storage shape required for an array with the given dimensions which is accessed up to a given number of halo points.

Parameters:

Name Type Description Default
dims Sequence[str]

dimension names, using dimension constants from ndsl.constants

required
halos Sequence[int]

number of halo points for each dimension, defaults to zero

tuple()

Returns:

Name Type Description
shape tuple[int, ...]

storage required for an array with the given dimensions

origin_compute(add=(0, 0, 0))

Returns the origin of the compute domain, plus an optional offset

origin_full(add=(0, 0, 0))

Returns the origin of the full domain including halos, plus an optional offset.

restrict_vertical(k_start=0, nk=None)

Returns a copy of itself with modified vertical origin and domain.

Parameters:

Name Type Description Default
k_start int

offset to apply to current vertical origin, must be greater than 0 and less than the size of the vertical domain

0
nk int | None

new vertical domain size as a number of grid cells, defaults to remaining grid cells in the current domain, can be at most the size of the vertical domain minus k_start

None

StencilFactory

Configurable class which creates stencil objects.

__init__(config, grid_indexing, comm=None)

Parameters:

Name Type Description Default
config StencilConfig

gt4py-specific stencil configuration

required
grid_indexing GridIndexing

configuration for domain and halo indexing

required
comm Comm | None

if given, stencils will compare all data before and after stencil execution to their "pair" rank on the comm. This is very expensive and only used for debugging.

None

build_report(key='build_time', **kwargs)

Report all stencils built by this factory.

exec_report(key='total_run_time', **kwargs)

Report all stencils executed that were built by this factory.

from_dims_halo(func, compute_dims, compute_halos=tuple(), externals=None, skip_passes=())

Initialize a stencil from dimensions and number of halo points.

Automatically injects axis_offsets into stencil externals.

Parameters:

Name Type Description Default
func Callable[..., None]

stencil definition function

required
compute_dims Sequence[str]

dimensionality of compute domain

required
compute_halos Sequence[int]

number of halo points to include in compute domain

tuple()
externals Mapping[str, Any] | None

compile-time external variables required by stencil

None
skip_passes tuple[str, ...]

compiler passes to skip when building stencil

()

from_origin_domain(func, origin, domain, externals=None, skip_passes=())

Parameters:

Name Type Description Default
func Callable[..., None]

stencil definition function

required
origin tuple[int, ...] | Mapping[str, tuple[int, ...]]

gt4py origin to use at call time

required
domain tuple[int, ...]

gt4py domain to use at call time

required
externals Mapping[str, Any] | None

compile-time external variables required by stencil

None
skip_passes tuple[str, ...]

compiler passes to skip when building stencil

()

TimingCollector dataclass

Attributes:

Name Type Description
build_info dict[str, dict]

contains info about the generation process for each stencil.

exec_info dict[str, Any]

contains info about the execution of each stencil.