Skip to content

test(cuda.bindings): run the headless-EGL GL interop test on CUDA 12 and require cudaSuccess - #3653

Open
mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:issue3575
Open

mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:issue3575

Conversation

@mdboom

@mdboom mdboom commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Closes #3575. Part of #2077.

Summary

cuda_bindings_12's test_graphics_api_smoketest needed DISPLAY or WAYLAND_DISPLAY, so it skipped on every Linux runner. cuda_bindings_13 already has a headless-EGL replacement, test_cuda_gl_register_image_smoketest (#3276). This PR shares that test's GL setup and uses it in both roots:

 cuda_python_test_helpers/graphics.py
+  configure_pyglet_headless()   # headless EGL on the device behind CUDA device 0
+  allocate_gl_texture()
+  gl_context()                  # TCC skip, headless setup, NVIDIA-GL check, cleanup

 cuda_bindings_13/tests/test_graphics_apis.py
-  _configure_pyglet_headless / _allocate_gl_texture / _gl_context
+  from cuda_python_test_helpers.graphics import gl_context

 cuda_bindings_12/tests/test_graphics_apis.py   # now identical to the CUDA 13 file
-  test_graphics_api_smoketest   # DISPLAY only
+  test_cuda_gl_register_image_smoketest[None, WriteDiscard]

Both roots now require success:

-        acceptable = {"cudaSuccess", "cudaErrorOperatingSystem"}
-        assert name in acceptable
-        if name == "cudaSuccess":
-            assert int(resource) != 0
-            cudart.cudaGraphicsUnregisterResource(resource)
+        assert name == "cudaSuccess"
+        assert int(resource) != 0
+        (err,) = cudart.cudaGraphicsUnregisterResource(resource)
+        assert cudaGetErrorName(err) == "cudaSuccess"

Evidence

CI coverage:

  • CUDA 12: on main, test_graphics_api_smoketest skips in all 20 configurations. After this change the GL test should pass on the 12 Linux CUDA 12 rows (x86-64 and aarch64; T4, V100, L4, A100, RTX PRO 6000). The WSL row should skip with "GL context is not on an NVIDIA GPU", and the 7 Windows rows skip (TCC, or no opengl32), as on CUDA 13.
  • CUDA 13: the test already passes on 20 Linux rows; requiring cudaSuccess tightens only those rows.
  • .github/workflows/test-wheel-linux.yml installs libegl1 for every Linux row.

Locally (headless, DISPLAY and WAYLAND_DISPLAY unset): all three tests in each file pass, the CUDA 13 file against cuda-bindings 13.5 and the CUDA 12 file against cuda-bindings 12.9.11.

Confirming in CI: in this PR's CI run, the Linux CUDA 12 cuda.bindings jobs should report test_cuda_gl_register_image_smoketest PASSED for both flags. For example:

gh run view <CI run id> --repo NVIDIA/cuda-python --log | grep -F "test_graphics_apis.py::test_cuda_gl_register_image_smoketest"

Merge Danger

Door: two-way. Test-only change.

Blast Radius: the GL interop tests in both bindings roots and cuda_python_test_helpers.graphics (existing functions unchanged; three added). If a CUDA 13 row has been passing on cudaErrorOperatingSystem, it now fails, which would expose a real interop problem.

Reviewers: please feel free to push commits directly to this PR to improve it.

🤖 Generated with Claude Code

…and require cudaSuccess

cuda_bindings_12's test_graphics_api_smoketest needed DISPLAY or
WAYLAND_DISPLAY, so it skipped on every Linux runner. cuda_bindings_13
already has a headless-EGL test (test_cuda_gl_register_image_smoketest).

Move that test's GL setup into cuda_python_test_helpers.graphics as public
helpers (configure_pyglet_headless, allocate_gl_texture, gl_context), and
use them from an identical test file in both roots, replacing the old CUDA
12 test.

