stream_guard

paddle.device.cuda. stream_guard ( stream ) [source]

Warning

API “paddle.device.cuda.stream_guard” is deprecated since 2.5.0, and will be removed in future versions. Please use “paddle.device.stream_guard” instead. Reason: stream_guard in paddle.device.cuda will be removed in future

Notes

This API only supports dynamic graph mode currently.

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

Parameters

stream (paddle.device.cuda.Stream) – the selected stream. If stream is None, just yield.

Examples

>>> 
>>> import paddle
>>> paddle.device.set_device('gpu')

>>> s = paddle.device.cuda.Stream()
>>> data1 = paddle.ones(shape=[20])
>>> data2 = paddle.ones(shape=[20])
>>> with paddle.device.cuda.stream_guard(s):
...     data3 = data1 + data2