coder.checkGpuInstall: Basic Code Generation : FAILED (GPU code generation failed with an error

Hi,
I am trying to use the GPU coder to compile a MATLAB function of gpuArrays into a .mex file, but I keep getting the error "Basic Code Generation : FAILED (GPU code generation failed with an error" when i test the coder.checkGpuInstall. Here is my setup:
  • MATLAB R2024b - academic use;
  • Visual Studio 2022 17.8 (Enterprise) as C/C++ compiler;
  • CUDA toolkit 12.2
Some related test commands and results are as follows
gpuDevice
CUDADevice - :
Name: 'Tesla V100-SXM2-32GB'
Index: 1/8
ComputeCapability: '7.0'
DriverModel: 'TCC'
TotalMemory: 34218311680 (34.22 GB)
AvailableMemory: 33668726784 (33.67 GB)
DeviceAvailable: true
DeviceSelected: true
coder.checkGpuInstall
Compatible GPU : PASSED
CUDA Environment : PASSED
Runtime : PASSED
cuFFT : PASSED
cuSOLVER : PASSED
cuBLAS : PASSED
cuDNN Environment : PASSED
Host Compiler : PASSED
Basic Code Generation : FAILED (GPU code generation failed with an error. View report for further information: View report)
ans =
struct:
gpu: 1
cuda: 1
cudnn: 1
tensorrt: 0
hostcompiler: 1
basiccodegen: 0
basiccodeexec: 0
deepcodegen: 0
tensorrtdatatype: 0
deepcodeexec: 0
mex -setup
MEX is configured to use 'Microsoft Visual C++ 2022 (C)' for C compilation.
mex -setup C++
MEX is configured to use 'Microsoft Visual C++ 2022' for C++ language compilation.
when I click the View report, it seems a C++ compiler error happens when compiling the gpuSimpleTest fcn, I cannot figure out what is the issue (see below for the build log)
[1/10] cl /c /Zc:__cplusplus /Zp8 /GR /W3 /EHs /nologo /MD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /DMATLAB_MEX_FILE /O2 /Oy- /DNDEBUG /fp:strict /utf-8 /I "." /I "C:\Users\admin\AppData\Local\Temp\tp23b343d4_825a_4aa8_ad85_d5999890735a" /I "D:\Program Files\Matlab\toolbox\gpucoder\src\gpucoderrt\export\include\gpucoderrt" /I "D:\Program Files\Matlab\sys\cuda\win64\cuda\include" /I ".\interface" /I "D:\Program Files\Matlab\extern\include" /I "." -DMW_CUDA_ARCH=700 -DMW_GPU_MEMORY_DEBUG -DMW_GPU_MEMORY_MANAGER -DMODEL=gpuSimpleTest_mex -DMW_NEEDS_VERSION_H interface\_coder_gpuSimpleTest_info.cpp /Fobuild\win64\_coder_gpuSimpleTest_info.obj
FAILED: build/win64/_coder_gpuSimpleTest_info.obj
cl /c /Zc:__cplusplus /Zp8 /GR /W3 /EHs /nologo /MD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /DMATLAB_MEX_FILE /O2 /Oy- /DNDEBUG /fp:strict /utf-8 /I "." /I "C:\Users\admin\AppData\Local\Temp\tp23b343d4_825a_4aa8_ad85_d5999890735a" /I "D:\Program Files\Matlab\toolbox\gpucoder\src\gpucoderrt\export\include\gpucoderrt" /I "D:\Program Files\Matlab\sys\cuda\win64\cuda\include" /I ".\interface" /I "D:\Program Files\Matlab\extern\include" /I "." -DMW_CUDA_ARCH=700 -DMW_GPU_MEMORY_DEBUG -DMW_GPU_MEMORY_MANAGER -DMODEL=gpuSimpleTest_mex -DMW_NEEDS_VERSION_H interface\_coder_gpuSimpleTest_info.cpp /Fobuild\win64\_coder_gpuSimpleTest_info.obj
CreateProcess failed: The system cannot find the file specified.
Thanks for any suggestion!

3 件のコメント

It seems that MATLAB cannot find cl.exe of Visual Studio.
Can you try a simple GPU mex codegen and check how the visual studio is setup?
cfg = coder.gpuConfig('mex');
codegen -config cfg -args {1} foo
function output = foo(input)
output = input * 2;
end
You can find the setup file SetEnv.bat in codegen\mex\foo. On my side, the file contains such line;
set PATH=C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64\
Can you check if there is such folder, like C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.39.33519\bin\HostX64\x64\, and there is a cl.exe in the folder?
Justin Hontz
Justin Hontz 2025 年 4 月 4 日
Hi Shi,
Based on the diagnostic, it appears that the ninja build system is unable to locate the MSVC compiler. Do you run into the same issue if you try generating a MEX with MATLAB Coder (without using GPU Coder)?
It is possible that the issue may be caused by an out-of-date MEX configuration. One thing you can try is locate your preferences directory (by running prefdir in MATLAB) and find files mex_C++_win64.xml and mex_C_win64.xml within. Then delete these files, re-run the MEX setup commands, and try code generation again.
Shi
Shi 2025 年 4 月 5 日
The problem was solved! Thanks for all your answers!!!
By running the code provided by Chao Luo, I found that the path in SetEnv.bat pointed to the VS version I had uninstalled. However, the problem was not solved after I reset the environment variables and restarted MATLAB. Then I used the method provided by Justin Hontz, deleted the corresponding files and re-run the mex setup command, and then coder.checkGpuInstall passed! I guess that the C/C++ compiler path recognized by Matlab should be updated by regenerating the files mex_C++_win64.xml and mex_C_win64.xml.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with GPU Coder についてさらに検索

製品

リリース

R2024b

質問済み:

Shi
2025 年 4 月 4 日

コメント済み:

Shi
2025 年 4 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by