Skip to content

Fix issue #300 - #301

Merged
lohedges merged 1 commit into
develfrom
fix_300
Nov 20, 2026
Merged

lohedges merged 1 commit into
develfrom
fix_300

Conversation

@lohedges

@lohedges lohedges commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #300.

Fixes an unhandled IndexError when querying GPU memory usage in environments where OpenCL exposes fewer GPUs than the requested physical device index.

When pyopencl queries the system's OpenCL platforms, all_devices can contain fewer devices than the physical device_index (for example, when OpenCL fails to enumerate devices on a platform, or in container/cgroup-isolated jobs where only a subset of /dev/nvidia* nodes is mounted).

Previously, when device_index >= len(all_devices), the function explicitly raised and re-raised an IndexError, aborting before it could reach the pynvml fallback block, even though pynvml is explicitly designed to handle NVIDIA device queries when OpenCL detection fails.

Changes

  • Log a warning and fall through to the pynvml fallback block when device_index is out of range for the OpenCL device list instead of raising an IndexError.
  • Wrap pynvml device queries in a try ... finally block so pynvml.nvmlShutdown() is always called even if nvmlDeviceGetHandleByIndex or nvmlDeviceGetHandleByUUID raises an exception.

@lohedges lohedges added the bug Something isn't working label Nov 20, 2026
@lohedges

Copy link
Copy Markdown
Contributor Author

This fixes the existing IndexError, but I think there are possibly more general issues with device mappings. I'll have a deeper think about this and come back to it next week.

@lohedges
lohedges merged commit bd430f4 into devel Nov 20, 2026
4 checks passed
@lohedges
lohedges deleted the fix_300 branch November 20, 2026 13:16
lohedges added a commit that referenced this pull request Nov 20, 2026

This branch was previously deployed

1 inactive deployment
somd2-build — fc1d5da6 Deployed Nov 20, 2026 by lohedges via build (3.14, macos) #162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Potential incorrect GPU device index used by pyopencl on NVIDIA

1 participant