matlabmatlab-coder

codegen : how to get rid of memset and memcpy in generated code in matlab?


I am trying to generate a static c lib from a matlab function.The generated code includes memset and memcpy function calls which I do not want because I want to use this code in vivado HLS for an FPGA project and these two operations are not permitted.

I have tried the following 1) Unchecking "Enable variable sizing" from the Matlab coder app. 2) Used the following command line script

cfg = coder.config('lib');
cfg.GenCodeOnly = true;
cfg.EnableVariableSizing = false;
cfg.EnableMemcpy = false;
cfg.SupportNonFinite = false;
cfg.InitFltsAndDblsToZero = false;
cfg.FilePartitionMethod = 'SingleFile';
cfg.DynamicMemoryAllocation = 'off';
codegen -config cfg harris -args { zeros(640,480,'uint8'),zeros(1,1,'int32')} 

The line cfg.InitFltsAndDblsToZero = false; is supposed to eliminate memset calls for initializing arrays,but in my generated code I still see memset function calls.

So, both methods do not work for me.

Please, tell me if it requires more changes in configuration and if this is possible through the matlab coder gui?

P.S. I have used this link to set codegen configuration object properties http://www.mathworks.com/help/coder/ref/coder.embeddedcodeconfig-class.html


Solution

  • To do this try setting the 'MemcpyThreshold' value to 'inf' in your configuration. By doing this all memcpy/memset convertible assignments will be below the threshold and not converted. Note 'MemcpyThreshold' affects both Memcpy and Memset optimization.

    http://www.mathworks.com/help/coder/ug/memcpy-optimization.html http://www.mathworks.com/help/coder/ug/memset-optimization.html

    The setting 'InitFltsAndDblsToZero' only affects memset calls when the source value is double 0.0. I am guessing in your case you have memset where the source value is an integer.