Skip to content

test(cuda.bindings): select the matching EGL device for headless GL interop - #3276

Open
0z5a wants to merge 1 commit into
NVIDIA:mainfrom
0z5a:test/bindings-gl-headless-egl-device
Open

0z5a wants to merge 1 commit into
NVIDIA:mainfrom
0z5a:test/bindings-gl-headless-egl-device

Conversation

@0z5a

@0z5a 0z5a commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #3212.

On headless multi-GPU hosts, EGL device 0 can differ from CUDA device 0 when CUDA_VISIBLE_DEVICES selects a subset. The GL interop tests then register a texture from the wrong GPU and can fail with cudaErrorInvalidDevice. Use the existing shared EGL selection helper, as cuda.core's graphics tests do, before creating the headless context. If the extension cannot identify a device, the existing pyglet default remains in use.

The original fix was written with Claude Opus 5.5 and reviewed by the contributor.

Testing

  • Historical B300 run, CUDA 13.4.2, driver 610.57.04, Python 3.12, base 2da9c65a: patched test_graphics_apis.py passed 3/3 with only the sixth GPU visible and no PYGLET_HEADLESS_DEVICE override. Before the fix, the two registration parameters failed unless the matching EGL device was selected manually.
  • Current rebased head: Ruff, Python syntax compilation and git diff --check passed. GPU/GL tests have not been rerun on this head.

…n the GL interop tests

NVIDIA#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 <dezhen.lu@student.uni-tuebingen.de>
@copy-pr-bot

copy-pr-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.bindings Everything related to the cuda.bindings module label Oct 29, 2026
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

📝 Summary

Summary by CodeRabbit

  • Tests
    • Graphics API tests on headless Linux now select the EGL device that matches CUDA device 0 when available. Existing EGL availability checks and skip behavior remain unchanged. This improves consistency when running graphics-related tests in headless environments without changing application behavior or adding user-facing features.

The graphics test helper now selects the EGL device associated with CUDA device 0 for Pyglet headless mode when a matching device is found. Existing EGL availability checks and skip behavior remain unchanged.

Changes: Headless EGL device selection

Layer / File(s) Summary
Configure the headless EGL device
cuda_bindings_13/tests/test_graphics_apis.py
The helper calls select_headless_egl_device_for_cuda(0) and sets Pyglet’s headless_device option when the function returns a device. Existing headless-mode and EGL availability behavior remains.

Assessment against linked issues

Objective Addressed Explanation
Select the EGL device that matches CUDA device 0 for headless GL interop tests [3212] ✅

Possibly related PRs

  • NVIDIA/cuda-python#3173: Updates the CUDA 12 graphics smoke test’s no-display handling; this PR updates the corresponding CUDA 13 headless setup.

Suggested labels: bug, cuda.bindings

Suggested reviewers: juenglin

Priority: Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Low · up to c9f0d

On affected headless hosts, the graphics tests may fail rather than skip when EGL is discoverable but unusable; the localized handler adjustment should be made before merge.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d4c71ef and c9f0ddf.

Files selected for processing: 1
  • cuda_bindings_13/tests/test_graphics_apis.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

# 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Stability & Availability · Quick win

important: Preserve GL-unavailable skips during the probe.

If find_library("EGL") finds a library that cannot be loaded, the selector raises ImportError before the existing is_gl_context_unavailable handler. The tests now fail instead of skipping. Include _configure_pyglet_headless() in that handler’s try block. (raw.githubusercontent.com)

@NVIDIA NVIDIA deleted a comment from copy-pr-bot Bot Oct 29, 2026
@NVIDIA NVIDIA deleted a comment from copy-pr-bot Bot Oct 29, 2026
@rparolin

Copy link
Copy Markdown
Collaborator

/ok to test c9f0ddf

@rparolin rparolin added the P1 Medium priority - Should do label Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.bindings Everything related to the cuda.bindings module P1 Medium priority - Should do

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: cuda.bindings GL interop tests open EGL device 0 on headless multi-GPU hosts and fail with cudaErrorInvalidDevice

2 participants