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
5a88c472
Commit
5a88c472
authored
4 years ago
by
Michael Kuron
Browse files
Options
Downloads
Patches
Plain Diff
improve TemporayMemoryAllocation: don't align more than necessary, behave correctly on MSVC
parent
9c784763
No related branches found
No related tags found
1 merge request
!230
Improve non-temporal stores
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
pystencils/backends/cbackend.py
+21
-5
21 additions, 5 deletions
pystencils/backends/cbackend.py
with
21 additions
and
5 deletions
pystencils/backends/cbackend.py
+
21
−
5
View file @
5a88c472
...
...
@@ -296,14 +296,22 @@ class CBackend:
return
''
def
_print_TemporaryMemoryAllocation
(
self
,
node
):
align
=
64
parent
=
node
.
parent
while
parent
.
parent
is
not
None
:
parent
=
parent
.
parent
instruction_set
=
parent
.
instruction_set
if
instruction_set
:
align
=
instruction_set
[
'
width
'
]
*
node
.
symbol
.
dtype
.
base_type
.
numpy_dtype
.
type
(
0
).
nbytes
else
:
align
=
node
.
symbol
.
dtype
.
base_type
.
numpy_dtype
.
type
(
0
).
nbytes
np_dtype
=
node
.
symbol
.
dtype
.
base_type
.
numpy_dtype
required_size
=
np_dtype
.
itemsize
*
node
.
size
+
align
size
=
modulo_ceil
(
required_size
,
align
)
code
=
"
#if __cplusplus >= 201703L || __STDC_VERSION__ >= 201112L
\n
"
code
+=
"
{dtype} {name}=({dtype})aligned_alloc({align}, {size}) + {offset};
\n
"
code
+=
"
#elif defined(_MSC_VER)
\n
"
code
=
"
#if defined(_MSC_VER)
\n
"
code
+=
"
{dtype} {name}=({dtype})_aligned_malloc({size}, {align}) + {offset};
\n
"
code
+=
"
#elif __cplusplus >= 201703L || __STDC_VERSION__ >= 201112L
\n
"
code
+=
"
{dtype} {name}=({dtype})aligned_alloc({align}, {size}) + {offset};
\n
"
code
+=
"
#else
\n
"
code
+=
"
{dtype} {name};
\n
"
code
+=
"
posix_memalign((void**) &{name}, {align}, {size});
\n
"
...
...
@@ -316,7 +324,15 @@ class CBackend:
align
=
align
)
def
_print_TemporaryMemoryFree
(
self
,
node
):
align
=
64
parent
=
node
.
parent
while
parent
.
parent
is
not
None
:
parent
=
parent
.
parent
instruction_set
=
parent
.
instruction_set
if
instruction_set
:
align
=
instruction_set
[
'
width
'
]
*
node
.
symbol
.
dtype
.
base_type
.
numpy_dtype
.
type
(
0
).
nbytes
else
:
align
=
node
.
symbol
.
dtype
.
base_type
.
numpy_dtype
.
type
(
0
).
nbytes
code
=
"
#if defined(_MSC_VER)
\n
"
code
+=
"
_aligned_free(%s - %d);
\n
"
%
(
self
.
sympy_printer
.
doprint
(
node
.
symbol
.
name
),
node
.
offset
(
align
))
code
+=
"
#else
\n
"
...
...
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