get_stream_from_external

paddle.cuda. get_stream_from_external ( data_ptr: int, device: DeviceLike = None ) Stream [source]

Wrap an externally allocated CUDA stream into a Paddle paddle.cuda.Stream object.

This function allows integrating CUDA streams allocated by other libraries into Paddle, enabling multi-library interoperability and data exchange.

Note

  • This function does not manage the lifetime of the external stream. It is the caller’s responsibility to ensure the external stream remains valid while the returned Paddle stream is in use.

  • Providing an incorrect device may result in errors during kernel launches.

Parameters
  • data_ptr (int) – Integer representation of the external cudaStream_t.

  • device (DeviceLike, optional) – The device where the external stream was created. Can be a Paddle device string (e.g., “cuda:0”), an int index (e.g., 0), or a PaddlePlace (CUDAPlace). Default: None (current device).

Returns

A Paddle Stream object that wraps the external CUDA stream.

Return type

paddle.cuda.Stream

Examples

System Message: ERROR/3 (/usr/local/lib/python3.10/site-packages/paddle/cuda/__init__.py:docstring of paddle.cuda.get_stream_from_external, line 20)

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

.. code-block:: python
    >>> # doctest: +REQUIRES(env:CUSTOM_DEVICE)
    >>> import paddle

    >>> # Assume an external library provides a stream pointer:original_raw_ptr
    >>> # doctest: +SKIP('original_raw_ptr not exist')
    >>> original_raw_ptr = 77777
    >>> external_stream = paddle.cuda.get_stream_from_external(original_raw_ptr)