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
Stephan Seitz
pystencils
Commits
ecb1614f
Commit
ecb1614f
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Implement fast approximations for OpenCL: fast_division, fast_inv_sqrt, fast_sqrt
parent
bc556567
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/backends/opencl_backend.py
+15
-2
15 additions, 2 deletions
pystencils/backends/opencl_backend.py
with
15 additions
and
2 deletions
pystencils/backends/opencl_backend.py
+
15
−
2
View file @
ecb1614f
...
@@ -2,6 +2,7 @@ import pystencils.data_types
...
@@ -2,6 +2,7 @@ import pystencils.data_types
from
pystencils.astnodes
import
Node
from
pystencils.astnodes
import
Node
from
pystencils.backends.cbackend
import
CustomSympyPrinter
,
generate_c
from
pystencils.backends.cbackend
import
CustomSympyPrinter
,
generate_c
from
pystencils.backends.cuda_backend
import
CudaBackend
,
CudaSympyPrinter
from
pystencils.backends.cuda_backend
import
CudaBackend
,
CudaSympyPrinter
from
pystencils.fast_approximation
import
fast_division
,
fast_inv_sqrt
,
fast_sqrt
def
generate_opencl
(
astnode
:
Node
,
signature_only
:
bool
=
False
)
->
str
:
def
generate_opencl
(
astnode
:
Node
,
signature_only
:
bool
=
False
)
->
str
:
...
@@ -67,5 +68,17 @@ class OpenClSympyPrinter(CudaSympyPrinter):
...
@@ -67,5 +68,17 @@ class OpenClSympyPrinter(CudaSympyPrinter):
def
_print_TextureAccess
(
self
,
node
):
def
_print_TextureAccess
(
self
,
node
):
raise
NotImplementedError
()
raise
NotImplementedError
()
# Avoid usage of CUDA intrinsics
# For math functions, OpenCL is more similar to the C++ printer CustomSympyPrinter
_print_Function
=
CustomSympyPrinter
.
_print_Function
# since built-in math functions are generic.
# In CUDA, you have to differentiate between `sin` and `sinf`
_print_math_func
=
CustomSympyPrinter
.
_print_math_func
_print_Pow
=
CustomSympyPrinter
.
_print_Pow
def
_print_Function
(
self
,
expr
):
if
isinstance
(
expr
,
fast_division
):
return
"
native_divide(%s, %s)
"
%
tuple
(
self
.
_print
(
a
)
for
a
in
expr
.
args
)
elif
isinstance
(
expr
,
fast_sqrt
):
return
"
native_sqrt(%s)
"
%
tuple
(
self
.
_print
(
a
)
for
a
in
expr
.
args
)
elif
isinstance
(
expr
,
fast_inv_sqrt
):
return
"
native_rsqrt(%s)
"
%
tuple
(
self
.
_print
(
a
)
for
a
in
expr
.
args
)
return
CustomSympyPrinter
.
_print_Function
(
self
,
expr
)
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