Skip to content

Commit c9f0ddf

Browse files
committed
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 <[email protected]>
1 parent d4c71ef commit c9f0ddf

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎cuda_bindings_13/tests/test_graphics_apis.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
gl_context_not_on_nvidia_gpu_reason,
1414
is_gl_context_unavailable,
1515
open_gl_window,
16+
select_headless_egl_device_for_cuda,
1617
tcc_skip_reason,
1718
)
1819

@@ -22,12 +23,20 @@
2223

2324

2425
def _configure_pyglet_headless():
25-
"""On headless Linux: enable EGL mode or skip if EGL is absent."""
26+
"""On headless Linux: enable EGL mode, matched to CUDA device 0, or skip if EGL is absent."""
2627
if sys.platform.startswith("linux") and not (os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY")):
2728
if ctypes.util.find_library("EGL") is None:
2829
pytest.skip("No DISPLAY and no EGL runtime available for headless context.")
2930
pyglet.options["headless"] = True
3031

32+
# CUDA_VISIBLE_DEVICES does not reorder EGL's device enumeration, so on
33+
# headless multi-GPU systems EGL device 0 may not be the physical GPU
34+
# behind CUDA device 0, which these tests register against. Pick the
35+
# EGL device that the driver reports as corresponding to it.
36+
egl_device = select_headless_egl_device_for_cuda(0)
37+
if egl_device is not None:
38+
pyglet.options["headless_device"] = egl_device
39+
3140

3241
def _allocate_gl_texture(win):
3342
"""Allocate a 2-D RGBA8 texture. Caller must have a current GL context.

0 commit comments

Comments
 (0)