Event#
- class torch.Event(device=None, *, enable_timing=False, blocking=False, interprocess=False)#
查詢和記錄流狀態以識別或控制流之間的依賴關係並測量時間。
- 引數
警告
當前不支援 blocking 和 interprocess,它們是無操作。
- 返回
一個 torch.Event 物件。
- 返回型別
示例
>>> event = torch.Event() >>> e_cuda = torch.Event(device='cuda')
- elapsed_time(end_event) float#
返回此事件和
end_event透過torch.Stream.record_event()記錄時之間的經過時間(以毫秒為單位)。- 引數
end_event (
torch.Event) – 已記錄的結束事件。- 返回
開始和結束事件之間的時間(以毫秒為單位)。
- 返回型別
示例
>>> 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#
檢查記錄此事件的流是否已透過事件記錄點。如果事件未被記錄,則始終返回
True。- 返回
一個布林值,指示當前由事件捕獲的所有工作是否已完成。
- 返回型別
示例
>>> s_cuda = torch.Stream(device='cuda') >>> e_cuda = s_cuda.record_event() >>> e_cuda.query() True
- record(stream=None) None#
在給定流中記錄事件。流的裝置必須與事件的裝置匹配。此函式等同於
stream.record_event(self)。- 引數
stream (
torch.Stream, optional) – 要記錄的流。如果未給出,則使用當前流。
示例
>>> e_cuda = torch.Event(device='cuda') >>> e_cuda.record()
- synchronize() None#
等待事件完成。這可以防止 CPU 執行緒在事件完成之前繼續執行。
示例
>>> s_cuda = torch.Stream(device='cuda') >>> e_cuda = s_cuda.record_event() >>> e_cuda.synchronize()
- wait(stream=None) None#
使提交給給定流的所有未來工作等待此事件。
- 引數
stream (
torch.Stream, optional) – 要同步的流。如果未給出,則使用當前流。
示例
>>> s1_cuda = torch.Stream(device='cuda') >>> s2_cuda = torch.Stream(device='cuda') >>> e_cuda = s1_cuda.record() >>> e_cuda.wait(s2)