# ExternalStream Source: https://www.tensorplay.cn/docs/generated/tensorplay.cuda.streams.ExternalStream.html ```python class tensorplay.cuda.streams.ExternalStream(stream_ptr, device=None, **kwargs) ``` 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](https://docs.python.org/3/builtins/functions.html#int)) – Integer representation of the cudaStream_t value allocated externally. - device ([tensorplay.Device](/docs/generated/tensorplay.Device.html#tensorplay.Device) or [int](https://docs.python.org/3/builtins/functions.html#int), optional) – the device where the stream was originally allocated. If device is specified incorrectly, subsequent launches using this stream may fail. ```python 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: [bool](https://docs.python.org/3/builtins/functions.html#bool) Example: ``` >>> s_cuda = tensorplay.Stream(device='cuda') >>> s_cuda.query() True ``` ```python 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: [Event](/docs/generated/tensorplay.cuda.streams.Event.html#tensorplay.cuda.streams.Event) Example: ``` >>> s_cuda = tensorplay.Stream(device='cuda') >>> e_cuda = s_cuda.record_event() ``` ```python synchronize() → None ``` Wait for all the kernels in this stream to complete. Example: ``` >>> s_cuda = tensorplay.Stream(device='cuda') >>> s_cuda.synchronize() ``` ```python 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) ``` ```python 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) ```