.run文件卸载
sh NVIDIA-Linux-x86_64-390.77.run --uninstall
yum 卸载
yum list installed | grep 384.145
yum remove nvidia-384.145
添加ELRepo源
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
安装
yum install nvidia-detect
运行
nvidia-detect -v
查找相应.run 文件:https://www.nvidia.cn/Download/index.aspx?lang=cn
下载
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/384.145/NVIDIA-Linux-x86_64-384.145.run
# yum -y update //注意这是升级系统
yum -y groupinstall "GNOME Desktop""Development Tools"
yum -y install kernel-devel #注意kernel版本,uname -r是否和kernel-devel版本一样
yum -y install epel-release
yum -y install dkms
编辑grub文件
vim /etc/default/grub
# 在“GRUB_CMDLINE_LINUX”中添加 rd.driver.blacklist=nouveau nouveau.modeset=0
grub2-mkconfig -o /boot/grub2/grub.cfg #随后生成配置
创建blacklist
vim /etc/modprobe.d/blacklist.conf
添加内容
blacklist nouveau
更新配置
mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img
dracut /boot/initramfs-$(uname -r).img $(uname -r)
重启
reboot
确认禁用了nouveau
lsmod | grep nouveau # 若无输出,则表示禁用成功
sh NVIDIA-Linux-x86_64-384.145.run # 安装完成重启
# 如果提示kernel版本不对
# sh NVIDIA-Linux-x86_64-384.145.run -k $(uname -r)
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 # 3.10.0
查看gcc版本
gcc -v # 4.8.5
查看GLIBC版本
ldd --version # 2.17
执行 .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
基本工具
yum -y install cmake
yum -y install gcc gcc-c++
yum -y install python python-devel numpy
OpenCV 的依赖项
yum -y install gtk2-devel
yum -y install libdc1394-devel
yum -y install libv4l-devel
yum -y install gstreamer-plugins-base-devel
yum -y install gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devel libpng-devel libavc1394-devel libraw1394-devel jasper-devel jasper-utils swig libtool nasm
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