two errors : "MEX compiler error" and "Index exceeds the number of array elements"

Hi all, I am using GPU coder and having problems.
This is my full script.
clear all
%% inputs
load mq % I attached it.
disp('Weights were loaded')
%% Answer
tic;
output_accu=Main2_4_fun(countMax,H1,H2,H3,H4,B1,B2,B3,B4,obsRad,obsCenterX,obsCenterY,minmax,freq_min );
toc;
I tried to make the function "Main2_4_fun" as a MEX file using GPU coder app.
function output_accu_cpu=Main2_4_fun(countMax,H1,H2,H3,H4,B1,B2,B3,B4,obsRad,obsCenterX,obsCenterY,minmax,freq_min )
output_accu = zeros(countMax,1);
minX= minmax(1); maxX= minmax(2); minY= minmax(3); maxY= minmax(4);
obsRad_norm = obsRad; % inputs for Main2_4_fun
obsCenterX_log = (obsCenterX - minX) / (maxX - minX);% inputs for Main2_4_fun
obsCenterY_log = (obsCenterY - minY) / (maxY - minY);% inputs for Main2_4_fun
for caseCount=0:countMax-1 %computing changing input freq_log.
freq_log = log(caseCount + freq_min);
X = transpose([obsRad_norm, obsCenterX_log, obsCenterY_log, freq_log]) ;
%% computing
output_accu(caseCount+1) = transpose(H4{caseCount+1})*max(0,transpose(H3{caseCount+1})*max(0,transpose(H2{caseCount+1})*max(0,transpose(H1{caseCount+1})*X+B1{caseCount+1})+B2{caseCount+1})+B3{caseCount+1})+B4{caseCount+1};
end
output_accu_cpu=output_accu;
end
and I got this error message in the run-time issue check step of MEX file build stage.
??? Unable to determine MEX compiler: use mex -setup to configure your system.
Compilation failed.
Index exceeds the number of array elements (196).
Use help codegen for more information on using this command.
Index exceeds the number of array elements (196).
My version is 2019a, windows 10.
Question 1:
I have installed MinGW-w64 C/C++ Compiler.
But why I got " Unable to determine MEX compiler: " error?
(I also installed Microsoft visual studio 2019, by this two pages. but errors are still not solved.
Quesiton 2:
I started using GPU coder after confirming that my code and function work well.
But why I have "exceeds the number of array elements" error?
I was doing this process even with the same workspace with code execution.

6 Comments

Did you install the NVIDIA toolkit and driver?
MinGW cannot be used for GPU Coder.
VS 2019 is not supported by GPU Coder, but VS 2017 is supported.
After you install VS 2017 you will probably need to use
mex -setup
and choose VS 2017.
The error about index exceeds dimension is probably caused by it not being able to find a compiler that it wants.
Thanks a lot. but still I have a problem.
Yes. I installed NVIDIA tookit and driver. I have no problem deep learning toolbox with my gpu.
I uninstalled VS 2019 and installed VS 2017.
(I refered this link to know what workload I shoud install.
and with
mex -setup
and chose VS 2017.
it removes the MEX comiler error.
But I still have a "Index exceeds the number of array elements" error.
This is the whole error message I got.
Compilation failed.
Index exceeds the number of array elements (196).
Use help codegen for more information on using this command.
Index exceeds the number of array elements (196).
Questions:
  • why the unnecessary brackets around the assignee in assignments like:
A = (B)
  • why are you using transpose instead of the lot more concise .'
To me, it makes it more difficult to understand your code, and hence find if there's indeed a problem with it.
Thank you very much. I made my code as simple and clear as possible, and I did it!
function output_accu_cpu=Main2_4_fun(countMax,H1,H2,H3,H4,B1,B2,B3,B4,obsRad,obsCenterX,obsCenterY,minmax,freq_min )
output_accu = zeros(countMax,1);
minX= minmax(1,1); maxX= minmax(1,2); minY= minmax(1,3); maxY= minmax(1,4);
obsRad_norm = obsRad; % inputs for Main2_4_fun
obsCenterX_log = (obsCenterX - minX) / (maxX - minX);% inputs for Main2_4_fun
obsCenterY_log = (obsCenterY - minY) / (maxY - minY);% inputs for Main2_4_fun
for caseCount=0:countMax-1 %computing changing input freq_log.
freq_log = log(caseCount + freq_min);
X = [obsRad_norm, obsCenterX_log, obsCenterY_log, freq_log]' ;
%% computing
output_accu(caseCount+1,1) = (H4{caseCount+1,1})'*max(0,(H3{caseCount+1,1})'*max(0,(H2{caseCount+1,1})'*max(0,(H1{caseCount+1,1})'*X+B1{caseCount+1,1})+B2{caseCount+1,1})+B3{caseCount+1,1})+B4{caseCount+1,1};
end
output_accu_cpu=output_accu;
end
Caution: the ' operator that you used is not the same as the transpose() call. The ' operator is ctranspose() . The short form of transpose() is the .' operator -- notice the period.
There's no need to build X as a row vector and then transpose it, build it directly as a column vector:
X = [obsRad_norm; obsCenterX_log; obsCenterY_log; freq_log];
As Walter said and as I wrote, the tranpose operator is the dotted apostrophe: .', not the plain '. If the numbers are pure real, it makes no difference though.
It's quite difficult to understand what's happening in the computing line as the expression is fairly complex. This also illustrates why it's a bad idea to have numbered variables. If you use indexing instead you can replace the lot by a simple loop.
function output_accu_cpu = Main2_4_fun(countMax, H, B , obs, minmax, freq_min)
%obs: three element vector consisting of obsRad, obscenterX, obsCenterY
%H and B: casecount x 4 cell arrays
%minmax is 4 element vector consisting of maxX, minX, maxY, minY
output_accu_cpu = zeros(countMax 1);
X_base = [obs(1);
(obs(2)-minmax(1)) / (minmax(2)-minmax(1));
(obs(3)-minmax(3)) / (minmax(4)-minmax(3));
];
for casecount = 1:countmax
X = [X_base; log(casecount - 1 + freq_min)];
for col = 1:4
X = max(H{casecount, col}.' * X + B{casecount, col}, 0); %set negative values to 0
end
output_accu_cpu(casecount) = X;
end
end
obviously, you have to change how you call it slightly:
H = [H1, H2, H3, H4];
B = [B1, B2, B3, B4];
obs = [obsRad, obsCenterX, obsCenterY];
output_accu = Main2_4_fun(countMax, H, B, obs, minmax, freq_min);
Now, none of this is going to help with your error. Unfortunately, I don't have the toolbox, so can't help with that. Mathworks even restrict access to the documentation, so I can't even look at that. The 196 is very puzzling, none of your data has that size and 196 is a multiple of 7 and none of your data has size that is a multiple of 7. I think you need to find out where that 196 comes from.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2019a

Asked:

on 24 Aug 2019

Commented:

on 24 Aug 2019

Community Treasure Hunt

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

Start Hunting!