MATLAB2018b默认支持的CUDA版本是CUDA9.1,所以我们直接编译NVCC会出现如下错误
>> vl_compilenn('enableGpu', true)
警告: Version 9.1 of the CUDA toolkit could not be found. If installed, set MW_NVCC_PATH environment variable to
location of nvcc compiler.
> In mexcuda (line 157)
In vl_compilenn>mexcuda_compile (line 603)
In vl_compilenn (line 489)
错误使用 mex
未找到支持的编译器。有关选项,请访问 https://www.mathworks.com/support/compilers。
出错 mexcuda (line 157)
[varargout{1:nargout}] = mex(mexArguments{:});
出错 vl_compilenn>mexcuda_compile (line 603)
mexcuda(args{:}) ;
出错 vl_compilenn (line 489)
mexcuda_compile(opts, srcs{i}, objfile, flags) ;
我们安装的CUDA版本为10.1,所以只需指定CUDA版本路径即可。
1、打开NVCC配置文件
sudo gedit /usr/local/MATLAB/R2018b/toolbox/distcomp/gpu/extern/src/mex/glnxa64/nvcc_g++.xml
将里面所有的9.1改为10.1,一共六处全部更改。
其实在/usr/local/MATLAB/R2018b/toolbox/distcomp/gpu/extern/src/mex/glnxa64/路径下有两个配置文件nvcc_g++.xml和nvcc_g++_dynamic.xml,保险起见,把两个配置文件都做同样更改。
2、再次编译还会报错
>> vl_compilenn('enableGpu', true)
使用 'nvcc' 编译。
错误使用 mex
nvcc fatal : '-DNDEBUG': expected a number
出错 mexcuda (line 157)
[varargout{1:nargout}] = mex(mexArguments{:});
出错 vl_compilenn>mexcuda_compile (line 603)
mexcuda(args{:}) ;
出错 vl_compilenn (line 489)
mexcuda_compile(opts, srcs{i}, objfile, flags) ;
以下三种解决方法,前两种只能用debug模式,推荐使用第三种。
解决方法1:
更改vl_compilenn第179行为“opts.debug = true;”
参考:https://www.cnblogs.com/samwoog/p/matconvnet_installation_problems.html
解决方法2:
运行时初始化为Debug模式
vl_compilenn('enableGpu',true,'Debug',true)
解决方法3:(最优解决方法)
Matlab2018b使用CUDA10.1错误nvcc fatal : ‘-DNDEBUG‘: expected a number_博博有个大大大的Dream-CSDN博客
3、再次编译可能还会出错
错误使用 mex
/usr/lib/gcc/x86_64-linux-gnu/7/include/avx512fintrin.h(11265): error: identifier "__builtin_ia32_scalefsd_round" is
undefined
/usr/lib/gcc/x86_64-linux-gnu/7/include/avx512fintrin.h(11274): error: identifier "__builtin_ia32_scalefss_round" is
undefined
这个错误可能是g++和gcc的版本过高导致的,将g++和gcc的版本降级即可解决
降级方法:Ubuntu 18.04 将gcc版本降级为5.5版本_阿耀的博客-CSDN博客
4、最后编译成功