Event

class paddle.cuda. Event ( enable_timing: bool = False, blocking: bool = False, interprocess: bool = False ) [source]

A device event wrapper around StreamBase.

Parameters
  • enable_timing (bool, optional) – indicates if the event should measure time, default is False

  • blocking (bool, optional) – if True, wait will be blocking, default is False

  • interprocess (bool) – if True, the event can be shared between processes, default is False

Returns

The event.

Return type

Event

Note

The device parameter has been removed in the latest version. The event will always use the current device context. Previously, you could specify the device like: `python # Old usage (no longer supported) e = paddle.device.Event(device="gpu:0") ` Now it will automatically use the current device: `python # New usage paddle.set_device("gpu:0")  # Set device first e = paddle.device.Event()  # Will use gpu:0 `

paddle.device.Event is equivalent to paddle.cuda.Event.

Examples

>>> 
>>> import paddle

>>> paddle.set_device('custom_cpu')
>>> e1 = paddle.device.Event()  # Uses current device (custom_cpu)
>>>
>>> # Old usage (no longer supported):
>>> # e2 = paddle.device.Event('custom_cpu')
>>> # e3 = paddle.device.Event('custom_cpu:0')
>>> # e4 = paddle.device.Event(paddle.CustomPlace('custom_cpu', 0))
>>>
>>> # New equivalent usage:
>>> paddle.set_device('custom_cpu:0')
>>> e5 = paddle.device.Event()  # Uses custom_cpu:0
record ( stream: Optional[Stream] = None ) None

record

Records the event in a given stream.

Parameters
  • stream (Stream, optional) – The given stream. By default, stream is None,

  • current_stream. (event will be recorded in) –

Returns

None.

Examples

>>> 
>>> import paddle

>>> paddle.set_device('custom_cpu')
>>> e = paddle.device.Event()
>>> e.record()

>>> s = paddle.device.Stream()
>>> e.record(s)
query ( ) bool

query

Checks if all work currently captured by event has completed.

Returns

Whether all work currently captured by event has completed.

Return type

bool

Examples

>>> 
>>> import paddle

>>> paddle.set_device('custom_cpu')
>>> e = paddle.device.Event()
>>> e.record()
>>> e.query()
elapsed_time ( end_event: Event ) int

elapsed_time

Returns the time elapsed in milliseconds after the event was recorded and before the end_event was recorded.

Returns

The time.

Return type

int

Examples

>>> 
>>> import paddle

>>> paddle.set_device('custom_cpu')
>>> e1 = paddle.device.Event()
>>> e1.record()

>>> e2 = paddle.device.Event()
>>> e2.record()
>>> e1.elapsed_time(e2)
synchronize ( ) None [source]

synchronize

Waits for the event to complete. Waits until the completion of all work currently captured in this event. This prevents the CPU thread from proceeding until the event completes.

Returns

None.

Examples

>>> 
>>> import paddle

>>> paddle.set_device('custom_cpu')
>>> e = paddle.device.Event()
>>> e.record()
>>> e.synchronize()