Torch device的基本用法
print("Default Device:{}".format(torch.Tensor([4,5,6]).device))
device = torch.Tensor([1,2,3],device="cpu:0").device
print(device)
cpu1 = torch.device("cpu:0")
print(cpu1)
gpu = torch.device(0)
print(gpu.type)
gpu = torch.device("cuda:0")
print(gpu)
print("Torch GPU Count:{}".format(torch.cuda.device_count()))
print("Torch CPU Count:{}".format(torch.cuda.os.cpu_count()))
print(torch.cuda.get_device_name(torch.device("cuda:0")))
print(torch.cuda.is_available())
-----------------------------------------------------------------------------
result:
Default Device:cpu
cpu
cpu:0
cuda
cuda:0
Torch GPU Count:1
Torch CPU Count:16
GeForce RTX 2060
True