Skip to content

Commit 19f1037

Browse files
Remove primary context reset tests to avoid test contamination
Primary context resets corrupt CuPy's internal state, causing cascading failures in unrelated tests. Keep only non-primary context destroy tests which isolate the library/context lifetime issue without side effects. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 44f812e commit 19f1037

File tree

1 file changed

+3
-65
lines changed

1 file changed

+3
-65
lines changed

cuda_core/tests/test_library_context_lifetime.py

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
66
These tests exercise scenarios where a CUDA library (CUlibrary) or kernel
77
(CUkernel) outlives the context in which it was created. This can happen
8-
when:
9-
- The primary context is reset (e.g. numba-cuda's test teardown)
10-
- A non-primary context is explicitly destroyed
8+
when a non-primary context is explicitly destroyed while libraries or
9+
kernels loaded within it are still alive.
1110
1211
Currently, LibraryBox in resource_handles.cpp does NOT store a
1312
ContextHandle, so nothing prevents the context from being destroyed
@@ -20,7 +19,7 @@
2019

2120
import pytest
2221
from cuda.bindings import driver
23-
from cuda.core import Device, Program
22+
from cuda.core import Program
2423
from cuda.core._utils.cuda_utils import handle_return
2524

2625
KERNEL_SOURCE = 'extern "C" __global__ void test_kernel() {}'
@@ -50,50 +49,6 @@ def _restore_primary_context():
5049
handle_return(driver.cuCtxSetCurrent(ctx))
5150

5251

53-
class TestPrimaryContextReset:
54-
"""Library/kernel destroyed after primary context reset."""
55-
56-
def test_objectcode_outlives_primary_context_reset(self):
57-
dev = Device(0)
58-
dev.set_current()
59-
60-
obj, kernel = _compile_and_get_kernel()
61-
del kernel
62-
63-
handle_return(driver.cuDevicePrimaryCtxReset(0))
64-
65-
del obj
66-
gc.collect()
67-
68-
def test_kernel_outlives_primary_context_reset(self):
69-
dev = Device(0)
70-
dev.set_current()
71-
72-
obj, kernel = _compile_and_get_kernel()
73-
del obj
74-
75-
handle_return(driver.cuDevicePrimaryCtxReset(0))
76-
77-
del kernel
78-
gc.collect()
79-
80-
def test_objectcode_outlives_primary_context_reset_and_reretain(self):
81-
"""The numba-cuda pattern: reset, then re-init for the next test."""
82-
dev = Device(0)
83-
dev.set_current()
84-
85-
obj, kernel = _compile_and_get_kernel()
86-
del kernel
87-
88-
handle_return(driver.cuDevicePrimaryCtxReset(0))
89-
90-
ctx = handle_return(driver.cuDevicePrimaryCtxRetain(0))
91-
handle_return(driver.cuCtxSetCurrent(ctx))
92-
93-
del obj
94-
gc.collect()
95-
96-
9752
class TestNonPrimaryContextDestroy:
9853
"""Library/kernel destroyed after non-primary context is destroyed."""
9954

@@ -119,23 +74,6 @@ def test_kernel_outlives_nonprimary_context(self):
11974
del kernel
12075
gc.collect()
12176

122-
123-
class TestKernelOutlivesObjectCode:
124-
"""Kernel transitively holds library; both outlive context."""
125-
126-
def test_kernel_outlives_objectcode_and_primary_context(self):
127-
dev = Device(0)
128-
dev.set_current()
129-
130-
obj, kernel = _compile_and_get_kernel()
131-
del obj
132-
gc.collect()
133-
134-
handle_return(driver.cuDevicePrimaryCtxReset(0))
135-
136-
del kernel
137-
gc.collect()
138-
13977
def test_kernel_outlives_objectcode_and_nonprimary_context(self):
14078
ctx = _create_nonprimary_context()
14179

0 commit comments

Comments
 (0)