Summary
In this post, I will introduce how to install the newest CUDA and corresponding Nvidia driver in Ubuntu 16.04.
Details
I want to use CUDA for neural network inference. But after I compile the executable files and run, it tells me driver not compatible with this version of CUDA.
I have GTX 1060 and CUDA 9.0 in my desktop. I decide to remove them and go through the installation process from scratch to get the newest CUDA 10.1 and driver 418.
1. Remove the Current CUDA
We are happy in the folders CUDA provides the uninstall scripts.
(base) zhoun14@zhoun14:~$ which nvcc
/usr/local/cuda/bin/nvcc
(base) zhoun14@zhoun14:~$ cd /usr/local/cuda/bin/
(base) zhoun14@zhoun14:/usr/local/cuda/bin$ ls
nvcc cuda-uninstaller ...
Run the uninstaller.
2. Remove the Current Driver
sudo apt-get remove --purge '^nvidia-.*'
It also helps if you have the following problems.
- Bad resolution;
- Loop login;
Alternatively, you can use autoinstaller to firstly avoid loop login,
sudo ubuntu-drivers autoinstall
3. Install CUDA and Drivers Using the Runfile
Go to the official page.
- Check the prerequisite;
- Download the CUDA Toolkit; choose your platform and use the runfile format;
Then it comes the most important part. Do the following commands.
Reboot to Test Mode
sudo reboot nomodeset
Press ctrl
+ alt
+ F1
. It may vary on different machines. Try combinations from F1
to F12
.
Disabling Nouveau
See here for details. But you can just create a file at /etc/modprobe.d/blacklist-nouveau.conf
with the following contents:
blacklist nouveau
options nouveau modeset=0
Regenerate the kernel initramfs.
sudo update-initramfs -u
Run the Runfile
sudo sh cuda_<version>_linux.run
4. Verify the Driver
It verifies the CUDA at the same time.
(base) zhoun14@zhoun14:~$ nvidia-smi
Sun Apr 7 09:58:49 2019
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.56 Driver Version: 418.56 CUDA Version: 10.1 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 106... Off | 00000000:01:00.0 On | N/A |
| 39% 40C P8 5W / 120W | 424MiB / 3016MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 314 G ...quest-channel-token=6420533192254872401 41MiB |
| 0 1739 G /usr/lib/xorg/Xorg 232MiB |
| 0 3175 G /opt/teamviewer/tv_bin/TeamViewer 2MiB |
| 0 3380 G compiz 146MiB |
+-----------------------------------------------------------------------------+
If nothing prints out. You can do step 2 again and reinstall the drivers using apt-get
.
sudo apt-get nvidia-418 nvidia-modprobe
If the OS tells you it can not locate the package. Please add the repository first.
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt upgrade
Then you will be prompted to disable Secure Boot. Select Disable. Reboot the machine but do enter BIOS to disable Secure Boot. Typically you can enter BIOS by hitting F12 rapidly as soon as the system restarts.
5. Verify the CUDA
(base) zhoun14@zhoun14:~$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Fri_Feb__8_19:08:17_PST_2019
Cuda compilation tools, release 10.1, V10.1.105