-
Notifications
You must be signed in to change notification settings - Fork 57
fix: extract handle value in Event.query() call to match other driver calls #747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
55d484a
b698a5d
876c90f
93e7577
0951c7c
dc4fb1a
f6d3c59
ddbb792
ce8c81a
1e92818
c24fc42
8138622
138411e
1175800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |||||
| # SPDX-License-Identifier: BSD-2-Clause | ||||||
|
|
||||||
| import numpy as np | ||||||
| from numba import cuda | ||||||
| from numba import cuda, int32 | ||||||
| from numba.cuda.testing import unittest, CUDATestCase | ||||||
| from numba.cuda._compat import Device | ||||||
| from numba.cuda.testing import skip_on_cudasim | ||||||
|
|
@@ -48,6 +48,42 @@ def event_elapsed_inner(self, stream): | |||||
| # Exercise the code path | ||||||
| evtstart.elapsed_time(evtend) | ||||||
|
|
||||||
| def test_event_query(self): | ||||||
| from time import perf_counter | ||||||
|
|
||||||
| @cuda.jit | ||||||
| def spin(ms): | ||||||
| # Sleep for ms | ||||||
| for i in range(ms): | ||||||
| cuda.nanosleep(int32(1_000_000)) # 1 ms | ||||||
|
|
||||||
| stream = cuda.stream() | ||||||
| evt = cuda.event() | ||||||
|
|
||||||
| # Run once to compile | ||||||
| spin[1, 1, stream](1) | ||||||
|
|
||||||
| t0 = perf_counter() | ||||||
| spin_ms = 250 | ||||||
| spin[1, 1, stream](250) | ||||||
| evt.record(stream) | ||||||
|
|
||||||
| # Query immediately. | ||||||
| # Query immediately. | ||||||
ccam80 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ccam80 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| event_time = perf_counter() - t0 | ||||||
| while not evt.query(): | ||||||
| event_time = perf_counter() - t0 | ||||||
cpcloud marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| # Synchronize and capture stream-finished time. | ||||||
| evt.synchronize() | ||||||
| sync_time = perf_counter() - t0 | ||||||
|
|
||||||
| assert event_time * 1000 > spin_ms * 0.9 # nanosleep isn't reliable | ||||||
| assert sync_time * 1000 > spin_ms * 0.9 # nanosleep isn't reliable | ||||||
|
|
||||||
| # Give a few ms overhead for the synchronize call to complete | ||||||
| assert sync_time - event_time < 2e-3 | ||||||
|
||||||
| assert sync_time - event_time < 2e-3 | |
| assert sync_time - event_time < 10e-3 |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we've had a very poor experience with trying to find healthy timing tolerances for things like this. What I would suggest is that we ensure the time is a positive number, but beyond that I don't think we should worry about actually trying to capture the timing in a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense - on a second look, this assertion is redundant anyway. If the event query time is >0.9 of the requested sleep time (250ms) then we can be pretty confident that the query didn't fall straight through and this extra test is pointless nitpicking. I'll reorder and clarify the two other assertions.
Uh oh!
There was an error while loading. Please reload this page.