来源:https://blog.csdn.net/u013548568/article/details/84350638

cuda上tensor的定义

a = torch.ones(1000,1000,3).cuda()


某一gpu上定义

cuda1 = torch.device('cuda:1')#使用该语句可以选择要使用的gpu
b = torch.randn((1000,1000,1000),device=cuda1)


删除某一变量

del a


在cpu定义tensor然后转到gpu

torch.zeros().cuda()


直接在gpu上定义,这样就减少了cpu的损耗

torch.cuda.FloatTensor(batch_size, self.hidden_dim, self.height, self.width).fill_(0)

相关文章:

  • 2022-12-23
  • 2021-06-23
  • 2021-09-28
  • 2021-05-22
  • 2022-12-23
  • 2022-01-05
  • 2022-01-26
  • 2022-12-23
猜你喜欢
  • 2021-04-18
  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案