Installation of CUDA9.0 in Ubuntu environment

Source: Internet
Author: User
Tags save file cuda toolkit nvcc

Objective:

This article is based on the experience of installing Cuda 9.0, CUDA9.0 currently supports Ubuntu16.04 and Ubuntu17.04 two versions, as shown (the bottom of the installation method we choose the first, that is, the Runfile method):

You can first download the Cuda file, but it is best not to rush to install, you must first give the official guidance manual nvidia look carefully, and then find a few good blog to see, a general understanding of CUDA installation process, the installation process may arise problems to have a general understanding, Do not reload the system as a last resort.

Installation recommendations:

1) Go to the official website to download cuda at the same time, be sure to find a corresponding official installation documents carefully read, as far as possible follow its step by step, not lazy. At the same time to find a few good blog as a reference, before installation to be confident.

2) before installation, it is important to check your computer configuration (supports or dual graphics card), the type of video card meets CUDA installation requirements, the system meets the installation requirements.

3) Every operation during the installation process, try to check if the operation is successful.

Installation process:

First, installation, familiar with the ubuntu16.04 system

Before installing the software, it is best to have some basic understanding of the Ubuntu command line, such as sudo, CD, LS, Nona, cat, chmod and so on, which can save a lot of unnecessary trouble during the installation process. (Recommended that you go to Baidu search Mo fan python, he has a video about the Ubuntu command, each episode is very refined, speak very well)

Second, check their own computer environment is equipped with the conditions of the installation of Cuda

1) Verify that your computer has a cuda-capable GPU

You can find the specific model of the video card in the configuration information of the computer, if you are a dual system, you can also check the video card details in the Device Manager under Windows;
You can also enter a command in the Ubuntu Terminal: $ LSPCI | Grep-i nvidia, will show you the NVIDIA GPU version information, but not very detailed.

My display is GeForce gt630m):

01:00.0 3D controller: NVIDIA Corporation GF117M [GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M] (rev a1)

Then go to Cuda's official website to see if your GPU version is in the Cuda support list.
2) Verify that your Linux version supports CUDA (Ubuntu 16.04 is no problem)

Enter the command:

