Installing CUDA 8 on CentOS 7

by computingNoob

Step 1: Ensure you have an nVidia GPU. You can use the ‘list PCI’ devices command (lspci) as follows:
$ /usr/sbin/lspci

This command will list all PCI devices, to limit view to only nVidia devices, we will ‘pipe’ a grep command as follows:
$ /usr/sbin/lspci | grep -i nvidia

On my computer I saw the following output, you should see something similar:
03:00.0 VGA compatible controller: NVIDIA Corporation Device 1430 (rev a1)
03:00.1 Audio device: NVIDIA Corporation Device 0fba (rev a1)

Step 2: Verify you have gcc. Type the following in terminal:
$ gcc --version

I got the following output:
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Step 3: Ensure you have kernel headers and other required packages for the kernel on your system:
$ sudo yum install kernel-devel-$(uname -r) kernel-headers-$(uname -r)

Step 4: Head over to nVidia website (link below) and download an installer:
https://developer.nvidia.com/cuda-downloads

I used the ‘RPM (Local)’ version. I initially tried with ‘runfile (local)’ option and ran into a lot of errors (see notes below), so I do not recommend that approach.

Step 5: Navigate to the downloads directory where your installer file is located. On my computer, I typed (and hit enter):
$ cd ~/Downloads

Step 6: We are ready to begin installation. Type the following commands in order:
$ sudo rpm -i cuda_installer_downloaded_file.rpm
$ sudo yum clean all
$ sudo yum install cuda

That’s it! Your newly installed CUDA library lives in this location: /usr/local/cuda/

INSTALL NOTES
1) Install Options: Ideally, we don’t want to install OpenGL with nVidia CUDA installation. With the RPM, that’s not an option. Follow this link in case you see issues reported in the below paragraph: https://devtalk.nvidia.com/default/topic/760614/using-repositories-without-opengl-files/
I DO NOT recommend that you install graphics driver during the installation process. If you chose the ‘runfile’ approach, carefully read the options that are presented, and only answer yes for the ‘toolkit’ if CUDA SDK is your primary interest (as was the case for me). I chose to install the graphics driver and ended up breaking libGL, swrast, and a few other processes that prevented gnome shell from successfully initializing during the boot process. I was presented with a login prompt, but after entering my login credentials, I was presented with a gray screen with the following message: “Oh no! Something has gone wrong. A problem has occurred and the system can’t recover. All extensions have been disabled as a precaution.” During installation, DO NOT answer ‘yes’ to install OpenGL option presented by nVidia installer (in the ‘runfile (local)’ approach. Answering yes will replace system installed libGL and cause other issues (the infamous ‘login-loop’ problem).

2) RPM vs runfile: At first I tried using the ‘runfile (local)’ approach. This led to a number of problems that I am listing here for anyone who runs into similar issues:
2.1) I had to ‘blacklist nouveau’. Nouveau is an open source driver for nVidia GPUs that can interfere with the installation.
2.2) “ERROR: You appear to be running an X server”. I resolved this by typing ‘sudo telinit 3’ on my terminal and killing the GUI completely. This took me to console mode. While this error went away, another one appeared (next point) that I couldn’t eventually resolve.
2.3) “The driver installation is unable to locate the kernel source. Please make sure that the kernel source packages are installed and set up correctly. If you know that the kernel source packages are installed and set up correctly, you may pass the location of the kernel source with the ‘–kernel-source-path’ flag.”
I tried to manually supply the kernel source path but that did not resolve the issue.

With the ‘runfile (local)’ approach, I realized there were several dependencies that were required to be already present in the system. I wasn’t aware of these dependencies hence the problem persisted and I decided to try the ‘RPM (local)’ installer, which worked flawlessly!

3) Post-installation Issues: If you see an error saying that cuda kernel cannot be launched, you need to turn OFF ‘Secure Boot’ in Bios.

To Uninstall: $ sudo yum remove cuda