1. 安裝準備
- ? matlab2017a ,參考:《centos 安裝matlab2017a(無root權限)》
- ? GCC 4.8(支持c++11) ? ?? 鍵入:sudo yum install gcc gcc-c++ ? (建議sudo裝)
- ? 至少CUDA 7.5,(本人選擇cuda8.0)
- ? CuDNN v4 (與cuda8對應,選擇cudnn v5.0)
- ? LibJPEG ? ? ? ? 鍵入:sudo yum install ? libjpeg-turbo-devel (建議sudo裝)
注意:直接使用以上命令安裝Libjpeg可能會出現找不到"jpeglib.h"的錯誤,這時需要運行:
sudo yum -y install libjpeg*
這時可以檢查如下目錄,確認文件存在即可。
首先需要下載matconvenet,然后打開matlab進入到matconvnet-1.0-beta25/matlab
目錄下,即vl_compilenn的目錄下。
2. ?開始安裝
1). 先設置mex ,即:
mex -setup mex -setup C++
結果:>> mex -setup
MEX configured to use 'gcc' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLABvariables with more than 2^32-1 elements. You will be requiredto update your code to utilize the new API.You can find more information about this at:http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.To choose a different language, select one from the following:mex -setup C++ mex -setup FORTRAN
MEX configured to use 'g++' for C++ language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLABvariables with more than 2^32-1 elements. You will be requiredto update your code to utilize the new API.You can find more information about this at:http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
>>
2).設置gpu支持? ?為了增加gpu加速,你需要NVIDIA GPU,且運算能力在2.0以上
你也可以使用?
gpuDevice
在matlab中查找合適的cuda版本
顯然我的是cuda8.0.?
3).如果只裝了一個cuda,且匹配matlab的版本,此時可以運行如下命令編譯:
vl_compilenn('enableGpu', true)
但如果裝了好幾個cuda,此時需要指定cuda的位置,即:vl_compilenn('enableGpu', true, 'cudaRoot', '/Developer/NVIDIA/CUDA-8.0')
4).編譯cuDNN支持
- ?一般編譯:
> vl_compilenn
- 使用CUDA編譯:?
vl_compilenn('enableGpu', true)
- 使用cudnn編譯(路徑名需要根據實際情況設置):
vl_compilenn('enableGpu', true, ...'cudaMethod', 'nvcc', ...'cudaRoot', '/usr/local/cuda/', ...'enableCudnn', true, ...'cudnnRoot', '/usr/local/cuda')
注意:以上命令進入matlab中執行。需要先進入matlab目錄下,然后執行vl_compilenn。
3. 測試
進入到xtest目錄下,執行
vl_testnn
如果測試gpu支持的話,執行:
vl_testnn('gpu', true)
運行結束,會有一個總結,如果沒有錯誤實例,則表明安裝成功。?
如果要在matlab指定使用gpu的話,可以提前使用gpuDevice ,參考:https://cn.mathworks.com/help/distcomp/gpudevice.html
4. 參考文獻
- MatConvNet在Ubuntu14.04上的配置筆記
- jpeglib.h: No such file or directory - CentOS 7
- windows下編譯Matconvnet的方法(CPU和GPU)
- gpuDevice設置
- Matconvnet官網