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
Package registry
Model registry
Operate
Environments
Terraform modules
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
itischler
pystencils
Commits
47aee5fa
Commit
47aee5fa
authored
5 years ago
by
Martin Bauer
Browse files
Options
Downloads
Plain Diff
Merge branch 'auto-for-assignments' into 'master'
Auto for assignments See merge request
!95
parents
9f6bbd4c
05aa005a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pystencils/astnodes.py
+2
-1
2 additions, 1 deletion
pystencils/astnodes.py
pystencils/backends/cbackend.py
+11
-7
11 additions, 7 deletions
pystencils/backends/cbackend.py
pystencils/kernelcreation.py
+8
-4
8 additions, 4 deletions
pystencils/kernelcreation.py
with
21 additions
and
12 deletions
pystencils/astnodes.py
+
2
−
1
View file @
47aee5fa
...
@@ -518,12 +518,13 @@ class LoopOverCoordinate(Node):
...
@@ -518,12 +518,13 @@ class LoopOverCoordinate(Node):
class
SympyAssignment
(
Node
):
class
SympyAssignment
(
Node
):
def
__init__
(
self
,
lhs_symbol
,
rhs_expr
,
is_const
=
True
):
def
__init__
(
self
,
lhs_symbol
,
rhs_expr
,
is_const
=
True
,
use_auto
=
False
):
super
(
SympyAssignment
,
self
).
__init__
(
parent
=
None
)
super
(
SympyAssignment
,
self
).
__init__
(
parent
=
None
)
self
.
_lhs_symbol
=
lhs_symbol
self
.
_lhs_symbol
=
lhs_symbol
self
.
rhs
=
sp
.
sympify
(
rhs_expr
)
self
.
rhs
=
sp
.
sympify
(
rhs_expr
)
self
.
_is_const
=
is_const
self
.
_is_const
=
is_const
self
.
_is_declaration
=
self
.
__is_declaration
()
self
.
_is_declaration
=
self
.
__is_declaration
()
self
.
use_auto
=
use_auto
def
__is_declaration
(
self
):
def
__is_declaration
(
self
):
if
isinstance
(
self
.
_lhs_symbol
,
cast_func
):
if
isinstance
(
self
.
_lhs_symbol
,
cast_func
):
...
...
This diff is collapsed.
Click to expand it.
pystencils/backends/cbackend.py
+
11
−
7
View file @
47aee5fa
...
@@ -33,9 +33,9 @@ def generate_c(ast_node: Node,
...
@@ -33,9 +33,9 @@ def generate_c(ast_node: Node,
with_globals
=
True
)
->
str
:
with_globals
=
True
)
->
str
:
"""
Prints an abstract syntax tree node as C or CUDA code.
"""
Prints an abstract syntax tree node as C or CUDA code.
This function does not need to distinguish between C, C++ or CUDA code, it just prints
'
C-like
'
code as encoded
This function does not need to distinguish
for most AST nodes
between C, C++ or CUDA code, it just prints
'
C-like
'
in the abstract syntax tree (AST). The AST is built differently for C or CUDA by calling different
create_kernel
code as encoded
in the abstract syntax tree (AST). The AST is built differently for C or CUDA by calling different
functions.
create_kernel
functions.
Args:
Args:
ast_node:
ast_node:
...
@@ -230,11 +230,15 @@ class CBackend:
...
@@ -230,11 +230,15 @@ class CBackend:
def
_print_SympyAssignment
(
self
,
node
):
def
_print_SympyAssignment
(
self
,
node
):
if
node
.
is_declaration
:
if
node
.
is_declaration
:
if
node
.
is_const
:
if
node
.
use_auto
:
prefix
=
'
const
'
data_type
=
'
auto
'
else
:
else
:
prefix
=
''
if
node
.
is_const
:
data_type
=
prefix
+
self
.
_print
(
node
.
lhs
.
dtype
).
replace
(
'
const
'
,
''
)
+
"
"
prefix
=
'
const
'
else
:
prefix
=
''
data_type
=
prefix
+
self
.
_print
(
node
.
lhs
.
dtype
).
replace
(
'
const
'
,
''
)
+
"
"
return
"
%s%s = %s;
"
%
(
data_type
,
return
"
%s%s = %s;
"
%
(
data_type
,
self
.
sympy_printer
.
doprint
(
node
.
lhs
),
self
.
sympy_printer
.
doprint
(
node
.
lhs
),
self
.
sympy_printer
.
doprint
(
node
.
rhs
))
self
.
sympy_printer
.
doprint
(
node
.
rhs
))
...
...
This diff is collapsed.
Click to expand it.
pystencils/kernelcreation.py
+
8
−
4
View file @
47aee5fa
...
@@ -26,7 +26,8 @@ def create_kernel(assignments,
...
@@ -26,7 +26,8 @@ def create_kernel(assignments,
gpu_indexing
=
'
block
'
,
gpu_indexing
=
'
block
'
,
gpu_indexing_params
=
MappingProxyType
({}),
gpu_indexing_params
=
MappingProxyType
({}),
use_textures_for_interpolation
=
True
,
use_textures_for_interpolation
=
True
,
cpu_prepend_optimizations
=
[]):
cpu_prepend_optimizations
=
[],
use_auto_for_assignments
=
False
):
"""
"""
Creates abstract syntax tree (AST) of kernel, using a list of update equations.
Creates abstract syntax tree (AST) of kernel, using a list of update equations.
...
@@ -102,12 +103,10 @@ def create_kernel(assignments,
...
@@ -102,12 +103,10 @@ def create_kernel(assignments,
vectorize
(
ast
,
**
cpu_vectorize_info
)
vectorize
(
ast
,
**
cpu_vectorize_info
)
else
:
else
:
raise
ValueError
(
"
Invalid value for cpu_vectorize_info
"
)
raise
ValueError
(
"
Invalid value for cpu_vectorize_info
"
)
return
ast
elif
target
==
'
llvm
'
:
elif
target
==
'
llvm
'
:
from
pystencils.llvm
import
create_kernel
from
pystencils.llvm
import
create_kernel
ast
=
create_kernel
(
assignments
,
type_info
=
data_type
,
split_groups
=
split_groups
,
ast
=
create_kernel
(
assignments
,
type_info
=
data_type
,
split_groups
=
split_groups
,
iteration_slice
=
iteration_slice
,
ghost_layers
=
ghost_layers
)
iteration_slice
=
iteration_slice
,
ghost_layers
=
ghost_layers
)
return
ast
elif
target
==
'
gpu
'
:
elif
target
==
'
gpu
'
:
from
pystencils.gpucuda
import
create_cuda_kernel
from
pystencils.gpucuda
import
create_cuda_kernel
ast
=
create_cuda_kernel
(
assignments
,
type_info
=
data_type
,
ast
=
create_cuda_kernel
(
assignments
,
type_info
=
data_type
,
...
@@ -115,10 +114,15 @@ def create_kernel(assignments,
...
@@ -115,10 +114,15 @@ def create_kernel(assignments,
iteration_slice
=
iteration_slice
,
ghost_layers
=
ghost_layers
,
iteration_slice
=
iteration_slice
,
ghost_layers
=
ghost_layers
,
skip_independence_check
=
skip_independence_check
,
skip_independence_check
=
skip_independence_check
,
use_textures_for_interpolation
=
use_textures_for_interpolation
)
use_textures_for_interpolation
=
use_textures_for_interpolation
)
return
ast
else
:
else
:
raise
ValueError
(
"
Unknown target %s. Has to be one of
'
cpu
'
,
'
gpu
'
or
'
llvm
'
"
%
(
target
,))
raise
ValueError
(
"
Unknown target %s. Has to be one of
'
cpu
'
,
'
gpu
'
or
'
llvm
'
"
%
(
target
,))
if
use_auto_for_assignments
:
for
a
in
ast
.
atoms
(
SympyAssignment
):
a
.
use_auto
=
True
return
ast
def
create_indexed_kernel
(
assignments
,
def
create_indexed_kernel
(
assignments
,
index_fields
,
index_fields
,
...
...
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