Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choose 2nd GPU on server

I am running code on server. There are 2 GPUs there, and the 1st one is busy. Yet, I can't find a way to switch between them. I am using pytorch if that is important. Following lines of code should be modified:

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

Modification may be stated only here. Thanks.

like image 801
fiendfire28 Avatar asked Jul 19 '26 19:07

fiendfire28


1 Answers

cuda by defaults chooses cuda:0, switching to the other GPU may be done through cuda:1

So, your line becomes:

device = 'cuda:1' if torch.cuda.is_available() else 'cpu'

You can read more about CUDA semantics.

like image 132
ndrwnaguib Avatar answered Jul 21 '26 09:07

ndrwnaguib



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!