Ubuntu 20.04: RuntimeError: CUDA error: all CUDA-capable devices are busy or unavailable

Hello,

everytime I try to transfer a tensor from my cpu to my gpu this error occurs:

RuntimeError: CUDA error: all CUDA-capable devices are busy or unavailable

I installed Pytorch via the suggested command line on the website, and run a Nvidia 1060 6 GB.
Can anyone tell me why it is not working?

nvidia-smi

Fri Apr 23 15:40:38 2021
±----------------------------------------------------------------------------+
| NVIDIA-SMI 460.32.03 Driver Version: 460.32.03 CUDA Version: 11.2 |
|-------------------------------±---------------------±---------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 GeForce GTX 106… Off | 00000000:26:00.0 On | N/A |
| 27% 56C P0 30W / 120W | 401MiB / 6075MiB | 0% Default |
| | | N/A |
±------------------------------±---------------------±---------------------+

±----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| 0 N/A N/A 948 G /usr/lib/xorg/Xorg 259MiB |
| 0 N/A N/A 1539 G /usr/bin/gnome-shell 66MiB |
| 0 N/A N/A 2699 G …gAAAAAAAAA --shared-files 8MiB |
| 0 N/A N/A 2817 G …AAAAAAAA== --shared-files 60MiB |
±----------------------------------------------------------------------------+

This error usually points to a broken driver/CUDA installation.
Are you able to compile and run other CUDA code such as the CUDA samples?

I get this error by a simple command like

torch.cuda.FloatTensor(1000, 1000).fill_(0)

But

torch.cuda.current_device()
torch.cuda.device(0)
torch.cuda.device_count()
torch.cuda.get_device_name(0)
torch.cuda.is_available()

works.

Ok I solved the problem by:

a) using NVIDIA driver metapackage from nvidia-driver-460 (proprietary, tested)
at Software & Updates → Additional Drivers
b) changing desktop from lightdm to gdm3 by
sudo dpkg-reconfigure gdm3
and rebooting

!DISCLAIMER!
I had issues that I couldn’t pass the login screen using gdm3 before, command b) might get you into this kind of trouble. Anyhow for me it works with the listed driver.

Thanks for the feedback.