matlab crashed when calling MEX

19 views (last 30 days)
Shi
Shi on 7 Apr 2025
Commented: Chao Luo on 8 Apr 2025
I successfully converted my MATLAB source code to CUDA C code using GPU coder and generated a MEX file, but when I call the MEX file, matlab crashes and quits. The matlab_crash_dump in the TMEP folder shows the following. Can anyone tell me what went wrong or how to find this error?
--------------------------------------------------------------------------------
Access violation detected at 2025-04-05 16:19:22 +0800
--------------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : UTF-8
Deployed : false
Graphics Driver : Uninitialized hardware
Graphics card 1 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 2 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 3 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 4 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 5 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 6 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 7 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 8 : (标准显示卡类型) ( 0x19e5 ) Microsoft 基本显示适配器 Version 10.0.22621.1 (2006-6-21)
Graphics card 9 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Interpreter 0 : Executing request: 4D61746C6162526571756573742E637070
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 9811929
MATLAB Root : D:\Program Files\Matlab
MATLAB Version : 24.2.0.2863752 (R2024b) Update 5
OpenGL : hardware
Operating System : Microsoft Windows 11 专业版
Process ID : 15416
Processor ID : x86 Family 6 Model 85 Stepping 4, GenuineIntel
Session Key : 140956f8-750d-47f4-81ea-83acb9360395
Window System : Version 10.0 (Build 22631)
  6 Comments
Manikanta Aditya
Manikanta Aditya on 7 Apr 2025
@Shi, I can tell you to check the temporary files directory. On Windows, crash logs are typically stored in the temporary files directory. You can access this directory by entering %temp% in the Windows search bar or by navigating to C:\Users\<YourUsername>\AppData\Local\Temp
You can also use the following MATLAB command to open the temp directory:
cd(tempdir)
  • MATLAB generates crash dump files with names like matlab_crash_dump.XXXX, java.log.XXXX, and hs_error_pidXXXX.log1. These files contain valuable information for debugging.
Justin Hontz
Justin Hontz on 7 Apr 2025
@Shi Unfortunately, the crash log does not provide much information about what exactly went wrong. With that said, the following are some initial debugging steps that you can try:
  • See if you can reproduce the crash using MATLAB Coder without using GPU Coder.
  • Try simplifying / minimizing the entry point you are generating code for until the issue is no longer reproducible to help narrow down the source of the issue.

Sign in to comment.

Accepted Answer

Manikanta Aditya
Manikanta Aditya on 7 Apr 2025
Hi @Shi,
Try out some troubleshooting steps to see if you can fix the issue:
  • Ensure that the input arguments passed to the MEX file are correctly formatted and of the expected type. Mismatched data types can cause crashes.
  • Ensure that memory allocation and deallocation are handled correctly in your CUDA C code. Improper memory management can lead to access violations.
  • Verify that your GPU drivers are up to date and properly configured. The crash log indicates multiple NVIDIA Tesla V100 GPUs, so ensure they are correctly initialized and accessible.
MATLAB Code to call MEX file (Debug):
try
result = myMexFunction(inputData);
catch ME
disp('Error occurred while calling MEX file:');
disp(ME.message);
end
I hope this helps you.
  2 Comments
