centos7+cuda+cudnn+caffe环境安装

本文目的是记录在 centos7 上面安装gpu+caffe编程环境

安装kernel header和相关开发包

rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

禁用默认nouveau驱动

/lib/modprobe.d/dist-blacklist.conf 将nvidiafb注释掉 2.再在该文件中添加一下配置:
blacklist nouveau
options nouveau modeset=0

mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak  
dracut /boot/initramfs-$(uname -r).img $(uname -r) 

重启系统
确认nouveau是否被禁用
没有输出则 ok!

[root@gemfield.org ~]# lsmod | grep nouveau
[root@gemfield.org ~]#

下载cuda_9.0.176_384.81_linux.run

https://developer.nvidia.com/cuda-toolkit-archive

运行 ./cuda_9.0.176_384.81_linux.run 完成安装

export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:/usr/local/cuda-9.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH
export CUDA_HOME=/usr/local/cuda-9.0/

下载cudnn-9.0-linux-x64-v7.4.1.5.solitairetheme8

https://developer.nvidia.com/rdp/cudnn-archive
在这里插入图片描述
解压 cudnn-9.0-linux-x64-v7.4.1.5.solitairetheme8
拷贝完成安装并且修改文件权限

sudo cp cuda/include/cudnn.h /usr/local/cuda-9.0/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h /usr/local/cuda-9.0/lib64/libcudnn*

下载NVIDIA驱动

https://www.nvidia.cn/Download/index.aspx?lang=cn
在这里插入图片描述
本次安装的一个疑惑,我这次安装是成功,我刚刚下载的NVIDIA驱动,没有主动去安装NVIDIA的驱动
我感觉是安装cuda_9.0.176_384.81_linux.run以后机器就成功安装驱动了。 否则就是我以前安装过NVDIA驱动。
这个需要在试一次。

nvidia-smi 检查是否安装成功
在这里插入图片描述

3 安装caffe编译的依赖

CentOS 安装 EPEL 第三方软件源

#sudo yum install epel-release

如果不安装第三方软件源,很多依赖包都不能通过yum安装
二、 caffe所要的各种依赖包

#sudo yum install leveldb-devel protobuf-devel snappy-devel opencv-devel boost-devel hdf5-devel atlas-devel

#sudo yum install gflags-devel glog-devel lmdb-devel

#sudo yum install openblas-devel

编译caffe 需要安装gcc, gcc-c++

#sudo yum install gcc

#sudo yum install gcc-c++

编译安装opencv3.4

unzip opencv-3.4.0 opencv

1 cd ~/opencv-3.4.0
2 mkdir build
3 cd build
配置:

1 sudo apt install cmake
2 sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local …
编译:

#sudo make -j8
#sudo make install

atlas有问题,MKL挺麻烦,换openblas

wget https://github.com/xianyi/OpenBLAS/archive/v0.2.20.tar.gz
tar -zxvf v0.2.20.tar.gz
cd OpenBLAS-0.2.20/
make
make PREFIX=/usr/local install

4 编译安装c/c++的caffe

下载
git clone https://github.com/BVLC/caffe.git

修改
USE_CUDNN := 1
BLAS := open

编译安装

5 编译安装python的caffe

#for req in $(cat requirements.txt); do sudo pip install $req;done
#sudo pip install -r requirements.txt
#export PYTHONPATH=/home/{user}/caffe/python:$PYTHONPATH
#LD_LIBRARY_PATH=/usr/lib:/usr/local/lib:/usr/lib64:$LD_LIBRARY_PATH
#python
>>Import caffe

6 安装tensorflow_gpu

pip install tensorflow-gpu

安装重点参考:
https://www.nzwang-lab.net/2018/07/18/Install-cuda9.0+tensorflow_gpu1.8+python2.7+-PIP-on-centos7/
https://zhuanlan.zhihu.com/p/27856581
https://blog.csdn.net/u012325865/article/details/73034018
http://whatbeg.com/2018/03/15/caffeinstall.html

学习caffe
http://blog.leanote.com/tag/fishing_piggy/Caffe
https://www.cnblogs.com/denny402/p/5075490.html

问题记录1:
Installing the NVIDIA display driver…
It appears that an X server is running. Please exit X before installation. If you’re sure that X is not running, but are getting this error, please delete any X lock files in /tmp.
解决:
sudo init 3
ps aux | grep X 搜索杀死X进程

问题记录2:
The driver installation is unable to locate the kernel source. Please make sure that the kernel source packages are installed and set up correctly.
If you know that the kernel source packages are installed and set up correctly, you may pass the location of the kernel source with the ‘–kernel-source-path’ flag.
解决
sudo yum install epel-release
yum install --enablerepo=epel dkms

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值