How to add an NVCC flag

42 次查看(过去 30 天)
Aidan Fishenden
Aidan Fishenden 2024-7-9
编辑: .json 2025-8-17,10:49
I am attempting to compile a program using CUDA, and am getting the following error in response
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.
I looked and it seems the problem is caused by a small glitch in a recent update of visual studio that shouldnt have any effect on the compiler. How do I add the flag to override the version check? My current code is as follows
mex -setup:'C:\Program Files\MATLAB\R2024a\bin\win64\mexopts\msvcpp2022.xml' C++
mexGPUall
  1 个评论
Matt J
Matt J 2024-10-9
I looked and it seems the problem is caused by a small glitch in a recent update of visual studio that shouldnt have any effect on the compiler.
I am having the same difficulty. How did you verify this?

请先登录,再进行评论。

采纳的回答

Xiao Haonan
Xiao Haonan 2024-7-13
Hi Aiden,
I encountered the same problem, and solved it by setting environmental variable "NVCC_APPEND_FLAGS".
To do this, you can try:
setenv("NVCC_APPEND_FLAGS", '-allow-unsupported-compiler')
mexcuda -v mexGPUExample.cu
Hope it helps!
  2 个评论
Aidan Fishenden
Aidan Fishenden 2024-7-15
This worked perfectly, thank you!
Matt J
Matt J 2024-10-11
Didn't work for me, unfortunately.

请先登录,再进行评论。

更多回答(3 个)

Akash
Akash 2024-7-10
Hi Aidan,
To address the issue, you can ensure that the compiler and its version are supported with the product. You can find the list of supported and compatible compilers at the following link:-
The tables on this page outline the compilers that are supported by various MathWorks products.
For configuring parameters for CUDA code generation, you can use "coder.gpuConfig". This allows setting additional flags for the GPU compiler, including the NVCC flag. You can find more information on how to set these properties in the below provided MATLAB documentation link:-
  1 个评论
Aidan Fishenden
Aidan Fishenden 2024-7-10
编辑:Walter Roberson 2024-7-10
Would it be possible for you to show example code? I've gone through the page you reccomended but am still getting the same error despite the changes. It still does not recognize the flag.
mex -setup:'C:\Program Files\MATLAB\R2024a\bin\win64\mexopts\msvcpp2022.xml' C++
cfg = coder.gpuConfig( "mex" );
cfg.TargetLang = "C++";
cfg.GpuConfig.CompilerFlags = "--allow-unsupported-compiler";
cfg.GpuConfig.SelectCudaDevice = 0;
mexGPUall

请先登录,再进行评论。


Matt J
Matt J 2024-10-11
编辑:Matt J 2024-10-11

.json
.json 2025-8-17,7:23
编辑:.json 2025-8-17,10:49
I had a similar problem using gpucoder on linux (ubuntu 24.04 is currently on gcc 13.2, matlab 2025a ships with cuda 12.2 which only supports gcc 12.2). The error message was:
#error -- unsupported GNU version! gcc versions later than 12 are not 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.
The "--allow-unsupported-compiler" flag didn't work for me (maybe the gcc version delta was too wide). I installed gcc-12 using anaconda:
conda create --name gcc-12 gcc=12.2 gxx=12.2
conda activate gcc-12
Then pointed matlab to the correct compiler with:
cfg = coder.gpuConfig('mex');
cfg.GpuConfig.CompilerFlags = '--compiler-bindir ${HOME}/miniforge3/envs/gcc-12/bin';
where ${HOME} is my home folder. codegen worked fine from there.

类别

Help CenterFile Exchange 中查找有关 Get Started with GPU Coder 的更多信息

标签

产品


版本

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by