get_stream_from_external

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

Return a Stream from an externally allocated CUDA stream.

This function is used to wrap streams allocated in other libraries in order to facilitate data exchange and multi-library interactions.

Note

This function doesn’t manage the stream life-cycle, it is the user responsibility to keep the referenced stream alive while this returned stream is being used.

Parameters
  • data_ptr (int) – Integer representation of the CUDA stream handle (cudaStream_t) that is allocated externally.

  • device (str|paddle.CUDAPlace(n), optional) – The CUDA device where the stream was originally allocated. If device is None, the current CUDA device is used. It can be gpu, gpu:x, or paddle.CUDAPlace(n).

Returns

The wrapped CUDA stream corresponding to the given external pointer.

Return type

Stream

Examples

>>> import paddle
>>> 
>>> original_raw_ptr = 77777
>>> external_stream = paddle.device.get_stream_from_external(original_raw_ptr,"cuda:0")