cupy.cuda.Stream¶
- class cupy.cuda.Stream(null=False, non_blocking=False, ptds=False)[source]¶
CUDA stream.
This class handles the CUDA stream handle in RAII way, i.e., when an Stream instance is destroyed by the GC, its handle is also destroyed.
Note that if both
nullandptdsareFalse, a plain new stream is created.- Parameters
null (bool) – If
True, the stream is a null stream (i.e. the default stream that synchronizes with all streams). Note that you can also use theStream.nullsingleton object instead of creating a new null stream object.ptds (bool) – If
TrueandnullisFalse, the per-thread default stream is used. Note that you can also use theStream.ptdssingleton object instead of creating a new per-thread default stream object.non_blocking (bool) – If
Trueand bothnullandptdsareFalse, the stream does not synchronize with the NULL stream.
- Variables
ptr (intptr_t) – Raw stream handle.
device_id (int) – The ID of the device that the stream was created on. The value
-1is used for the singleton stream objects.
Methods
- __enter__(self)¶
- __exit__(self, *args)¶
- add_callback(self, callback, arg)¶
Adds a callback that is called when all queued work is done.
- Parameters
callback (function) – Callback function. It must take three arguments (Stream object, int error status, and user data object), and returns nothing.
arg (object) – Argument to the callback.
Note
Whenever possible, use the
launch_host_func()method instead of this one, as it may be deprecated and removed from CUDA at some point.
- launch_host_func(self, callback, arg)¶
Launch a callback on host when all queued work is done.
- Parameters
callback (function) – Callback function. It must take only one argument (user data object), and returns nothing.
arg (object) – Argument to the callback.
Note
Whenever possible, this method is recommended over
add_callback(), which may be deprecated and removed from CUDA at some point.See also
- record(self, event=None)¶
Records an event on the stream.
- Parameters
event (None or cupy.cuda.Event) – CUDA event. If
None, then a new plain event is created and used.- Returns
The recorded event.
- Return type
See also
- synchronize(self)¶
Waits for the stream completing all queued work.
- use(self)¶
Makes this stream current.
If you want to switch a stream temporarily, use the with statement.
- wait_event(self, event)¶
Makes the stream wait for an event.
The future work on this stream will be done after the event.
- Parameters
event (cupy.cuda.Event) – CUDA event.
- __eq__(self, other)¶
- __ne__(value, /)¶
Return self!=value.
- __lt__(value, /)¶
Return self<value.
- __le__(value, /)¶
Return self<=value.
- __gt__(value, /)¶
Return self>value.
- __ge__(value, /)¶
Return self>=value.
Attributes
- done¶
True if all work on this stream has been done.
- null = <Stream 0 (device -1)>¶
- ptds = <Stream 2 (device -1)>¶