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

9 次查看(过去 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