print("CUDA available: ", torch.cuda.is_available())
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
可用的CUDA:是
x = torch.tensor([1, 2, 3]).to(device)
y = torch.tensor([1, 2, 3])
%%timeit -n 10000
z = x + 1
10000次循环,最佳为3次:每个循环15.6 µs
%%timeit -n 10000
z = y + 1
10000次循环,每循环3:5.19 µs最佳