• 文档 >
  • torch 加速器 >
  • torch.accelerator.synchronize
快捷键

torch.accelerator.synchronize

torch.accelerator.synchronize(device=None, /)[source][source]

等待给定设备上所有流中的所有内核完成。

参数:

设备( torch.device ,str,int,可选)- 要同步的设备。它必须与当前加速器设备类型匹配。如果未提供,则默认使用 torch.accelerator.current_device_index()

注意

如果当前加速器未初始化,则此函数为空操作。

示例:

>>> assert torch.accelerator.is_available() "No available accelerators detected."
>>> start_event = torch.Event(enable_timing=True)
>>> end_event = torch.Event(enable_timing=True)
>>> start_event.record()
>>> tensor = torch.randn(100, device=torch.accelerator.current_accelerator())
>>> sum = torch.sum(tensor)
>>> end_event.record()
>>> torch.accelerator.synchronize()
>>> elapsed_time_ms = start_event.elapsed_time(end_event)

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,主题由 Read the Docs 提供。

文档

查看 PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源并获得您的疑问解答

查看资源