1. Install NVIDIA graphics driver
1. Disable nouveau
ubuntu 16.04 installs the third-party open source driver nouveau by default. To install the nvidia graphics driver, first disable nouveau, otherwise you will encounter conflicts, which prevents the installation of the nvidia graphics driver
a. Open the file:
sudo gedit /etc/modprobe.d/blacklist.conf
b. Add at the end of the file:
blacklist nouveau
options nouveau modeset=0
c. Update system modification:
sudo update-initramfs -u
d, restart the system
e, verify that nouveau is disabled
lsmod | grep nouveau
If nothing appears, it is successful
2. Download the driver file and instruct the installation
a, in Nvidia's official website to find and download the appropriate drivers on your computer's video card model, run files contained copied to your home directory, the file is: NVIDIA-Linux-x86_64-xxx.run:
b. Press ctrl + alt + f1 + f2 + ... f6 under ubuntu (until you enter the command line interface to stop)
Note: ctrl + alt + f7 is to exit the command interface and return to the graphical interface
c, login: computer account name, password : Password, log in to the command line interface
d, close the graphical interface (must be closed)
sudo service lightdm stop
e. Uninstall the driver existing in the system, there is installed by default
sudo apt-get remove nvidia-*
f. Give file permissions
sudo chmod a+x NVIDIA-Linux-x86_64-xxx.run(根据自己下载的文件)
sudo ./NVIDIA-Linux-x86_64-xxx.run -no-x-check -no-nouveau-check -no-opengl-files
Among them:
-no-x-check: turn off the X service when installing the driver
-no-nouveau-check: disable nouveau when installing the driver
-no-opengl-files: only install the driver files, not the OpenGL files
If the installation does not start next, the error message seems to be two codes. At this time, the information is said to be the driver version problem. I then downloaded the driver again. The 440 version was replaced by 430 as shown in the figure, and then you can reinstall it:
g
1. Installation process 1. he distribution-provided pre-install script failed! Are you sure you want to continue? Select yes to continue.
2、Would you like to register the kernel module souces with DKMS? This will allow DKMS to automatically build a new module, if you install a different kernel later? 选择NO继续
3、Would you like to run the nvidia-xconfigutility to automatically update your x configuration so that the NVIDIA x driver will be used when you restart x? Any pre-existing x confile will be backed up. 选择 Yes 继续
h. Restart the graphical interface
sudo service lightdm start
Press Ctrl + Alt + F7 to return to the graphical interface
i. Check if the driver is installed successfully
nvidia-smi
The installation is successful!
Second, install CUDA9.0
Reference: 1 2 3
1 official website on the download CUDA9.0:
Here select runfile installed, downloaded, such as: cuda_9.0.176_384.81_linux.run, I put it home folder, and easy to find the next path
2. Install CUDA9.0
a. Press ctrl + alt + f1 + f2 + ... f6 under ubuntu (until you enter the command line interface to stop), and log in
b. Close the graphical interface
sudo service lightdm stop
c. Switch to the path of the cuda installation file and run the installation
cd ~
sudo sh cuda_9.0.176_384.81_linux.run
Then keep pressing enter until the terms of service show 100%, and then follow the question:
accept
n (don't install the driver)
y
y
y
and then display the successful installation
3. Restart the graphical interface
sudo service lightdm start
Press Alt + ctrl + F7 to return to the graphical login interface
4. Restart the computer and check Device Node Verification
ls /dev/nvidia*
There may be two results, a and b, please check the
seats : a. If the result shows / dev / nvidia0 / dev / nvidiactl / dev / nvidia-uvm or displays similar information, there should be three (including a similar / dev / nvidia- nvm), the installation was successful.
b. Most of the results may be like this ls: cannot access / dev / nvidia *: No such file or directory or like this, only one or two of / dev / nvidia0 / dev / nvidiactl a appears, but there is no / dev / nvidia-num, that is, the file is not displayed completely.
If it is b, then:
sudo vi /etc/rc.local
If you are opening this file for the first time, it should be empty (except for the #comment line after line);
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 the text) Then copy the following content into it except #! / Bin / bash , (Before exit 0) save and exit;
#!/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$i c 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
Restart! re-enter:
ls /dev/nvidia*
The results show: / dev / nvidia0 / dev / nvidiactl / dev / nvidia-uvm succeeded!
If not, check here:
5. Set environment variables
sudo gedit /etc/profile
At the end of the opened file, add the following two lines:
64位系统:
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位系统:
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, because source / etc / profile is temporarily effective, restarting the computer is permanently effective
6. Check whether the above environment variables are set successfully
a. Verify the driver version
cat /proc/driver/nvidia/version
The result shows that 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
nvcc -V
The CUDA version information will be output if it is like this: The program 'nvcc' is 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 the above step 5 )
Note: If you encounter an error: Missing recommended library:
then:
`sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-dev`
Then reinstall, refer to: https://blog.csdn.net/weixin_43506858/article/details/89845768
7. Try to compile the example provided by cuda
cd /home/xxx/NVIDIA_CUDA-9.0_Samples
make
The whole process takes about ten to twenty minutes, please be patient. If an error occurs, the system will immediately report the error and stop. An error may be reported during the first run. The error message may be that there is no gcc in the system. The solution is to reinstall gcc through the command:
sudo apt-get install gcc
After installing gcc, make is normal again; if the compilation is successful, the Finished building CUDA samples will be displayed at the end, as shown in the following figure:
`cd /home/lxxx/NVIDIA_CUDA-9.0_Samples/bin/x86_64/linux/release`
./deviceQuery
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, if it fails Result = FAIL
./bandwidthTest
Seeing a display similar to the picture below, it means success!
Three, install CUDNN7.05
1. Download the installation file
Official website download: https://developer.nvidia.com/rdp/cudnn-archive
2. Installation
Unzip the downloaded file, you can see the cuda folder, open the terminal in the current directory (upper layer of cudnn), execute the following command:
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
3. Check the cudnn version
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
If the version information shown in the figure below appears, the installation is successful:
4. View the GPU in real time (per second)
watch -n 1 nvidia-smi
Fourth, install OpenCv3.4.5
Reference: https://blog.csdn.net/gaoyu1253401563/article/details/89380270
1, downloading codecs
Shang official website source version of OpenCV download, choose Sources version of OPenCV3.4.5;
Baidu cloud disk has been downloaded: https: / /download.csdn.net/download/gaoyu1253401563/11129399
2. Install dependent libraries and cmake
into the decompressed file package (opencv-3.4.5)
sudo apt-get update
sudo apt-get install cmake
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff4.dev libswscale-dev libjasper-dev
After installing cmake, execute the command, create a compilation folder, and enter the compilation folder
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
When the above command is executed, the IPPICV will be downloaded: Download: ippicv_2019_lnx_intel64_general_20180723.tgz, to this line during runtime, the download does not move, there is a situation where it cannot be downloaded, it may be because the wall cannot download, so we manually download this file Come down and run again:
Baidu SkyDrive (free): link: https://pan.baidu.com/s/1eyG7mqKLY6CvUQdh7CbUgA extraction code: 1miu
After downloading, replace the files with the same name in the opencv-3.4.5 / 3rdparty / ippicv / downloads / linux- * directory, and restart cmake (under the build directory)
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
The results are as follows:
3. Perform the compilation process
sudo make
4. Installation
sudo make install
5. Configure some OpenCV compilation environment
Add the OPenCV library to the path so that the system can find:
sudo gedit /etc/ld.so.conf.d/opencv.conf
After executing this command, it may be a blank document. This does not need to be controlled. Just add the following statement to the end:
/usr/local/lib
Execute the following command to make the path just configured take effect:
sudo ldconfig
Configure bash:
sudo gedit /etc/bash.bashrc
At the end of the open file, add the following command at a new line:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
Save and execute the following command to make the configuration take effect:
source /etc/bash.bashrc
Last update:
sudo updatedb
6. Test opencv
into the example_cmake directory of the opencv directory and execute:
cmake .
make
./opencv_example
Result:
Success!