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
e607e5bd
Commit
e607e5bd
authored
5 years ago
by
Martin Bauer
Browse files
Options
Downloads
Patches
Plain Diff
Formatting and style
parent
c391dbb6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
pystencils/backends/cbackend.py
+1
-8
1 addition, 8 deletions
pystencils/backends/cbackend.py
pystencils/backends/cuda_backend.py
+6
-9
6 additions, 9 deletions
pystencils/backends/cuda_backend.py
pystencils/cpu/cpujit.py
+1
-2
1 addition, 2 deletions
pystencils/cpu/cpujit.py
with
8 additions
and
19 deletions
pystencils/backends/cbackend.py
+
1
−
8
View file @
e607e5bd
...
@@ -22,18 +22,11 @@ try:
...
@@ -22,18 +22,11 @@ try:
except
ImportError
:
except
ImportError
:
from
sympy.printing.ccode
import
CCodePrinter
# for sympy versions < 1.1
from
sympy.printing.ccode
import
CCodePrinter
# for sympy versions < 1.1
__all__
=
[
'
generate_c
'
,
'
CustomCodeNode
'
,
'
PrintNode
'
,
'
get_headers
'
,
'
CustomSympyPrinter
'
]
__all__
=
[
'
generate_c
'
,
'
CustomCodeNode
'
,
'
PrintNode
'
,
'
get_headers
'
,
'
CustomSympyPrinter
'
]
KERNCRAFT_NO_TERNARY_MODE
=
False
KERNCRAFT_NO_TERNARY_MODE
=
False
class
UnsupportedCDialect
(
Exception
):
def
__init__
(
self
):
super
(
UnsupportedCDialect
,
self
).
__init__
()
def
generate_c
(
ast_node
:
Node
,
signature_only
:
bool
=
False
,
dialect
=
'
c
'
,
custom_backend
=
None
)
->
str
:
def
generate_c
(
ast_node
:
Node
,
signature_only
:
bool
=
False
,
dialect
=
'
c
'
,
custom_backend
=
None
)
->
str
:
"""
Prints an abstract syntax tree node as C or CUDA code.
"""
Prints an abstract syntax tree node as C or CUDA code.
...
@@ -63,7 +56,7 @@ def generate_c(ast_node: Node, signature_only: bool = False, dialect='c', custom
...
@@ -63,7 +56,7 @@ def generate_c(ast_node: Node, signature_only: bool = False, dialect='c', custom
from
pystencils.backends.cuda_backend
import
CudaBackend
from
pystencils.backends.cuda_backend
import
CudaBackend
printer
=
CudaBackend
(
signature_only
=
signature_only
)
printer
=
CudaBackend
(
signature_only
=
signature_only
)
else
:
else
:
raise
UnsupportedCD
ialect
raise
ValueError
(
"
Unknown dialect:
"
+
str
(
d
ialect
))
code
=
printer
(
ast_node
)
code
=
printer
(
ast_node
)
if
not
signature_only
and
isinstance
(
ast_node
,
KernelFunction
):
if
not
signature_only
and
isinstance
(
ast_node
,
KernelFunction
):
code
=
"
\n
"
+
code
code
=
"
\n
"
+
code
...
...
This diff is collapsed.
Click to expand it.
pystencils/backends/cuda_backend.py
+
6
−
9
View file @
e607e5bd
from
os.path
import
dirname
,
join
from
os.path
import
dirname
,
join
from
pystencils.astnodes
import
Node
from
pystencils.astnodes
import
Node
from
pystencils.backends.cbackend
import
(
CBackend
,
CustomSympyPrinter
,
from
pystencils.backends.cbackend
import
CBackend
,
CustomSympyPrinter
,
generate_c
generate_c
)
from
pystencils.fast_approximation
import
fast_division
,
fast_inv_sqrt
,
fast_sqrt
from
pystencils.fast_approximation
import
(
fast_division
,
fast_inv_sqrt
,
fast_sqrt
)
CUDA_KNOWN_FUNCTIONS
=
None
with
open
(
join
(
dirname
(
__file__
),
'
cuda_known_functions.txt
'
))
as
f
:
with
open
(
join
(
dirname
(
__file__
),
'
cuda_known_functions.txt
'
))
as
f
:
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
CUDA_KNOWN_FUNCTIONS
=
{
l
.
strip
():
l
.
strip
()
for
l
in
lines
if
l
}
CUDA_KNOWN_FUNCTIONS
=
{
l
.
strip
():
l
.
strip
()
for
l
in
lines
if
l
}
...
@@ -17,8 +13,8 @@ def generate_cuda(astnode: Node, signature_only: bool = False) -> str:
...
@@ -17,8 +13,8 @@ def generate_cuda(astnode: Node, signature_only: bool = False) -> str:
"""
Prints an abstract syntax tree node as CUDA code.
"""
Prints an abstract syntax tree node as CUDA code.
Args:
Args:
ast
_
node:
astnode:
KernelFunction node to generate code for
signature_only:
signature_only:
if True only the signature is printed
Returns:
Returns:
C-like code for the ast node and its descendants
C-like code for the ast node and its descendants
...
@@ -41,7 +37,8 @@ class CudaBackend(CBackend):
...
@@ -41,7 +37,8 @@ class CudaBackend(CBackend):
name
=
self
.
sympy_printer
.
doprint
(
node
.
symbol
.
name
),
name
=
self
.
sympy_printer
.
doprint
(
node
.
symbol
.
name
),
num_elements
=
'
*
'
.
join
([
str
(
s
)
for
s
in
node
.
shared_mem
.
shape
]))
num_elements
=
'
*
'
.
join
([
str
(
s
)
for
s
in
node
.
shared_mem
.
shape
]))
def
_print_ThreadBlockSynchronization
(
self
,
node
):
@staticmethod
def
_print_ThreadBlockSynchronization
(
node
):
code
=
"
__synchtreads();
"
code
=
"
__synchtreads();
"
return
code
return
code
...
...
This diff is collapsed.
Click to expand it.
pystencils/cpu/cpujit.py
+
1
−
2
View file @
e607e5bd
...
@@ -60,8 +60,7 @@ from appdirs import user_cache_dir, user_config_dir
...
@@ -60,8 +60,7 @@ from appdirs import user_cache_dir, user_config_dir
from
pystencils
import
FieldType
from
pystencils
import
FieldType
from
pystencils.backends.cbackend
import
generate_c
,
get_headers
from
pystencils.backends.cbackend
import
generate_c
,
get_headers
from
pystencils.include
import
get_pystencils_include_path
from
pystencils.include
import
get_pystencils_include_path
from
pystencils.utils
import
(
atomic_file_write
,
file_handle_for_atomic_write
,
from
pystencils.utils
import
atomic_file_write
,
file_handle_for_atomic_write
,
recursive_dict_update
recursive_dict_update
)
def
make_python_function
(
kernel_function_node
,
custom_backend
=
None
):
def
make_python_function
(
kernel_function_node
,
custom_backend
=
None
):
...
...
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