1. 安装相关依赖项
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
2.安装CUDA
在终端下输入:
sudo gedit /etc/modprobe.d/blacklist.conf
输入密码后在最后一行加上 blacklist nouveau . 这里是将Ubuntu自带的显卡驱动加入黑名单。
在终端输入:
sudo update-initramfs -u
然后重启电脑~记住一定要重启电脑,不然后面的驱动会安装失败的。
这里要尤其注意,安装显卡驱动要先切换到文字界面,(按Ctrl+Alt+F1~F6).所以,启动电脑后,先进入字符界面。
下载cuda
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=runfilelocal
然后,输入命令:
sudo service lightdm stop
(2)下载完成后执行以下命令(我用的是cuda7.5):
1 sudo chmod 777 cuda_7.5.44_linux.run
2 sudo ./cuda_7.5.44_linux.run
按照提示安装,注意这里会提示是否安装nvidia驱动,记住需要选择是,因为我们之前没有安装驱动。
安装完成之后,注意需要修改bashrc文件
可以编译sample文件夹中的文件测试,运行cuda/samples/1_Utilities/deviceQuery/deviceQuery
安装成功的话会有相关的信息提示。
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GTX 1080"
CUDA Driver Version / Runtime Version 9.2 / 9.2
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 8112 MBytes (8505524224 bytes)
(20) Multiprocessors, (128) CUDA Cores/MP: 2560 CUDA Cores
GPU Max Clock rate: 1772 MHz (1.77 GHz)
Memory Clock rate: 5005 Mhz
Memory Bus Width: 256-bit
L2 Cache Size: 2097152 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 75 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.2, CUDA Runtime Version = 9.2, NumDevs = 1
Result = PASS
3 安装cudnn
登录官网:https://developer.nvidia.com/rdp/cudnn-download ,下载对应 cuda 版本且 linux 系统的 cudnn 压缩包,注意官网下载 cudnn 需要注册帐号并登录
tar -xzvf cudnn-6.5-linux-R1.tgz
cd cudnn-6.5-linux-R1
sudo cp lib* /usr/local/cuda/lib64/
sudo cp cudnn.h /usr/local/cuda/include/
cd /usr/local/cuda/lib64/
sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
sudo ln -s libcudnn.so.5.1.10 libcudnn.so.5 #生成软衔接(注意这里要和自己下载的cudnn版本对应,可以在/usr/local/cuda/lib64下查看自己libcudnn的版本)
sudo ln -s libcudnn.so.5 libcudnn.so #生成软链接
#需要和自己的版本号对应
sudo cp /usr/local/cuda-8.0/lib64/libcudart.so.8.0 /usr/local/lib/libcudart.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcublas.so.8.0 /usr/local/lib/libcublas.so.8.0 && sudo ldconfig
sudo cp /usr/local/cuda-8.0/lib64/libcurand.so.8.0 /usr/local/lib/libcurand.so.8.0
sudo cp /usr/local/cuda-8.0/lib64/libcudnn.so.5 /usr/local/lib/libcudnn.so.5
4 安装caffe
接下来就需要正式的安装caffe了。
首席爱呢clone下caffe的github目录来
git clone https://github.com/BVLC/caffe.git
然后修改makefile
cp Makefile.config.exemple Makefile.config
#修改makefile和makefile.config 减少出错
#修改Makefile.config
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
#修改Makefile文件
将:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
改为:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
#安装
make all -j12#为你的cpu数目
make test
make runtest
some question:
one: libcudart.so is not found
sloved: sudo ldconfig /usr/local/cuda/lib64
联系邮箱20737506@qq.com