Shi
Shi on 7 Apr 2025
I have enabled logging via diary('debug_log.txt') and the crash log is as follows, but I'm still not sure what went wrong, can you help me?
MATLAB Log File: C:\Users\admin\AppData\Local\Temp\matlab_crash_dump.7396-1
------------------------------------------------
MATLAB Log File
------------------------------------------------
--------------------------------------------------------------------------------
Access violation detected at 2025-04-07 16:05:18 +0800
--------------------------------------------------------------------------------
Configuration:
Crash Decoding : Disabled - No sandbox or build area path
Crash Mode : continue (default)
Default Encoding : UTF-8
Deployed : false
Graphics Driver : Uninitialized hardware
Graphics card 1 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 2 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 3 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 4 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 5 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 6 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 7 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Graphics card 8 : (标准显示卡类型) ( 0x19e5 ) Microsoft 基本显示适配器 Version 10.0.22621.1 (2006-6-21)
Graphics card 9 : NVIDIA ( 0x10de ) NVIDIA Tesla V100-SXM2-32GB Version 31.0.15.3625 (2023-6-10)
Interpreter 0 : Executing request: 4D61746C6162526571756573742E637070
Java Version : Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Architecture : win64
MATLAB Entitlement ID : 9811929
MATLAB Root : D:\Program Files\Matlab
MATLAB Version : 24.2.0.2863752 (R2024b) Update 5
OpenGL : hardware
Operating System : Microsoft Windows 11 专业版
Process ID : 7396
Processor ID : x86 Family 6 Model 85 Stepping 4, GenuineIntel
Session Key : 4f43c3d6-1765-48a5-a52e-13009b0a2632
Window System : Version 10.0 (Build 22631)
Fault Count: 1
Abnormal termination:
Access violation
Current Thread: 'MCR 0 interpreter thread' id 4852
Register State (from fault):
RAX = 00000036e89dbe58 RBX = 00000036e89de800
RCX = 000000007fffffff RDX = 0000000000000004
RSP = 00000036e89dcbf0 RBP = 00000036e89dd2c0
RSI = 00000036e89decf0 RDI = 00000036e89dda70
R8 = 00000036e89dbfc0 R9 = 0070007300690064
R10 = 0073006900770065 R11 = 0073006900640065
R12 = 0000000000000000 R13 = 00000036e89dcd20
R14 = 0000000000000002 R15 = 00000036e89ddbd8
RIP = 00007ffba98efabc EFL = 00000202
CS = 0033 FS = 0053 GS = 002b
Stack Trace (from fault):
[ 0] 0x00007ffba98efabc C:\Windows\System32\KERNELBASE.dll+00391868 RaiseException+00000108
[ 1] 0x00007ffba6662610 D:\Program Files\Matlab\bin\win64\VCRUNTIME140_1.dll+00009744
[ 2] 0x00007ffbac194896 C:\Windows\SYSTEM32\ntdll.dll+00673942 RtlCaptureContext2+00001190
[ 3] 0x00007ffa64f8cfdd D:\SHY\CPU_GPU_Program\code0405\TABU_ALNS_mex.mexw64+00249821 mexFunction+00000109
[ 4] 0x00007ffb08506149 D:\Program Files\Matlab\bin\win64\libmex.dll+00680265 mexfile::Inspector::needs_upgrade+00023801
[ 5] 0x00007ffb08509152 D:\Program Files\Matlab\bin\win64\libmex.dll+00692562 MexRetrieveVersion+00009074
[ 6] 0x00007ffb085094b8 D:\Program Files\Matlab\bin\win64\libmex.dll+00693432 MexRetrieveVersion+00009944
[ 7] 0x00007ffb084eb6b8 D:\Program Files\Matlab\bin\win64\libmex.dll+00571064 mexUnlock+00018024
[ 8] 0x00007ffb08112a48 D:\Program Files\Matlab\bin\win64\m_dispatcher.dll+01190472 Mfh_file::dispatch_file_common+00000152
[ 9] 0x00007ffb08111909 D:\Program Files\Matlab\bin\win64\m_dispatcher.dll+01186057 Mfh_error::lookup+00012425
[ 10] 0x00007ffb0811299d D:\Program Files\Matlab\bin\win64\m_dispatcher.dll+01190301 Mfh_file::dispatch+00000045
[ 11] 0x00007ffb07a4753d D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00423229 coretypes::array::Array<MathWorks::String::detail::StringArrayVariant,MathWorks::String::detail::StringArrayPolicy,coretypes::array::ArrayTypeList<MathWorks::String::detail::StringArrayVariant> >::resize+00351613
[ 12] 0x00007ffb07a5639e D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00484254 coretypes::array::Array<MathWorks::String::detail::StringArrayVariant,MathWorks::String::detail::StringArrayPolicy,coretypes::array::ArrayTypeList<MathWorks::String::detail::StringArrayVariant> >::resize+00412638
[ 13] 0x00007ffb034f0fe6 D:\Program Files\Matlab\bin\win64\m_lxe.dll+06361062 MathWorks::lxe::ReadOnlyXvaluePtr::operator=+00006966
[ 14] 0x00007ffb034f2e2b D:\Program Files\Matlab\bin\win64\m_lxe.dll+06368811 MathWorks::lxe::ReadOnlyXvaluePtr::operator=+00014715
[ 15] 0x00007ffb0341e7e8 D:\Program Files\Matlab\bin\win64\m_lxe.dll+05498856 MathWorks::lxe::XvalueFactory::XvalueDeleter::XvalueDeleter+00225192
[ 16] 0x00007ffb0343dbc9 D:\Program Files\Matlab\bin\win64\m_lxe.dll+05626825 MathWorks::lxe::XvalueFactory::XvalueDeleter::XvalueDeleter+00353161
[ 17] 0x00007ffb031d5f76 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03104630 MathWorks::lxe::LXEConstants::IsIfElse+00547062
[ 18] 0x00007ffb031da162 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03121506 MathWorks::lxe::LXEConstants::IsY+00012018
[ 19] 0x00007ffb031d7983 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03111299 MathWorks::lxe::LXEConstants::IsY+00001811
[ 20] 0x00007ffb031db265 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03125861 MathWorks::lxe::LXEConstants::IsY+00016373
[ 21] 0x00007ffb031db513 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03126547 MathWorks::lxe::LXEConstants::IsY+00017059
[ 22] 0x00007ffb031dae7e D:\Program Files\Matlab\bin\win64\m_lxe.dll+03124862 MathWorks::lxe::LXEConstants::IsY+00015374
[ 23] 0x00007ffb031d70c6 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03109062 MathWorks::lxe::LxeTypes::GetTypeXvalueOf+00000262
[ 24] 0x00007ffb032d3e67 D:\Program Files\Matlab\bin\win64\m_lxe.dll+04144743 MathWorks::lxe::SetEngineImplUnlinkFlagForAllCallsOnStack+00049303
[ 25] 0x00007ffb032d79e5 D:\Program Files\Matlab\bin\win64\m_lxe.dll+04159973 MathWorks::lxe::SetEngineImplUnlinkFlagForAllCallsOnStack+00064533
[ 26] 0x00007ffb07b49816 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+01480726 FeatureTestObservableWorkspace+00212358
[ 27] 0x00007ffb07a3f783 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00391043 coretypes::array::Array<MathWorks::String::detail::StringArrayVariant,MathWorks::String::detail::StringArrayPolicy,coretypes::array::ArrayTypeList<MathWorks::String::detail::StringArrayVariant> >::resize+00319427
[ 28] 0x00007ffb07a3edd3 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00388563 coretypes::array::Array<MathWorks::String::detail::StringArrayVariant,MathWorks::String::detail::StringArrayPolicy,coretypes::array::ArrayTypeList<MathWorks::String::detail::StringArrayVariant> >::resize+00316947
[ 29] 0x00007ffb07a419e2 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00399842 coretypes::array::Array<MathWorks::String::detail::StringArrayVariant,MathWorks::String::detail::StringArrayPolicy,coretypes::array::ArrayTypeList<MathWorks::String::detail::StringArrayVariant> >::resize+00328226
[ 30] 0x00007ffb08112a48 D:\Program Files\Matlab\bin\win64\m_dispatcher.dll+01190472 Mfh_file::dispatch_file_common+00000152
[ 31] 0x00007ffb08111909 D:\Program Files\Matlab\bin\win64\m_dispatcher.dll+01186057 Mfh_error::lookup+00012425
[ 32] 0x00007ffb0811299d D:\Program Files\Matlab\bin\win64\m_dispatcher.dll+01190301 Mfh_file::dispatch+00000045
[ 33] 0x00007ffb07a4753d D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00423229 coretypes::array::Array<MathWorks::String::detail::StringArrayVariant,MathWorks::String::detail::StringArrayPolicy,coretypes::array::ArrayTypeList<MathWorks::String::detail::StringArrayVariant> >::resize+00351613
[ 34] 0x00007ffb07a5639e D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00484254 coretypes::array::Array<MathWorks::String::detail::StringArrayVariant,MathWorks::String::detail::StringArrayPolicy,coretypes::array::ArrayTypeList<MathWorks::String::detail::StringArrayVariant> >::resize+00412638
[ 35] 0x00007ffb034f0fe6 D:\Program Files\Matlab\bin\win64\m_lxe.dll+06361062 MathWorks::lxe::ReadOnlyXvaluePtr::operator=+00006966
[ 36] 0x00007ffb034f2675 D:\Program Files\Matlab\bin\win64\m_lxe.dll+06366837 MathWorks::lxe::ReadOnlyXvaluePtr::operator=+00012741
[ 37] 0x00007ffb0341e7e8 D:\Program Files\Matlab\bin\win64\m_lxe.dll+05498856 MathWorks::lxe::XvalueFactory::XvalueDeleter::XvalueDeleter+00225192
[ 38] 0x00007ffb0343d7b9 D:\Program Files\Matlab\bin\win64\m_lxe.dll+05625785 MathWorks::lxe::XvalueFactory::XvalueDeleter::XvalueDeleter+00352121
[ 39] 0x00007ffb031d5f76 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03104630 MathWorks::lxe::LXEConstants::IsIfElse+00547062
[ 40] 0x00007ffb031da162 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03121506 MathWorks::lxe::LXEConstants::IsY+00012018
[ 41] 0x00007ffb031d7983 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03111299 MathWorks::lxe::LXEConstants::IsY+00001811
[ 42] 0x00007ffb031db265 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03125861 MathWorks::lxe::LXEConstants::IsY+00016373
[ 43] 0x00007ffb031db513 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03126547 MathWorks::lxe::LXEConstants::IsY+00017059
[ 44] 0x00007ffb031dae7e D:\Program Files\Matlab\bin\win64\m_lxe.dll+03124862 MathWorks::lxe::LXEConstants::IsY+00015374
[ 45] 0x00007ffb031d70c6 D:\Program Files\Matlab\bin\win64\m_lxe.dll+03109062 MathWorks::lxe::LxeTypes::GetTypeXvalueOf+00000262
[ 46] 0x00007ffb032d3e67 D:\Program Files\Matlab\bin\win64\m_lxe.dll+04144743 MathWorks::lxe::SetEngineImplUnlinkFlagForAllCallsOnStack+00049303
[ 47] 0x00007ffb032d79e5 D:\Program Files\Matlab\bin\win64\m_lxe.dll+04159973 MathWorks::lxe::SetEngineImplUnlinkFlagForAllCallsOnStack+00064533
[ 48] 0x00007ffb07b49816 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+01480726 FeatureTestObservableWorkspace+00212358
[ 49] 0x00007ffb07a8b0f6 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00700662 mwboost::archive::detail::pointer_oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::PreLineExecutionEvent>::save_object_ptr+00074918
[ 50] 0x00007ffb07a8cbf4 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+00707572 mwboost::archive::detail::pointer_oserializer<mwboost::archive::xml_oarchive,MathWorks::lxe::PreLineExecutionEvent>::save_object_ptr+00081828
[ 51] 0x00007ffb07b0cb77 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+01231735 mwboost::archive::detail::oserializer<mwboost::archive::text_oarchive,MathWorks::MatlabComponents::ComponentIdentifier>::save_object_data+00327655
[ 52] 0x00007ffb07b0e977 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+01239415 mwboost::archive::detail::oserializer<mwboost::archive::text_oarchive,MathWorks::MatlabComponents::ComponentIdentifier>::save_object_data+00335335
[ 53] 0x00007ffb07b0dc60 D:\Program Files\Matlab\bin\win64\libmwlxemainservices.dll+01236064 mwboost::archive::detail::oserializer<mwboost::archive::text_oarchive,MathWorks::MatlabComponents::ComponentIdentifier>::save_object_data+00331984
[ 54] 0x00007ffb08b49ca9 D:\Program Files\Matlab\bin\win64\libmwbridge.dll+00302249 mnGetPrompt+00013993
[ 55] 0x00007ffb0878b676 D:\Program Files\Matlab\bin\win64\iqm.dll+00505462 iqm::Iqm::instance+00002358
[ 56] 0x00007ffb087e4ed2 D:\Program Files\Matlab\bin\win64\iqm.dll+00872146 iqm::UserEvalPlugin::execute+00001314
[ 57] 0x00007ffb087b229f D:\Program Files\Matlab\bin\win64\iqm.dll+00664223 iqm::Iqm::setupIqmFcnPtrs+00110911
[ 58] 0x00007ffb087be32d D:\Program Files\Matlab\bin\win64\iqm.dll+00713517 iqm::Iqm::setupIqmFcnPtrs+00160205
[ 59] 0x00007ffb0877ea0f D:\Program Files\Matlab\bin\win64\iqm.dll+00453135 iqm::Iqm::create+00010543
[ 60] 0x00007ffb08b19546 D:\Program Files\Matlab\bin\win64\libmwbridge.dll+00103750 ioReadLine+00000406
[ 61] 0x00007ffb08b19375 D:\Program Files\Matlab\bin\win64\libmwbridge.dll+00103285 ioReadLine+00000165
[ 62] 0x00007ffb08b4a070 D:\Program Files\Matlab\bin\win64\libmwbridge.dll+00303216 mnGetCommandLineBuffer+00000288
[ 63] 0x00007ffb08b4a517 D:\Program Files\Matlab\bin\win64\libmwbridge.dll+00304407 mnParser+00000487
[ 64] 0x00007ffb085fd19f D:\Program Files\Matlab\bin\win64\mcr.dll+00446879 mcr_initialize_main+00016975
[ 65] 0x00007ffb085a91de D:\Program Files\Matlab\bin\win64\mcr.dll+00102878 mcrFunctionSignature::set_signature+00080062
[ 66] 0x00007ffb085c63c2 D:\Program Files\Matlab\bin\win64\mcr.dll+00222146 mwboost::archive::codecvt_null<wchar_t>::`default constructor closure'+00017266
[ 67] 0x00007ffb087dfe2a D:\Program Files\Matlab\bin\win64\iqm.dll+00851498 iqm::PackagedTaskPlugin::execute+00000074
[ 68] 0x00007ffb087b229f D:\Program Files\Matlab\bin\win64\iqm.dll+00664223 iqm::Iqm::setupIqmFcnPtrs+00110911
[ 69] 0x00007ffb0877f32a D:\Program Files\Matlab\bin\win64\iqm.dll+00455466 iqm::Iqm::create+00012874
[ 70] 0x00007ffb0877f811 D:\Program Files\Matlab\bin\win64\iqm.dll+00456721 iqm::Iqm::create+00014129
[ 71] 0x00007ffb0877ec9d D:\Program Files\Matlab\bin\win64\iqm.dll+00453789 iqm::Iqm::create+00011197
[ 72] 0x00007ffb085e1b7c D:\Program Files\Matlab\bin\win64\mcr.dll+00334716 mcrInstantiationError::operator=+00010652
[ 73] 0x00007ffb085e263f D:\Program Files\Matlab\bin\win64\mcr.dll+00337471 mcrInstantiationError::operator=+00013407
[ 74] 0x00007ffb085dfc41 D:\Program Files\Matlab\bin\win64\mcr.dll+00326721 mcrInstantiationError::operator=+00002657
[ 75] 0x00007ffb9fc98fba D:\Program Files\Matlab\bin\win64\mwboost_thread-vc143-mt-x64-1_81.dll+00036794 mwboost::detail::win32::handle_manager::swap+00000650
[ 76] 0x00007ffba96a9333 C:\Windows\System32\ucrtbase.dll+00168755 recalloc+00000163
[ 77] 0x00007ffbaa88257d C:\Windows\System32\KERNEL32.DLL+00075133 BaseThreadInitThunk+00000029
[ 78] 0x00007ffbac14af28 C:\Windows\SYSTEM32\ntdll.dll+00372520 RtlUserThreadStart+00000040
This error was detected while a MEX-file was running. If the MEX-file is not an official MathWorks function, please examine its source code for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.
Chao Luo
Chao Luo on 8 Apr 2025
Hi Shi,
We cannot figure out the issue with this report. Can you reach out to customer support to provide the reprodcution with your MATLAB design? Once we have your files, we can investigate more.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with GPU Coder in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!