Clear Filters
Clear Filters

mexcuda() can't find Visual Studio 2022, but mex() can.

91 views (last 30 days)
In R2024a, I encounter the following when trying to compile with mexcuda in conjunction with Visual Studio 2022.
>> mexcuda -largeArrayDims vectorAdd.cu
Building with 'NVIDIA CUDA Compiler'.
Error using mex
vectorAdd.cu
C:\Program Files\MATLAB\R2024a\sys\cuda\win64\cuda\include\crt/host_config.h(164): fatal error C1189:
#error: -- unsupported Microsoft Visual Studio version! Only the versions between 2017 and 2022
(inclusive) are supported! The nvcc flag '-allow-unsupported-compiler' can be used to override this
version check; however, using an unsupported host compiler may cause compilation failure or incorrect run
time execution. Use at your own risk.
Error in mexcuda (line 185)
[varargout{1:nargout}] = mex(mexArguments{:});
mexcuda() seems to think Visual Studio 2022 is not installed, but mex() sees that it is,
>> mex -setup C++
MEX configured to use 'Microsoft Visual C++ 2022' for C++ language compilation.
I would welcome any and all troubleshooting advice.
If it matters, here are the details of my Cuda Toolkit installation,
>> !nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Thu_Sep_12_02:55:00_Pacific_Daylight_Time_2024
Cuda compilation tools, release 12.6, V12.6.77
Build cuda_12.6.r12.6/compiler.34841621_0

Accepted Answer

Avgoustinos Vouros
Avgoustinos Vouros on 10 Oct 2024 at 9:34
I believe the issue is incompatibility among the specific versions of Visual Studio 2022, CUDA, and MATLAB:
  • MATLAB R2024a comes with CUDA Toolkit 12.2 which is compatible with Visual Studio 2022 but specifically up to v17.9.x.
  • CUDA 12.4 was the version that started supporting Visual Studio 2022 (v17.10) onward.
  • Earlier CUDA versions do work with Visual Studio 2022 (v17.9.x) but not Visual Studio 2022 (v17.10) or later.
  • There is the way to downgrade Visual Studio 2022 to an earlier version to make it compatible with an earlier CUDA version but only the Professional edition of Visual Studio allows that. Alternatively, Visual Studio 2019 should work in your case.
You may want to use the -v flag in your mexcuda command which should list what MATLAB attempts to do in order to compile your code. I believe the log will indicate that the incompatibility is the use of CUDA Toolkit 12.2 with your specific Visual Studio 2022 version.
  4 Comments
Matt J
Matt J on 1 Nov 2024 at 16:07
Edited: Matt J on 1 Nov 2024 at 16:09
Thanks, Joss, though maybe it's worth mentioning, the data I found there says that CUDA 12.2 is compatible with VS2022 upt to v17.0, not up to v17.9.x as mentioned by @Avgoustinos Vouros.
Avgoustinos Vouros
Avgoustinos Vouros on 1 Nov 2024 at 18:04
Edited: Avgoustinos Vouros on 1 Nov 2024 at 18:05
This is where things get even trickier: when you download the toolkit and access the header files, you can see that the cutoff is actually v17.9.x rather than v17.0. It would have been quite constrained if it was exactly until 17.0, but this certainly adds more confusion.

Sign in to comment.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!