Versión en español de esta publicación.
This post explains how to install CUDA 9.1 Production Release on a Debian Stretch system. The first thing to do is to download the driver from the official Nvidia website and select the model of the video card you have. In my case, I have a server with 2 video cards, the first is a GeForce GTX660 and the second is a GeForce GTX650. If you are not sure which version of the driver should be installed, this information can be verified in the following link.
The latest version of the driver available in the case of my video cards is 390.25 and is available in the following link http://us.download.nvidia.com/XFree86/Linux-x86_64/390.25/NVIDIA-Linux-x86_64-390.25.run, the most desirable thing is to make sure to download the latest version of the driver available for your video card.
Also, it is necessary to download the CUDA Toolkit 9.1 from the Nvidia page located in the following link https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1704&target_type=runfilelocal. The toolkit installation file that is needed is the RUN version for Ubuntu, the file name is: cuda_9.1.85_387.26_linux.run.
Now we proceed to verify the requirements to install CUDA. First of all you need to confirm that you have a device that supports GPUs.
# verify we have a cuda capable gpu lspci | grep -i nvidia
The previous instruction should yield results, otherwise, you should check the status of the video card. Then, we proceed to check our version of Linux
# Linux version uname -m && cat /etc/*release
What tells us that we have Debian Stretch and is the version that is being used and supported for this post
x86_64 PRETTY_NAME="Debian GNU/Linux 9 (stretch)" NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
Now you need to check that you have a valid GCC compiler
# verify gcc version gcc --version
If you do not have a valid GCC compiler you can install it with the following command
# gcc install sudo apt-get install build-essential
Before proceeding with the installation process you need to uninstall any version of CUDA that has been previously installed, if this is the first time you install CUDA you can skip this step. To uninstall previous versions of CUDA the following command is used
# cuda uninstall sudo /usr/local/cuda-X.Y/bin/uninstall_cuda_X.Y.pl
Where X and Y is the CUDA version. If you are updating the Nvidia driver you do not need to do anything since the installer removes the previous drivers automatically. If you want to uninstall the CUDA driver, you can do it with the following command.
# cuda driver uninstall sudo /usr/bin/nvidia-uninstall
It is likely that you will need to uninstall nvidia packages if they have been installed through the repository. For this it could be sufficient to execute the following command
sudo apt-get remove 'nvidia*'
Once the previous steps have been completed and since the necessary files for the installation are available, we proceed to disable the nouveau driver, which is the default driver that comes with the Debian versions. In order to accomplish this a new file needs to be created
# edit debian driver configuration file vim /etc/modprobe.d/disable-nouveau.conf
And we add the following lines
# blacklist defualt driver blacklist nouveau options nouveau modeset=0
Note: to verify the nouveau driver is running or not, the following command needs to be executed and in the case the command shows results that means that you have the nouveau driver running in the system
# verify driver lsmod | grep nouveau
After having created the file to block the default driver, we proceed to restart the system in default mode. Once restarted we will notice that the resolution has dropped quality, this means that the default nouveau driver was not loaded, now we will proceed to install the linux headers from our repository in order to compile the Nvidia driver, we do this through the next command.
# dependencies sudo apt-get install linux-headers-$(uname -r)
After installing these packages we proceed to remove the nouveau driver completely from our system with the following command
# remove apt-get remove --purge xserver-xorg-video-nouveau
Once the driver is removed, the system is restarted in recovery mode. Once rebooted and in the console, we will proceed with the driver installation process. First, you need to know with what version of the compiler the kernel was compiled, this is because the system needs to compile the Nvidia driver. If you do not know the version of the compiler or the kernel, you can know that information by using the following command
# find curr gcc version cat /proc/version
Once you know the correct version of the compiler, you need to set it up by means of an export in the following way
# set gcc version export CC=gcc-4.8
Now you can proceed with the driver installation, navigate to the driver download directory and run
# execute driver install sudo sh NVIDIA-Linux-x86_64-390.25.run
Once the installation is finished, we proceed to restart our system. Note that the resolution went up in quality which means that our Nvidia drivers were installed correctly. Now, we proceed with the installation of the Cuda toolkit in the following way
# execute toolkit install sudo sh cuda_9.1.85_387.26_linux.run
When asked, you need to select the option of not install the Nvidia driver since it has already been installed previously, and select the default installation directory for the examples. The last thing you have to do is to compile these examples and execute them, this is done by navigating to the installation directory of the examples using the make command. Usually the default directory of the examples lies in our home directory so the following command should do the trick
cd ~/NVIDIA_CUDA-9.1_Samples make
And that is pretty much it!
Cuda Installation Guide
CUDA Quick Start Guide
CUDA Toolkit Official Documentation
CUDA Download Page
Nvidia Driver Download Page
CUDA 9.1 Performance Presentation
CUDA Toolkit Release Notes