Skip to content

Commit 8436944

Browse files
committed
chore: move all deallocations test to a single process to avoid cross process deallocation pollution during testing
1 parent f901a10 commit 8436944

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import numpy as np
77

8+
import pytest
9+
810
from numba import cuda
911
from numba.cuda.testing import (
1012
unittest,
@@ -15,10 +17,12 @@
1517
from numba.cuda.tests.support import captured_stderr
1618
from numba.cuda.core import config
1719

20+
pytestmark = pytest.mark.xdist_group("deallocations")
21+
1822

1923
@skip_on_cudasim("not supported on CUDASIM")
20-
@skip_if_external_memmgr("Deallocation specific to Numba memory management")
2124
class TestDeallocation(CUDATestCase):
25+
@skip_if_external_memmgr("Deallocation specific to Numba memory management")
2226
def test_max_pending_count(self):
2327
# get deallocation manager and flush it
2428
deallocs = cuda.current_context().memory_manager.deallocations
@@ -32,6 +36,7 @@ def test_max_pending_count(self):
3236
cuda.to_device(np.arange(1))
3337
self.assertEqual(len(deallocs), 0)
3438

39+
@skip_if_external_memmgr("Deallocation specific to Numba memory management")
3540
def test_max_pending_bytes(self):
3641
# get deallocation manager and flush it
3742
ctx = cuda.current_context()
@@ -73,11 +78,8 @@ def test_max_pending_bytes(self):
7378
# restore old ratio
7479
config.CUDA_DEALLOCS_RATIO = old_ratio
7580

76-
77-
@skip_on_cudasim("defer_cleanup has no effect in CUDASIM")
78-
@skip_if_external_memmgr("Deallocation specific to Numba memory management")
79-
class TestDeferCleanup(CUDATestCase):
80-
def test_basic(self):
81+
@skip_if_external_memmgr("Deallocation specific to Numba memory management")
82+
def test_defer_cleanup(self):
8183
harr = np.arange(5)
8284
darr1 = cuda.to_device(harr)
8385
deallocs = cuda.current_context().memory_manager.deallocations
@@ -95,7 +97,8 @@ def test_basic(self):
9597
deallocs.clear()
9698
self.assertEqual(len(deallocs), 0)
9799

98-
def test_nested(self):
100+
@skip_if_external_memmgr("Deallocation specific to Numba memory management")
101+
def test_nested_defer_cleanup(self):
99102
harr = np.arange(5)
100103
darr1 = cuda.to_device(harr)
101104
deallocs = cuda.current_context().memory_manager.deallocations
@@ -116,6 +119,7 @@ def test_nested(self):
116119
deallocs.clear()
117120
self.assertEqual(len(deallocs), 0)
118121

122+
@skip_if_external_memmgr("Deallocation specific to Numba memory management")
119123
def test_exception(self):
120124
harr = np.arange(5)
121125
darr1 = cuda.to_device(harr)
@@ -141,64 +145,50 @@ class CustomError(Exception):
141145
deallocs.clear()
142146
self.assertEqual(len(deallocs), 0)
143147

144-
145-
class TestDeferCleanupAvail(CUDATestCase):
146-
def test_context_manager(self):
147-
# just make sure the API is available
148-
with cuda.defer_cleanup():
149-
pass
150-
151-
152-
@skip_on_cudasim("not supported on CUDASIM")
153-
class TestDel(CUDATestCase):
154-
"""
155-
Ensure resources are deleted properly without ignored exception.
156-
"""
157-
158148
@contextmanager
159149
def check_ignored_exception(self, ctx):
160150
with captured_stderr() as cap:
161151
yield
162152
ctx.deallocations.clear()
163153
self.assertFalse(cap.getvalue())
164154

165-
def test_stream(self):
155+
def test_del_stream(self):
166156
ctx = cuda.current_context()
167157
stream = ctx.create_stream()
168158
with self.check_ignored_exception(ctx):
169159
del stream
170160

171-
def test_event(self):
161+
def test_del_event(self):
172162
ctx = cuda.current_context()
173163
event = ctx.create_event()
174164
with self.check_ignored_exception(ctx):
175165
del event
176166

177-
def test_pinned_memory(self):
167+
def test_del_pinned_memory(self):
178168
ctx = cuda.current_context()
179169
mem = ctx.memhostalloc(32)
180170
with self.check_ignored_exception(ctx):
181171
del mem
182172

183-
def test_mapped_memory(self):
173+
def test_del_mapped_memory(self):
184174
ctx = cuda.current_context()
185175
mem = ctx.memhostalloc(32, mapped=True)
186176
with self.check_ignored_exception(ctx):
187177
del mem
188178

189-
def test_device_memory(self):
179+
def test_del_device_memory(self):
190180
ctx = cuda.current_context()
191181
mem = ctx.memalloc(32)
192182
with self.check_ignored_exception(ctx):
193183
del mem
194184

195-
def test_managed_memory(self):
185+
def test_del_managed_memory(self):
196186
ctx = cuda.current_context()
197187
mem = ctx.memallocmanaged(32)
198188
with self.check_ignored_exception(ctx):
199189
del mem
200190

201-
def test_pinned_contextmanager(self):
191+
def test_del_pinned_contextmanager(self):
202192
# Check that temporarily pinned memory is unregistered immediately,
203193
# such that it can be re-pinned at any time
204194
class PinnedException(Exception):
@@ -227,7 +217,7 @@ class PinnedException(Exception):
227217
with cuda.pinned(arr):
228218
pass
229219

230-
def test_mapped_contextmanager(self):
220+
def test_del_mapped_contextmanager(self):
231221
# Check that temporarily mapped memory is unregistered immediately,
232222
# such that it can be re-mapped at any time
233223
class MappedException(Exception):

0 commit comments

Comments
 (0)