From 498b134ab756191e6930b82a2364af53f5010b64 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 18 Nov 2026 00:08:41 +0000 Subject: [PATCH 1/5] fix(samples): check host pool support before image copies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — codex GPT-6 on behalf of Ralf — Device memory-pool support does not imply host memory-pool support. Waive the pinned-memory sample before stream creation when host pools are unavailable, and cover the waiver and supported-path error behavior. --- .../example_tests/test_sample_verification.py | 35 +++++++++++++++++++ .../copyImageArraytoGPU.py | 4 +++ 2 files changed, 39 insertions(+) diff --git a/cuda_core/tests/example_tests/test_sample_verification.py b/cuda_core/tests/example_tests/test_sample_verification.py index 4130632c8d3..1216d4f797a 100644 --- a/cuda_core/tests/example_tests/test_sample_verification.py +++ b/cuda_core/tests/example_tests/test_sample_verification.py @@ -4,7 +4,9 @@ from __future__ import annotations import ast +import sys from pathlib import Path +from types import SimpleNamespace import numpy as np import pytest @@ -14,6 +16,7 @@ UTILITIES_DIR = REPO_ROOT / "samples" / "cuda_core" / "Utilities" WAIVER_SAMPLE_NAMES = ( "blurImageUnifiedMemory", + "copyImageArraytoGPU", "glInteropFluid", "glInteropMipmapLod", "glInteropPlasma", @@ -30,6 +33,38 @@ ) +def _load_sample_function(sample_name: str, function_name: str, **namespace): + """Exercise sample functions without importing their optional GPU packages.""" + sample_path = REPO_ROOT / "samples" / "cuda_core" / sample_name / f"{sample_name}.py" + tree = ast.parse(sample_path.read_text(encoding="utf-8"), filename=str(sample_path)) + function = next(node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name == function_name) + module = ast.Module(body=[function], type_ignores=[]) + exec(compile(module, str(sample_path), "exec"), namespace) # noqa: S102 - trusted sample source + return namespace[function_name] + + +@pytest.mark.parametrize("host_pools_supported", [False, True]) +@pytest.mark.agent_authored(model="GPT-6") +def test_image_sample_requires_host_memory_pools(host_pools_supported: bool) -> None: + def create_stream(): + raise RuntimeError("stream setup failed") + + device = SimpleNamespace( + properties=SimpleNamespace(memory_pools_supported=True, host_memory_pools_supported=host_pools_supported), + set_current=lambda: None, + create_stream=create_stream, + ) + main = _load_sample_function("copyImageArraytoGPU", "main", Device=lambda: device, np=np, sys=sys, EXIT_WAIVED=77) + + if host_pools_supported: + with pytest.raises(RuntimeError, match="stream setup failed"): + main() + else: + with pytest.raises(SystemExit) as exc_info: + main() + assert exc_info.value.code == 77 + + @pytest.mark.parametrize("sample_name", WAIVER_SAMPLE_NAMES) @pytest.mark.agent_authored(model="gpt-5") def test_core_sample_waivers_use_negotiated_exit_code( diff --git a/samples/cuda_core/copyImageArraytoGPU/copyImageArraytoGPU.py b/samples/cuda_core/copyImageArraytoGPU/copyImageArraytoGPU.py index 7fd0361e4bc..102ebbdeb3f 100644 --- a/samples/cuda_core/copyImageArraytoGPU/copyImageArraytoGPU.py +++ b/samples/cuda_core/copyImageArraytoGPU/copyImageArraytoGPU.py @@ -200,6 +200,10 @@ def main(): print("PinnedMemoryResource requires CUDA memory pools, which are not supported on this device. Waiving.") sys.exit(EXIT_WAIVED) + if not dev.properties.host_memory_pools_supported: + print("PinnedMemoryResource requires host memory pools, which are not supported on this device. Waiving.") + sys.exit(EXIT_WAIVED) + stream = dev.create_stream() # Create stream for async operations print(f"Device: {dev.name}") From 09c50aa1e5c22ed9562c4add6c1ea2bb1debf5b1 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 18 Nov 2026 00:09:15 +0000 Subject: [PATCH 2/5] fix(samples): check IPC memory pool handle support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — codex GPT-6 on behalf of Ralf — Generic POSIX file-descriptor handle support does not guarantee memory pool IPC support. Check the pool-specific POSIX-FD bit before creating the pool, and test masks with and without that bit. --- .../example_tests/test_sample_verification.py | 24 +++++++++++++++++++ .../cuda_core/ipcMemoryPool/ipcMemoryPool.py | 5 ++++ 2 files changed, 29 insertions(+) diff --git a/cuda_core/tests/example_tests/test_sample_verification.py b/cuda_core/tests/example_tests/test_sample_verification.py index 1216d4f797a..91ed5a418bd 100644 --- a/cuda_core/tests/example_tests/test_sample_verification.py +++ b/cuda_core/tests/example_tests/test_sample_verification.py @@ -4,6 +4,7 @@ from __future__ import annotations import ast +import io import sys from pathlib import Path from types import SimpleNamespace @@ -65,6 +66,29 @@ def create_stream(): assert exc_info.value.code == 77 +@pytest.mark.parametrize(("handle_types", "supported"), [(2, False), (3, True)]) +@pytest.mark.agent_authored(model="GPT-6") +def test_ipc_sample_checks_memory_pool_handle_support(handle_types: int, supported: bool) -> None: + from cuda.bindings import driver + + check_ipc_support = _load_sample_function( + "ipcMemoryPool", + "check_ipc_support", + platform=SimpleNamespace(system=lambda: "Linux"), + open=lambda _path: io.StringIO("6.1.0"), + driver=driver, + ) + device = SimpleNamespace( + properties=SimpleNamespace( + memory_pools_supported=True, + handle_type_posix_file_descriptor_supported=True, + mempool_supported_handle_types=handle_types, + ) + ) + + assert check_ipc_support(device) is supported + + @pytest.mark.parametrize("sample_name", WAIVER_SAMPLE_NAMES) @pytest.mark.agent_authored(model="gpt-5") def test_core_sample_waivers_use_negotiated_exit_code( diff --git a/samples/cuda_core/ipcMemoryPool/ipcMemoryPool.py b/samples/cuda_core/ipcMemoryPool/ipcMemoryPool.py index 57727e76bab..b75d2bfdf4e 100644 --- a/samples/cuda_core/ipcMemoryPool/ipcMemoryPool.py +++ b/samples/cuda_core/ipcMemoryPool/ipcMemoryPool.py @@ -69,6 +69,7 @@ import numpy as np from cuda_samples_utils import print_gpu_info + from cuda.bindings import driver from cuda.core import ( Device, DeviceMemoryResource, @@ -103,6 +104,10 @@ def check_ipc_support(device) -> bool: if not device.properties.handle_type_posix_file_descriptor_supported: print("Device/platform does not support POSIX-fd IPC handles.") return False + posix_fd = int(driver.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR) + if not device.properties.mempool_supported_handle_types & posix_fd: + print("Device/platform does not support POSIX-fd IPC memory pools.") + return False return True From bcf02a82df8fea25b7b0323e2b8766bacd875b22 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 18 Nov 2026 00:09:15 +0000 Subject: [PATCH 3/5] fix(samples): waive the MLIR fluid sample without a display MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — codex GPT-6 on behalf of Ralf — On headless Linux, waive before CUDA setup or OpenGL window creation. Cover the negotiated waiver code and preserve CUDA setup errors when a display is present. --- .../example_tests/test_sample_verification.py | 25 +++++++++++++++++++ .../glInteropFluidNumbaCudaMlir.py | 4 +++ 2 files changed, 29 insertions(+) diff --git a/cuda_core/tests/example_tests/test_sample_verification.py b/cuda_core/tests/example_tests/test_sample_verification.py index 91ed5a418bd..ae7368afe11 100644 --- a/cuda_core/tests/example_tests/test_sample_verification.py +++ b/cuda_core/tests/example_tests/test_sample_verification.py @@ -19,6 +19,7 @@ "blurImageUnifiedMemory", "copyImageArraytoGPU", "glInteropFluid", + "glInteropFluidNumbaCudaMlir", "glInteropMipmapLod", "glInteropPlasma", "ipcMemoryPool", @@ -89,6 +90,30 @@ def test_ipc_sample_checks_memory_pool_handle_support(handle_types: int, support assert check_ipc_support(device) is supported +@pytest.mark.parametrize("display", [None, ":0"]) +@pytest.mark.agent_authored(model="GPT-6") +def test_mlir_sample_waives_missing_display_before_cuda_setup(display: str | None) -> None: + def is_available(): + raise RuntimeError("CUDA query failed") + + main = _load_sample_function( + "glInteropFluidNumbaCudaMlir", + "main", + os=SimpleNamespace(environ={} if display is None else {"DISPLAY": display}), + sys=SimpleNamespace(platform="linux", stderr=sys.stderr, exit=sys.exit), + cuda=SimpleNamespace(is_available=is_available), + EXIT_WAIVED=77, + ) + + if display is None: + with pytest.raises(SystemExit) as exc_info: + main() + assert exc_info.value.code == 77 + else: + with pytest.raises(RuntimeError, match="CUDA query failed"): + main() + + @pytest.mark.parametrize("sample_name", WAIVER_SAMPLE_NAMES) @pytest.mark.agent_authored(model="gpt-5") def test_core_sample_waivers_use_negotiated_exit_code( diff --git a/samples/cuda_core/glInteropFluidNumbaCudaMlir/glInteropFluidNumbaCudaMlir.py b/samples/cuda_core/glInteropFluidNumbaCudaMlir/glInteropFluidNumbaCudaMlir.py index b01de06e02c..60420651ade 100644 --- a/samples/cuda_core/glInteropFluidNumbaCudaMlir/glInteropFluidNumbaCudaMlir.py +++ b/samples/cuda_core/glInteropFluidNumbaCudaMlir/glInteropFluidNumbaCudaMlir.py @@ -471,6 +471,10 @@ def upload_and_draw(gl, shader_prog, vao_id, tex_id, host_rgba): def main(): + if sys.platform == "linux" and not os.environ.get("DISPLAY"): + print("No DISPLAY available; waiving glInteropFluidNumbaCudaMlir.", file=sys.stderr) + sys.exit(EXIT_WAIVED) + if not cuda.is_available(): print("No CUDA GPU available to numba.", file=sys.stderr) sys.exit(1) From 5838c4ea8ac5365989a8e6a6a28f7b21283892c9 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 18 Nov 2026 00:09:15 +0000 Subject: [PATCH 4/5] test(core): isolate memory resource capture from finalizers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit — codex GPT-6 on behalf of Ralf — Collect unrelated buffer finalizers with the worker context current before capture begins. Always close the graph builder so an invalidated capture cannot cause cascading failures in later tests. --- .../tests/graph/test_graph_memory_resource.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cuda_core/tests/graph/test_graph_memory_resource.py b/cuda_core/tests/graph/test_graph_memory_resource.py index faf56c061a3..57c463f912e 100644 --- a/cuda_core/tests/graph/test_graph_memory_resource.py +++ b/cuda_core/tests/graph/test_graph_memory_resource.py @@ -4,6 +4,7 @@ """Tests for GraphMemoryResource allocation and attributes during graph capture.""" +import gc import threading import pytest @@ -385,10 +386,16 @@ def worker(): try: device = Device(device_id) device.set_current() - gb = device.create_stream().create_graph_builder().begin_building(mode=mode) - device.memory_resource # noqa: B018 - first touch on this thread constructs the resource - result["building"] = gb.is_building - gb.end_building().complete() + # Unrelated buffer finalizers must run before capture, not during it. + gc.collect() + gb = device.create_stream().create_graph_builder() + try: + gb.begin_building(mode=mode) + device.memory_resource # noqa: B018 - first touch on this thread constructs the resource + result["building"] = gb.is_building + gb.end_building().complete() + finally: + gb.close() except BaseException as exc: result["error"] = exc From e6b5638d11bf3a31fdd0f9203adbdeca445cc36f Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 18 Nov 2026 00:09:15 +0000 Subject: [PATCH 5/5] ci: require manual copy-pr-bot approval