是不是可以在不使用像TF或torch这样的深度学习包的情况下检查GPU是否可用?

huangapple go评论74阅读模式
英文:

Is it possible to check if GPU is available without using deep learning packages like TF or torch?

问题

我想检查是否有访问GPU的权限,除了使用tensorflow或PyTorch之外的任何软件包。我找到了psutil.virtual_memory().percent函数,它返回GPU的使用情况。但是,如果GPU被利用但没有加载,这个函数仍然可能返回0。我想知道是否还有其他检查的方法。谢谢!

英文:

I would like to check if there is access to GPUs by using any packages other than tensorflow or PyTorch. I have found the psutil.virtual_memory().percent function that returns the usage of the GPU. However, this function could still return 0 if GPUs are utilized but not loaded. I wonder if there is another way to check it. Thanks!

答案1

得分: 1

有另一个名为GPUtil的库,它会将可用的GPU列出为一个列表。

您只需使用pip命令进行安装:pip install GPUtil,然后运行以下代码:

import GPUtil
print(GPUtil.getAvailable()) # 返回可用GPU的列表,如果没有可用GPU,则为空
print(GPUtil.showUtilization()) # 返回GPU及其处理和内存利用率的列表
英文:

There is also another library called GPUtil that gives you the available GPUs as a list.

You simply need to install it as a pip command pip install GPUtil and then run the following

import GPUtil
print(GPUtil.getAvailable()) # Returns a list of available GPUs. Will be empty of no GPU is available
print(GPUtil.showUtilization()) #Returns a list of GPUs and their processing and memory utilization

huangapple
  • 本文由 发表于 2023年6月29日 20:49:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76581229.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定