🚀 优质资源分享 🚀
学习路线指引(点击解锁) | 知识定位 | 人群定位 |
---|---|---|
🧡 Python实战微信订餐小程序 🧡 | 进阶级 | 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。 |
💛Python量化交易实战💛 | 入门级 | 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统 |
CUDA(Compute Unified Device Architecture)是NVIDIA推出的异构计算平台,PyTorch中有专门的模块torch.cuda来设置和运行CUDA相关操作。本地安装环境为Windows10,Python3.7.8和CUDA 11.6,安装PyTorch最新稳定版本1.12.1如下:
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116
一.常见CPU和GPU操作命令
1.查看PyTorch版本
print(torch.__version__)
1.12.1+cu116
2.查看GPU设备是否可用
print(torch.cuda.is_available())
True
3.PyTorch默认使用设备是CPU
print("default device: {}".format(torch.Tensor([4,5,6]).device))
default device: cpu
4.查看所有可用的cpu设备的数量
print("available cpu devices: {}".format(torch.cuda.os.cpu_count()))
available cpu devices: 20
这里CPU设备数量指的是逻辑处理器的数量。
5.查看所有可用的gpu设备的数量
print("available gpu devices: {}".format(torch.cuda.device_count()))
available gpu devices: 1
6.获取gpu设备的名称
print("gpu device name: {}".format(torch.cuda.get_device_name(torch.device("cuda