How to set default cuda device in libtorch?

There is a function in pytorch to set the default cuda device. But I cannot find something similar in libtorch. Can someone help me out here?

Iā€™m unsure if you can set the default device globally, but you could use the CUDAGuard() inside your method instead:

CUDAGuard device_guard(device);

which makes sure to use the specified device id.
(Thanks @tom for clarification :slight_smile: )

1 Like

Thanks for the tip :slight_smile: