stream_guard

class paddle.device. stream_guard ( stream=None ) [source]

Notes

This API only supports dynamic graph mode currently.

A context manager that specifies the current stream context by the given stream.

Parameters

stream (Stream, optional) – the selected stream. If stream is None, just yield.

Returns

None.

Examples

>>> 
>>> import paddle

>>> paddle.set_device('custom_cpu')
>>> s = paddle.device.Stream()
>>> data1 = paddle.ones(shape=[20])
>>> data2 = paddle.ones(shape=[20])
>>> data3 = data1 + data2
>>> with paddle.device.stream_guard(s):
...     s.wait_stream(paddle.device.default_stream())
...     data4 = data1 + data3