英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论