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
a39e2997
Commit
a39e2997
authored
2 years ago
by
Alexandru Fikl
Committed by
Andreas Klöckner
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
clean up docs for ReductionKernel
parent
17074c59
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/algorithm.rst
+1
-44
1 addition, 44 deletions
doc/algorithm.rst
pyopencl/reduction.py
+52
-2
52 additions, 2 deletions
pyopencl/reduction.py
with
53 additions
and
46 deletions
doc/algorithm.rst
+
1
−
44
View file @
a39e2997
...
...
@@ -31,50 +31,7 @@ Sums and counts ("reduce")
.. module:: pyopencl.reduction
.. class:: ReductionKernel(ctx, dtype_out, neutral, reduce_expr, map_expr=None, arguments=None, name="reduce_kernel", options=[], preamble="")
Generate a kernel that takes a number of scalar or vector *arguments*
(at least one vector argument), performs the *map_expr* on each entry of
the vector argument and then the *reduce_expr* on the outcome of that.
*neutral* serves as an initial value. *preamble* offers the possibility
to add preprocessor directives and other code (such as helper functions)
to be added before the actual reduction kernel code.
Vectors in *map_expr* should be indexed by the variable *i*. *reduce_expr*
uses the formal values "a" and "b" to indicate two operands of a binary
reduction operation. If you do not specify a *map_expr*, ``in[i]`` is
automatically assumed and treated as the only one input argument.
*dtype_out* specifies the :class:`numpy.dtype` in which the reduction is
performed and in which the result is returned. *neutral* is specified as
float or integer formatted as string. *reduce_expr* and *map_expr* are
specified as string formatted operations and *arguments* is specified as a
string formatted as a C argument list. *name* specifies the name as which
the kernel is compiled. *options* are passed unmodified to
:meth:`pyopencl.Program.build`. *preamble* specifies a string of code that
is inserted before the actual kernels.
.. method:: __call__(*args, queue=None, wait_for=None, return_event=False, out=None)
|explain-waitfor|
With *out* the resulting single-entry :class:`pyopencl.array.Array` can
be specified. Because offsets are supported one can store results
anywhere (e.g. ``out=a[3]``).
:return: the resulting scalar as a single-entry :class:`pyopencl.array.Array`
if *return_event* is *False*, otherwise a tuple ``(scalar_array, event)``.
.. note::
The returned :class:`pyopencl.Event` corresponds only to part of the
execution of the reduction. It is not suitable for profiling.
.. versionadded:: 2011.1
.. versionchanged:: 2014.2
Added *out* parameter.
.. autoclass:: ReductionKernel
Here's a usage example::
...
...
This diff is collapsed.
Click to expand it.
pyopencl/reduction.py
+
52
−
2
View file @
a39e2997
...
...
@@ -268,6 +268,33 @@ _SMALL_SEQ_COUNT = 4
class
ReductionKernel
:
"""
A kernel that performs a generic reduction on arrays.
Generate a kernel that takes a number of scalar or vector *arguments*
(at least one vector argument), performs the *map_expr* on each entry of
the vector argument and then the *reduce_expr* on the outcome of that.
*neutral* serves as an initial value. *preamble* offers the possibility
to add preprocessor directives and other code (such as helper functions)
to be added before the actual reduction kernel code.
Vectors in *map_expr* should be indexed by the variable *i*. *reduce_expr*
uses the formal values
"
a
"
and
"
b
"
to indicate two operands of a binary
reduction operation. If you do not specify a *map_expr*, ``in[i]`` is
automatically assumed and treated as the only one input argument.
*dtype_out* specifies the :class:`numpy.dtype` in which the reduction is
performed and in which the result is returned. *neutral* is specified as
float or integer formatted as string. *reduce_expr* and *map_expr* are
specified as string formatted operations and *arguments* is specified as a
string formatted as a C argument list. *name* specifies the name as which
the kernel is compiled. *options* are passed unmodified to
:meth:`pyopencl.Program.build`. *preamble* specifies a string of code that
is inserted before the actual kernels.
.. automethod:: __init__
.. automethod:: __call__
"""
def
__init__
(
self
,
ctx
:
cl
.
Context
,
...
...
@@ -316,7 +343,25 @@ class ReductionKernel:
max_group_size
=
max_group_size
)
def
__call__
(
self
,
*
args
:
Any
,
**
kwargs
:
Any
)
->
cl
.
Event
:
"""
"""
Invoke the generated kernel.
|explain-waitfor|
With *out* the resulting single-entry :class:`pyopencl.array.Array` can
be specified. Because offsets are supported one can store results
anywhere (e.g. ``out=a[3]``).
.. note::
The returned :class:`pyopencl.Event` corresponds only to part of the
execution of the reduction. It is not suitable for profiling.
.. versionadded:: 2011.1
.. versionchanged:: 2014.2
Added *out* parameter.
.. versionchanged:: 2016.2
*range_* and *slice_* added.
...
...
@@ -328,7 +373,12 @@ class ReductionKernel:
Specifies the range of indices on which the kernel will be
executed, relative to the first vector-like argument.
May not be given at the same time as *range*.
:arg allocator:
:arg return_event: a boolean flag used to return an event for the
reduction.
:return: the resulting scalar as a single-entry :class:`pyopencl.array.Array`
if *return_event* is *False*, otherwise a tuple
``(scalar_array, event)``.
"""
queue
=
kwargs
.
pop
(
"
queue
"
,
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