cupy.cuda.ExternalStream

class cupy.cuda.ExternalStream(ptr, device_id=- 1)[source]

CUDA stream not managed by CuPy.

This class allows to use external streams in CuPy by providing the stream pointer obtained from the CUDA runtime call. The user is in charge of managing the life-cycle of the stream.

Parameters
  • ptr (intptr_t) – Address of the cudaStream_t object.

  • device_id (int) – The ID of the device that the stream was created on. Default is -1, indicating it is unknown.

Variables
  • ptr (intptr_t) – Raw stream handle.

  • device_id (int) – The ID of the device that the stream was created on. The value -1 is used to indicate it is unknown.

Warning

If device_id is not specified, the user is required to ensure legal operations of the stream. Specifically, the stream must be used on the device that it was created on.

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.

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

cupy.cuda.Event

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.