Event#
- class torch.mtia.Event(device=None, *, enable_timing=False, blocking=False, interprocess=False)#
查询和记录流状态以识别或控制流之间的依赖关系并测量时间。
- 参数
警告
目前,阻塞和进程间共享均不受支持,且为noops。
- 返回
一个 torch.Event 对象。
- 返回类型
示例
>>> event = torch.Event() >>> e_cuda = torch.Event(device='cuda')
- elapsed_time(end_event) float #
返回此事件与通过
torch.Stream.record_event()
记录的end_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)