Skip to content

Commit 8aca468

Browse files
committed
address review comments
1 parent 9ca8bd6 commit 8aca468

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

cuda_core/cuda/core/experimental/_event.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class Event:
4848
4949
Events can be used to monitor device's progress, query completion
5050
of work up to event's record, help establish dependencies
51-
between GPU work submissions, and record the elapsed time on GPU:
51+
between GPU work submissions, and record the elapsed time (in milliseconds)
52+
on GPU:
5253
5354
.. code-block:: python
5455
@@ -58,14 +59,14 @@ class Event:
5859
# ... run some GPU works ...
5960
e2 = s.record(options={"enable_timing": True})
6061
e2.sync()
61-
print(f"time = {e2 - e1}")
62+
print(f"time = {e2 - e1} milliseconds")
6263
6364
# Or, if events are already created:
6465
s.record(e1)
6566
# ... run some more GPU works ...
6667
s.record(e2)
6768
e2.sync()
68-
print(f"time = {e2 - e1}")
69+
print(f"time = {e2 - e1} milliseconds")
6970
7071
Directly creating an :obj:`~_event.Event` is not supported due to ambiguity,
7172
and they should instead be created through a :obj:`~_stream.Stream` object.
@@ -120,7 +121,7 @@ def __rsub__(self, other):
120121
return NotImplemented
121122

122123
def __sub__(self, other):
123-
# return self - other
124+
# return self - other (in milliseconds)
124125
timing = handle_return(driver.cuEventElapsedTime(other.handle, self.handle))
125126
return timing
126127

cuda_core/tests/test_event.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@
1111
import pytest
1212

1313
from cuda.core.experimental import Device, EventOptions
14+
from cuda.core.experimental._utils import CUDAError
1415

1516

1617
@pytest.mark.parametrize("enable_timing", [True, False, None])
1718
def test_timing(init_cuda, enable_timing):
1819
options = EventOptions(enable_timing=enable_timing)
1920
stream = Device().create_stream()
20-
n_seconds = 0.5
21+
delay_seconds = 0.5
2122
e1 = stream.record(options=options)
22-
time.sleep(n_seconds)
23+
time.sleep(delay_seconds)
2324
e2 = stream.record(options=options)
25+
e2.sync()
2426
for e in (e1, e2):
25-
assert e.is_timing_disabled == (not enable_timing if enable_timing is not None else True)
27+
assert e.is_timing_disabled == (True if enable_timing is None else not enable_timing)
2628
if enable_timing:
27-
e2.sync()
28-
elapsed_time = e2 - e1
29-
assert isinstance(elapsed_time, float)
30-
assert n_seconds * 1000 <= elapsed_time < n_seconds * 1000 + 2 # tolerance 2 ms
29+
elapsed_time_ms = e2 - e1
30+
assert isinstance(elapsed_time_ms, float)
31+
assert delay_seconds * 1000 <= elapsed_time_ms < delay_seconds * 1000 + 2 # tolerance 2 ms
32+
else:
33+
with pytest.raises(CUDAError) as e:
34+
elapsed_time_ms = e2 - e1
35+
assert "CUDA_ERROR_INVALID_HANDLE" in str(e)
3136

3237

3338
def test_is_sync_busy_waited(init_cuda):

0 commit comments

Comments
 (0)