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:
ctx (KernelCreationContext)
dimensions (Sequence[FullIterationSpace.Dimension])
archetype_field (Field | None)
- class Dimension(start, stop, step, counter)#
One dimension of a dense iteration space
- Parameters:
start (PsExpression)
stop (PsExpression)
step (PsExpression)
counter (PsSymbol)
- static create_with_ghost_layers(ctx, ghost_layers, archetype_field)#
Create an iteration space over an archetype field with ghost layers.
- Return type:
- 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 contextiteration_slice (
int
|slice
|tuple
[int
|slice
,...
]) – The iteration slices for each dimension; for valid formats, seeAstFactory.parse_slice
archetype_field (
Optional
[Field
]) – Optionally, an archetype field that dictates the upper slice limits and loop order.
- property dimensions#
The dimensions of this iteration space
- property lower: tuple[PsExpression, ...]#
Lower limits of each dimension
- property upper: tuple[PsExpression, ...]#
Upper limits of each dimension
- property steps: tuple[PsExpression, ...]#
Iteration steps of each dimension
- property archetype_field: Field | None#
Field whose shape and memory layout act as archetypes for this iteration space’s dimensions.
- property loop_order: tuple[int, ...]#
Return the loop order of this iteration space, ordered from slowest to fastest coordinate.
- dimensions_in_loop_order()#
Return the dimensions of this iteration space ordered from the slowest to the fastest coordinate.
If this iteration space has an
archetype field
set, its field layout is used to determine the ideal loop order; otherwise, the dimensions are returned as they are
- actual_iterations(dimension=None)#
Construct an expression representing the actual number of unique points inside the iteration space.
- 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:
- 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:
spatial_indices (Sequence[PsSymbol])
index_list (PsBuffer)
coordinate_members (Sequence[PsStructType.Member])
sparse_counter (PsSymbol)
- 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.
- pystencils.backend.kernelcreation.iteration_space.create_full_iteration_space(ctx, assignments, ghost_layers=None, iteration_slice=None, infer_ghost_layers=False)#
Create a dense iteration space from a sequence of assignments and iteration slice information.
This function finds all accesses to fields in the given assignment collection, analyzes the set of fields involved, and determines the iteration space bounds from these. This requires that either all fields are of the same, fixed, shape, or all of them are variable-shaped. Also, all fields need to have the same memory layout of their spatial dimensions.
- Parameters:
ctx (
KernelCreationContext
) – The kernel creation contextassignments (
AssignmentCollection
) – Collection of assignments the iteration space should be inferred fromghost_layers (
Union
[None
,int
,Sequence
[int
|tuple
[int
,int
]]]) – If set, strip off that many ghost layers from all sides of the iteration cuboiditeration_slice (
Union
[None
,int
,slice
,tuple
[int
|slice
,...
]]) – If set, constrain iteration to the given slice. For details on the parsing of slices, seeAstFactory.parse_slice
.infer_ghost_layers (
bool
) – IfTrue
, infer the number of ghost layers from the stencil ranges used in the kernel.
- Returns:
The constructed iteration space.
- Return type:
- Raises:
KernelConstraintsError – If field shape or memory layout conflicts are detected
ValueError – If the iteration slice could not be parsed
Attention
The
ghost_layers
anditeration_slice
arguments are mutually exclusive. Also, ifinfer_ghost_layers=True
, none of them may be set.