Stream

class paddle.device.cuda. Stream [source]

The handle of the CUDA stream.

Parameters
  • device (paddle.CUDAPlace()|int|None, optional) – The device which wanted to allocate the stream.

  • integer (If device is positive) –

  • device. (device will be the current) –

  • integer – None.

  • Default (it must less than the device count.) – None.

  • priority (int|None, optional) – The priority of stream. The priority can be 1(high) or 2(normal).

  • None (If priority is) – None.

  • 2 (the priority is) – None.

Examples

# required: gpu
import paddle
s1 = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1)
s2 = paddle.device.cuda.Stream(0, 1)
s3 = paddle.device.cuda.Stream()
property cuda_stream

retrun the raw cuda stream of type cudaStream_t as type int.

Examples

# required: gpu
import paddle
import ctypes
cuda_stream = paddle.device.cuda.current_stream().cuda_stream
print(cuda_stream)

ptr = ctypes.c_void_p(cuda_stream)  # convert back to void*
print(ptr)
query ( self: paddle.fluid.core_avx.CUDAStream ) bool

query

Return the status whether if all operations in stream have completed.

Returns: A boolean value.

Examples

# required: gpu
import paddle
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1)
is_done = s.query()
record_event ( self: paddle.fluid.core_avx.CUDAStream, event: paddle::platform::CudaEvent = None ) paddle::platform::CudaEvent

record_event

Record a CUDA event in the stream.

Parameters
  • event (CUDAEvent, optional) – The event to be record. If event is None, a new event is created.

  • Default – None.

Returns

The recored event.

Examples

# required: gpu
import paddle
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1)
event = s.record_event()
synchronize ( self: paddle.fluid.core_avx.CUDAStream ) None [source]

synchronize

Waits for stream tasks to complete.

Examples

# required: gpu
import paddle
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1)
s.synchronize()
wait_event ( self: paddle.fluid.core_avx.CUDAStream, arg0: paddle::platform::CudaEvent ) None

wait_event

Makes all future work submitted to stream wait for all work captured in event.

Parameters

event (CUDAEvent) – The event to wait on.

Examples

# required: gpu
import paddle
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1)
event = paddle.device.cuda.Event()
s.wait_event(event)
wait_stream ( self: paddle.fluid.core_avx.CUDAStream, arg0: paddle.fluid.core_avx.CUDAStream ) None

wait_stream

Synchronizes with the given stream.

Parameters

stream (CUDAStream) – The stream to synchronize with.

Examples

# required: gpu
import paddle
s1 = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1)
s2 = paddle.device.cuda.Stream(0, 1)
s1.wait_stream(s2)