In both roots, require cudaGraphicsGLRegisterImage and
cudaGraphicsUnregisterResource to return cudaSuccess. The
cudaErrorOperatingSystem allowance (NVIDIA#1210) predates the check that the GL
context is on an NVIDIA GPU (NVIDIA#3276); gl_context() now skips that case
before registering.

Closes NVIDIA#3575.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdboom mdboom added this to the cuda.bindings 13.6.0 & 12.9.12 milestone Nov 30, 2026
@mdboom mdboom added test Improvements or additions to tests cuda.bindings Everything related to the cuda.bindings module labels Nov 30, 2026
@mdboom mdboom self-assigned this Nov 30, 2026
@mdboom
mdboom requested review from rparolin and rwgk November 30, 2026 16:28
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • Tests
    • Graphics API checks now verify successful CUDA/OpenGL resource registration and unregistration with multiple registration options.
    • Graphics test setup is shared across supported CUDA versions, with handling for headless environments and unavailable or unsupported graphics contexts.

The pull request adds shared OpenGL context and texture helpers. Tests in both CUDA bindings roots use those helpers and require successful image registration, a nonzero resource, and successful unregistration.

Changes: GL interop registration tests

Layer / File(s) Summary
Shared headless GL context
cuda_python_test_helpers/cuda_python_test_helpers/graphics.py
The helper configures headless pyglet on supported Linux systems, allocates a texture, and manages context and texture cleanup.
Registration checks in both bindings roots
cuda_bindings_12/tests/test_graphics_apis.py, cuda_bindings_13/tests/test_graphics_apis.py
Both tests use the shared context. They require cudaSuccess, a nonzero resource, and successful unregistration. CUDA 12 also tests both registration flag values.

Assessment against linked issues

Objective Addressed Explanation
Port the headless-EGL GL interop test to CUDA 12 and require successful registration in both bindings roots [#3575] ✅
Require a nonzero resource and successful unregistration in both roots [#3575] ✅

Possibly related issues

  • NVIDIA/cuda-python#3576: This PR adds shared headless EGL helpers used by the bindings tests, but does not update the cuda.core GL samples described in the issue.

Possibly related PRs

Suggested reviewers: rwgk, juenglin, jpascucci-nv

Change: Other · Severity of issue fixed: Medium

Merge Risk: Low · up to 5c1a1

Test setup can error instead of skipping when libEGL is present but cannot load its dependencies. Moving the configuration call inside the existing try fixes this. Production code is unaffected, so the risk of merging is low.

Security architecture risk: Minimal · up to 5c1a1

The change shares graphics setup between the CUDA 12 and CUDA 13 smoke tests and makes those tests stricter without changing the CUDA bindings interface.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Finishing Touches
Fix failing CI checks

  • Create a new PR

@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 1c9ed66 and 5c1a15b.

Files selected for processing: 3

  • cuda_bindings_12/tests/test_graphics_apis.py
  • cuda_bindings_13/tests/test_graphics_apis.py
  • cuda_python_test_helpers/cuda_python_test_helpers/graphics.py

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


if reason := tcc_skip_reason():
pytest.skip(reason)
configure_pyglet_headless()

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 · Functional Correctness · Quick win

important: Move configure_pyglet_headless() into the try in gl_context.

When libEGL is found but one of its dependencies fails to load, the EGL import in select_headless_egl_device_for_cuda raises ImportError('Library "EGL" not found.'). That import (lines 62-63) runs before the helper's own try, so the error propagates through configure_pyglet_headless() and out of gl_context(). is_gl_context_unavailable() handles this error only inside the try that wraps open_gl_window(). The test therefore errors instead of skipping. Before this change, the CUDA 12 test skipped in this headless environment. Both CUDA roots use gl_context(), so both are affected.

Move the call inside the existing try. The classifier then skips on this error, and other exceptions still propagate.

Suggested fix

--- "a/cuda_python_test_helpers/cuda_python_test_helpers/graphics.py"
+++ "b/cuda_python_test_helpers/cuda_python_test_helpers/graphics.py"
@@ -288,10 +288,9 @@
 
     if reason := tcc_skip_reason():
         pytest.skip(reason)
-    configure_pyglet_headless()
-
     try:
+        configure_pyglet_headless()
         win = open_gl_window()
     except Exception as e:
         if is_gl_context_unavailable(e):
             pytest.skip(f"Could not create GL context: {type(e).__name__}: {e}")

@github-actions

Copy link
Copy Markdown
Contributor

@rwgk rwgk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

codex GPT-6.2-Sol ultra review at commit 5c1a15b:

Initial findings:

  • P2 · The smoke test can pair OpenGL with the wrong CUDA device. An X11 display can render on NVIDIA GPU A while CUDA_VISIBLE_DEVICES exposes only GPU B. The NVIDIA vendor check still passes, so the strict registration assertion can fail because of the device pairing. Headless setup also assumes CUDA device 0 without selecting it. Match EGL to the active CUDA device and use cudaGLGetDevices() to check the association before requiring registration success. This is a source-level finding. EGL setup · CUDA API
  • P3 · A discoverable but unloadable EGL library fails setup. Headless configuration runs outside the handler that recognizes pyglet’s EGL ImportError. I reproduced the failure with the pinned pyglet and a mocked loader error. Moving configuration inside the existing setup try produced the expected skip. Setup handler
  • P3 · Mark the duplicated smoke test as synchronized. The CUDA 12 and CUDA 13 test files match byte-for-byte. Add matching SYNCED markers around the shared test so future edits preserve that parity. The existing PYTEST PLUGIN BOOTSTRAP blocks match across both bindings roots and Core. CUDA 12 test · CUDA 13 test

After asking which are existing problems:

The first two findings are inherited CUDA 13 setup issues. The PR changes where they can surface.

  • Wrong GPU pairing — existing setup issue, stricter assertion. CUDA 13 already selected EGL for CUDA device 0 and checked only the GL vendor. The PR preserves that setup and removes the allowance for cudaErrorOperatingSystem, so a mismatch that returns that status can now fail. CUDA 12 newly uses the same headless setup. Previous CUDA 13 test
  • Unloadable EGL — existing on CUDA 13, newly reachable on CUDA 12. The configuration call was already outside the try in CUDA 13. CUDA 12 previously skipped without a display, so porting the test exposes that failure path there. CodeRabbit’s fix would address the inherited issue in both roots. Previous CUDA 12 test

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 test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(cuda.bindings): port the headless-EGL GL interop test to cuda_bindings_12 and require cudaSuccess

2 participants