MATLAB Answers

mexcuda not finding CUDA 9.0 even when I specify it via setenv('MW​_NVCC_PATH​',...)

62 views (last 30 days)
When I try to use mexcuda I get the error:
Warning: Version 9.0 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)
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.
Error in mexcuda (line 157)
[varargout{1:nargout}] = mex(mexArguments{:});
This happens even if I call:
setenv('MW_NVCC_PATH','C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin')
prior to mexcuda just like the error suggests I do. So what is the problem here? Matlab obviously knowns where CUDA 9.0 is located…
If I do a verbose mexuda attempt this is what I get:
>> mexcuda -v mycudafcn.cu
Trying MEX options 'D:\Matlab 2018a\toolbox\distcomp\gpu\extern\src\mex\win64\nvcc_msvcpp2015.xml'...FAILED
Trying MEX options 'D:\Matlab 2018a\toolbox\distcomp\gpu\extern\src\mex\win64\nvcc_msvcpp2017.xml'...FAILED
Trying MEX options 'D:\Matlab 2018a\toolbox\distcomp\gpu\extern\src\mex\win64\nvcc_msvcpp2013.xml'...FAILED
Trying MEX options 'D:\Matlab 2018a\toolbox\distcomp\gpu\extern\src\mex\win64\nvcc_msvcpp2012.xml'...FAILED
Warning: No supported host compiler found, or other problem with the environment.
Continuing with selected compiler to provide detailed diagnosis.
> In mexcuda (line 130)
mex -largeArrayDims -f D:\Matlab 2018a\toolbox\distcomp\gpu\extern\src\mex\win64\nvcc_msvcpp2015.xml NVCC_FLAGS="" -v mycudafcn.cu
Verbose mode is on.
... Looking for compiler 'NVIDIA CUDA Compiler' ...
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...Yes ('D:\Visual Studio 2015\VC\').
... Looking for file 'D:\Visual Studio 2015\VC\bin\amd64\cl.exe' ...Yes.
... Looking for folder 'D:\Visual Studio 2015\VC' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1' InstallationFolder ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.1' InstallationFolder ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v8.1' InstallationFolder ...Yes ('C:\Program Files (x86)\Windows Kits\8.1\').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 14.0 ...Yes ('D:\Visual Studio 2015\').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...Yes ('D:\Visual Studio 2015\VC\').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VC7' 14.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VC7' 14.0 ...Yes ('D:\Visual Studio 2015\VC\').
... Looking for file 'D:\Visual Studio 2015\VC\vcvarsall.bat' ...Yes.
... Looking for folder 'D:\Visual Studio 2015\VC' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots' KitsRoot10 ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots' KitsRoot10 ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Executing command 'echo off&set "sdkversion="&(for /f %a IN ('dir "C:\Program Files (x86)\Windows Kits\10\include\" /b /ad-h /on') do ( @if exist "C:\Program Files (x86)\Windows Kits\10\include\%a\ucrt\" set "sdkversion=%a" ))&call echo %sdkversion%' ...Yes ('10.0.14393.0').
... Looking for environment variable 'MW_NVCC_PATH' ...No.
... Looking for environment variable 'CUDA_LIB_PATH' ...No.
... Looking for environment variable 'CUDA_PATH' ...Yes ('C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0').
... Looking for file 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64\cudart.lib' ...Yes.
... Looking for folder 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64' ...Yes.
... Looking for environment variable 'MW_NVCC_PATH' ...No.
... Looking for environment variable 'CUDA_BIN_PATH' ...No.
... Looking for environment variable 'CUDA_PATH' ...Yes ('C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0').
... Looking for file 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe' ...Yes.
... Executing command 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc --version | findstr /c:"release 9.0" > NUL && echo C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin' ...No.
... Looking for environment variable 'MW_NVCC_PATH' ...No.
... Looking for environment variable 'CUDA_BIN_PATH' ...No.
... Looking for environment variable 'CUDA_PATH' ...Yes ('C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0').
... Looking for file 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc.exe' ...Yes.
... Executing command '"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc" --version | findstr /c:"release 9.0" > NUL && echo C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin' ...No.
Did not find installed compiler 'NVIDIA CUDA Compiler'.
Warning: Version 9.0 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)
Error using mex
No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.
Error in mexcuda (line 157)
[varargout{1:nargout}] = mex(mexArguments{:});
Compiling with mexcuda worked fine about a week ago. Since then I must have updated a driver or something which has broken the frustratingly fragile connection Matlab has with visual studio and CUDA. So far I have tried:
  • Uninstalling and reinstalling CUDA 9.0 several times
  • Uninstalling and reinstalling Visual studio 2015 several times
  • Uninstalling and reinstalling Visual studio 2017
  • Uninstalling and reinstalling Matlab 2018a
