import torch# 1. 检查 PyTorch 版本 print("PyTorch 版本:", torch.__version__) # 应为 2.4.0# 2. 检查 CUDA 是否可用 print("CUDA 可用:", torch.cuda.is_available()) # 应为 True# 3. 检查可用的 GPU 设备 print("GPU 数量:", torch.cuda.device_count()) # 应为 1(单卡) print("当前 GPU:", torch.cuda.current_device()) print("GPU 名称:", torch.cuda.get_device_name(0)) # 应为 RTX 4090# 4. 测试张量计算(验证 CUDA 后端) x = torch.randn(3, 3).cuda() # 将张量移动到 GPU y = torch.randn(3, 3).cuda() z = x + y print("张量计算结果:", z.device) # 应为 cuda:0
##############