Check for Run-Time Issues failed on GPU but successed on CPU(cudaEr​rorIllegal​Instructio​n)

7 views (last 30 days)
When I use GPU coder to convert MATLAB source code, I get an error when I choose GPU to run the MEX file in Check for Run-Time Issues, but it runs successfully if I choose to test on the CPU. The error log is as follows.
Error using TABU_ALNS (line 5655)
Error generated while running CUDA-enabled program: [715,cudaErrorIllegalInstruction] an illegal instruction was encountered
Error in MainScript (line 89)
 [BestSolution_M1, Best_obj] = TABU_ALNS(Order_inf,SN_nu,SN_rand,SBR_REL,R_qi_range,q_B,c_B,C_UNIT,t_ib,Tabu_PARA,ALNS_PARA);
It seems that there is a problem of using illegal instructions, but I don't know how to further locate the error, or what causes the file to run on the CPU but not on the GPU?
All suggestions are appreciated
  5 Comments
Shi
Shi on 11 Apr 2025
Hi Luo,
Many Thanks! The following is my entry-point function and the structure of its input parameters. This function also calls other functions designed by myself, such as Tabu_LocalSearch, ALNS_for_M2, etc. However, since they all run normally in MATLAB and the MEX file generated by MATLAB coder, I think it should be able to find the issues by only looking at the entry-point function.
Hope to get your reply!
function [BestSolution_M1,Best_obj] = TABU_ALNS(Order_inf,SN_nu,SN_rand,SBR_REL,R_qi_range,q_B,C_UNIT,t_ib,Tabu_PARA,ALNS_PARA) %#codegen
coder.gpu.kernelfun
coder.cstructname(Tabu_PARA, 'Tabu_PARA_struct');
coder.cstructname(ALNS_PARA, 'ALNS_PARA_struct');
coder.cstructname(SBR_REL, 'SBR_REL_struct');
coder.cstructname(C_UNIT, 'C_UNIT_struct');
tabuLoop = Tabu_PARA.tabuLoop;
tabuTenure = Tabu_PARA.tabuTenure;
tabuNeighbors= Tabu_PARA.tabuNeighbors;
so=Order_inf(:,1);
qo=Order_inf(:,2);
to=Order_inf(:,3);
S_B=SBR_REL.S_B;
B_R=SBR_REL.B_R;
S_R=SBR_REL.S_R;
c_B=C_UNIT.c_B;
B=single(length(q_B));
%% Tabu Search loop to optimize Solution_M1
% Initialize the M1 solution, BUS schedules' availability
InitialSolution_M1 = M1InitialSolutionGeneration(B_R, R_qi_range, q_B, c_B);
BestSolution_M1 =InitialSolution_M1;
Best_obj = single(Inf); % Initialize the best objective value
tabuMoves = single(zeros(3,tabuTenure)); % Initialize the tabuMove list as a matrix
tabuIndex = single(1); % Index to manage the circular tabu list
% Main Tabu Search loop
for iter = 1:tabuLoop
disp(['Iteration: ', sprintf('%f', iter)]);
% Generate neighborhood solutions
[numNeighbors,neighborhoodSolutions,candidateMoves] = Tabu_LocalSearch(BestSolution_M1, B_R, S_R, q_B, R_qi_range, tabuNeighbors, tabuMoves);
% Evaluate neighborhood solutions in parallel
for i = 1:numNeighbors
candidateSolution_M1 = neighborhoodSolutions(:,i);
% Calculate the fixed operating cost
M1_obj = sum(candidateSolution_M1 .* c_B);
% Calculate the second-stage cost using ALNS
M2_obj = single(0);
q_B_adjusted = q_B .* candidateSolution_M1;
currentso = so;
currentqo = qo;
currentto = to;
so_SN=currentso(SN_rand);
qo_SN=currentqo(SN_rand);
to_SN=currentto(SN_rand);
for sn = 1:SN_nu
Order_inf_SN = [qo_SN(:, sn), so_SN(:, sn), to_SN(:, sn)];
IniS_M2 = M2InitialSolutionGeneration(Order_inf_SN, SBR_REL, q_B_adjusted, t_ib);
BestS_Found_M2 = ALNS_for_M2(IniS_M2,Order_inf_SN, SBR_REL, q_B_adjusted, C_UNIT, t_ib);
BestS_M2_obj = GetM2_obj(BestS_Found_M2,Order_inf_SN,B);
M2_obj = M2_obj + BestS_M2_obj/ SN_nu;
end
% Calculate the total objective value of neighborhood solution
neighborObj = M1_obj + M2_obj;
% Update the best solution if the neighbor is better
if neighborObj < Best_obj
BestSolution_M1 = neighborhoodSolutions(:,i);
Best_obj = neighborObj;
% Add the best neighbor to the tabu list
BestMove = candidateMoves(:,i);
if any(BestMove)
tabuMoves(:,tabuIndex) = BestMove;
tabuIndex = mod(tabuIndex, tabuTenure) + 1;
end % Circular index for tabu list
end
end
end
end
Chao Luo
Chao Luo on 11 Apr 2025
Hi Shi,
We cannot identify the issue with only the entry-point function. Can you call customer support to create a case with all the code and reproduction steps? You can ask the customer support to escalate to dev team directly.

Sign in to comment.

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!