Skip to content

Commit b1ea1b4

Browse files
committed
test(graphics): share TCC-mode skip helper across graphics test suites
Add tcc_skip_reason() to cuda_python_test_helpers.graphics so both cuda_core/tests/test_graphics.py and cuda_bindings/tests/test_graphics_apis.py skip CUDA-GL interop tests on a TCC device using one shared predicate. The helper queries the current device via cuda.bindings.runtime (not cuda.core) so the cuda_bindings suite does not take a cuda.core dependency. Runtime query failures propagate rather than being masked as a skip. test_cuda_register_image_invalid stays enabled: it does not open a GL context and only checks the error path for an invalid handle. Signed-off-by: Ralf Juengling <[email protected]>
1 parent f833a8c commit b1ea1b4

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

‎cuda_bindings/tests/test_graphics_apis.py‎

Lines changed: 3 additions & 0 deletions
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+
tcc_skip_reason,
1617
)
1718

1819
from cuda.bindings import runtime as cudart
@@ -56,6 +57,8 @@ def _allocate_gl_texture(win):
5657
@contextlib.contextmanager
5758
def _gl_context():
5859
"""Yield ``(tex_id, tex_target)`` with a current GL context, or skip if GL is unavailable."""
60+
if reason := tcc_skip_reason():
61+
pytest.skip(reason)
5962
_configure_pyglet_headless()
6063

6164
try:

‎cuda_core/tests/test_graphics.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
is_gl_context_unavailable,
2121
open_gl_window,
2222
select_headless_egl_device_for_cuda,
23+
tcc_skip_reason,
2324
)
2425

2526
import cuda_python_test_helpers
@@ -62,8 +63,8 @@ def _register_gl_image(tex_id, target):
6263

6364
def _skip_if_tcc():
6465
"""Skip on TCC: compute-only driver model, no OpenGL, so CUDA-GL interop is unavailable."""
65-
if Device().properties.tcc_driver:
66-
pytest.skip("Device is in TCC mode; TCC does not support OpenGL, so CUDA-GL interop is unavailable.")
66+
if reason := tcc_skip_reason():
67+
pytest.skip(reason)
6768

6869

6970
def _configure_pyglet_headless():

‎cuda_python_test_helpers/cuda_python_test_helpers/graphics.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,35 @@ def open_gl_window():
128128
return None
129129

130130

131+
def tcc_skip_reason() -> str | None:
132+
"""Return a skip reason if the current CUDA device uses the TCC driver model, else None.
133+
134+
TCC (Tesla Compute Cluster) is a Windows compute-only driver model with no
135+
OpenGL support, so CUDA-GL interop is unavailable on a TCC device. The
136+
check queries the currently-selected device via the CUDA runtime API
137+
(``cuda.bindings``) rather than ``cuda.core``, so both the ``cuda_core``
138+
and ``cuda_bindings`` graphics tests can share it without the latter
139+
taking a ``cuda.core`` dependency.
140+
141+
Runtime query failures (e.g. no CUDA device) propagate rather than being
142+
masked as a skip, so a real environment problem surfaces instead of being
143+
hidden behind a skipped test.
144+
"""
145+
from cuda.bindings import runtime as cudart
146+
147+
err, device = cudart.cudaGetDevice()
148+
if err != cudart.cudaError_t.cudaSuccess:
149+
raise RuntimeError(f"cudaGetDevice failed: {cudart.cudaGetErrorString(err)[1].decode()!r}")
150+
err, is_tcc = cudart.cudaDeviceGetAttribute(cudart.cudaDeviceAttr.cudaDevAttrTccDriver, device)
151+
if err != cudart.cudaError_t.cudaSuccess:
152+
raise RuntimeError(
153+
f"cudaDeviceGetAttribute(cudaDevAttrTccDriver) failed: {cudart.cudaGetErrorString(err)[1].decode()!r}"
154+
)
155+
if is_tcc:
156+
return "Device is in TCC mode; TCC does not support OpenGL, so CUDA-GL interop is unavailable."
157+
return None
158+
159+
131160
def gl_context_not_on_nvidia_gpu_reason() -> str | None:
132161
"""Return a skip reason if the current GL context is not on an NVIDIA GPU, else None.
133162

0 commit comments

Comments
 (0)