Skip to content

[XPU] Support XPU devices mostly by unifying XPU, CUDA and other supported backends - #252

Merged
bowen-bd merged 3 commits into
CederGroupHub:mainfrom
abagusetty:xpu-support
Sep 15, 2026
Merged

bowen-bd merged 3 commits into
CederGroupHub:mainfrom
abagusetty:xpu-support

Conversation

@abagusetty

@abagusetty abagusetty commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Major changes:

  • Added feature support to target Intel GPUs (on Aurora) and generalize device selection so CUDA, Intel XPUs, MPS and CPU are handled through one code path
  • Removed pynvml dependency with more robust torch.cuda.mem_get_info for generalized support
  • Helps to support models in this matrix for Intel GPU (Aurora): https://garden-ai.github.io/almanac/

Checklist

  • All existing tests pass.
  • Tests have been added for any new features/fixes.
  • Docstrings have been added in the Google docstring format.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 7 high · 13 minor

Results:
20 new issues

Category Results
Documentation 13 minor
Security 7 high

View in Codacy

🟢 Metrics 18 complexity

Metric Results
Complexity 18

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@abagusetty

Copy link
Copy Markdown
Contributor Author

Hey @bowen-bd, gentle ping to gauge your interest in handling the XPU backend alongside CUDA with this PR, while keeping the approach generic for HIP and other backends in the future

Add Intel GPU (XPU) as a selectable torch backend alongside CUDA, MPS and
CPU, so CHGNet runs on Intel Data Center GPU Max systems such as ALCF Aurora.

`pynvml` was a mandatory dependency imported at module scope, so `import
chgnet` failed on any machine without NVIDIA's management library. It only
ranked GPUs by free memory, which `mem_get_info` already does on both CUDA
and XPU, so the dependency is dropped rather than made optional.

Indices now come from `device_count()`, which fixes two latent CUDA bugs:
NVML ignored `CUDA_VISIBLE_DEVICES` and could name an unaddressable GPU, and
an empty device list raised IndexError.

`cuda_devices_sorted_by_free_mem` stays as an alias and `check_cuda_mem`
keeps its name, so existing callers are unaffected. Ranking degrades to an
unindexed device where free memory cannot be queried: `torch.xpu.mem_get_info`
needs torch 2.6, and on multi-tile Intel GPUs the underlying SYCL query is
per card rather than per tile.
Test `determine_device` backend precedence by monkeypatching each
`is_available`, so CUDA/XPU/MPS/CPU selection is exercised on any runner.

`test_gpu_devices_are_valid_torch_indices` asserts the returned indices match
`device_count()`, which fails if a library that ignores the visible-device
mask is reintroduced. Verified unmasked and under `ZE_AFFINITY_MASK=3,7`.
Two jobs, both gated on `workflow_dispatch` or an `xpu` pull request label,
so repositories without Intel GPUs are unaffected and `test.yml` is untouched.

`test-xpu-build` runs on `ubuntu-latest`: XPU torch ships from a separate
index, so it installs that build with no GPU attached and checks device
selection falls back to cpu. `test-xpu` runs the suite on a self-hosted
runner labelled `intel-gpu`.

A SYCL OpenCL-CPU runner cannot substitute, as torch filters `torch.xpu` to
Level Zero GPU platforms only.

Also document the supported devices in the README.
@bowen-bd

bowen-bd commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the contribution!

@bowen-bd
bowen-bd enabled auto-merge (squash) September 8, 2026 18:03
@bowen-bd
bowen-bd disabled auto-merge September 15, 2026 06:23
@bowen-bd
bowen-bd merged commit b9a6c15 into CederGroupHub:main Sep 15, 2026
9 checks passed
@abagusetty

Copy link
Copy Markdown
Contributor Author

Great! Thanks so much for taking time @bowen-bd

@abagusetty
abagusetty deleted the xpu-support branch September 15, 2026 22:07
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.

2 participants