Ubuntu16.04+NVIDIA驅動418.56+CUDA10+CUDNN7.5.1+opencv3.4.0

Vegetable__發表於2020-10-31

重灌了幾次系統後,終於能含淚寫下自己的安裝過程,為以後重灌做個記錄T T

一、NVIDIA驅動

Ubuntu18.04安裝英偉達顯示卡驅動
安裝nvidia驅動418.56
在這裡插入圖片描述

安裝後續步驟或環境必需的依賴包,依次輸入以下命令:


sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
 
sudo apt-get install --no-install-recommends libboost-all-dev
 
sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
 
sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
 
sudo apt-get install git cmake build-essential

二、CUDA

1.安裝缺失的依賴庫

sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libgl1-mesa-dev libglu1-mesa libglu1-mesa-dev libxi-dev

2.安裝CUDA

在CUDA所在的資料夾中開啟終端,輸入以下命令:

sudo sh cuda_10.0.130_410.48_linux.run  

在這裡插入圖片描述
按q跳過(截圖沒顯示)

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 410.48?
(y)es/(n)o/(q)uit: n  ##一定要選N

Install the CUDA 10.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-10.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 10.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/srq ]: 

Installing the CUDA Toolkit in /usr/local/cuda-10.0 ...
Installing the CUDA Samples in /home/srq ...
Copying samples to /home/srq/NVIDIA_CUDA-10.0_Samples now...
Finished copying samples.

3.設定環境變數

sudo gedit ~/.bashrc

在檔案末尾新增:

export PATH=/usr/local/cuda-10.0/bin:$PATH 
export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda
source ~/.bashrc

4.檢測CUDA是否安裝正確

nvcc --version
cat /usr/local/cuda/version.txt

在這裡插入圖片描述
CUDA安裝完成。保險起見,測試一哈:

cd /usr/local/cuda-10.0/samples
sudo make all -j16
cd ./bin/x86_64/linux/release
./deviceQuery 

在這裡插入圖片描述
顯示Result = PASS字樣,測試通過。

三、CUDNN

1.安裝CUDNN

在cudnn所在資料夾中,開啟終端,執行以下命令解壓:

tar -xzvf cudnn-10.0-linux-x64-v7.5.1.10.tgz 
cd cuda
cd ./include
sudo cp cudnn.h  /usr/local/cuda/include/
cd ../lib64
sudo cp lib*  /usr/local/cuda/lib64/
sudo chmod a+r /usr/local/cuda/include/cudnn.h 
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
cd /usr/local/cuda/lib64/ 
sudo rm -rf libcudnn.so libcudnn.so.7
sudo ln -s libcudnn.so.7.5.1 libcudnn.so.7
sudo ln -s libcudnn.so.7 libcudnn.so
sudo ldconfig -v

2.檢測CUDNN是否安裝正確

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

在這裡插入圖片描述

四、opencv3.4.0

1.安裝和編譯

解壓壓縮包,進入解壓好的opencv-3.4.0中

mkdir build 
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
sudo make all -j16

在這裡插入圖片描述

sudo make install

在這裡插入圖片描述

2.配置環境變數

sudo gedit /etc/ld.so.conf.d/opencv.conf 

開啟的是一個空白的檔案,在檔案中新增

/usr/local/lib  

執行如下命令使得剛才的配置路徑生效:

sudo ldconfig 

配置bash:

sudo gedit /etc/bash.bashrc 

在檔案末尾新增:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
export PKG_CONFIG_PATH

執行如下命令使得配置生效:

source /etc/bash.bashrc

更新:

sudo updatedb

3.測試

cd opencv-3.4.0/samples/cpp/example_cmake
cmake .
make
./opencv_example

相關文章