Skip to content

Commit b19d0ae

Browse files
committed
test(cuda.core): temporary MR-leak trace diagnostic (drop before merge)
TEMPORARY -- drop this commit before merge. It emits a MemoryResourceLeakTraceWarning from the pytest_runtest_protocol hook for any item whose live-MemoryResource count changed, so a Windows-only cross-test leaker (the one that trips UnreleasedMemoryResourceWarning at a later init_cuda test) can be pinned to the exact non-init_cuda item that left resources alive. pytest always includes the warning in its summary, so it surfaces in CI with no workflow changes. The helper, the warning class, and the call site are the only changes and are clearly marked for removal.
1 parent f50ec59 commit b19d0ae

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎cuda_core/tests/conftest.py‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from helpers.constants import POOL_SIZE
3333
from helpers.memory import (
3434
BaselineMemoryResourceReleasedWarning,
35+
MemoryResourceLeakTraceWarning,
3536
UnreleasedMemoryResourceWarning,
3637
skip_if_pinned_memory_unsupported,
3738
)
@@ -165,6 +166,29 @@ def _release_device_default_memory_resources():
165166
d._memory_resource = None
166167

167168

169+
# TEMPORARY DIAGNOSTIC -- drop this helper and its call site before merge.
170+
def _warn_mr_leak_trace(item, live_at_start, live_at_end, expected_live):
171+
"""Emit a warning naming any item whose live-MemoryResource count changed.
172+
173+
pytest always includes the warnings summary in its report output, so this
174+
surfaces in the CI log without any workflow changes -- the goal is to pin
175+
the Windows-only cross-test leaker (the non-init_cuda item that leaves
176+
resources alive and later trips UnreleasedMemoryResourceWarning) to the
177+
exact test. Only nonzero deltas are warned about; init_cuda items are
178+
tagged so they can be told apart (they self-heal via the teardown gate).
179+
"""
180+
delta = live_at_end - live_at_start
181+
if delta == 0:
182+
return
183+
kind = "init_cuda" if _item_uses_init_cuda(item) else "plain"
184+
warnings.warn(
185+
f"[mr-leak-trace] {kind} {item.nodeid} live_delta={delta:+d} "
186+
f"(start={live_at_start} end={live_at_end} expected={expected_live})",
187+
MemoryResourceLeakTraceWarning,
188+
stacklevel=2,
189+
)
190+
191+
168192
@pytest.hookimpl(wrapper=True)
169193
def pytest_runtest_protocol(item, nextitem):
170194
# Leftover check: compare with the count after the previous init_cuda test,
@@ -183,6 +207,15 @@ def pytest_runtest_protocol(item, nextitem):
183207
# Only lower it: a released resource must not hide a later leak.
184208
_mr_expected_live = min(_mr_expected_live, live)
185209

210+
# TEMPORARY DIAGNOSTIC -- drop this whole block (and the commit it is
211+
# in) before merge. It warns about any item whose live-MemoryResource
212+
# count changed, so a Windows-only cross-test leaker (one that trips
213+
# UnreleasedMemoryResourceWarning at a later init_cuda test) can be
214+
# pinned to the exact non-init_cuda item that left resources alive.
215+
# The warning always appears in the pytest warnings summary, so it
216+
# surfaces in CI with no workflow changes.
217+
_warn_mr_leak_trace(item, _mr_live_at_item_start, live, _mr_expected_live)
218+
186219

187220
class _CudaCoreParallelPlugin:
188221
"""A mini pytest plugin used only for pytest-run-parallel testing.

‎cuda_core/tests/helpers/memory.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ class BaselineMemoryResourceReleasedWarning(Warning):
1717
"""An ``init_cuda`` test released a resource that existed before it started."""
1818

1919

20+
# TEMPORARY DIAGNOSTIC -- drop this class and its uses before merge.
21+
class MemoryResourceLeakTraceWarning(Warning):
22+
"""Diagnostic: a test changed the live ``MemoryResource`` count.
23+
24+
Emitted by the ``pytest_runtest_protocol`` hook in ``conftest.py`` to pin
25+
the Windows-only cross-test leaker. Not part of the gate; remove with its
26+
commit.
27+
"""
28+
29+
2030
def skip_if_pinned_memory_unsupported(device):
2131
try:
2232
if not device.properties.host_memory_pools_supported:

0 commit comments

Comments
 (0)