Skip to content
Snippets Groups Projects
Commit d62cf638 authored by Frederik Hennig's avatar Frederik Hennig
Browse files

Add documentation for transformations module. Fix some doc comments.

parent 17935011
No related branches found
No related tags found
1 merge request!376Loop Transformations: Cutting and Peeling
Pipeline #64969 failed
...@@ -14,6 +14,7 @@ who wish to customize or extend the behaviour of the code generator in their app ...@@ -14,6 +14,7 @@ who wish to customize or extend the behaviour of the code generator in their app
iteration_space iteration_space
translation translation
platforms platforms
transformations
jit jit
Internal Representation Internal Representation
......
*******************
AST Transformations
*******************
`pystencils.backend.transformations`
.. automodule:: pystencils.backend.transformations
...@@ -161,7 +161,7 @@ class KernelCreationContext: ...@@ -161,7 +161,7 @@ class KernelCreationContext:
def duplicate_symbol(self, symb: PsSymbol) -> PsSymbol: def duplicate_symbol(self, symb: PsSymbol) -> PsSymbol:
"""Canonically duplicates the given symbol. """Canonically duplicates the given symbol.
A new symbol with the same data type an name ``symb.name + "__<counter>"`` is created, A new symbol with the same data type, and new name ``symb.name + "__<counter>"`` is created,
added to the symbol table, and returned. added to the symbol table, and returned.
The ``counter`` reflects the number of previously created duplicates of this symbol. The ``counter`` reflects the number of previously created duplicates of this symbol.
""" """
......
...@@ -3,15 +3,15 @@ This module contains various transformation and optimization passes that can be ...@@ -3,15 +3,15 @@ This module contains various transformation and optimization passes that can be
executed on the backend AST. executed on the backend AST.
Canonical Form Canonical Form
^^^^^^^^^^^^^^ ==============
Many transformations in this module require that their input AST is in *canonical form*. Many transformations in this module require that their input AST is in *canonical form*.
This means that: This means that:
- Each symbol, constant, and expression node is annotated with a data type; - Each symbol, constant, and expression node is annotated with a data type;
- Each symbol has at most one declaration; - Each symbol has at most one declaration;
- Each symbol that is never written to apart from its declaration has a ``const`` type; and - Each symbol that is never written to apart from its declaration has a ``const`` type; and
- Each symbol whose type is *not* ``const`` has at least one non-declaring assignment. - Each symbol whose type is *not* ``const`` has at least one non-declaring assignment.
The first requirement can be ensured by running the `Typifier` on each newly constructed subtree. The first requirement can be ensured by running the `Typifier` on each newly constructed subtree.
The other three requirements are ensured by the `CanonicalizeSymbols` pass, The other three requirements are ensured by the `CanonicalizeSymbols` pass,
...@@ -23,6 +23,53 @@ to prove their legality. ...@@ -23,6 +23,53 @@ to prove their legality.
Certain transformations, like the auto-vectorizer (TODO), state additional requirements, e.g. Certain transformations, like the auto-vectorizer (TODO), state additional requirements, e.g.
the absence of loop-carried dependencies. the absence of loop-carried dependencies.
Transformations
===============
Canonicalization
----------------
.. autoclass:: CanonicalizeSymbols
:members: __call__
AST Cloning
-----------
.. autoclass:: CanonicalClone
:members: __call__
Simplifying Transformations
---------------------------
.. autoclass:: EliminateConstants
:members: __call__
.. autoclass:: EliminateBranches
:members: __call__
Code Motion
-----------
.. autoclass:: HoistLoopInvariantDeclarations
:members: __call__
Loop Reshaping Transformations
------------------------------
.. autoclass:: ReshapeLoops
:members:
Code Lowering and Materialization
---------------------------------
.. autoclass:: EraseAnonymousStructTypes
:members: __call__
.. autoclass:: SelectFunctions
:members: __call__
""" """
from .canonicalize_symbols import CanonicalizeSymbols from .canonicalize_symbols import CanonicalizeSymbols
...@@ -30,6 +77,7 @@ from .canonical_clone import CanonicalClone ...@@ -30,6 +77,7 @@ from .canonical_clone import CanonicalClone
from .eliminate_constants import EliminateConstants from .eliminate_constants import EliminateConstants
from .eliminate_branches import EliminateBranches from .eliminate_branches import EliminateBranches
from .hoist_loop_invariant_decls import HoistLoopInvariantDeclarations from .hoist_loop_invariant_decls import HoistLoopInvariantDeclarations
from .reshape_loops import ReshapeLoops
from .erase_anonymous_structs import EraseAnonymousStructTypes from .erase_anonymous_structs import EraseAnonymousStructTypes
from .select_functions import SelectFunctions from .select_functions import SelectFunctions
from .select_intrinsics import MaterializeVectorIntrinsics from .select_intrinsics import MaterializeVectorIntrinsics
...@@ -40,6 +88,7 @@ __all__ = [ ...@@ -40,6 +88,7 @@ __all__ = [
"EliminateConstants", "EliminateConstants",
"EliminateBranches", "EliminateBranches",
"HoistLoopInvariantDeclarations", "HoistLoopInvariantDeclarations",
"ReshapeLoops",
"EraseAnonymousStructTypes", "EraseAnonymousStructTypes",
"SelectFunctions", "SelectFunctions",
"MaterializeVectorIntrinsics", "MaterializeVectorIntrinsics",
......
...@@ -69,7 +69,7 @@ class HoistLoopInvariantDeclarations: ...@@ -69,7 +69,7 @@ class HoistLoopInvariantDeclarations:
in particular, each symbol may have at most one declaration. in particular, each symbol may have at most one declaration.
To ensure this, a `CanonicalizeSymbols` pass should be run before `HoistLoopInvariantDeclarations`. To ensure this, a `CanonicalizeSymbols` pass should be run before `HoistLoopInvariantDeclarations`.
`HoistLoopInvariants` assumes that all `PsMathFunction`s are pure (have no side effects), `HoistLoopInvariantDeclarations` assumes that all `PsMathFunction` s are pure (have no side effects),
but makes no such assumption about instances of `CFunction`. but makes no such assumption about instances of `CFunction`.
""" """
......
...@@ -26,7 +26,7 @@ class ReshapeLoops: ...@@ -26,7 +26,7 @@ class ReshapeLoops:
) -> tuple[Sequence[PsBlock], PsLoop]: ) -> tuple[Sequence[PsBlock], PsLoop]:
"""Peel off iterations from the front of a loop. """Peel off iterations from the front of a loop.
Removes `num_iterations` from the front of the given loop and returns them as a sequence of Removes ``num_iterations`` from the front of the given loop and returns them as a sequence of
independent blocks. independent blocks.
Args: Args:
...@@ -36,7 +36,7 @@ class ReshapeLoops: ...@@ -36,7 +36,7 @@ class ReshapeLoops:
be executed, and omit their enclosing conditional. be executed, and omit their enclosing conditional.
Returns: Returns:
(peeled_iters, loop): Tuple containing the peeled-off iterations as a sequence of blocks, Tuple containing the peeled-off iterations as a sequence of blocks,
and the remaining loop. and the remaining loop.
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment