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
ee64e7e1
Commit
ee64e7e1
authored
1 year ago
by
Frederik Hennig
Browse files
Options
Downloads
Patches
Plain Diff
array associated symbols cleanup
parent
0b14e421
No related branches found
No related tags found
No related merge requests found
Pipeline
#63215
failed
1 year ago
Stage: pretest
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pystencils/backend/arrays.py
+12
-56
12 additions, 56 deletions
src/pystencils/backend/arrays.py
src/pystencils/backend/jit/cpu_extension_module.py
+4
-4
4 additions, 4 deletions
src/pystencils/backend/jit/cpu_extension_module.py
with
16 additions
and
60 deletions
src/pystencils/backend/arrays.py
+
12
−
56
View file @
ee64e7e1
...
@@ -5,7 +5,7 @@ An array has a fixed name, dimensionality, and element type, as well as a number
...
@@ -5,7 +5,7 @@ An array has a fixed name, dimensionality, and element type, as well as a number
variables.
variables.
The associated variables are the *shape* and *strides* of the array, modelled by the
The associated variables are the *shape* and *strides* of the array, modelled by the
`PsArrayShape
Var
` and `PsArrayStride
Var
` classes. They have integer type and are used to
`PsArrayShape
Symbol
` and `PsArrayStride
Symbol
` classes. They have integer type and are used to
reason about the array
'
s memory layout.
reason about the array
'
s memory layout.
...
@@ -68,7 +68,7 @@ class PsLinearizedArray:
...
@@ -68,7 +68,7 @@ class PsLinearizedArray:
For constant entries, their value must be given as an integer.
For constant entries, their value must be given as an integer.
For variable shape entries and strides, the Ellipsis `...` must be passed instead.
For variable shape entries and strides, the Ellipsis `...` must be passed instead.
Internally, the passed ``index_dtype`` will be used to create typed constants (`PsTypedConstant`)
Internally, the passed ``index_dtype`` will be used to create typed constants (`PsTypedConstant`)
and variables (`PsArrayShape
Var
` and `PsArrayStride
Var
`) from the passed values.
and variables (`PsArrayShape
Symbol
` and `PsArrayStride
Symbol
`) from the passed values.
"""
"""
def
__init__
(
def
__init__
(
...
@@ -86,18 +86,18 @@ class PsLinearizedArray:
...
@@ -86,18 +86,18 @@ class PsLinearizedArray:
if
len
(
shape
)
!=
len
(
strides
):
if
len
(
shape
)
!=
len
(
strides
):
raise
ValueError
(
"
Shape and stride tuples must have the same length
"
)
raise
ValueError
(
"
Shape and stride tuples must have the same length
"
)
self
.
_shape
:
tuple
[
PsArrayShape
Var
|
PsConstant
,
...]
=
tuple
(
self
.
_shape
:
tuple
[
PsArrayShape
Symbol
|
PsConstant
,
...]
=
tuple
(
(
(
PsArrayShape
Var
(
self
,
i
,
index_dtype
)
PsArrayShape
Symbol
(
self
,
i
,
index_dtype
)
if
s
==
Ellipsis
if
s
==
Ellipsis
else
PsConstant
(
s
,
index_dtype
)
else
PsConstant
(
s
,
index_dtype
)
)
)
for
i
,
s
in
enumerate
(
shape
)
for
i
,
s
in
enumerate
(
shape
)
)
)
self
.
_strides
:
tuple
[
PsArrayStride
Var
|
PsConstant
,
...]
=
tuple
(
self
.
_strides
:
tuple
[
PsArrayStride
Symbol
|
PsConstant
,
...]
=
tuple
(
(
(
PsArrayStride
Var
(
self
,
i
,
index_dtype
)
PsArrayStride
Symbol
(
self
,
i
,
index_dtype
)
if
s
==
Ellipsis
if
s
==
Ellipsis
else
PsConstant
(
s
,
index_dtype
)
else
PsConstant
(
s
,
index_dtype
)
)
)
...
@@ -117,8 +117,8 @@ class PsLinearizedArray:
...
@@ -117,8 +117,8 @@ class PsLinearizedArray:
return
self
.
_base_ptr
return
self
.
_base_ptr
@property
@property
def
shape
(
self
)
->
tuple
[
PsArrayShape
Var
|
PsConstant
,
...]:
def
shape
(
self
)
->
tuple
[
PsArrayShape
Symbol
|
PsConstant
,
...]:
"""
The array
'
s shape, expressed using `PsTypedConstant` and `PsArrayShape
Var
`
"""
"""
The array
'
s shape, expressed using `PsTypedConstant` and `PsArrayShape
Symbol
`
"""
return
self
.
_shape
return
self
.
_shape
@property
@property
...
@@ -129,8 +129,8 @@ class PsLinearizedArray:
...
@@ -129,8 +129,8 @@ class PsLinearizedArray:
)
)
@property
@property
def
strides
(
self
)
->
tuple
[
PsArrayStride
Var
|
PsConstant
,
...]:
def
strides
(
self
)
->
tuple
[
PsArrayStride
Symbol
|
PsConstant
,
...]:
"""
The array
'
s strides, expressed using `PsTypedConstant` and `PsArrayStride
Var
`
"""
"""
The array
'
s strides, expressed using `PsTypedConstant` and `PsArrayStride
Symbol
`
"""
return
self
.
_strides
return
self
.
_strides
@property
@property
...
@@ -144,32 +144,6 @@ class PsLinearizedArray:
...
@@ -144,32 +144,6 @@ class PsLinearizedArray:
def
element_type
(
self
):
def
element_type
(
self
):
return
self
.
_element_type
return
self
.
_element_type
def
_hashable_contents
(
self
):
"""
Contents by which to compare two instances of `PsLinearizedArray`.
Since equality checks on shape and stride variables internally check equality of their associated arrays,
if these variables would occur in here, an infinite recursion would follow.
Hence they are filtered and replaced by the ellipsis.
"""
shape_clean
=
self
.
shape_spec
strides_clean
=
self
.
strides_spec
return
(
self
.
_name
,
self
.
_element_type
,
self
.
_index_dtype
,
shape_clean
,
strides_clean
,
)
def
__eq__
(
self
,
other
:
object
)
->
bool
:
if
not
isinstance
(
other
,
PsLinearizedArray
):
return
False
return
self
.
_hashable_contents
()
==
other
.
_hashable_contents
()
def
__hash__
(
self
)
->
int
:
return
hash
(
self
.
_hashable_contents
())
def
__repr__
(
self
)
->
str
:
def
__repr__
(
self
)
->
str
:
return
(
return
(
f
"
PsLinearizedArray(
{
self
.
_name
}
:
{
self
.
element_type
}
[
{
len
(
self
.
shape
)
}
D])
"
f
"
PsLinearizedArray(
{
self
.
_name
}
:
{
self
.
element_type
}
[
{
len
(
self
.
shape
)
}
D])
"
...
@@ -182,24 +156,18 @@ class PsArrayAssocSymbol(PsSymbol, ABC):
...
@@ -182,24 +156,18 @@ class PsArrayAssocSymbol(PsSymbol, ABC):
Instances of this class represent pointers and indexing information bound
Instances of this class represent pointers and indexing information bound
to a particular array.
to a particular array.
"""
"""
init_arg_names
:
tuple
[
str
,
...]
=
(
"
name
"
,
"
dtype
"
,
"
array
"
)
__match_args__
=
(
"
name
"
,
"
dtype
"
,
"
array
"
)
__match_args__
=
(
"
name
"
,
"
dtype
"
,
"
array
"
)
def
__init__
(
self
,
name
:
str
,
dtype
:
PsAbstractType
,
array
:
PsLinearizedArray
):
def
__init__
(
self
,
name
:
str
,
dtype
:
PsAbstractType
,
array
:
PsLinearizedArray
):
super
().
__init__
(
name
,
dtype
)
super
().
__init__
(
name
,
dtype
)
self
.
_array
=
array
self
.
_array
=
array
def
__getinitargs__
(
self
):
return
self
.
name
,
self
.
dtype
,
self
.
array
@property
@property
def
array
(
self
)
->
PsLinearizedArray
:
def
array
(
self
)
->
PsLinearizedArray
:
return
self
.
_array
return
self
.
_array
class
PsArrayBasePointer
(
PsArrayAssocSymbol
):
class
PsArrayBasePointer
(
PsArrayAssocSymbol
):
init_arg_names
:
tuple
[
str
,
...]
=
(
"
name
"
,
"
array
"
)
__match_args__
=
(
"
name
"
,
"
array
"
)
__match_args__
=
(
"
name
"
,
"
array
"
)
def
__init__
(
self
,
name
:
str
,
array
:
PsLinearizedArray
):
def
__init__
(
self
,
name
:
str
,
array
:
PsLinearizedArray
):
...
@@ -208,9 +176,6 @@ class PsArrayBasePointer(PsArrayAssocSymbol):
...
@@ -208,9 +176,6 @@ class PsArrayBasePointer(PsArrayAssocSymbol):
self
.
_array
=
array
self
.
_array
=
array
def
__getinitargs__
(
self
):
return
self
.
name
,
self
.
array
class
TypeErasedBasePointer
(
PsArrayBasePointer
):
class
TypeErasedBasePointer
(
PsArrayBasePointer
):
"""
Base pointer for arrays whose element type has been erased.
"""
Base pointer for arrays whose element type has been erased.
...
@@ -224,14 +189,13 @@ class TypeErasedBasePointer(PsArrayBasePointer):
...
@@ -224,14 +189,13 @@ class TypeErasedBasePointer(PsArrayBasePointer):
self
.
_array
=
array
self
.
_array
=
array
class
PsArrayShape
Var
(
PsArrayAssocSymbol
):
class
PsArrayShape
Symbol
(
PsArrayAssocSymbol
):
"""
Variable that represents an array
'
s shape in one coordinate.
"""
Variable that represents an array
'
s shape in one coordinate.
Do not instantiate this class yourself, but only use its instances
Do not instantiate this class yourself, but only use its instances
as provided by `PsLinearizedArray.shape`.
as provided by `PsLinearizedArray.shape`.
"""
"""
init_arg_names
:
tuple
[
str
,
...]
=
(
"
array
"
,
"
coordinate
"
,
"
dtype
"
)
__match_args__
=
(
"
array
"
,
"
coordinate
"
,
"
dtype
"
)
__match_args__
=
(
"
array
"
,
"
coordinate
"
,
"
dtype
"
)
def
__init__
(
self
,
array
:
PsLinearizedArray
,
coordinate
:
int
,
dtype
:
PsIntegerType
):
def
__init__
(
self
,
array
:
PsLinearizedArray
,
coordinate
:
int
,
dtype
:
PsIntegerType
):
...
@@ -243,18 +207,13 @@ class PsArrayShapeVar(PsArrayAssocSymbol):
...
@@ -243,18 +207,13 @@ class PsArrayShapeVar(PsArrayAssocSymbol):
def
coordinate
(
self
)
->
int
:
def
coordinate
(
self
)
->
int
:
return
self
.
_coordinate
return
self
.
_coordinate
def
__getinitargs__
(
self
):
return
self
.
array
,
self
.
coordinate
,
self
.
dtype
class
PsArrayStrideSymbol
(
PsArrayAssocSymbol
):
class
PsArrayStrideVar
(
PsArrayAssocSymbol
):
"""
Variable that represents an array
'
s stride in one coordinate.
"""
Variable that represents an array
'
s stride in one coordinate.
Do not instantiate this class yourself, but only use its instances
Do not instantiate this class yourself, but only use its instances
as provided by `PsLinearizedArray.strides`.
as provided by `PsLinearizedArray.strides`.
"""
"""
init_arg_names
:
tuple
[
str
,
...]
=
(
"
array
"
,
"
coordinate
"
,
"
dtype
"
)
__match_args__
=
(
"
array
"
,
"
coordinate
"
,
"
dtype
"
)
__match_args__
=
(
"
array
"
,
"
coordinate
"
,
"
dtype
"
)
def
__init__
(
self
,
array
:
PsLinearizedArray
,
coordinate
:
int
,
dtype
:
PsIntegerType
):
def
__init__
(
self
,
array
:
PsLinearizedArray
,
coordinate
:
int
,
dtype
:
PsIntegerType
):
...
@@ -265,6 +224,3 @@ class PsArrayStrideVar(PsArrayAssocSymbol):
...
@@ -265,6 +224,3 @@ class PsArrayStrideVar(PsArrayAssocSymbol):
@property
@property
def
coordinate
(
self
)
->
int
:
def
coordinate
(
self
)
->
int
:
return
self
.
_coordinate
return
self
.
_coordinate
def
__getinitargs__
(
self
):
return
self
.
array
,
self
.
coordinate
,
self
.
dtype
This diff is collapsed.
Click to expand it.
src/pystencils/backend/jit/cpu_extension_module.py
+
4
−
4
View file @
ee64e7e1
...
@@ -17,8 +17,8 @@ from ..arrays import (
...
@@ -17,8 +17,8 @@ from ..arrays import (
PsLinearizedArray
,
PsLinearizedArray
,
PsArrayAssocSymbol
,
PsArrayAssocSymbol
,
PsArrayBasePointer
,
PsArrayBasePointer
,
PsArrayShape
Var
,
PsArrayShape
Symbol
,
PsArrayStride
Var
,
PsArrayStride
Symbol
,
)
)
from
..types
import
(
from
..types
import
(
PsAbstractType
,
PsAbstractType
,
...
@@ -290,12 +290,12 @@ if( !kwargs || !PyDict_Check(kwargs) ) {{
...
@@ -290,12 +290,12 @@ if( !kwargs || !PyDict_Check(kwargs) ) {{
match
variable
:
match
variable
:
case
PsArrayBasePointer
():
case
PsArrayBasePointer
():
code
=
f
"
{
variable
.
dtype
}
{
variable
.
name
}
= (
{
variable
.
dtype
}
)
{
buffer
}
.buf;
"
code
=
f
"
{
variable
.
dtype
}
{
variable
.
name
}
= (
{
variable
.
dtype
}
)
{
buffer
}
.buf;
"
case
PsArrayShape
Var
():
case
PsArrayShape
Symbol
():
coord
=
variable
.
coordinate
coord
=
variable
.
coordinate
code
=
(
code
=
(
f
"
{
variable
.
dtype
}
{
variable
.
name
}
=
{
buffer
}
.shape[
{
coord
}
];
"
f
"
{
variable
.
dtype
}
{
variable
.
name
}
=
{
buffer
}
.shape[
{
coord
}
];
"
)
)
case
PsArrayStride
Var
():
case
PsArrayStride
Symbol
():
coord
=
variable
.
coordinate
coord
=
variable
.
coordinate
code
=
(
code
=
(
f
"
{
variable
.
dtype
}
{
variable
.
name
}
=
"
f
"
{
variable
.
dtype
}
{
variable
.
name
}
=
"
...
...
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