Any ideas on what I can do to get mexcuda to work again? Can I manually enter the paths matlab is unable to find in some other way than with setenv?
Compiling C code with normal mex works fine, the only problem I have is with mexcuda. Im using Matlab2018a.

  7 Comments

Show 4 older comments
Petter Stefansson
Petter Stefansson on 20 Jul 2018
Im using 64-bit Windows 10 Educational (Version 1803 OS Build 17134.165).
When I type this:
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin\nvcc" --version | findstr /c:"release 9.0"
in cmd I get the error:
'findstr' is not recognized as an internal or external command, operable program or batch file.
So probably that is the problem, Matlab failed to do the version check because it couldn’t use findstr. I have no idea how that’s possible though, because like I said, mexcuda was working fine a week ago without modifying nvcc_msvcpp2015.xml.
I’m using a Swedish character set, and we have all the letters the English alphabet has so that’s usually not an issue.
Joss Knight
Joss Knight on 22 Jul 2018
This is unusual, and perhaps indicates that findstr has been removed from Windows in a recent update, which will affect everyone. Thanks for reporting this, and I will look into it further.
Note that instead of modifying your MATLAB installation, you can copy the options file, make your modifications, then have mexcuda use it using the -f option.
Joss Knight
Joss Knight on 23 Jul 2018
It has been suggested that you check your PATH environment variable, which may have become corrupted. It should contain "C:\WINDOWS\system32" to find findstr. You can check this in MATLAB as follows (ironically, using findstr):
>> findstr(getenv('PATH'), 'C:\WINDOWS\system32')
ans =
161 487

Sign in to comment.

Accepted Answer

Petter Stefansson
Petter Stefansson on 20 Jul 2018
I managed to solve the problem myself by editing the ‘nvcc_msvcpp2015.xml’ file and simply commenting out the line:
<cmdReturns name="$$\nvcc --version | findstr /c:"release 9.0" > NUL && echo $$" />
Which I guess indicates that there is a bug or flaw in the way that Matlab verifies the installed CUDA version. Pretty frustrating to spend hours uninstalling/reinstalling things when the solution is as simple as removing the Matlab version check...

  1 Comment

Joss Knight
Joss Knight on 20 Jul 2018
It is a nuisance. We have tests for this so I'm baffled why it doesn't work for you. I'll get someone to look into it. What version of Windows are you running?

Sign in to comment.

More Answers (1)

Tara Prasad Mishra
Tara Prasad Mishra on 28 Sep 2018
I am having the same problem. I am trying to compile some CUDA codes, but the NVCC compiler automatically changes to 8.0 version. Any suggestions?

  3 Comments

Tara Prasad Mishra
Tara Prasad Mishra on 28 Sep 2018
Thank you. I got the problem. The 'mex.m' file in the software was intrinsically checking for a CUDA toolkit 8.0. Changing that Path fixed it.
Joss Knight
Joss Knight on 30 Sep 2018
If it was doing that it was because you are encouraged to use the same version of the toolkit as the one MATLAB is using. If you don't have any particular reason to use a later toolkit, you should use the compatible version.

Sign in to comment.

Sign in to answer this question.