查看 PyTorch 是否使用 GPU
借助 torch.cuda 中的命令,可以帮助我们查看 PyTorch 是否使用 GPU。
![image-20221218225825151](../assets/2022-12-18-check-device-in-pytorch/index-image/image-20221218225825151.png)
当前设备索引
Pythontorch.cuda.current_device()
![image-20221218225800410](../assets/2022-12-18-check-device-in-pytorch/index-image/image-20221218225800410.png)
可用的 GPU 数量
Pythontorch.cuda.device_count()
![image-20221218225816075](../assets/2022-12-18-check-device-in-pytorch/index-image/image-20221218225816075.png)
GPU 设备名字,设备索引默认从 0 开始
Pythontorch.cuda.get_device_name(0)
![image-20221218225825151](../assets/2022-12-18-check-device-in-pytorch/index-image/image-20221218225825151.png)
检查 CUDA 是否可用
Pythontorch.cuda.is_available()
![image-20221218225834009](../assets/2022-12-18-check-device-in-pytorch/index-image/image-20221218225834009.png)