MATLAB crashes during MEX file generation with GPU Coder:Access violation detected

조회 수: 5 (최근 30일)
I attempted to generate CUDA code for the ALNS_insert function using GPU Coder. This function is invoked by TestScript and selects between two subfunctions based on the value of insert_operator:​
  • If insert_operator == 1, it calls MinCost_greedy_insert.
  • If insert_operator == 2, it calls MinCost_regretK_insert.​
function newS = ALNS_insert(PartialS, orders_removed, insert_operator, Order_inf, S_B, q_B, t_ib, B, C_UNIT) %#codegen
% ALNS_remove: Applies a specified insert operator to generate a new solution.
%
% Inputs:
% PartialS - Partial solution after removal.
% orders_removed - Orders that were removed.
% insert_operator - Integer indicating the insert operator to use:
% 1: MinCost_greedy_insert
% 2: MinCost_regretK_insert
%
% Outputs:
% newS - Updated solution with orders re-inserted.
if insert_operator==1
newS = MinCost_greedy_insert(PartialS, orders_removed, Order_inf, S_B, q_B, t_ib, B, C_UNIT);
% newS = MinCost_greedy_insert_mex(PartialS, orders_removed, Order_inf, S_B, q_B, t_ib, B, C_UNIT);
else
newS = MinCost_regretK_insert(PartialS, orders_removed, Order_inf, S_B, q_B, t_ib, B, 2, C_UNIT);
% newS = MinCost_regretK_insert_mex(PartialS, orders_removed, Order_inf, S_B, q_B, t_ib, B, 2, C_UNIT);
end
end
The code executes successfully on the CPU. However, during GPU testing, MATLAB crashes during the MEX file generation phase, reporting an "Access violation detected" error in the crash logs.
Interestingly, when I use GPU Coder to generate MEX files for the two subfunctions individually and invoke the mex files with the same input data, they run without any issue. The crash only occurs when generating a MEX file with ALNS_insert as the entry-point function.
I have attached the system crash logs and the relevant source code files for your reference. I would greatly appreciate any suggestions you might have to help resolve this problem.​
  댓글 수: 7
Shi
Shi 2025년 4월 28일
Thank you very much for your prompt and detailed reply. I would like to accept your answer to help others who encounter similar problems, but I found that this question is locked. How can I unlock it?
Gary Liu
Gary Liu 2025년 4월 28일
Glad to help. I wasn't aware of any locking on this post. I've now added my response as an official answer. Could you try accepting it again? If the issue persists, it might be a temporary glitch. Refreshing the page or trying a different browser could help. Let me know if you still encounter problems.

댓글을 달려면 로그인하십시오.

채택된 답변

Gary Liu
Gary Liu 2025년 4월 28일
The crash is due to a bug in GPU Coder. To work around it, apply coder.inline('never') to prevent GPU code generation for sum(sorted_costs). For more details, refer to the comment section.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with GPU Coder에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by