Nvidia-smi sometimes work and sometimes doesn't work after reboot ubuntu18.04

Sometimes nvidia-smi doesn’t work and after reboot it shows the error:
NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

Even if I reinstall the driver it doesn’t work, please find the nvidia-bug-report.log (1.2 MB) and let me know the steps to proceed.

But sometimes after rebooting several times and doing nvidia-smi after few minutes it starts working again, this is something weird.

Looks like there’s a blacklist file somewhere, please try this:

  • switch to nvidia (sudo prime-select nvidia)
  • remove stray blacklist files (sudo rm /lib/modprobe.d/blacklist-nvidia.conf /etc/modprobe.d/blacklist-nvidia.conf)
  • update the initrd (sudo update-initramfs -u)
  • reboot
    If this doesn’t resolve the issue, please create a new nvidia-bug-report.log.

After switching to nvidia (using sudo prime-select nvidia), both of the files /lib/modprobe.d/blacklist-nvidia.conf and /etc/modprobe.d/blacklist-nvidia.conf disappears but if I switch back to intel it appears again.

I found out that If I reboot my laptop after switching to Nvidia (sudo prime-select nvidia) then nvidia-smi works but if I reboot my laptop after switching to intel (sudo prime-select intel) then it doesn’t works.

I am attaching nvidia-bug-report.log with and without switching to nvidia, please let me know if I have to remove those files even during the intel mode? nvidia-bug-report_with_prime-select-intel.log (1.9 MB) nvidia-bug-report_with-prime-select-nvidia.log (2.1 MB)

It’s the only purpose of prime-select intel to turn off the nvidia gpu.
If you want to use the intel for graphics and have the nvidia gpu available for cuda, youl have to use the on-demand profile (don’t know if that’s available on 18.04) or configure it yourself:

  • switch to nvidia profile
  • use nogpumanager kernel parameter
  • create /etc/X11/xorg.conf:
Section "Device"
  Identifier "iGPU"
  Driver "modesetting"
  BusID "PCI:0:2:0"

Could you please elaborate on your second point about " * use nogpumanager kernel parameter" ?

I installed Ubuntu 20.04.1 and it has Nvidia on demand mode which already solved the issue.