Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pyopencl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Klöckner
pyopencl
Commits
ff42f561
Commit
ff42f561
authored
12 years ago
by
Andreas Klöckner
Browse files
Options
Downloads
Patches
Plain Diff
Warn about use of 'return' in elementwise kernels. Add PYOPENCL_ELWISE_CONTINUE.
parent
9e3fef65
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/source/algorithm.rst
+1
-15
1 addition, 15 deletions
doc/source/algorithm.rst
pyopencl/elementwise.py
+33
-0
33 additions, 0 deletions
pyopencl/elementwise.py
with
34 additions
and
15 deletions
doc/source/algorithm.rst
+
1
−
15
View file @
ff42f561
...
@@ -12,21 +12,7 @@ is created for each intermediate result. The functionality in the module
...
@@ -12,21 +12,7 @@ is created for each intermediate result. The functionality in the module
:mod:`pyopencl.elementwise` contains tools to help generate kernels that
:mod:`pyopencl.elementwise` contains tools to help generate kernels that
evaluate multi-stage expressions on one or several operands in a single pass.
evaluate multi-stage expressions on one or several operands in a single pass.
.. class:: ElementwiseKernel(context, arguments, operation, name="kernel", preamble="", options=[])
.. autoclass:: ElementwiseKernel(context, arguments, operation, name="kernel", preamble="", options=[])
Generate a kernel that takes a number of scalar or vector *arguments*
and performs the scalar *operation* on each entry of its arguments, if that
argument is a vector.
*arguments* is specified as a string formatted as a C argument list.
*operation* is specified as a C assignment statement, without a semicolon.
Vectors in *operation* should be indexed by the variable *i*.
*name* specifies the name as which the kernel is compiled,
and *options* are passed unmodified to :meth:`pyopencl.Program.build`.
*preamble* is a piece of C source code that gets inserted outside of the
function context in the elementwise operation's kernel source code.
.. method:: __call__(*args, wait_for=None)
.. method:: __call__(*args, wait_for=None)
...
...
This diff is collapsed.
Click to expand it.
pyopencl/elementwise.py
+
33
−
0
View file @
ff42f561
...
@@ -70,9 +70,20 @@ def get_elwise_program(context, arguments, operation,
...
@@ -70,9 +70,20 @@ def get_elwise_program(context, arguments, operation,
}
}
"""
"""
import
re
return_match
=
re
.
search
(
r
"
\breturn\b
"
,
operation
);
if
return_match
is
not
None
:
from
warnings
import
warn
warn
(
"
Using a
'
return
'
statement in an element-wise operation will likely
"
"
lead to incorrect results. Use PYOPENCL_ELWISE_CONTINUE instead.
"
,
stacklevel
=
3
)
source
=
(
"""
//CL//
source
=
(
"""
//CL//
%(preamble)s
%(preamble)s
#define PYOPENCL_ELWISE_CONTINUE continue
__kernel void %(name)s(%(arguments)s)
__kernel void %(name)s(%(arguments)s)
{
{
int lid = get_local_id(0);
int lid = get_local_id(0);
...
@@ -168,6 +179,28 @@ def get_elwise_kernel(context, arguments, operation,
...
@@ -168,6 +179,28 @@ def get_elwise_kernel(context, arguments, operation,
# {{{ ElementwiseKernel driver
# {{{ ElementwiseKernel driver
class
ElementwiseKernel
:
class
ElementwiseKernel
:
"""
A kernel that takes a number of scalar or vector *arguments* and performs
an *operation* specified as a snippet of C on these arguments.
:arg arguments: a string formatted as a C argument list.
:arg operation: a snippet of C that carries out the desired
'
map
'
operation.
The current index is available as the variable *i*.
*operation* may contain the statement ``PYOPENCL_ELWISE_CONTINUE``, which
will terminate processing for the current element.
:arg name: the function name as which the kernel is compiled
:arg options: passed unmodified to :meth:`pyopencl.Program.build`.
:arg preamble: a piece of C source code that gets inserted outside of the
function context in the elementwise operation
'
s kernel source code.
.. warning :: Using a `return` statement in *operation* will lead to incorrect
results, as some elements may never get processed. Use ``PYOPENCL_ELWISE_CONTINUE``
instead.
.. versionchanged:: 2013.1
Added ``PYOPENCL_ELWISE_CONTINUE``.
"""
def
__init__
(
self
,
context
,
arguments
,
operation
,
def
__init__
(
self
,
context
,
arguments
,
operation
,
name
=
"
elwise_kernel
"
,
options
=
[],
**
kwargs
):
name
=
"
elwise_kernel
"
,
options
=
[],
**
kwargs
):
self
.
context
=
context
self
.
context
=
context
...
...
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