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. :param stream: the selected stream. If stream is None, just yield. :type stream: Stream, optional

Returns

None.

Examples

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/device/__init__.py:docstring of paddle.device.stream_guard, line 13)

Error in “code-block” directive: maximum 1 argument(s) allowed, 6 supplied.

.. code-block:: python
    # required: custom_device
    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