Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I determine if a GPU is available on my OS?

People are talking about GPU computing these days. How do I know if a GPU is available on my computer? I would like to have a python way, or alternatively using a shell command, to know if a GPU is available. I am using Mac OS Catalina version 10.15 if that matters.

BTW, could I safely assume GPU is available in most computers today?

like image 346
zell Avatar asked Nov 26 '25 09:11

zell


2 Answers

I think that using the PyTorch library you can determine this. Usually, the CUDA platform is used in order to make the computation on the GPU.

So, in Python you have to do the following:

import torch

torch.cuda.is_available()

This will return if the GPU/CUDA is available or not.

Then you can do the following to select the device (CPU or GPU)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
like image 87
xavidejuan Avatar answered Nov 28 '25 00:11

xavidejuan


According to This, You should be able to tell if there's a GPU installed by opening the “Settings” dialog, and then click “Details” in the sidebar. In the “About” panel, look for a “Graphics” entry. This tells you what kind of graphics card is in the computer, or, more specifically, the graphics card that’s currently in use. Your machine might have more than one GPU.

like image 31
Mina Abd El-Massih Avatar answered Nov 27 '25 22:11

Mina Abd El-Massih



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!