概述
最近使用Matlab跑深度学习的项目,需要安装MatConvnet,在这个过程中遇到了一些问题,成功解决后特在此总结如下。
一、安装及编译流程
1. MatConvNet介绍: Installing - MatConvNet
2. 配置编译器
> mex -setup
3. 编译用于CPU的库
> cd <MatConvNet>
> addpath matlab
> vl_compilenn
4. 编译用于GPU的库
> vl_compilenn('enableGpu',true,'cudaRoot','C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0','cudaMethod' ,'nvcc','enableCudnn','true','cudnnRoot','C:Program FilesNVIDIA GPU Computing ToolkitCUDA')
上述4步执行完如无报错则说明安装编译成功。
下面介绍安装编译过程中遇到的问题及成功解决方法。
二、问题及解决方法(注意本文中所涉及的文件路径请根据自身实际情况就行修改)
1. 报错1
Warning: CL.EXE not found in PATH. Trying to guess out of mex setup.
> In vl_compilenn>check_clpath (line 650)
In vl_compilenn (line 426)
'cl.exe' is not recognized as an internal or external command,
operable program or batch file.
Error using vl_compilenn>check_clpath (line 656)
Unable to find cl.exe
Error in vl_compilenn (line 426)
cl_path = fileparts(check_clpath()); % check whether cl.exe in path
解决方法:把 C:Program Files (x86)Microsoft Visual Studio2017CommunityVCToolsMSVC14.16.27023binHostx64x64 下的cl.exe复制到 D:Matlabmatconvnet-1.0-beta25matconvnet-1.0-beta25 下。
2. 报错2
Error using vl_compilenn>nvcc_compile (line 615)
Command "C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0binnvcc" -c -o
"D:Matlabmatconvnet-1.0-beta25matconvnet-1.0-beta25matlabmex.buildbitsdata.obj"
"D:Matlabmatconvnet-1.0-beta25matconvnet-1.0-beta25matlabsrcbitsdata.cu" -DENABLE_GPU -DENABLE_DOUBLE
-DENABLE_CUDNN -I".localcudnninclude" -O -DNDEBUG -D_FORCE_INLINES --std=c++11
-I"D:Matlabexterninclude" -I"D:Matlabtoolboxdistcompgpuexterninclude"
-gencode=arch=compute_52,code="sm_52,compute_52" --compiler-options=/MD --compiler-bindir="C:Program
Files (x86)Microsoft Visual Studio2017CommunityVCbin" failed.
Error in vl_compilenn (line 487)
nvcc_compile(opts, srcs{i}, objfile, flags) ;
解决方法:在 C:Program Files (x86)Microsoft Visual Studio2017CommunityVC 下创建bin文件夹。
3. 报错3
c:program filesnvidia gpu computing toolkitcudav9.0includecrt/host_config.h(133): fatal error C1189: #error: -- unsupported Microsoft Visual Studio version! Only the versions 2012, 2013, 2015 and 2017 are supported!
nvcc warning : The -std=c++11 flag is not supported with the configured host compiler. Flag will be ignored.
data.cu
Error using vl_compilenn>nvcc_compile (line 615)
Command "C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0binnvcc" -c -o
"D:Matlabmatconvnet-1.0-beta25matconvnet-1.0-beta25matlabmex.buildbitsdata.obj"
"D:Matlabmatconvnet-1.0-beta25matconvnet-1.0-beta25matlabsrcbitsdata.cu" -DENABLE_GPU -DENABLE_DOUBLE
-DENABLE_CUDNN -I"C:Program FilesNVIDIA GPU Computing ToolkitCUDAinclude" -O -DNDEBUG -D_FORCE_INLINES
--std=c++11 -I"D:Matlabexterninclude" -I"D:Matlabtoolboxdistcompgpuexterninclude"
-gencode=arch=compute_52,code="sm_52,compute_52" --compiler-options=/MD --compiler-bindir="C:Program
Files (x86)Microsoft Visual Studio2017CommunityVCbin" failed.
Error in vl_compilenn (line 487)
nvcc_compile(opts, srcs{i}, objfile, flags) ;
错误原因:CUDA和VS版本不匹配。
解决方法:打开C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0includecrthost_config.h,把
#if _MSC_VER < 1600 || _MSC_VER > 1911
改为:
#if _MSC_VER < 1600 || _MSC_VER > 1920 // 只要版本号够高就行,随便挑个数字
即可解决。
4. 报错4
0x00007FF64188ADD0 (0x0000000000000000 0x000001E56C1C7F18 0x000066BA00000001 0x00000004000304ED)
0x00007FF641886F3D (0x0000009EBEFFE798 0x0000000000000000 0x0000000000000000 0x000001E56C1DCE20)
0x00007FF641888713 (0xnvcc warning : The -std=c++11 flag is not supported with the configured host compiler. Flag will be ignored.
data.cu
nvcc error : 'cicc' died with status 0xC0000005 (ACCESS_VIOLATION)
Error using vl_compilenn>nvcc_compile (line 615)
Command "C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0binnvcc" -c -o
"D:Matlabmatconvnet-1.0-beta25matconvnet-1.0-beta25matlabmex.buildbitsdata.obj"
"D:Matlabmatconvnet-1.0-beta25matconvnet-1.0-beta25matlabsrcbitsdata.cu" -DENABLE_GPU -DENABLE_DOUBLE
-DENABLE_CUDNN -I"C:Program FilesNVIDIA GPU Computing ToolkitCUDAinclude" -O -DNDEBUG -D_FORCE_INLINES
--std=c++11 -I"D:Matlabexterninclude" -I"D:Matlabtoolboxdistcompgpuexterninclude"
-gencode=arch=compute_52,code="sm_52,compute_52" --compiler-options=/MD --compiler-bindir="C:Program
Files (x86)Microsoft Visual Studio2017CommunityVCbin" failed.
Error in vl_compilenn (line 487)
nvcc_compile(opts, srcs{i}, objfile, flags) ;
错误原因:使用CUDA9.0可能会导致上述错误。
解决方法:当使用Visual Studio 2017 Community时,CUDA使用 10.0版本。即搭配为Compatible: Visual Studio 2017 | Cuda 10.0 | Matlab R2018a。重新编译即可解决。
> vl_compilenn('enableGpu', true, ...
'cudaRoot', 'C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.0', ...
'cudaMethod', 'nvcc', ...
'enableCudnn', true, ...
'cudnnRoot', 'C:Program FilesNVIDIA GPU Computing ToolkitCUDAv10.0');
5. 报错5
MatConvNet compiled with '-R2018a' and linked with '-R2017b'
解决方法:把 {MatConvNet路径}/matlab/vl_compilenn.m 第620行附近改成:
args = horzcat({'-outdir', mex_dir}, ...
flags.base, flags.mexlink, ...
'-R2018a',...//新增
{['LDFLAGS=$LDFLAGS ' strjoin(flags.mexlink_ldflags)]}, ...
{['LDOPTIMFLAGS=$LDOPTIMFLAGS ' strjoin(flags.mexlink_ldoptimflags)]}, ...
{['LINKLIBS=' strjoin(flags.mexlink_linklibs) ' $LINKLIBS']}, ...
objs) ;
同时把第359行附近改成:
flags.mexlink = {'-lmwblas'};
即可解决。
至此,使用Matlab编译安装MatConvnet的流程及在这个过程中遇到的问题和解决方法总结如上所示,请各位小伙伴认真对照修改,一定可以解决!如有问题请在评论区留言,我会及时回复!
最后
以上就是怡然电源为你收集整理的Matlab编译安装MatConvnet流程及问题解决的全部内容,希望文章能够帮你解决Matlab编译安装MatConvnet流程及问题解决所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复