From c9f0ddf0c6faa5b655a9723b08bc3c3fe87bb029 Mon Sep 17 00:00:00 2001 From: 0z5a Date: Sat, 24 Oct 2026 17:28:37 +0200 Subject: [PATCH] test(cuda.bindings): match the headless EGL device to CUDA device 0 in the GL interop tests #2865 made cuda.core's graphics tests pick the EGL device that backs the current CUDA device, because CUDA_VISIBLE_DEVICES does not reorder EGL's device enumeration. The cuda.bindings GL interop tests still opened EGL device 0, so on a headless multi-GPU host where CUDA device 0 is another GPU, cudaGraphicsGLRegisterImage returned cudaErrorInvalidDevice. Use the same select_headless_egl_device_for_cuda helper for CUDA device 0, which these tests register against. Tests written with Claude Opus 5.5 and reviewed by the contributor. Signed-off-by: 0z5a --- cuda_bindings_13/tests/test_graphics_apis.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cuda_bindings_13/tests/test_graphics_apis.py b/cuda_bindings_13/tests/test_graphics_apis.py index 491aa7bd837..9b357620db8 100644 --- a/cuda_bindings_13/tests/test_graphics_apis.py +++ b/cuda_bindings_13/tests/test_graphics_apis.py @@ -13,6 +13,7 @@ gl_context_not_on_nvidia_gpu_reason, is_gl_context_unavailable, open_gl_window, + select_headless_egl_device_for_cuda, tcc_skip_reason, ) @@ -22,12 +23,20 @@ def _configure_pyglet_headless(): - """On headless Linux: enable EGL mode or skip if EGL is absent.""" + """On headless Linux: enable EGL mode, matched to CUDA device 0, or skip if EGL is absent.""" if sys.platform.startswith("linux") and not (os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY")): if ctypes.util.find_library("EGL") is None: pytest.skip("No DISPLAY and no EGL runtime available for headless context.") pyglet.options["headless"] = True + # CUDA_VISIBLE_DEVICES does not reorder EGL's device enumeration, so on + # headless multi-GPU systems EGL device 0 may not be the physical GPU + # behind CUDA device 0, which these tests register against. Pick the + # EGL device that the driver reports as corresponding to it. + egl_device = select_headless_egl_device_for_cuda(0) + if egl_device is not None: + pyglet.options["headless_device"] = egl_device + def _allocate_gl_texture(win): """Allocate a 2-D RGBA8 texture. Caller must have a current GL context.