Stream¶
- class paddle.device. Stream ( device=None, priority=2, stream_base=None ) [source]
-
A device stream wrapper around StreamBase.
- Parameters
-
device (str|paddle.CUDAPlace(n)|paddle.CustomPlace(n)) – Which device the stream run on. If device is None, the device is the current device. Default: None. It can be
gpu
,gpu:x
,custom_device
,custom_device:x
, wherecustom_device
is the name of CustomDevice, wherex
is the index of the GPUs, XPUs. And it can be paddle.CUDAPlace(n) or paddle.CustomPlace(n).priority (int, optional) – priority of the CUDA stream. Can be either 1 (high priority) or 2 (low priority). By default, streams have priority 2.
- Returns
-
The stream.
- Return type
-
Stream
Examples
>>> >>> import paddle >>> paddle.set_device('custom_cpu') >>> s1 = paddle.device.Stream() >>> s2 = paddle.device.Stream('custom_cpu') >>> s3 = paddle.device.Stream('custom_cpu:0') >>> s4 = paddle.device.Stream(paddle.CustomPlace('custom_cpu', 0))
-
wait_event
(
event
)
wait_event¶
-
Makes all future work submitted to the stream wait for an event.
- Parameters
-
event (Event) – an event to wait for.
- Returns
-
None.
Examples
>>> >>> import paddle >>> paddle.set_device('custom_cpu') >>> s1 = paddle.device.Stream() >>> s2 = paddle.device.Stream() >>> e = paddle.device.Event() >>> e.record(s1) >>> s2.wait_event(e)
-
wait_stream
(
stream
)
wait_stream¶
-
Synchronizes with another stream. All future work submitted to this stream will wait until all kernels submitted to a given stream at the time of call complete.
- Parameters
-
stream (Stream) – a stream to synchronize.
- Returns
-
None.
Examples
>>> >>> import paddle >>> paddle.set_device('custom_cpu') >>> s1 = paddle.device.Stream() >>> s2 = paddle.device.Stream() >>> s1.wait_stream(s2)
-
record_event
(
event=None
)
record_event¶
-
Records an event.
- Parameters
-
event (Event, optional) – event to record. If not given, a new one
allocated. (will be) –
- Returns
-
Recorded event.
- Return type
-
Event
Examples
>>> >>> import paddle >>> paddle.set_device('custom_cpu') >>> s = paddle.device.Stream() >>> e1 = s.record_event() >>> e2 = paddle.device.Event() >>> s.record_event(e2)
-
query
(
)
query¶
-
Checks if all the work submitted has been completed.
- Returns
-
Whether all kernels in this stream are completed.
- Return type
-
bool
Examples
>>> >>> import paddle >>> paddle.set_device('custom_cpu') >>> s = paddle.device.Stream() >>> s.query()