Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pystencils
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pycodegen
pystencils
Commits
5157ca73
Commit
5157ca73
authored
7 months ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
Some documentation on symbols and symbol properties
parent
04d1e754
No related branches found
No related tags found
1 merge request
!421
Refactor Field Modelling
Pipeline
#69744
failed
7 months ago
Stage: Code Quality
Stage: Unit Tests
Stage: legacy_test
Stage: docs
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/source/backend/index.rst
+1
-1
1 addition, 1 deletion
docs/source/backend/index.rst
docs/source/backend/objects.rst
+69
-10
69 additions, 10 deletions
docs/source/backend/objects.rst
src/pystencils/backend/memory.py
+2
-2
2 additions, 2 deletions
src/pystencils/backend/memory.py
with
72 additions
and
13 deletions
docs/source/backend/index.rst
+
1
−
1
View file @
5157ca73
...
...
@@ -30,7 +30,7 @@ The IR comprises *symbols*, *constants*, *arrays*, the *iteration space* and the
* `PsSymbol` represents a single symbol in the kernel, annotated with a type. Other than in the frontend,
uniqueness of symbols is enforced by the backend: of each symbol, at most one instance may exist.
* `PsConstant` provides a type-safe representation of constants.
* `Ps
LinearizedArray
` is the backend counterpart to the ubiquitous `Field`, representing a contiguous
* `Ps
Buffer
` is the backend counterpart to the ubiquitous `Field`, representing a contiguous
n-dimensional array.
These arrays do not occur directly in the IR, but are represented through their *associated symbols*,
which are base pointers, shapes, and strides.
...
...
This diff is collapsed.
Click to expand it.
docs/source/backend/objects.rst
+
69
−
10
View file @
5157ca73
...
...
@@ -2,8 +2,8 @@
Constants and Memory Objects
****************************
Memory Objects: Symbols and
Field Array
s
===================================
=====
Memory Objects: Symbols and
Buffer
s
===================================
The Memory Model
----------------
...
...
@@ -12,32 +12,91 @@ In order to reason about memory accesses, mutability, invariance, and aliasing,
a very simple memory model. There are three types of memory objects:
- Symbols (`PsSymbol`), which act as registers for data storage within the scope of a kernel
- Field
arrays (`PsLinearizedArray
`), which represent a contiguous block of memory the kernel has access to, and
- Field
buffers (`PsBuffer
`), which represent a contiguous block of memory the kernel has access to, and
- the *unmanaged heap*, which is a global catch-all memory object which all pointers not belonging to a field
array point into.
All of these objects are disjoint, and cannot alias each other.
Each symbol exists in isolation,
field
array
s do not overlap,
field
buffer
s do not overlap,
and raw pointers are assumed not to point into memory owned by a symbol or field array.
Instead, all raw pointers point into unmanaged heap memory, and are assumed to *always* alias one another:
Each change brought to unmanaged memory by one raw pointer is assumed to affect the memory pointed to by
another raw pointer.
Classe
s
Symbol
s
-------
.. autoclass:: pystencils.backend.symbols.PsSymbol
:members:
In the pystencils IR, instances of `PsSymbol` represent what is generally known as "virtual registers".
These are memory locations that are private to a function, cannot be aliased or pointed to, and will finally reside
either in physical registers or on the stack.
Each symbol has a name and a data type. The data type may initially be `None`, in which case it should soon after be
determined by the `Typifier`.
.. automodule:: pystencils.backend.arrays
:members:
Other than their front-end counterpart `sympy.Symbol <sympy.core.symbol.Symbol>`, `PsSymbol` instances are mutable;
their properties can and often will change over time.
As a consequence, they are not comparable by value:
two `PsSymbol` instances with the same name and data type will in general *not* be equal.
In fact, most of the time, it is an error to have two identical symbol instances active.
Creating Symbols
----------------
During kernel translation, symbols never exist in isolation, but should always be managed by a `KernelCreationContext`.
Symbols can be created and retrieved using `KernelCreationContext.add_symbol` and `KernelCreationContext.find_symbol`.
A symbol can also be duplicated using `KernelCreationContext.duplicate_symbol`, which assigns a new name to the symbol's copy.
The `KernelCreationContext` keeps track of all existing symbols during a kernel translation run
and makes sure that no name and data type conflicts may arise.
Never call the constructor of `PsSymbol` directly unless you really know what you are doing.
Symbol Properties
-----------------
Symbols can be annotated with arbitrary information using *symbol properties*.
Each symbol property type must be a subclass of `PsSymbolProperty`.
It is strongly recommended to implement property types using frozen
`dataclasses <https://docs.python.org/3/library/dataclasses.html>`_.
For example, this snippet defines a property type that models pointer alignment requirements:
.. code-block:: python
@dataclass(frozen=True)
class AlignmentProperty(PsSymbolProperty)
"""Require this pointer symbol to be aligned at a particular byte boundary."""
byte_boundary: int
_unique: ClassVar[bool] = True
The ``_unique`` flag in the above example ensures that only one property of this type can at any time
be attached to a symbol.
Properties can be added, queried, and removed using the `PsSymbol` properties API listed below.
Many symbol properties are more relevant to consumers of generated kernels than to the code generator itself.
The above alignment property, for instance, may be added to a pointer symbol by a vectorization pass
to document its assumption that the pointer be properly aligned, in order to emit aligned load and store instructions.
It then becomes the responsibility of the runtime system embedding the kernel to check this prequesite before calling the kernel.
To make sure this information becomes visible, any properties attached to symbols exposed as kernel parameters will also
be added to their respective `KernelParameter` instance.
Constants and Literals
======================
.. autoclass:: pystencils.backend.constants.PsConstant
API Documentation
=================
The `memory <pystencils.backend.memory>` Module
-----------------------------------------------
.. automodule:: pystencils.backend.memory
:members:
The `constants <pystencils.backend.constants>` Module
-----------------------------------------------------
.. automodule:: pystencils.backend.constants
:members:
.. autoclass:: pystencils.backend.literals.PsLiteral
...
...
This diff is collapsed.
Click to expand it.
src/pystencils/backend/memory.py
+
2
−
2
View file @
5157ca73
...
...
@@ -122,7 +122,7 @@ class PsSymbol:
@dataclass
(
frozen
=
True
)
class
BufferBasePtr
(
PsSymbolProperty
):
"""
Symbol acts as a base pointer to a
field
.
"""
"""
Symbol acts as a base pointer to a
buffer
.
"""
buffer
:
PsBuffer
...
...
@@ -140,7 +140,7 @@ class PsBuffer:
All indexing expressions must have the same data type, which will be selected as the buffer
'
s
`index_dtype`.
Each buffer has at least one base pointer, which can be retrieved via the `base_pointer`
Each buffer has at least one base pointer, which can be retrieved via the `
PsBuffer.
base_pointer`
property.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment