CUDA on CentOS 7 - shawfdong/hyades GitHub Wiki

I recently installed CentOS 7 on the HP xw8600 Workstation. The graphics card is an NVIDIA Quadro FX 5600:

# lspci | grep VGA
60:00.0 VGA compatible controller: NVIDIA Corporation G80GL [Quadro FX 5600] (rev a2)

By default, RHEL/CentOS 7 uses the open source driver nouveau for NVIDIA cards:

# lsmod | grep nouveau
nouveau               974305  3 
video                  19267  1 nouveau
mxm_wmi                13021  1 nouveau
i2c_algo_bit           13413  1 nouveau
drm_kms_helper         52758  1 nouveau
ttm                    83948  1 nouveau
drm                   297829  5 ttm,drm_kms_helper,nouveau
i2c_core               40325  4 drm,drm_kms_helper,i2c_algo_bit,nouveau
wmi                    19070  3 hp_wmi,mxm_wmi,nouveau

However, the quality of nouveau is very poor — the screen would flicker constantly — and it doesn't support CUDA nor OpenCL. So let's replace it with NVIDIA's proprietary driver.

Download latest CUDA release from https://developer.nvidia.com/cuda-downloads. There is no RPM packages for RHEL/CentOS 7 yet; so we downloaded the RUN file:

$ wget http://developer.download.nvidia.com/compute/cuda/6_5/rel/installers/cuda_6.5.14_linux_64.run

Extract individual installers from the Run file:

$ chmod +x cuda_6.5.14_linux_64.run
$ ./cuda_6.5.14_linux_64.run -extract=/home/dong/Downloads

which resulted in 3 installers: NVIDIA-Linux-x86_64-340.32.run (for the driver), cuda-linux64-rel-6.5.14-18749181.run (for CUDA 6.5), and cuda-samples-linux-6.5.14-18745345.run (for sample codes).

I also downloaded the standalone driver from http://www.nvidia.com/Download/index.aspx?lang=en-us. The installer was NVIDIA-Linux-x86_64-340.32.run. The version was slightly newer (340.32 vs. 340.29); so we'll use this installer.

We'll need to compile the kernel module for NVIDIA driver. Let's install the required packages first:

# yum -y groupinstall "Development Tools"
# yum -y install kernel-devel kernel-headers

Blacklist nouveau:

# echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf

Update the initial ram file system, so it won't contain the kernel module for nouveau:

# mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak   
# dracut -v /boot/initramfs-$(uname -r).img $(uname -r)

We'll boot into multi-user target to install the NVIDIA driver. systemd is the system and service manager for RHEL/CentOS 7, replacing the venerable SysV init. Let's change the default target to multi-user (roughly equivalent to run level 3 of init):[1]

# systemctl set-default multi-user.target

Reboot.

Tip: In case we mess it up, we can still boot into multi-user target without loading the nouveau kernel module, by editing the menu entry of grub2 during boot, and appending the following kernel parameters:

modprobe.blacklist=nouveau systemd.unit=multi-user.target

Install NVIDIA driver and CUDA:

# ./NVIDIA-Linux-x86_64-340.32.run
# ./cuda-linux64-rel-6.5.14-18749181.run
# ./cuda-samples-linux-6.5.14-18745345.run

Change the default systemd target back to graphical (roughly equivalent to run level 5 of init):

# systemctl set-default graphical.target

Reboot. If nothing has gone wrong, we are now using the NVIDIA driver and enjoying flickerless graphics:

# lsmod | grep nvidia 
nvidia              10540234  39 
drm                   297829  2 nvidia
i2c_core               40325  2 drm,nvidia

See Also

To avoid the chore of manually reinstalling the NVIDIA driver whenever we update the kernel, we can use DKMS (Dynamic Kernel Module Support) to automatically compile the kernel module for NVIDIA driver when a new kernel is installed. For further details, see DKMS on CentOS 7.

References

  1. ^ https://fedoraproject.org/wiki/Systemd
⚠️ **GitHub.com Fallback** ⚠️