[MAHOUT-1414][QDP] Expose native cuda_available() and gate GPU tests on it#1416
Merged
Conversation
Follow-up to #1321 (addresses #1414). After #1321, `_qdp` can build and import without the CUDA toolkit (stub runtime), so "extension importable" no longer implies a usable GPU. The test suite gated GPU tests on `torch.cuda.is_available()`, a proxy that is wrong on this PR's headline scenario -- a GPU host with PyTorch but no toolkit, where `_qdp` is a stub build yet torch still reports a device. - qdp-core: add `cuda_runtime_available()`, which queries `cudaGetDeviceCount` (false in a stub build via the existing 999 sentinel stub, and on hosts with no device). Re-exported from the crate root. - _qdp: expose it as `_qdp.cuda_available()`. - qumat_qdp: add `is_cuda_available()`, mirroring `is_triton_amd_available()`, as the single Python source of truth. - testing/conftest: gate the `@pytest.mark.gpu` auto-skip on the native signal (falling back to torch only if the helper is absent). - test_fallback: coverage that runs on a stub build too, guarding that querying availability returns a bool without aborting. Verified on GPU (tests run and pass) and with CUDA hidden (tests skip); full Rust suite, clippy --all-features, ruff, and ty all clean.
ryankert01
force-pushed
the
qdp-unify-gpu-detection
branch
from
June 28, 2026 15:50
1c9078b to
bffb3ed
Compare
Contributor
|
@ryankert01 thanks for the patch, Nice one Two tiny nits, both optional:
|
rich7420
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1414.
Why
#1321 lets
_qdpbuild and import without the CUDA toolkit (stub CUDA Runtime symbols). That breaks the long-standing assumption that "the_qdpextension imports" ⟺ "a GPU is usable", which the test suite relied on to gate GPU tests. #1321 patched the immediate breakage by skipping@pytest.mark.gputests ontorch.cuda.is_available(), but that is a proxy: on this feature's headline scenario — a GPU host with PyTorch but no toolkit —_qdpis a stub build, yettorch.cuda.is_available()is stillTrue, so the GPU tests would run against the stub and abort.This PR makes the engine report the truth.
What
qdp-core: addcuda_runtime_available()— queriescudaGetDeviceCountand returnstrueonly when a device is actually present. In aqdp_no_cuda(stub) build it resolves to the existing 999-sentinel stub, so it returnsfalsewith nocfgbranching or dead code. Re-exported from the crate root._qdp: expose it as_qdp.cuda_available().qumat_qdp: addis_cuda_available()(mirrors the existingis_triton_amd_available()) as the single Python source of truth.testing/conftest.py: gate the@pytest.mark.gpuauto-skip on the native signal, falling back totorchonly if the helper is absent.test_fallback.py: coverage that also runs on a stub build, guarding that querying availability returns aboolwithout aborting.Test plan
Verified locally on 4× NVIDIA GPUs (CUDA 12.8), real build:
_qdp.cuda_available()/qumat_qdp.is_cuda_available()→Truewith a GPU,FalseunderCUDA_VISIBLE_DEVICES="".testing/qdp+testing/qdp_pythonwith CUDA hidden: 130 passed, 156 skipped, 0 failed (no aborts).qdp-corebuilds in both real andQDP_NO_CUDA=1stub modes; full Rust suite,clippy --all-features -D warnings,ruff, andtyall clean.Out of scope (left in #1414)
Making the stub path raise a clean
RuntimeErrorinstead of aborting for direct (non-test) callers, and collapsing the ~65 redundant inlinetorch.cuda.is_available()checks now that the conftest gate is accurate.