pixelart-50m / pixelart /device.py
kuyumcu
Initial release
5ae1940 verified
Raw History Blame Contribute Delete
521 Bytes
"""Pick the fastest available torch device: NVIDIA (cuda) > Apple Silicon (mps) > cpu."""
from __future__ import annotations
import torch
def pick_device() -> torch.device:
if torch.cuda.is_available():
return torch.device("cuda")
if torch.backends.mps.is_available():
return torch.device("mps")
return torch.device("cpu")
def synchronize(dev: torch.device) -> None:
if dev.type == "cuda":
torch.cuda.synchronize()
elif dev.type == "mps":
torch.mps.synchronize()