1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
.. include:: subst.rst
OpenCL Runtime: Command Queues and Events
=========================================
.. currentmodule:: pyopencl
Command Queue
-------------
.. class:: CommandQueue(context, device=None, properties=None)
Create a new command queue. *properties* is a bit field
consisting of :class:`command_queue_properties` values.
If *device* is None, one of the devices in *context* is chosen
in an implementation-defined manner.
*properties* may be a bitwise combination of values from
:class:`queue_properties` (or *None* which is equivalent to
passing *0*). This is compatible with both OpenCL 1.x and 2.x.
For OpenCL 2.0 and above, *properties* may also be a sequence
of keys and values from :class:`queue_properties` as accepted
by :c:func:`clCreateCommandQueueWithProperties` (see the OpenCL
spec for details). The trailing *0* is added automatically
and does not need to be included.
A :class:`CommandQueue` may be used as a context manager, like this::
with cl.CommandQueue(self.cl_context) as queue:
enqueue_stuff(queue, ...)
:meth:`finish` is automatically called at the end of the ``with``-delimited
context, and further operations on the queue are considered an error.
.. versionadded:: 2013.1
Context manager capability.
.. versionchanged:: 2018.2
Added the sequence-of-properties interface for OpenCL 2.
.. versionchanged:: 2022.1.4
Use of a command queue after its context manager completes
is now considered an error. :mod:`pyopencl` will warn about this
for a transitionary period and will start raising an exception
in 2023.
.. attribute:: info
Lower case versions of the :class:`command_queue_info` constants
may be used as attributes on instances of this class
to directly query info attributes.
.. method:: get_info(param)
See :class:`command_queue_info` for values of *param*.
.. method:: set_property(prop, enable)
See :class:`command_queue_properties` for possible values of *prop*.
*enable* is a :class:`bool`.
Unavailable in OpenCL 1.1 and newer.
.. method:: flush()
.. method:: finish()
.. automethod:: from_int_ptr
.. autoattribute:: int_ptr
|comparable|
Event
-----
.. class:: Event
.. attribute:: info
Lower case versions of the :class:`event_info` constants
may be used as attributes on instances of this class
to directly query info attributes.
.. attribute:: profile
An instance of :class:`ProfilingInfoGetter`.
.. method:: get_info(param)
See :class:`event_info` for values of *param*.
.. method:: get_profiling_info(param)
See :class:`profiling_info` for values of *param*.
See :attr:`profile` for an easier way of obtaining
the same information.
.. method:: wait()
.. automethod:: from_int_ptr
.. autoattribute:: int_ptr
.. method:: set_callback(type, cb)
Add the callback *cb* with signature ``cb(status)`` to the callback
queue for the event status *type* (one of the values of
:class:`command_execution_status`, except :attr:`command_execution_status.QUEUED`).
See the OpenCL specification for restrictions on what *cb* may and may not do.
.. versionadded:: 2015.2
|comparable|
.. class:: ProfilingInfoGetter
.. attribute:: info
Lower case versions of the :class:`profiling_info` constants
may be used as attributes on the attribute ``profile`` of this
class to directly query profiling info.
For example, you may use *evt.profile.end* instead of
*evt.get_profiling_info(pyopencl.profiling_info.END)*.
Event Subclasses
----------------
.. class:: UserEvent(context)
A subclass of :class:`Event`. Only available with OpenCL 1.1 and newer.
.. versionadded:: 0.92
.. method:: set_status(status)
See :class:`command_execution_status` for possible values of *status*.
.. class:: NannyEvent
Transfers between host and device return events of this type. They hold
a reference to the host-side buffer and wait for the transfer to complete
when they are freed. Therefore, they can safely release the reference to
the object they're guarding upon destruction.
A subclass of :class:`Event`.
.. versionadded:: 2011.2
.. method:: get_ward()
.. method:: wait()
In addition to performing the same wait as :meth:`Event.wait()`, this
method also releases the reference to the guarded object.
Synchronization Functions
-------------------------
.. function:: wait_for_events(events)
.. function:: enqueue_barrier(queue, wait_for=None)
Enqueues a barrier operation. which ensures that all queued commands in
command_queue have finished execution. This command is a synchronization
point.
.. versionadded:: 0.91.5
.. versionchanged:: 2011.2
Takes *wait_for* and returns an :class:`Event`
.. function:: enqueue_marker(queue, wait_for=None)
Returns an :class:`Event`.
.. versionchanged:: 2011.2
Takes *wait_for*.
|