torch.Tensor.get_device
- Tensor.get_device() -> 设备序号 (整数))
-
对于 CUDA 张量,该函数返回张量所在的 GPU 设备序号。对于 CPU 张量,则返回-1。
示例:
>>> x = torch.randn(3, 4, 5, device='cuda:0') >>> x.get_device() 0 >>> x.cpu().get_device() -1
对于 CUDA 张量,该函数返回张量所在的 GPU 设备序号。对于 CPU 张量,则返回-1。
示例:
>>> x = torch.randn(3, 4, 5, device='cuda:0') >>> x.get_device() 0 >>> x.cpu().get_device() -1