From e3663b25a16cae921af6f5d48878cd9494a6fa4d Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Wed, 15 Jul 2026 12:47:56 +0200 Subject: [PATCH] Release transient SYCL queues at the end of each test file Every distinct SyclQueue a test creates is retained forever as a key in dpctl's SequentialOrderManager (keyed by queue identity), which pins its host-task events and the backing USM memory for the whole session. Over a full run this accumulates hundreds of queues and steadily drains device memory, occasionally triggering out-of-resources failures on low-memory GPU devices. Add a pytest_runtest_teardown hook that drains and drops the order-manager entries at each test-file boundary, keeping the footprint flat without paying the cost after every individual test. Co-Authored-By: Claude Opus 4.8 (1M context) --- dpnp/tests/conftest.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dpnp/tests/conftest.py b/dpnp/tests/conftest.py index 8e3cb97ad41f..c4cb94845db9 100644 --- a/dpnp/tests/conftest.py +++ b/dpnp/tests/conftest.py @@ -31,6 +31,7 @@ import warnings import dpctl +import dpctl.utils as dpu import numpy import pytest @@ -186,6 +187,27 @@ def pytest_collection_modifyitems(config, items): item.add_marker(skip_slow) +def pytest_runtest_teardown(item, nextitem): + """ + Release transient SYCL queues at the end of each test file. + + Every distinct ``SyclQueue`` a test creates is retained forever as a key in + dpctl's ``SequentialOrderManager`` (keyed by queue identity), which pins its + host-task events and the backing USM memory for the whole session. Over a + full run this accumulates hundreds of queues and steadily drains device + memory. Draining and dropping them at each file boundary keeps the footprint + flat without paying the cost after every individual test. + """ + # Only act on the last test of the current file (``nextitem`` is None at the + # very end of the session, or points at the first test of the next file). + if nextitem is not None and item.path == nextitem.path: + return + try: + dpu.SequentialOrderManager.clear() + except Exception as e: # never let cleanup break the run + warnings.warn(f"Failed to clear SequentialOrderManager: {e}") + + @pytest.fixture def allow_fall_back_on_numpy(monkeypatch): monkeypatch.setattr(