0.檢查配置 1. VMWare上運行的Ubuntu,並不能支持真實的GPU(除了特定版本的VMWare和特定的GPU,要求條件嚴格,所以我在VMWare上搭建好了Caffe環境後,又重新在Windows 7 64bit系統上安裝了Ubuntu 14.04 64bit系統,鏈接 "在此" ,以此來搭 ...
0.檢查配置
1. VMWare上運行的Ubuntu,並不能支持真實的GPU(除了特定版本的VMWare和特定的GPU,要求條件嚴格,所以我在VMWare上搭建好了Caffe環境後,又重新在Windows 7 64bit系統上安裝了Ubuntu 14.04 64bit系統,鏈接在此,以此來搭建Caffe GPU版本);
2. 確定GPU支持CUDA
輸入:
lspci | grep -i nvidia
顯示結果:
我的是GTX 650,然後到http://developer.nvidia.com/cuda-gpus去驗證,支持CUDA;
3. 確定Linux版本支持CUDA
輸入:
uname -m && cat /etc/*release
結果顯示:
4. 確定系統已經安裝了GCC
輸入:
gcc --version
結果顯示:
5. 確定系統已經安裝了正確的Kernel Headers和開發包
輸入:
uname -r
結果:4.2.0-36-generic,這個是必須安裝的kernel headers和開發包的版本;
安裝對應的kernels header和開發包,
sudo apt-get install linux-headers-$(uname -r)
1.安裝CUDA
下載CUDA,從https://developer.nvidia.com/cuda-downloads,下載對應版本的cuda安裝包,我下載的是deb(local)版,
安裝CUDA,運行如下命令,即可安裝CUDA;
sudo dpkg -i cuda-repo-ubuntu1404_7.5-18_amd64.deb
sudo apt-get update
sudo apt-get install cuda
安裝完成後,重啟一下;
2.安裝cuDNN
下載cuDNN,從https://developer.nvidia.com/rdp/cudnn-download,註冊,然後下載,
註意事項:
有可能由於最新cuDNN不穩定,導致後續caffe工程編譯失敗,報出如下錯誤,詳情參考第三個鏈接,這時可以回退一下,下載較新版本的cuDNN;
CXX src/caffe/test/test_im2col_layer.cpp
In file included from ./include/caffe/util/device_alternate.hpp:40:0,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from src/caffe/test/test_im2col_layer.cpp:5:
./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::createPoolingDesc(cudnnPoolingStruct**, caffe::PoolingParameter_PoolMethod, cudnnPoolingMode_t*, int, int, int, int, int, int)’:
./include/caffe/util/cudnn.hpp:127:41: error: too few arguments to function ‘cudnnStatus_t cudnnSetPooling2dDescriptor(cudnnPoolingDescriptor_t, cudnnPoolingMode_t, cudnnNanPropagation_t, int, int, int, int, int, int)’
pad_h, pad_w, stride_h, stride_w));
^
./include/caffe/util/cudnn.hpp:15:28: note: in definition of macro ‘CUDNN_CHECK’
cudnnStatus_t status = condition; \
^
In file included from ./include/caffe/util/cudnn.hpp:5:0,
from ./include/caffe/util/device_alternate.hpp:40,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from src/caffe/test/test_im2col_layer.cpp:5:
/usr/local/cuda/include/cudnn.h:799:27: note: declared here
cudnnStatus_t CUDNNWINAPI cudnnSetPooling2dDescriptor(
^
Makefile:572: recipe for target '.build_release/src/caffe/test/test_im2col_layer.o' failed
make: *** [.build_release/src/caffe/test/test_im2col_layer.o] Error 1
拷貝cuDNN庫文件到cuda目錄下,
tar -zxvf cudnn-7.0-linux-x64-v4.0-prod.tgz
cd cuda
sudo cp lib64/* /usr/local/cuda/lib64/
sudo cp include/cudnn.h /usr/local/cuda/include/
設置環境變數,在/etc/profile中添加CUDA環境變數,
sudo gedit /etc/profile
在打開的文件中加入如下兩句話
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
保存後,使環境變數立即生效,
source /etc/profile
進入/usr/local/cuda/samples,執行下麵的命令來build samples,
sudo make all -j4
全部編譯完成後,進入 samples/bin/x86_64/linux/release,運行deviceQuery,
./deviceQuery
如果出現顯卡信息,則驅動及顯卡安裝成功,結果如下:
3.編譯caffe
修改caffe/Makefile.config,
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1#去掉這個註釋
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1#加上這個註釋
然後輸入,
make clean#第一次編譯,不需要執行
make all
make test
make runtest
顯示結果:
cpu版本Caffe學習筆記1--Ubuntu 14.04 64bit caffe安裝的編測試行結果是共1058項,GPU版本的測試運行結果是2005項;
編譯pycaffe,
make pycaffe
make distribute
4.mnist數據測試
cd caffe
# 下載mnist數據
sh data/mnist/get_mnist.sh
sh examples/mnist/create_mnist.sh
./examples/mnist/train_lenet.sh
執行結果,
和CPU版本Caffe學習筆記1--Ubuntu 14.04 64bit caffe安裝的mnist數據測試相比,速度明顯提升;當時我運行腳本後,就開始看書,剛看完一頁,抬頭髮現已經運行完畢,第一次用GPU計算,雖然只是很渣的GTX 650,但依然對GPU的運算能力感到佩服;
5.深度學習開源庫環境搭建大禮包
昨晚群里一個哥們分享了一個github鏈接,涵蓋了主流深度學習開源庫的環境搭建,包括Nvidia驅動、CUDA、cuDNN、TensorFlow、Caffe、Theano、Keras、Torch,鏈接在此,他的配置是Ubuntu 14.04 64bit + Nvidia Titan X,還是適用於好多朋友的機器的,所以好東西還是要分享給大家;
6.參考鏈接
Ubuntu 14.04 + Caffe + Cuda 7.5 + Opencv 3.0安裝教程