评价此页

Event#

class torch.mtia.Event(device=None, *, enable_timing=False, blocking=False, interprocess=False)#

查询和记录流状态以识别或控制流之间的依赖关系并测量时间。

参数
  • device (torch.device, optional) – desired device for the Event. If not given, the current accelerator type will be used.

  • enable_timing (bool, optional) – 指示事件是否应测量时间(默认值:False

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

  • interprocess (bool) – 如果为 True,则事件可以在进程之间共享(默认值:False

警告

Currently, both blocking and interprocess are not supported and are no-ops.

返回

An torch.Event object.

返回类型

事件

示例

>>> event = torch.Event()
>>> e_cuda = torch.Event(device='cuda')
elapsed_time(end_event) float#

Returns the elapsed time in milliseconds between when this event and the end_event are each recorded via torch.Stream.record_event().

参数

end_event (torch.Event) – The ending event has been recorded.

返回

Time between starting and ending event in milliseconds.

返回类型

浮点数

示例

>>> s_cuda = torch.Stream(device='cuda')
>>> e1_cuda = s_cuda.record_event()
>>> e2_cuda = s_cuda.record_event()
>>> ms = e1_cuda.elapsed_time(e2_cuda)
query() bool#

Check if the stream where this event was recorded has already moved past the point where the event was recorded. Always returns True if the Event was not recorded.

返回

一个布尔值,指示当前由事件捕获的所有工作是否已完成。

返回类型

布尔值

示例

>>> s_cuda = torch.Stream(device='cuda')
>>> e_cuda = s_cuda.record_event()
>>> e_cuda.query()
True
record(stream=None) None#

Record the event in a given stream. The stream’s device must match the event’s device. This function is equivalent to stream.record_event(self).

参数

stream (torch.Stream, optional) – A stream to be recorded. If not given, the current stream will be used.

示例

>>> e_cuda = torch.Event(device='cuda')
>>> e_cuda.record()
synchronize() None#

Wait for the event to complete. This prevents the CPU thread from proceeding until the event completes.

示例

>>> s_cuda = torch.Stream(device='cuda')
>>> e_cuda = s_cuda.record_event()
>>> e_cuda.synchronize()
wait(stream=None) None#

使提交给给定流的所有未来工作等待此事件。

参数

stream (torch.Stream, optional) – A stream to synchronize. If not given, the current stream will be used.

示例

>>> s1_cuda = torch.Stream(device='cuda')
>>> s2_cuda = torch.Stream(device='cuda')
>>> e_cuda = s1_cuda.record()
>>> e_cuda.wait(s2)