Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Device Truly Available by Creating Trivial Object #234

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/senselab/utils/data_structures/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,22 @@ def _select_device_and_dtype(
if user_preference:
if not isinstance(user_preference, DeviceType):
raise ValueError(f"user_preference should be of type DeviceType, not {type(user_preference)}")

available_devices = [DeviceType.CPU]

if torch.cuda.is_available():
available_devices.append(DeviceType.CUDA)
try:
torch.empty(0, device=DeviceType.CUDA.value)
available_devices.append(DeviceType.CUDA)
except Exception as e:
print(f"CUDA is available but encountered an error: {e}")

if torch.backends.mps.is_available():
available_devices.append(DeviceType.MPS)
try:
torch.empty(0, device=DeviceType.MPS.value)
available_devices.append(DeviceType.MPS)
except Exception as e:
print(f"MPS is available but encountered an error: {e}")

# Check compatible and available
useable_devices = []
Expand Down
Loading