已合并
add test case for event elapsed_time #26734
kuhn7创建于 2025年11月19日
add test case for event elapsed_time #26734
已合并
共 1 个文件变更+12-0
| @@ -74,6 +74,18 @@ class TestAccelerator(TestCase): | |||
| 74 | self.assertTrue(t_host.is_pinned()) | 74 | self.assertTrue(t_host.is_pinned()) |
| 75 | self.assertEqual(t_acc.cpu(), t_host) | 75 | self.assertEqual(t_acc.cpu(), t_host) |
| 76 | 76 | ||
| 77 | + def test_event_elapsed_time(self): | ||
| 78 | + start_event = torch.Event(enable_timing=True) | ||
| 79 | + end_event = torch.Event(enable_timing=True) | ||
| 80 | + start_event.record() | ||
| 81 | + x = torch.randn(1000, 1000, device='npu') | ||
| 82 | + y = torch.randn(1000, 1000, device='npu') | ||
| 83 | + z = torch.matmul(x, y) | ||
| 84 | + end_event.record() | ||
| 85 | + torch.npu.synchronize() | ||
| 86 | + ms = start_event.elapsed_time(end_event) | ||
| 87 | + self.assertGreater(ms, 0) | ||
| 88 | + | ||
| 77 | 89 | ||
| 78 | if __name__ == "__main__": | 90 | if __name__ == "__main__": |
| 79 | run_tests() | 91 | run_tests() |