Solve cuInit: CUDA_ERROR_UNKNOWN: unkown error

Steps

  1. Enable the following services in systemd:

    • nvidia-suspend.service

    • nvidia-resume.service

    • nvidia-hibernate.service

Enable via sudo systemctl enable <service name>.

  1. Create a file named /etc/modprobe.d/nvidia-suspend.conf.

  2. Add the following line to the file:

     options nvidia NVreg_PreserveVideoMemoryAllocations=1
    
  3. Reboot

This shall prevent the cuInit: CUDA_ERROR_UNKNOWN: unknown error.

If that does not work

Execute the following:

sudo modprobe -r nvidia_uvm # or: sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm

Read more about the problem here.