温馨提示×

python中如何查看cuda是否可用

小新
9924
2021-05-20 08:59:13
栏目: 编程语言

python中查看cuda是否可用的方法:1、找到python程序;2、打开idle工具;3、在idle中新建一个shell脚本;4、输入“import torch”指令导入torch模块;5、通过“print(torch.cuda.is_available())”指令查看cuda是否可用即可。

python中如何查看cuda是否可用

具体操作方法:

1、在电脑开始菜单中找到python程序。

2、在python程序中打开idle工具。

3、在idle工具中点击左上角的“File”并选择“New File”新建一个shell脚本。

4、在shell脚本中输入以下指令导入torch模块。

import torch #导入torch模块

5、最后通过以下指令查看cuda是否可用即可。

print(torch.cuda.is_available())

运行结果示例:

>>>print(torch.cuda.is_available())

True #返回True说明cuda可用

相关操作指令:

print(torch.cuda.device_count()) #查看可行的cuda数目

0