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_eventare each recorded viatorch.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
Trueif 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)