@@ -21,30 +21,29 @@ def test_event_init_disabled():
2121
2222
2323def test_timing_success (init_cuda ):
24- device = Device ()
2524 options = EventOptions (enable_timing = True )
25+ device = Device ()
2626 stream = device .create_stream ()
2727
28- # Create a nanosleep kernel that sleeps for 20 ms to ensure a measurable delay
29- # This guarantees delta_ms > 10 without depending on OS/driver timing characteristics
28+ # Create a nanosleep kernel that sleeps for 20 ms to ensure a measurable delay.
29+ # This guarantees elapsed_time_ms > 10 without depending on OS/driver timing characteristics.
3030 nanosleep = NanosleepKernel (device , sleep_duration_ms = 20 )
3131
3232 e1 = stream .record (options = options )
3333 nanosleep .launch (stream ) # Insert a guaranteed delay
3434 e2 = stream .record (options = options )
3535 e2 .sync ()
36- delta_ms = e2 - e1
37- assert isinstance (delta_ms , float )
36+ elapsed_time_ms = e2 - e1
37+ assert isinstance (elapsed_time_ms , float )
3838 # Sanity check: cuEventElapsedTime should always return a finite float for two completed
3939 # events. This guards against unexpected driver/HW anomalies (e.g. NaN or inf) or general
4040 # undefined behavior, without asserting anything about the magnitude of the measured time.
41- assert math .isfinite (delta_ms )
42- # With the nanosleep kernel between events, we can assert a positive elapsed time.
43- # The kernel sleeps for 20 ms using clock64(), so delta_ms should be at least ~10 ms.
44- # Using a 10 ms threshold (half the sleep duration) provides a large safety margin above
45- # the ~0.5 microsecond resolution of cudaEventElapsedTime, making this test deterministic
46- # and non-flaky.
47- assert delta_ms > 10
41+ assert math .isfinite (elapsed_time_ms )
42+ # With the nanosleep kernel between events, the kernel sleeps for 20 ms using clock64(),
43+ # so elapsed_time_ms should definitely be larger than 10 ms. This provides a large safety
44+ # margin above the ~0.5 microsecond resolution of cudaEventElapsedTime(), which should
45+ # make this test deterministic and non-flaky.
46+ assert elapsed_time_ms > 10
4847
4948
5049def test_is_sync_busy_waited (init_cuda ):
0 commit comments