The errors have been caused because Nouveau is controlling the GPU, not the NVIDIA driver. So, before installing NVIDIA driver and CUDA toolkit, nouveau should be blacklisted.
sudo nano /etc/modprobe.d/blacklist.conf
Insert nouveau
at the end of the file.
If the NVIDIA driver is already installed, then re-install the NVIDIA driver.