.run文件卸载
sh NVIDIA-Linux-x86_64-390.77.run --uninstall
apt-get 卸载
apt-get --purge remove nvidia-*
查找相应.run 文件:https://www.nvidia.cn/Download/index.aspx?lang=cn
下载
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/390.77/NVIDIA-Linux-x86_64-390.77.run
查看属性
sudo ls -lh /etc/modprobe.d/blacklist.conf
修改属性
sudo chmod 666 /etc/modprobe.d/blacklist.conf
用vim编辑器打开
sudo vim /etc/modprobe.d/blacklist.conf
在该文件末尾添加以下几行
blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist rivatv
blacklist nvidiafb
执行下列命令
sudo update-initramfs -u
# 如果出现 W: mdadm: /etc/mdadm/mdadm.conf defines no arrays.
# 删掉/etc/mdadm/mdadm.conf ,重新执行一遍命令即可
重启后查看
reboot
lsmod | grep nouveau # 没有输出即为屏蔽好了
sudo apt-get install -y gcc g++ make
确认禁用了nouveau
lsmod | grep nouveau # 若无输出,则表示禁用成功
sudo chmod a+x NVIDIA-Linux-x86_64-390.77.run
sudo ./NVIDIA-Linux-x86_64-390.77.run -no-x-check -no-nouveau-check -no-opengl-files
# -no-opengl-files 表示只安装驱动文件,不安装OpenGL文件,这个参数最重要
# -no-x-check 安装驱动时不检查X服务
# -no-nouveau-check 安装驱动时不检查nouveau(ps:这个选项和1.3禁止集成的nouveau驱动组成双保险,其实一项操作就可以了)
nvidia-smi # 查看GPU和驱动程序信息
cat /proc/driver/nvidia/version # 查看驱动程序版本
安装后,没启动程序,GPU使用率高,执行下列命令
nvidia-smi -pm 1 # 这个是设定持久模式,(没人用GPU的时候,驱动不自动卸载,而是一直都处于加载状态)
# 本次有效下次重启还需要重新设定。
# 默认状态是驱动每次用完都自动卸载的,然后重新加载。
查找相应版本:https://developer.nvidia.com/cuda-90-download-archive
下载
wget https://developer.download.nvidia.com/compute/cuda/9.0/secure/Prod/local_installers/cuda_9.0.176_384.81_linux.run?Uu9ajYqvEe_TaZRbY_6Q7PaV5tItXM0i2mSlMNfkVmW6DIBhYzeY0zQTbxaUCui3QxDRTSOfKmycj_qdmzS9Qb-6me6c75bSQhOOKiw8q938EU5_pekPzdG6wRgMGwfO59xUHfuDoxWHKXevbfG22fPKzBdnE_HltZKJa78mMhDpu5QgWZoeYovE
cd /usr/local/cuda-9.0/bin
./nvidia uninstall_cuba_9.0.pl
版本要求网址:https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html
查看内核版本(kernel)
uname -r # 4.4.0
查看gcc版本
gcc -v # 5.4.0
查看GLIBC版本
ldd --version # 2.23
执行 .run 文件
sh cuda_9.0.176_384.81_linux.run
按一下q跳过阅读
q
选择 accept接受
Do you accept the previously read EULA?accept/decline/quit: accept
是否自动安装nvidia显卡驱动,选择no
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.86?(y)es/(n)o/(q)uit: n
后面的都选yes,看到以下输出信息说明安装成功
The driver installation has failed due to an unknown error. Please consult the driver
installation log located at /var/log/nvidia-installer.log.
===========
= Summary =
===========
Driver: Not Selected
Toolkit: Installed in /usr/local/cuda-9.0
Samples: Installed in /root, but missing recommended libraries
......
编辑~/.bashrc文件
vim ~/.bashrc
末尾添加如下内容
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
确认/etc/profile中的路径包含了cuda 9.0 的安装路径及相应的库文件
vim /etc/profile
末尾添加如下内容
export PATH=$PATH:/usr/local/cuda/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/cuda/lib64
使配置文件生效
source /etc/profile
cd /usr/local/cuda-9.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
# 如果显示的是关于GPU的信息,则说明安装成功了。
查看CUDA版本
cat /usr/local/cuda/version.txt
下载地址:https://developer.nvidia.com/rdp/cudnn-archive
解压
tar -zxvf cudnn-9.0-linux-x64-v7.tgz
cd cuda
cp include/* /usr/local/cuda
cp lib64/* /usr/local/cuda/lib64
查看cuDNN 版本
cat /usr/local/cuda/cudnn.h | grep CUDNN_MAJOR -A 2
wget https://jaist.dl.sourceforge.net/project/opencvlibrary/opencv-unix/3.2.0/opencv-3.2.0.zip
OpenCV的依赖项
apt -y install --assume-yes libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff5-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg libgtk-3-dev python-numpy python3-numpy libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev qtbase5-dev libcurl4-openssl-dev
wget https://raw.githubusercontent.com/Itseez/opencv_3rdparty/81a676001ca8075ada498583e4166079e5744668/ippicv/ippicv_linux_20151201.tgz
unzip opencv-3.2.0.zip
# 替换ippicv_linux_20151201.tgz
mkdir -p opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e
cp ippicv_linux_20151201.tgz opencv-3.2.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e
cd opencv-3.2.0
mkdir build
cd build
# cmake(一步一步进行,不用理会warning)
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..
cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF ..
cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
# make
make -j64
make install
/bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
加载动态库
ldconfig
vim test.cpp
添加内容
//test.cpp
#include
#include
#include
int main(int argc,char *argv[])
{
cv::Mat image;
image=cv::imread("1.png");
cv::namedWindow("1.png");
cv::imshow("1.png",image);
cv::waitKey();
return 0;
}
编译前设置pkgconfig路径
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
用g++编译
g++ -g -o test test.cpp `pkg-config --cflags --libs opencv`
运行
./test