Error using gpucoder.profile (line 41)

I have a problem running:
cfg = coder.gpuConfig('exe');
cfg.GpuConfig.MallocMode = 'discrete';
gpucoder.profile('tvd_sim2_MEX',ARGS{1},'CodegenConfig',cfg,...
'CodegenArguments','-d profilingdir','Threshold',0.001);
I get error:
Error using gpucoder.profile (line 41)
Incorrect class for expression 'x': expected 'double' but found 'coder.PrimitiveType'.
What to do?
I have NVIDIA GPU Computing Toolkit\CUDA\v10.2
Microsoft Visual C++ 2019 (C)
Matlab R2020b
CUDA 5.2 compute capability
Thanks!

6 Comments

This appears to be a limitation with gpucoder.profile in that it does not properly handle certain codegen input specification types created with e.g. coder.typeof. I will submit an enhancement request for this.
For your particular example, can you try manually converting the codegen inputs to the runtime inputs and then pass the runtime inputs to gpucoder.profile? For instance, coder.typeof(1) should be converted to 1.
I think I have not understood well the use of coder.typeof. Among other things, the manual says not to use it to compile mex files. Anyway I tried :
ARGS {1} {1} = coder.typeof (1, [sz1 sz2]);
&
ARGS {1} {1} = coder.typeof (1, [sz1 sz2], 'Gpu', true);
&
ARGS {1} {1} = coder.typeof (0, [sz1 sz2], 'Gpu', true);
I forgot 'Gpu', true !!!
The first gives me the same error:
Error using gpucoder.profile (line 41)
Incorrect class for expression 'a': expected 'double' but found 'coder.PrimitiveType'.
The 2° & 3° give me:
Error using gpucoder.profile (line 41)
The input must contain numeric or logical data.
This is my original working code for codegen:
[mex1,mex2]=size(x);
ARGS = cell(1,1);
ARGS{1} = cell(5,1);
ARGS{1}{1} = coder.typeof(0,[mex1 mex1]);
ARGS{1}{2} = coder.typeof(0,[mex1 1]);
ARGS{1}{3} = coder.typeof(0,[mex1 1]);
ARGS{1}{4} = coder.typeof(0);
ARGS{1}{5} = coder.typeof(0,[mex1 1]);
cfg = coder.gpuConfig('mex');
cfg.GpuConfig.CompilerFlags = '--fmad=false';
cfg.GenerateReport = true;
cfg.GpuConfig.ComputeCapability='5.2';
cfg.MATLABSourceComments=true;
codegen -config cfg myH_MEX -args ARGS{1}
There's a problem with ARGS{1}{4} when using 'Gpu',true because it's scalar but I verified it on a different example.
And this is the proflier code which gives me the error:
cfg = coder.gpuConfig('exe');
cfg.GpuConfig.MallocMode = 'discrete';
gpucoder.profile('myH_MEX',ARGS{1},'CodegenConfig',cfg,...
'CodegenArguments','-d profilingdir','Threshold',0.001);
Thanks!
In your example, can you try changing
ARGS{1}{1} = coder.typeof(0,[mex1 mex1]);
to something like
ARGS{1}{1} = zeros(mex1, mex1);
and do something similar for the other inputs? If you want the input to be passed on GPU, you can instead do
ARGS{1}{1} = zeros(mex1, mex1, 'gpuArray');
but for SIL execution, I'm not sure there is much reason to want to use GPU inputs.
SOLVED.
it works for both cases (with and without gpuarray).
Is this profiling equivalent to my code in codegen or are there differences?
Why was it returning an error?
What is the difference if I use "'Gpu', true" in coder.typeof?
THANKS!
The code generated for profiling is roughly the same as the code generated from usual SIL codegen, though with some additional profiling API calls inserted in some places to enable the profiling to work as expected.
The error was occurring because the profiler was trying to pass the codegen input specification value (e.g. produced by coder.typeof) to the SIL executable, which is not valid as a runtime input.
The 'Gpu' option of coder.typeof simply controls whether the input of the generated entry-point function will be passed on GPU or not. This can improve performance by eliminating cudaMemcpy calls each time the entry-point function is executed in the case the input comes from GPU (e.g. a GPU array input for MEX).
Thanks for all! I finished.

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with GPU Coder in Help Center and File Exchange

Products

Release

R2020b

Asked:

on 2 Nov 2022

Commented:

on 8 Nov 2022

Community Treasure Hunt

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

Start Hunting!