本文簡要介紹python語言中 torch.Tensor.get_device
的用法。
用法:
Tensor.get_device() -> Device ordinal(Integer)
對於 CUDA 張量,此函數返回張量所在的 GPU 的設備序號。對於 CPU 張量,會引發錯誤。
例子:
>>> x = torch.randn(3, 4, 5, device='cuda:0') >>> x.get_device() 0 >>> x.cpu().get_device() # RuntimeError: get_device is not implemented for type torch.FloatTensor
相關用法
- Python PyTorch Tensor.unflatten用法及代碼示例
- Python PyTorch Tensor.register_hook用法及代碼示例
- Python PyTorch Tensor.storage_offset用法及代碼示例
- Python PyTorch Tensor.to用法及代碼示例
- Python PyTorch Tensor.sparse_mask用法及代碼示例
- Python PyTorch Tensor.is_leaf用法及代碼示例
- Python PyTorch Tensor.imag用法及代碼示例
- Python PyTorch Tensor.unfold用法及代碼示例
- Python PyTorch Tensor.real用法及代碼示例
- Python PyTorch Tensor.refine_names用法及代碼示例
- Python PyTorch Tensor.rename用法及代碼示例
- Python PyTorch Tensor.view用法及代碼示例
- Python PyTorch Tensor.new_empty用法及代碼示例
- Python PyTorch Tensor.index_copy_用法及代碼示例
- Python PyTorch Tensor.new_tensor用法及代碼示例
- Python PyTorch Tensor.scatter_用法及代碼示例
- Python PyTorch Tensor.fill_diagonal_用法及代碼示例
- Python PyTorch Tensor.repeat用法及代碼示例
- Python PyTorch Tensor.item用法及代碼示例
- Python PyTorch Tensor.tolist用法及代碼示例
- Python PyTorch Tensor.put_用法及代碼示例
- Python PyTorch Tensor.map_用法及代碼示例
- Python PyTorch Tensor.stride用法及代碼示例
- Python PyTorch Tensor.index_fill_用法及代碼示例
- Python PyTorch Tensor.align_as用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.Tensor.get_device。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。