$ uname -m && cat /etc/*release

The results show:

x86_64
Distrib_id=ubuntu
distrib_release=16.04

......

3) Verify that GCC is installed on the system

Enter in Terminal: $ gcc–version

The results show:

GCC (Ubuntu 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
......

If not installed, use the following command to install:

sudo apt-get install build-essential

4) Verify that the kernel header and package development are installed on the system

A. View the version of the system kernel that is running:

Enter in Terminal: $ uname–r

The results show:

4.10.0-40-generic

b, enter in Terminal: $ sudo apt-get install linux-headers-$ (uname-r)

You can install the kernel header and package development for the corresponding kernel version

The results show:

......

0 packages were upgraded, 0 new packages were installed, 0 packages were uninstalled, 4 packages were not upgraded.

Indicates that the system is already in use and does not have to be installed repeatedly.

If all the above verification checks meet the requirements, the following formal installation process can be carried out. If you do not meet the requirements, you can refer to Cuda's official documentation, which has a detailed solution for each problem.

Three, choose the installation method
Cuda offers two types of installation: Package Manager installation and Runfile installation, Package Manager installation is relatively simple, but I found in the process of reading other people's blog, the choice of this way in the installation process may be a little more problems, the probability of failure is greater. In order to reduce unnecessary trouble I choose Runfile installation method.
Download Cuda installation package: Cuda official website Download, according to system information choose corresponding version, Runfile install the last item to select Runfile file.

After downloading, with MD5 test, if the serial number is not, you have to re-download (because there is no save, here I adopted someone else, pay attention to the Cuda version number here, others use the cuda_8.0)

Input command: $md5sum cuda_9.0.176_linux.run

Four, runfile installation Cuda

1) Disable Nouveau drive

Run in Terminal: $ lsmod | grep nouveau, if there is an output, indicates that Nouveau is loading. We need to manually ban Nouveau.

Ubuntu Nouveau Disable Method:
A. Create a file in/ETC/MODPROBE.D blacklist-nouveau.conf

Input command: $ sudo vi/etc/modprobe.d/blacklist-nouveau.conf (Edit and save file with VI editor)

Enter the contents of the file:

Blacklist nouveau
Options Nouveau modeset=0

B. Implementation:
$ sudo update-initramfs–u

c, re-execution:
$ lsmod | grep nouveau
If there is no content output, the success is disabled, if there is still content output, please check the operation, and repeat the above operation.

Note: VI is a common editor under the Linux Terminal or under the console, the basic mode of operation is: VI/path/file name
For example, Vi/etc/fstab indicates that the contents of the/etc/fstab file are displayed. Use the page UP and PAGE DOWN keys on your keyboard to page up and down, press the INSERT key to see the word "insert" in the lower-left corner of the window to indicate that you are currently inserting an edit state, and then insert the contents from the keyboard into the cursor position, and then press the INSERT key and the lower left corner will have " Replace word, which means that the contents of the cursor position are replaced by the content entered from the keyboard when the edit state is currently replaced. When you are finished editing the content, press ESC and enter ": Wq" and then enter to save the exit.
If you do not want to save and exit directly, press the ESC key, enter ": q!", and then return. "Wq" means write and quit, that is, save exit; "Q!" Indicates that the modify forced exit is ignored.

The following actions suggest that the phone take pictures, it is recommended to rename the downloaded cuda_9.0.176_384.81_linux.run file to Cuda.run and moved to the home folder (for easy installation)

2) Restart the computer, enter the login interface, do not log in to the desktop (otherwise it may fail, if not carefully enter, please restart the computer), directly press CTRL+ALT+F1 into the text mode (command line interface), login account.

3) Enter the sudo service LIGHTDM stop to turn off the graphical interface

4) switch to the Cuda installation file path: $ cd home/

Run $ sudo sh cuda_7.5.18_linux.run
Follow the prompts to step through the steps

Note: A, be sure to follow the prompts to enter the corresponding characters, for example, some need to input accept, some need to enter Yes;

b, if you are prompted to install OpenGL, select No (if your computer is the same as me, and the main display is the non-NVIDIA GPU in the work need to select No, otherwise yes), others choose Yes or default. (If your computer is a dual graphics card and you choose Yes in this step, then you are most likely to install CUDA, after restarting the graphical interface after the login interface loop problem: Enter the password and then jump back to the password input interface.)

This is because your computer is double-displayed, and the GPU used to display it is not nvidia, then OpenGL libraries should not be installed, otherwise you are using the GPU (non-NVIDIA GPU) OpenGL libraries will be overwritten, Then the GUI will not work. )

After the installation is successful, installed will be displayed, otherwise the failed will be displayed.

5) Enter the sudo service LIGHTDM start to restart the graphical interface.

Press ALT + CTRL +F7 to return to the graphical login interface and enter the password to log in.
If you are able to log in successfully, you will not encounter a circular logon problem, and the basic instructions for CUDA installation are successful.

If you encounter a repeat landing situation, do not need to focus on the system, the official tutorial has mentioned, the reasons mentioned in the previous step, in the installation of OpenGL you may not pay attention to the choice of Yes, please uninstall Cuda, and then reinstall.
Uninstall: Because the login does not come into the graphical user interface (GUI), but we can enter into the text user interface (TUI)

In the Login screen state, press CTRL + ALT + F1 to enter TUI
Perform
$ sudo/usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl
$ sudo/usr/bin/nvidia-uninstall
And then restart
$ sudo reboot
Reinstall. Run install again, be sure to note that when prompted to install OpenGL, your dual graphics should be selected N.

6) Restart your computer and check device Node verification.

Perform
$ ls/dev/nvidia*
There may be a, b two results, please seat.

---------notice-------.

If the prompt does not install the Toolkit tool, you can follow the system prompts to install, I probably Ann 3, if the direct use of sudo apt-get install Tookit unsuccessful, he will be prompted to install the remaining three packages, the three packages installed, command

Ls/dev/nvidia* will show the/dev/nvidia0/dev/nvidiactl, then use the following script, and then restart the three have appeared!

--------------------


A, if the results show

/dev/nvidia0/dev/nvidiactl/dev/nvidia-uvm

or display similar information, there should be three (containing a similar/DEV/NVIDIA-NVM), then the installation is successful.

b, most of the results may be the case

Ls:cannot access/dev/nvidia*: No such file or directory

Or something like that, only appears.

/dev/nvidia0/dev/nvidiactl

One or two in a, but no/dev/nvidia-num, that is, the file is not displayed completely.

There is no need to worry about installing the system (which is the case at the time of installation), there is a detailed solution in the official guide, but my approach is slightly out of the way with the official.

First of all to add a startup script (there are two ways to add a startup script, I use the most direct method, the other can first create a file and then through the MV to move to the Startup folder, can self-Baidu)
Perform

$ sudo vi/etc/rc.local
If you are opening this file for the first time, it should be empty (except for a line-by-line # comment Item). The first line of this file is
#!/bin/sh-e
Remove-E (This step is important, otherwise it will not load the contents of this text)
Then copy the following except #!/bin/bash to it, (before exit 0) to save the exit.

#!/bin/bash

/sbin/modprobe nvidia

If ["$?"-eq 0]; then
# Count The number of Nvidia controllers Fou nd.
nvdevs= ' lspci | grep-i NVIDIA '
n3d= ' echo ' $NVDEVS ' | grep ' 3D controller ' | wc-l '
nvga= ' echo ' $NVDEVS ' | grep "VGA Compatible Controller" | Wc-l '

n= ' expr $N 3D + $NVGA-1 '
for I in ' seq 0 $N ', do
mknod-m 666/dev/nvidia$i C 195 $i
done

M Knod-m 666/dev/nvidiactl C 195 255

Else
Exit 1
Fi

/sbin/modprobe NVIDIA-UVM

If ["$?"-eq 0] ; Then
# "Find out" the major device number used by the NVIDIA-UVM driver
d= ' grep nvidia-uvm/proc/devices | awk ' {PRINT $ '

mknod-m 666/DEV/NVIDIA-UVM C $D 0
Else
Exit 1
Fi


Next time you restart, you should be able to see the three Nvidia files in the/dev directory directly
Input: $ ls/dev/nvidia*
Results display:/dev/nvidia0      /dev/nvidiactl      /DEV/NVIDIA-UVM

Success!

7) Set environment variables.

Terminal input $ sudo gedit/etc/profile
At the end of the open file, add the following two lines.
64-bit system:
Export Path=/usr/local/cuda-9.0/bin${path:+:${path}}
Export ld_library_path=/usr/local/cuda-9.0/lib64\
${ld_library_path:+:${ld_library_path}}

32-bit system:

Export Path=/usr/local/cuda-9.0/bin${path:+:${path}}

Export Ld_library_path=/usr/local/cuda-9.0/lib\
${ld_library_path:+:${ld_library_path}}

Save the file and restart it. Because the source/etc/profile is temporarily in effect, restarting the computer is the permanent effect.

This is a bit different from the official installation documentation, which needs to be explained:
In the official documentation, it is only possible to run the above two export statements in the terminal, but if you do not write them to the/etc/profile file, such an environment variable disappears after you exit the terminal and does not work, so writing is a permanent practice.

8) Restart the computer to check if the above environment variables are set successfully.

A, verify the driver version
Knock
$ cat/proc/driver/nvidia/version
Results show
NVRM version:nvidia UNIX x86_64 Kernel Module 384.81 Sat Sep 2 02:43:11 PDT 2017
GCC VERSION:GCC version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)

B, verify Cuda Toolkit
Knock
$ nvcc-v will output Cuda version information

If this is the case:
The program ' NVCC ' was currently not installed. You can install it by typing:
sudo apt-get install Nvidia-cuda-toolkit

The environment configuration may not be successful, please repeat step 7 above).

Five, try to compile the example provided by Cuda

1) Open terminal input: $ cd/home/xxx/nvidia_cuda-9.0_samples where xxx is your own user name, enter the Nvidia_cuda-9.0_samples directory via the command CD.
Then terminal input: $ make
The system will automatically enter the compilation process, the whole process will take about more than 10 to 20 minutes, please wait patiently. If there is an error, the system will immediately stop.

The first run may be an error, and the wrong message may be that there is no GCC in the system,

The solution is to re-install GCC by command, and in terminal input: sudo apt-get install gcc after installing GCC, make is normal.

If the compilation succeeds, the finished building CUDA samples is displayed, as shown in.

2) Run compile-generated binaries.
The compiled binaries are stored by default in Nvidia_cuda-9.0_samples/bin.
Then enter in the previous terminal: $ cd/home/lxxx/nvidia_cuda-9.0_samples/bin/x86_64/linux/release where xxx is your own user name
Then enter in the terminal: $./devicequery

As shown in the results: see similar as shown in the slice, then the CUDA installation and configuration succeeds, where result = Pass represents success, if failure result = fail

3) Finally, check the connection of the system and the cuda-capable device.
Terminal Input: $ ./bandwidthTest
Seen similar to the display in the slice, it represents a successful

Finally, I wish you all a pleasant installation using Cuda

Installation of CUDA9.0 in Ubuntu environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.