Skip to content

Commit 4314886

Browse files
committed
TST: Use infinite kernel instead of unrecorded event for testing event error
1 parent 99218bb commit 4314886

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

cuda_core/tests/test_event.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import pytest
1313

1414
import cuda.core.experimental
15-
from cuda.core.experimental import Device, EventOptions
15+
from cuda.core.experimental import Device, EventOptions, LaunchConfig, Program, ProgramOptions, launch
1616

1717

1818
def test_event_init_disabled():
@@ -116,14 +116,32 @@ def test_error_timing_recorded():
116116
def test_error_timing_incomplete():
117117
device = Device()
118118
device.set_current()
119+
120+
# This kernel is designed to not complete
121+
code = """
122+
extern "C"
123+
__global__ void wait() {
124+
while (1 > 0) {
125+
}
126+
}
127+
"""
128+
129+
arch = "".join(f"{i}" for i in device.compute_capability)
130+
program_options = ProgramOptions(std="c++11", arch=f"sm_{arch}")
131+
prog = Program(code, code_type="c++", options=program_options)
132+
mod = prog.compile(target_type="cubin")
133+
ker = mod.get_kernel("wait")
134+
135+
config = LaunchConfig(grid=1, block=1)
136+
ker_args = ()
137+
119138
enabled = EventOptions(enable_timing=True)
120139
stream = device.create_stream()
121140

122141
event1 = stream.record(options=enabled)
123-
event2 = device.create_event(options=enabled)
124-
stream.wait(event2)
142+
launch(stream, config, ker, *ker_args)
125143
event3 = stream.record(options=enabled)
126144

127-
# event3 will never complete because the stream is waiting on event2 which is never recorded
145+
# event3 will never complete because the stream is waiting on wait() to complete
128146
with pytest.raises(RuntimeError, match="^One or both events have not completed."):
129147
event3 - event1

0 commit comments

Comments
 (0)