Repository navigation
fix(samples): count CUDA-visible devices in multi-GPU examples - #3277
Conversation
…cuda.core samples simpleP2P, simpleMultiGpu and multiGPUGradientAverage sized their device lists with cuda.core.system.get_num_devices(), which returns NVML's device count: every GPU on the system, regardless of CUDA_VISIBLE_DEVICES. With two of eight GPUs visible, simpleP2P reported 8 devices and failed on Device(2) with "device_id must be within [0, 2)"; multiGPUGradientAverage could map a rank to a device that is not visible. Use len(Device.get_all_devices()) and correct the two README lines that described get_num_devices() as the CUDA device count. Written with Claude Opus 5.5 and reviewed by the contributor. Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Use process-visible device counts samples/cuda_core/multiGPUGradientAverage/multiGPUGradientAverage.py, samples/cuda_core/simpleMultiGpu/simpleMultiGpu.py, samples/cuda_core/simpleP2P/simpleP2P.py, samples/cuda_core/simpleMultiGpu/README.md, samples/cuda_core/simpleP2P/README.md |
The three samples replace system.get_num_devices() with len(Device.get_all_devices()). The existing minimum-device checks and device selection remain in place. The README descriptions now name Device.get_all_devices(). |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
Count process-visible devices in the three samples and update the related README descriptions [#3215] |
✅ |
Possibly related PRs
- NVIDIA/cuda-python#3220: Both PRs update the same samples and README descriptions to use
Device.get_all_devices().
Suggested reviewers: danielfrg
Priority:
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: 
Minimal · up to 1e426
-
The samples now count CUDA-visible devices, so they should work when only a subset of GPUs is exposed. No merge-blocking risk was found. GPU and MPI runs were not repeated on the final head.
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Reran the samples on the current head ( Setup: 8-GPU host with physical GPUs 4 and 5 visible (
With only GPU 4 visible, head's simpleP2P and simpleMultiGpu both report one device and waive (exit code 2). multiGPUGradientAverage passes on the base too: with |
|
/ok to test 1e42667 |
|
Description
Closes #3215.
When
CUDA_VISIBLE_DEVICESexposes two GPUs on an eight-GPU host,simpleP2Puses NVML's system-wide count of eight and fails while constructingDevice(2). Count CUDA-visible devices withDevice.get_all_devices()insimpleP2P,simpleMultiGpu, andmultiGPUGradientAverage; update the relevant README API descriptions.system.get_num_devices()retains its NVML semantics.The fix was written with Claude Opus 5.5 and reviewed by the contributor. Related PR #3220 covers the same issue; this branch is based on the fix prepared before that PR.
Testing
On B300 (8 GPUs, physical GPUs 4 and 5 visible, CUDA 13.4.2, driver 610.57.04, Python 3.12, base
2da9c65a), the sample test runner reported:Device(2)out of rangeThe source change was tested there before rebasing. The current head has passed Ruff, syntax compilation and
git diff --check; GPU and MPI tests have not been rerun on this head. TheCUDA-capable device countlabel in the script matches the README expected output.