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 个评论
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with GPU Coder 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!