Matlab使用coder.checkGpuInstall时报错‘emlc:compilationError‘

一、问题描述

环境:
CUDA11.5
cuDNN8.3 for CUDA 11.5
MATLABR2021b
MATLAB已安装 “GPU Coder Interface for Deep Learning Libraries support package”, “MATLAB Support for MinGW-w64 C/C++ Compiler”
未安装Microsoft Visual Studio
运行如下代码检查环境:

envCfg = coder.gpuEnvConfig('host');
envCfg.DeepLibTarget = 'cudnn';
envCfg.DeepCodegen = 1;
envCfg.Quiet = 1;
coder.checkGpuInstall(envCfg);

显示错误:

Error using coder.checkGpuInstall (line 32)
One or more of the system checks did not pass, with the following errors ...
Basic Code Generation: (Test GPU code generation failed with the error 'emlc:compilationError'. View report for further information: View report)

点击View report,显示 :

Build error: C++ compiler produced errors. See the Build Log for further details.

因此继续用*coder.checkGpuInstall();*详细检查各环境,显示:

Compatible GPU           : PASSED 
CUDA Environment         : PASSED 
	Runtime   : PASSED 
	cuFFT     : PASSED 
	cuSOLVER  : PASSED 
	cuBLAS    : PASSED 
cuDNN Environment        : PASSED 
Basic Code Generation    : FAILED (Test GPU code generation failed with the error 'emlc:compilationError'. View report for further information: View report)

二、问题解决

回想起之前安装CUDA时,按照教程取消勾选Visual Studio Integration,防止与已安装的Visual Studio冲突。但是那时我并没有安装Visual Studio,因此推测是由于未安装Visual Studio导致的。
因此,首先安装Visual Studio 2019后重启(Visual Studio 2015及以上版本,包含C++),再次运行coder.checkGpuInstall,显示:

Compatible GPU           : PASSED 
CUDA Environment         : PASSED 
	Runtime   : PASSED 
	cuFFT     : PASSED 
	cuSOLVER  : PASSED 
	cuBLAS    : PASSED 
cuDNN Environment        : PASSED 
Basic Code Generation    : PASSED 
Basic Code Execution     : PASSED 

再次运行开头的代码段:

envCfg = coder.gpuEnvConfig('host');
envCfg.DeepLibTarget = 'cudnn';
envCfg.DeepCodegen = 1;
envCfg.Quiet = 1;
coder.checkGpuInstall(envCfg);

正常运行未报错。
问题解决。

解决方法参照此连接

你可能感兴趣的:(matlab)