How can I check if my GPU is being used or activate it for use?

1k views Asked by At

enter image description here enter image description here Geforce 4080 problem

Hello Stack Overflow community,

I am currently working on a project that requires the use of a GPU, and I am not sure whether it is being used or not. Could someone please guide me on how to check if my GPU is being used or how to activate it for use?

I have already checked my GPU's status using the nvidia-smi command, but I am not sure how to interpret the output. Could someone explain to me how to read the nvidia-smi output or suggest another method for checking my GPU's usage status?

Thank you in advance for your help.

1

There are 1 answers

0
kev_ta On

From your code you are working with pytorch, pytroch needs to specify which device to run on, either cuda or cpu. So you need to move everything dataset, model to cuda device using .to() function.

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

And then move everything to device using:

model.to(device)

and when you run your script, check nvidia-smi again and look in the bottom all the processes that are using the GPU will be reported.