Search code examples
pythongpu

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


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!


Solution

  • 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