Install Nvidia CUDA toolkit on Ubuntu 12.04 x86_64

Good day to the Khabrovsk residents, in this post I will try to clearly explain about installing the Nvidia CUDA toolkit on Ubuntu 12.04 x86_64. To begin with, I was encouraged to write this post. Most recently, I needed to install the Nvidia CUDA toolkit on my home computer. imageAfter reading a good portion of the installation manuals, and not only in Russian, I decided that installing the package from Nvidia would be easier than a steamed turnip, but here I was mistaken. Most of the manuals are designed for older versions of ubuntu, in addition, they often lack some highlight of the installation, which sooner or later leads the reader to a dead end. And so who is interested - you are welcome to cut ...

We will break the installation into several stages:
1) Download the necessary software components.
2) Preparing for installation.
3) Installing the driver, toolkit and SDK.
4) System setup after installation.
5) Compilation and launch of examples to test the health.

Stage 1 - Download the required software components.

I think it's silly to tell people reading this post why CUDA technology is needed, because if you are reading it, you’ve decided what you need it for. Because CUDA technology exists only on Nvidia graphic cards; you will need a card from this manufacturer. The list of cards supporting CUDA technology can be found on the official Nvidia website - developer.nvidia.com/cuda-gpus. The benchmark in the desktop segment can be considered the GeForce 8100 mGPU, and accordingly in the notebook segment - the GeForce 8400M GT. So with the card sorted out. Now you need to go to developer.nvidia.com and select the “Cuda Download” column (Figure 1).

imageFig. 1. Developer.nvidia.com Homepage.

Immediately after clicking on the "Cuda Download" link, we get to the software download page. Because Ubuntu 12.04 was released relatively recently, the site still has software for previous stable versions, namely 11.04 and 10.04. When installing on my pc, I chose 11.04 x64. With the other components, it is intuitively clear - depending on the version of the distribution package, select the correct product and download it (Fig. 2).

imageFig. 2. Software for installation.

As a result, the selected folder (I have it Downloads) should contain 3 files (Fig. 3):
1) cudatoolkit_4.2.9_linux_64_ubuntu11.04.run
2) devdriver_4.2_linux_64_295.41.run
3) gpucomputingsdk_4.2.9_linux.run

imageFig. 3. Browse the folder with downloaded files.

Stage 2 - Preparing for installation

Actually, the whole problem during installation is the Nvidia development driver that needs to be installed, we will install it first. First you need to add free drivers to blacklist. Open with any blacklist text editor (in my case gedit), in the terminal (Fig. 4):
sudo gedit /etc/modprobe.d/blacklist.conf

and add the following lines to the very end of the blacklist:
blacklist amd76x_edac #как правило данная строчка уже добавлена, считайте ее за ориентир.
blacklist vga16fb
blacklist nouveau
blacklist lbm-nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv 

image
Fig. 4. We edit blacklist.

We save it and close it until better times. After that, you can try installing the driver. But before that, you need to get rid of all sorts of garbage that old drivers leave, in the terminal we enter:
sudo apt-get remove --purge nvidia*

After the operation has completed, you must restart the PC:
sudo reboot

But here it is worth noting an interesting thing that the above manipulations do not disable the nouveau driver, and on a clean system it is it that prevents the CUDA driver from being installed, so we need to arm ourselves with a text editor again and do the following (Fig. 5):
sudo gedit /etc/modprobe.d/nvidia-graphics-drivers.conf

open this file and add the following to it:
blacklist nouveau
blacklist lbm-nouveau
blacklist nvidia-173
blacklist nvidia-96
blacklist nvidia-current
blacklist nvidia-173-updates
blacklist nvidia-96-updates
alias nvidia nvidia_current_updates
alias nouveau off
alias lbm-nouveau off

image
Fig. 5. We edit nvidia-graphics-drivers.conf.

Stage 3 - Installing the driver, toolkit and SDK.

This stage will show how correctly you did everything. And so, we booted up until the user was selected and the password was entered (the so-called login screen). It is on the login screen that we press the key combination:
ctrl + alt + F1

We get into console mode. You need to log in and go to the folder with the previously downloaded Nvidia software products, as well as disable gdm or lightdm to install the CUDA driver, after that you need to change the access rights for our driver and directly install it:
cd Downloads
sudo service lightdm stop
#или
sudo service gdm stop
chmod +x devdriver_4.2_linux_64_295.41.run
sudo ./devdriver_4.2_linux_64_295.41.run

Then everything is simple, click "Accept" and the installation has begun. During installation, you will be asked if you need to install OpenGL libraries - the thing is, as the owner says. Next, the system will notify you of the successful installation of the CUDA driver. You must restart the system again. After a reboot, you should install the remaining components, namely cudatoolkit_4.2.9_linux_64_ubuntu11.04.run and gpucomputingsdk_4.2.9_linux.run, go to the folder with the downloaded files and install the necessary components:
cd Downloads
sudo ./cudatoolkit_4.2.9_linux_64_ubuntu11.04.run
sudo ./gpucomputingsdk_4.2.9_linux.run

It can be noted here that during installation the program will ask you to specify various paths, you should not bother actually - if this situation occurs, just press "Enter".

Step 4 - Configure the system after installation.
Next, you need to configure the system, for this in the terminal we enter:
export PATH=/usr/local/cuda/bin:$PATH &&export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc && echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc

Uuuuf, well, everything seems, the system is configured. The matter is left to the small, move on to the fifth stage.

Stage 5 - Compiling and running the examples to test the health.

Now all you need to do is compile the examples and finally test the functionality. To do this, enter in the terminal:
cd ~/NVIDIA_GPU_Computing_SDK/C 
make

Errors may occur when assembling the examples, well then you need to run the “make” utility under the root and try to build again or run the make utility with the -k flag:
make -k

And so the climax, it remains to run any of the compiled examples, we enter in the terminal (Fig. 6):
cd ~/NVIDIA_GPU_Computing_SDK/C/bin/linux/release
./deviceQuery

image
Fig. 6. The result of running the deviceQuery program.

Well, that's basically all that I wanted to tell you about setting up the CUDA toolkit. I ask you not to judge strictly, because This is my first post on Habr, I tried to do everything thoroughly. I hope this post helps someone in setting up the CUDA toolkit. Thanks for attention.

Also popular now: