cupy.cuda.Stream¶
- class cupy.cuda.Stream(null=False, non_blocking=False, ptds=False)¶
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
null
andptds
areFalse
, 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.null
singleton object instead of creating a new null stream object.ptds (bool) – If
True
andnull
isFalse
, the per-thread default stream is used. Note that you can also use theStream.ptds
singleton object instead of creating a new per-thread default stream object.non_blocking (bool) – If
True
and bothnull
andptds
areFalse
, the stream does not synchronize with the NULL stream.
- Variables
ptr (intptr_t) – Raw stream handle.
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>¶
- ptds = <Stream 2>¶