mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
[Easy] Add more check for elapsedTime of torch.xxx.Event and torch.Event (#151404)
As the title stated **Changes:** - Add **record**, **query** and **enable_timing** check - Add related tests Pull Request resolved: https://github.com/pytorch/pytorch/pull/151404 Approved by: https://github.com/albanD
This commit is contained in:
@ -112,6 +112,23 @@ class TestAccelerator(TestCase):
|
||||
self.assertTrue(t_host.is_pinned())
|
||||
self.assertEqual(t_acc.cpu(), t_host)
|
||||
|
||||
def test_generic_event_behavior(self):
|
||||
event1 = torch.Event(enable_timing=False)
|
||||
event2 = torch.Event(enable_timing=False)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"Both events must be created with argument 'enable_timing=True'",
|
||||
):
|
||||
event1.elapsed_time(event2)
|
||||
|
||||
event1 = torch.Event(enable_timing=True)
|
||||
event2 = torch.Event(enable_timing=True)
|
||||
with self.assertRaisesRegex(
|
||||
ValueError,
|
||||
"Both events must be recorded before calculating elapsed time",
|
||||
):
|
||||
event1.elapsed_time(event2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_tests()
|
||||
|
Reference in New Issue
Block a user