loki.transform.transform_loop

Collection of utility routines that provide loop transformations.

Functions

eliminate_variable(polyhedron, index_or_variable)

Eliminate a variable from the polyhedron.

generate_loop_bounds(iteration_space, ...)

Generate loop bounds according to a changed iteration order.

get_loop_components(loops)

Helper routine to extract loop variables, ranges and bodies of list of loops.

get_nested_loops(loop, depth)

Helper routine to extract all loops in a loop nest.

loop_fission(routine[, promote, ...])

Search for !$loki loop-fission pragmas in loops and split them.

loop_fusion(routine)

Search for loops annotated with the loki loop-fusion pragma and attempt to fuse them into a single loop.

loop_interchange(routine[, project_bounds])

Search for loops annotated with the loki loop-interchange pragma and attempt to reorder them.

pragma_ranges_to_loop_ranges(parameters, scope)

Convert loop ranges given in the pragma parameters from string to a tuple of LoopRange objects.

Classes

FissionTransformer(loop_pragmas[, active])

Bespoke transformer that splits loops or loop nests at !$loki loop-fission pragmas.

Polyhedron(A, b[, variables])

Halfspace representation of a (convex) polyhedron.

loop_interchange(routine, project_bounds=False)

Search for loops annotated with the loki loop-interchange pragma and attempt to reorder them.

Note that this effectively just exchanges variable and bounds for each of the loops, leaving the rest (including bodies, pragmas, etc.) intact.

loop_fusion(routine)

Search for loops annotated with the loki loop-fusion pragma and attempt to fuse them into a single loop.

loop_fission(routine, promote=True, warn_loop_carries=True)

Search for !$loki loop-fission pragmas in loops and split them.

The expected pragma syntax is !$loki loop-fission [collapse(n)] [promote(var-name, var-name, ...)] where collapse(n) gives the loop nest depth to be split (defaults to n=1) and promote optionally specifies a list of variable names to be promoted by the split iteration space dimensions.

Parameters:
  • routine (Subroutine) – The subroutine in which loop fission is to be applied.

  • promote (bool, optional) – Try to automatically detect read-after-write across fission points and promote corresponding variables. Note that this does not affect promotion of variables listed directly in the pragma’s promote option.

  • warn_loop_carries (bool, optional) – Try to automatically detect loop-carried dependencies and warn when the fission point sits after the initial read and before the final write.

class Polyhedron(A, b, variables=None)

Bases: object

Halfspace representation of a (convex) polyhedron.

A polyhedron P c R^d is described by a set of inequalities, in matrix form ` P = { x=[x1,...,xd]^T c R^d | Ax <= b } ` with n-by-d matrix A and d-dimensional right hand side b.

In loop transformations, polyhedrons are used to represent iteration spaces of d-deep loop nests.

Parameters:
  • A (np.array) – the representation matrix A.

  • b (np.array) – the right hand-side vector b.

  • variables (list) – list of variables representing the dimensions in the polyhedron.

variable_to_index(variable)
lower_bounds(index_or_variable, ignore_variables=None)

Return all lower bounds imposed on a variable.

Lower bounds for variable j are given by the index set ` L = {i in {0,...,d-1} | A_ij < 0} `

Parameters:
  • index_or_variable (int or str or sym.Array or sym.Scalar) – the index, name, or expression symbol for which the lower bounds are produced.

  • ignore_variables (list or None) – optional list of variable names, indices or symbols for which constraints should be ignored if they depend on one of them.

Returns list:

the bounds for that variable.

upper_bounds(index_or_variable, ignore_variables=None)

Return all upper bounds imposed on a variable.

Upper bounds for variable j are given by the index set ` U = {i in {0,...,d-1} | A_ij > 0} `

Parameters:
  • index_or_variable (int or str or sym.Array or sym.Scalar) – the index, name, or expression symbol for which the upper bounds are produced.

  • ignore_variables (list or None) – optional list of variable names, indices or symbols for which constraints should be ignored if they depend on one of them.

Returns list:

the bounds for that variable.

static generate_entries_for_lower_bound(bound, variables, index)

Helper routine to generate matrix and right-hand side entries for a given lower bound.

NB: This can only deal with affine bounds, i.e. expressions that are

constant or can be reduced to a linear polynomial.

Upper bounds can be derived from this by multiplying left-hand side and right-hand side with -1.

Parameters:
  • bound – the expression representing the lower bound.

  • variables (list) – the list of variable names.

  • index (int) – the index of the variable constrained by this bound.

Returns:

the pair (lhs, rhs) of the row in the matrix inequality.

Return type:

tuple(np.array, np.array)

classmethod from_loop_ranges(loop_variables, loop_ranges)

Create polyhedron from a list of loop ranges and associated variables.