Skip to content

qumat_qdp: intersect GPU compute capability with PyTorch's arch list#1323

Merged
ryankert01 merged 1 commit into
mainfrom
pytorch-gpu-capability-check
May 18, 2026
Merged

qumat_qdp: intersect GPU compute capability with PyTorch's arch list#1323
ryankert01 merged 1 commit into
mainfrom
pytorch-gpu-capability-check

Conversation

@andrewmusselman
Copy link
Copy Markdown
Contributor

Fixes Issue #1320 .

Adds _select_torch_device(torch, device_id) in qumat_qdp.loader. It:

  • returns "cpu" when CUDA isn't available,
  • raises ValueError on out-of-range device_id (preserves prior
    contract),
  • checks torch.cuda.get_device_capability(device_id) against
    torch.cuda.get_arch_list() and falls back to "cpu" with a clear
    warnings.warn when the device's sm_NN isn't in the list,
  • otherwise returns f"cuda:{device_id}".
    Both qumat_qdp.loader.QuantumDataLoader._create_pytorch_iterator and
    qumat_qdp.api.QdpBenchmark._run_throughput_pytorch use the new helper
    (the latter previously duplicated the same incomplete selection logic).

testing/qdp_python/test_torch_ref.py gets a mirror helper
_torch_cuda_usable() used by the two @skipifs that previously only
checked is_available().

After this change, on an incompatible GPU:

  • 8 pytorch-backend loader tests + 4 benchmark tests silently fall back
    to CPU and pass (each emits one UserWarning),
  • the 5 explicit GPU tests skip with "CUDA not available or GPU compute capability not supported by this PyTorch build".
    Verified on Linux + GTX 1060 (sm_61) with PyTorch wheel targeting
    sm_70+: tests that previously errored with
    cudaErrorNoKernelImageForDevice now pass or skip cleanly.

Copy link
Copy Markdown
Member

@ryankert01 ryankert01 left a comment

Choose a reason for hiding this comment

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

Make sense! Let copilot double check for me.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes #1320 by ensuring PyTorch device selection accounts for the GPU's compute capability against the installed wheel's compiled arch list, avoiding opaque cudaErrorNoKernelImageForDevice failures on older GPUs (e.g., Pascal sm_61 against a sm_70+ wheel). Introduces a shared _select_torch_device helper in qumat_qdp.loader, reuses it in the benchmark path, and mirrors the logic in test skip predicates.

Changes:

  • Add _select_torch_device(torch, device_id) in loader.py that validates device_id, intersects device capability with torch.cuda.get_arch_list(), and warns + falls back to CPU on mismatch.
  • Replace duplicated CUDA selection logic in QdpBenchmark._run_throughput_pytorch with the shared helper.
  • Add _torch_cuda_usable() in test_torch_ref.py and use it in the two GPU-only test skipifs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
qdp/qdp-python/qumat_qdp/loader.py New _select_torch_device helper; loader uses it for pytorch backend device pick.
qdp/qdp-python/qumat_qdp/api.py Benchmark throughput path delegates to the shared helper instead of duplicated logic.
testing/qdp_python/test_torch_ref.py New _torch_cuda_usable() mirroring the helper's capability check, applied to GPU-only test skipifs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ryankert01 ryankert01 merged commit 54b0f23 into main May 18, 2026
6 checks passed
@ryankert01 ryankert01 deleted the pytorch-gpu-capability-check branch May 18, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants