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
Markus Holzer
pystencils
Commits
77e4f5e6
Commit
77e4f5e6
authored
4 years ago
by
Michael Kuron
Browse files
Options
Downloads
Patches
Plain Diff
Automatically align to what is required for vectorization
If this cannot be detected because cpuinfo is missing, use 512 bit
parent
facd3ab4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pystencils/alignedarray.py
+16
-3
16 additions, 3 deletions
pystencils/alignedarray.py
with
16 additions
and
3 deletions
pystencils/alignedarray.py
+
16
−
3
View file @
77e4f5e6
import
numpy
as
np
import
numpy
as
np
from
pystencils.data_types
import
BasicType
def
aligned_empty
(
shape
,
byte_alignment
=
32
,
dtype
=
np
.
float64
,
byte_offset
=
0
,
order
=
'
C
'
,
align_inner_coordinate
=
True
):
def
aligned_empty
(
shape
,
byte_alignment
=
True
,
dtype
=
np
.
float64
,
byte_offset
=
0
,
order
=
'
C
'
,
align_inner_coordinate
=
True
):
"""
"""
Creates an aligned empty numpy array
Creates an aligned empty numpy array
Args:
Args:
shape: size of the array
shape: size of the array
byte_alignment: alignment in bytes, for the start address of the array holds (a % byte_alignment) == 0
byte_alignment: alignment in bytes, for the start address of the array holds (a % byte_alignment) == 0
By default, use the maximum required by the CPU (or 512 bits if this cannot be detected).
dtype: numpy data type
dtype: numpy data type
byte_offset: offset in bytes for position that should be aligned i.e. (a+byte_offset) % byte_alignment == 0
byte_offset: offset in bytes for position that should be aligned i.e. (a+byte_offset) % byte_alignment == 0
typically used to align first inner cell instead of ghost layer
typically used to align first inner cell instead of ghost layer
order: storage linearization order
order: storage linearization order
align_inner_coordinate: if True, the start of the innermost coordinate lines are aligned as well
align_inner_coordinate: if True, the start of the innermost coordinate lines are aligned as well
"""
"""
if
byte_alignment
is
True
:
from
pystencils.backends.simd_instruction_sets
import
(
get_supported_instruction_sets
,
get_vector_instruction_set
)
type_name
=
BasicType
.
numpy_name_to_c
(
np
.
dtype
(
dtype
).
name
)
instruction_sets
=
get_supported_instruction_sets
()
if
instruction_sets
is
None
:
byte_alignment
=
64
else
:
byte_alignment
=
max
([
get_vector_instruction_set
(
type_name
,
is_name
)[
'
width
'
]
*
np
.
dtype
(
dtype
).
itemsize
for
is_name
in
instruction_sets
])
if
(
not
align_inner_coordinate
)
or
(
not
hasattr
(
shape
,
'
__len__
'
)):
if
(
not
align_inner_coordinate
)
or
(
not
hasattr
(
shape
,
'
__len__
'
)):
size
=
np
.
prod
(
shape
)
size
=
np
.
prod
(
shape
)
d
=
np
.
dtype
(
dtype
)
d
=
np
.
dtype
(
dtype
)
...
@@ -51,7 +64,7 @@ def aligned_empty(shape, byte_alignment=32, dtype=np.float64, byte_offset=0, ord
...
@@ -51,7 +64,7 @@ def aligned_empty(shape, byte_alignment=32, dtype=np.float64, byte_offset=0, ord
return
tmp
return
tmp
def
aligned_zeros
(
shape
,
byte_alignment
=
16
,
dtype
=
float
,
byte_offset
=
0
,
order
=
'
C
'
,
align_inner_coordinate
=
True
):
def
aligned_zeros
(
shape
,
byte_alignment
=
True
,
dtype
=
float
,
byte_offset
=
0
,
order
=
'
C
'
,
align_inner_coordinate
=
True
):
arr
=
aligned_empty
(
shape
,
dtype
=
dtype
,
byte_offset
=
byte_offset
,
arr
=
aligned_empty
(
shape
,
dtype
=
dtype
,
byte_offset
=
byte_offset
,
order
=
order
,
byte_alignment
=
byte_alignment
,
align_inner_coordinate
=
align_inner_coordinate
)
order
=
order
,
byte_alignment
=
byte_alignment
,
align_inner_coordinate
=
align_inner_coordinate
)
x
=
np
.
zeros
((),
arr
.
dtype
)
x
=
np
.
zeros
((),
arr
.
dtype
)
...
@@ -59,7 +72,7 @@ def aligned_zeros(shape, byte_alignment=16, dtype=float, byte_offset=0, order='C
...
@@ -59,7 +72,7 @@ def aligned_zeros(shape, byte_alignment=16, dtype=float, byte_offset=0, order='C
return
arr
return
arr
def
aligned_ones
(
shape
,
byte_alignment
=
16
,
dtype
=
float
,
byte_offset
=
0
,
order
=
'
C
'
,
align_inner_coordinate
=
True
):
def
aligned_ones
(
shape
,
byte_alignment
=
True
,
dtype
=
float
,
byte_offset
=
0
,
order
=
'
C
'
,
align_inner_coordinate
=
True
):
arr
=
aligned_empty
(
shape
,
dtype
=
dtype
,
byte_offset
=
byte_offset
,
arr
=
aligned_empty
(
shape
,
dtype
=
dtype
,
byte_offset
=
byte_offset
,
order
=
order
,
byte_alignment
=
byte_alignment
,
align_inner_coordinate
=
align_inner_coordinate
)
order
=
order
,
byte_alignment
=
byte_alignment
,
align_inner_coordinate
=
align_inner_coordinate
)
x
=
np
.
ones
((),
arr
.
dtype
)
x
=
np
.
ones
((),
arr
.
dtype
)
...
...
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