[转载]pytorch cuda上tensor的定义 以及 减少cpu操作的方法

安稳与你 提交于 2020-01-14 12:57:45

[转载]pytorch cuda上tensor的定义 以及 减少cpu操作的方法

来源: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)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!