import torch # 使用torch.cuda.is_available()方法来判断是否有可用的GPU if torch.cuda.is_available(): device = torch.device("cuda") # 创建一个表示GPU设备的对象 print(f"当前设备是GPU,设备名称为: {torch.cuda.get_device_name(0)}") else: device = torch.device("cpu") # 创建一个表示CPU设备的对象 print("当前设备是CPU") # 输出设备信息 print(f"当前使用的设备为: {device}")
检测深度学习环境是GPU还是CPU(代码)
于 2025-02-27 18:45:20 首次发布