2025年3月20日 星期四 甲辰(龙)年 月十九 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > 人工智能

查看电脑torch能否使用GPU

时间:01-17来源:作者:点击数:48

查看电脑torch能否使用GPU

  • import torch
  • device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
  • print(device) #cpu
  • import torch
  • flag = torch.cuda.is_available()
  • print(flag)
  • ngpu= 1
  • # Decide which device we want to run on
  • device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
  • print(device)
  • print(torch.cuda.get_device_name(0))
  • print(torch.rand(3,3).cuda())
  • True
  • cuda:0
  • NVIDIA GeForce GTX 1650
  • tensor([[0.6134, 0.0682, 0.9818],
  • [0.2449, 0.2887, 0.8753],
  • [0.8587, 0.6035, 0.9593]], device='cuda:0')
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门