Iteration Spaces

class pystencils.backend.kernelcreation.iteration_space.IterationSpace(spatial_indices)

Represents the n-dimensonal iteration space of a pystencils kernel.

Instances of this class represent the kernel’s iteration region during translation from SymPy, before any indexing sources are generated. It provides the counter symbols which should be used to translate field accesses to array accesses.

There are two types of iteration spaces, modelled by subclasses:
  • The full iteration space translates to an n-dimensional loop nest or the corresponding device indexing scheme.

  • The sparse iteration space translates to a single loop over an index list which in turn provides the spatial indices.

Parameters:

spatial_indices (Sequence[PsSymbol]) –

class pystencils.backend.kernelcreation.iteration_space.FullIterationSpace(ctx, dimensions, archetype_field=None)

N-dimensional full iteration space.

Each dimension of the full iteration space is represented by an instance of FullIterationSpace.Dimension. Dimensions are ordered slowest-to-fastest: The first dimension corresponds to the slowest coordinate, translates to the outermost loop, while the last dimension is the fastest coordinate and translates to the innermost loop.

Parameters:
class Dimension(start, stop, step, counter)
Parameters:
static create_with_ghost_layers(ctx, ghost_layers, archetype_field)

Create an iteration space over an archetype field with ghost layers.

Return type:

FullIterationSpace

Parameters:
static create_from_slice(ctx, iteration_slice, archetype_field=None)

Create an iteration space from a sequence of slices, optionally over an archetype field.

Parameters:
  • ctx (KernelCreationContext) – The kernel creation context

  • iteration_slice (Union[slice, Sequence[slice]]) – The iteration slices for each dimension; for valid formats, see AstFactory.parse_slice

  • archetype_field (Optional[Field]) – Optionally, an archetype field that dictates the upper slice limits and loop order.

compressed_counter()

Expression counting the actual number of items processed at the iteration defined by the counter tuple.

Used primarily for indexing buffers.

Return type:

PsExpression

class pystencils.backend.kernelcreation.iteration_space.SparseIterationSpace(spatial_indices, index_list, coordinate_members, sparse_counter)

Represents a sparse iteration space defined by an index list.

Parameters:
pystencils.backend.kernelcreation.iteration_space.get_archetype_field(fields, check_compatible_shapes=True, check_same_layouts=True, check_same_dimensions=True)

Retrieve an archetype field from a collection of fields, which represents their common properties.

Raises:

KernelConstrainsError – If any two fields with conflicting properties are encountered.

Parameters:
  • fields (set[Field]) –

  • check_compatible_shapes (bool) –

  • check_same_layouts (bool) –

  • check_same_dimensions (bool) –