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

[转载]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)

猜你喜欢

转载自www.cnblogs.com/jiading/p/12191353.html