Torch学习笔记—CUDA,Tensor

版权声明:本文为博主原创文章,如需转载请注明出处。 https://blog.csdn.net/qq_36215315/article/details/88912611

1.CUDA,Tensor
使用.to把张量放置在任何设备上运行

y: 直接在GPU上创建
x:使用.to(“cuda”)创建
在这里插入图片描述
附上代码:
import torch

x = torch.rand(3, 4)
z = torch.rand(3, 4)
if torch.cuda.is_available():
torch_device = torch.device(“cuda”)
y = torch.ones_like(x, device=torch_device)
x = x.to(torch_device)
z = x + y
print(z)

猜你喜欢

转载自blog.csdn.net/qq_36215315/article/details/88912611