Preface: This article is based on the experience of installing CUDA 9.0. CUDA 9.0 currently supports Ubuntu 16.04 and Ubuntu 17.04, as shown in the following figure (the installation method at the bottom is the first one, that is, the runfile method): You can download the CUDA file first, but it is best not to rush to install it. You must first carefully read the official guide provided by NVIDIA, and then find a few good blogs to read to get a general understanding of the CUDA installation process. You should have a general understanding of the problems that may arise during the installation process. Do not reinstall the system unless it is absolutely necessary. Installation suggestions: 1) When you download CUDA from the official website, be sure to find a copy of the official installation document and read it carefully. Follow the steps step by step as much as possible and don't be lazy. At the same time, find a few good blogs for reference so that you can be confident before installation. 2) Before installation, be sure to check your computer configuration (single graphics card or dual graphics cards), whether the type of graphics card meets the CUDA installation requirements, and whether the system meets the installation requirements. 3) During the installation process, try to check whether each operation is successful. Installation process: 1. Install and familiarize yourself with the Ubuntu 16.04 system Before installing the software, it is best to have some basic understanding of Ubuntu's command line, such as sudo, cd, ls, nona, cat, chmod, etc., which can save a lot of unnecessary trouble during the installation process. (I recommend you to search for Mofan Python on Baidu. He has videos about Ubuntu commands. Each episode is very concise and well explained.) 2. Check whether your computer environment has the conditions for installing CUDA 1) Verify that your computer has a CUDA-capable GPU You can find the specific model of the graphics card in the computer's configuration information. If you have a dual system, you can also find detailed information about the graphics card in the device manager under Windows. My display is (GeForceGT630M):
Then go to the CUDA official website to check whether your GPU version is in the CUDA support list. 2) Verify that your Linux version supports CUDA (Ubuntu 16.04 is fine) Enter the command: $ uname -m && cat /etc/*release The results show:
3) Verify whether gcc is installed on the system Type in the terminal: $ gcc –version The results show:
If it is not installed, please use the following command to install it: sudo apt-get install build-essential 4) Verify that the kernel header and package development are installed on the system a. Check the running system kernel version: Type in the terminal: $ uname –r The results show:
b. Enter in the terminal: $ sudo apt-get install linux-headers-$(uname -r) You can install the kernel header and package development of the corresponding kernel version The results show:
0 packages upgraded, 0 packages newly installed, 0 packages to be removed, and 4 packages not upgraded. It means that it is already in the system and there is no need to install it again. If all the above verification checks meet the requirements, you can proceed to the following formal installation process. If the requirements are not met, you can refer to the official documentation of CUDA, which contains detailed solutions to each problem. 3. Choose the installation method CUDA provides two installation methods: package manager installation and runfile installation. The package manager installation method is relatively simple, but when I read other people's blogs, I found that choosing this method may cause more problems during the installation process and the probability of failure is higher. In order to reduce unnecessary trouble, I chose the runfile installation method. After downloading, use MD5 to check. If the serial number does not match, you have to download it again (because I didn't save it at the time, I used someone else's screenshot here. Note the cuda version number here, which is cuda_8.0) Enter the command: 4. Runfile installs cuda 1) Disable the nouveau driver Run in the terminal: $ lsmod | grep nouveau. If there is output, it means nouveau is being loaded. We need to manually disable nouveau. How to disable nouveau in Ubuntu: a. Create the file blacklist-nouveau.conf in /etc/modprobe.d Enter the command: Enter the following content into the file: blacklist nouveau options nouveau modeset=0 b. Execution: $ sudo update-initramfs –u c. Execute again: $ lsmod | grep nouveau If there is no content output, the disabling is successful. If there is still content output, please check the operation and repeat the above operation. Note: vi is a commonly used editor in Linux terminals or consoles. The basic operation method is: vi /path/file name. For example: vi /etc/fstab means displaying the contents of the /etc/fstab file. Use the Page Up and Page Down keys on the keyboard to turn pages up and down; press the Insert key, you can see the word "Insert" in the lower left corner of the window, indicating that the current state is insert editing, and the content entered from the keyboard will be inserted into the cursor position; press the Insert key again, there will be the word "Replace" in the lower left corner, indicating that the current state is replace editing, and the content entered from the keyboard will replace the content at the cursor position. After editing the content, press the Esc key, enter ":wq", and press Enter to save and exit. It is recommended to take a photo with your phone for the following operations. It is recommended to rename the downloaded cuda_9.0.176_384.81_linux.run file to cuda.run and move it to the Home folder (for easy installation) 2) Restart the computer. When you enter the login interface, do not log in to the desktop (otherwise it may fail. If you accidentally enter, please restart the computer). Press Ctrl+Alt+F1 to enter the text mode (command line interface) and log in to your account. 3) Enter $ sudo service lightdm stop to close the graphical interface 4) Switch to the path of the cuda installation file: $ cd Home/ Run $ sudo sh cuda_7.5.18_linux.run Note: a. Be sure to enter the corresponding characters according to the prompts. For example, some require you to enter accept, and some require you to enter yes; b. When prompted whether to install OpenGL, select no (if your computer has dual display like mine, and the main display is a non-NVIDIA GPU, you need to select no, otherwise you can select yes). For the rest, select yes or the default. (If your computer has dual graphics cards and you selected yes in this step, you will most likely encounter a login screen loop problem after restarting the graphical interface after installing CUDA: after entering the password, it jumps back to the password input interface. This is because your computer has dual display, and the GPU used for display is not NVIDIA, then OpenGL Libraries should not be installed, otherwise the OpenGL Libraries of the GPU you are using (non-NVIDIA GPU) will be overwritten, and then the GUI will not work. ) If the installation is successful, it will display "installed", otherwise it will display "failed". 5) Enter $ sudo service lightdm start to restart the graphical interface. Press Alt + ctrl + F7 at the same time to return to the graphical login interface and enter the password to log in. If you encounter repeated logins, don't rush to reinstall the system. The official tutorial mentions this. The reason is mentioned in the note in the previous step. You may have accidentally selected yes when installing openGL. Please uninstall cuda and then reinstall it. In the login interface, press Ctrl + Alt + f1 to enter TUI $ sudo /usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl $ sudo /usr/bin/nvidia-uninstall Then reboot $ sudo reboot Reinstall .run When you install again, please be sure to pay attention. When prompted whether to install OpenGL, if you have dual graphics cards, you should choose n. 6) Restart the computer and check Device Node Verification. implement $ ls /dev/nvidia* There may be two results, a and b. Please choose the one that suits you best. a. If the result shows
Or similar information is displayed. There should be three (including one similar to /dev/nvidia-nvm), which means the installation is successful. b. Most of the results may be like this
Or something like this, only
One or both of a, but no /dev/nvidia-num, that is, the file display is incomplete. Don't worry or rush to reinstall the system (this is what happened when I was installing it). The official guide has a detailed solution, but my method is slightly different from the official one. First, you need to add a startup script (there are two ways to add a startup script. I use the most direct method. The other method is to create a file first and then move it to the startup folder through mv. You can search Baidu by yourself) $ sudo vi /etc/rc.local If you are opening this file for the first time, it should be empty (except for lines and lines of # comments). The first line of this file is #!/bin/sh -e Remove -e (this step is very important, otherwise it will not load the content of this text) #!/bin/bash /sbin/modprobe nvidia if [ "$?" -eq 0 ]; then # Count the number of NVIDIA controllers found. NVDEVS=`lspci | grep -i NVIDIA` N3D=`echo "$NVDEVS" | grep "3D controller" | wc -l` NVGA=`echo "$NVDEVS" | grep "VGA compatible controller" | wc -l` N = `expr $N3D + $NVGA - 1` for i in `seq 0 $N`; do mknod -m 666 /dev/nvidia$ic 195 $i done mknod -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 $1}'` mknod -m 666 /dev/nvidia-uvm c $D 0 else exit 1 fi Next time you reboot, you should be able to see the three nvidia files directly in the /dev directory. Type: $ ls /dev/nvidia* success! 7) Set environment variables. Enter $ sudo gedit /etc/profile in the terminal 64-bit Systems: 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 systems: 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 reboot. Because source /etc/profile is only effective temporarily, it will take effect permanently only after restarting the computer. This is slightly different from the official installation documentation and needs to be explained: 8) Restart the computer and check whether the above environment variables are set successfully. a. Verify the driver version Knock in $ cat /proc/driver/nvidia/version Results
b. Verify CUDA Toolkit Knock in $ nvcc -V will output CUDA version information If it is like this:
It may be that the environment configuration was not successful, please repeat the above step 7). 5. Try to compile the examples provided by cuda 1) Open the terminal and enter: $ cd /home/xxx/NVIDIA_CUDA-9.0_Samples, where xxx is your own user name. Use the cd command to enter the NVIDIA_CUDA-9.0_Samples directory. Then enter in the terminal: $ make The system will automatically enter the compilation process. The whole process will take about ten to twenty minutes. Please wait patiently. If an error occurs, the system will immediately report an error and stop. The first time you run it, an error may be reported, and the error message may be that there is no gcc in the system. The solution is to reinstall gcc through the command. Enter in the terminal: $ sudo apt-get install gcc After installing gcc, make will work normally. If the compilation is successful, Finished building CUDA samples will be displayed at the end, as shown in the following figure. 2) Run the compiled binary file. The result is as shown in the figure below: If you see a display similar to the following picture, it means that CUDA is installed and configured successfully, where Result = PASS means success, and Result = FAIL if it fails 3) Finally, check the connection between the system and the CUDA-Capable device. Enter in the terminal: $ Finally, I wish everyone a happy installation and use of CUDA This is the end of this article about the detailed tutorial on installing CUDA9.0 on Ubuntu16.04. For more information about installing CUDA9.0 on Ubuntu16.04, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: React+Typescript implements countdown hook method
>>: Detailed explanation of MySQL foreign key constraints
1. MySQL's own stress testing tool - Mysqlsla...
This article shares the specific code of js to ac...
How to modify the style of the el-select componen...
Hello everyone, today we will talk about how to u...
FileReader is an important API for front-end file...
1. List The list ul container is loaded with a fo...
Table of contents Common array methods pop() unsh...
I recently wanted to convert a website to https a...
Customizing images using Dockerfile Image customi...
Tutorial Series MySQL series: Basic concepts of M...
Delete a file by its inode number First use ls -i...
In web page production, displaying and hiding ele...
We often use click events in the a tag: 1. a href=...
Table of contents 1. Redux 1.1. Store (librarian)...
Table of contents 1. What is a custom instruction...