latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
ExternalStream
- class tensorplay.cuda.streams.ExternalStream(stream_ptr, device=None, **kwargs)[source]
Wrapper around an externally allocated CUDA stream.
This class is used to wrap streams allocated in other libraries in order to facilitate data exchange and multi-library interactions.
Note
This class doesn’t manage the stream life-cycle, it is the user responsibility to keep the referenced stream alive while this class is being used.
- Parameters:
stream_ptr (int) – Integer representation of the cudaStream_t value allocated externally.
device (tensorplay.Device or int, optional) – the device where the stream was originally allocated. If device is specified incorrectly, subsequent launches using this stream may fail.
- query() bool
Check if all the work submitted has been completed.
- Returns:
A boolean indicating if all kernels in this stream are completed.
- Return type:
Example:
>>> s_cuda = tensorplay.Stream(device='cuda') >>> s_cuda.query() True
- record_event(event) Event
Record an event. En-queuing it into the Stream to allow further synchronization from the current point in the FIFO queue.
- Parameters:
event (
tensorplay.Event, optional) – event to record. If not given, a new one will be allocated.- Returns:
Recorded event.
- Return type:
Example:
>>> s_cuda = tensorplay.Stream(device='cuda') >>> e_cuda = s_cuda.record_event()
- synchronize() None
Wait for all the kernels in this stream to complete.
Example:
>>> s_cuda = tensorplay.Stream(device='cuda') >>> s_cuda.synchronize()
- wait_event(event) None
Make all future work submitted to the stream wait for an event.
- Parameters:
event (
tensorplay.Event) – an event to wait for.
Example:
>>> s1_cuda = tensorplay.Stream(device='cuda') >>> s2_cuda = tensorplay.Stream(device='cuda') >>> e_cuda = s1_cuda.record_event() >>> s2_cuda.wait_event(e_cuda)
- wait_stream(stream) None
Synchronize with another stream. All future work submitted to this stream will wait until all kernels already submitted to the given stream are completed.
- Parameters:
stream (
tensorplay.Stream) – a stream to synchronize.
Example:
>>> s1_cuda = tensorplay.Stream(device='cuda') >>> s2_cuda = tensorplay.Stream(device='cuda') >>> s2_cuda.wait_stream(s1_cuda)
Help improve this page
Found an error, an unclear step, or a missing example?

