问题
I know I can access the current GPU using torch.cuda.current_device()
, but how can I get a list of all the currently available GPUs?
回答1:
You can list all the available GPUs by doing:
>>> import torch
>>> available_gpus = [torch.cuda.device(i) for i in range(torch.cuda.device_count())]
>>> available_gpus
[<torch.cuda.device object at 0x7f2585882b50>]
来源:https://stackoverflow.com/questions/64776822/how-do-i-list-all-currently-available-gpus-with-pytorch