Matlab coder automatically inlines m file returning multiple values

조회 수: 8 (최근 30일)
I have a coder project with 2 .m files. The main .m file calls another .m file that returns multiple values. When I generate c files for the project, it automatically inlines the c code for the 2nd .m file in the c file for the main .m file (i.e. the c file generated for the 2nd .m is not used at all). I understand c functions can't return multiple values, but should the coder at least issue a warning and provide suggestions how to change the m code if I want to maintain the design hierarchy?

채택된 답변

Mike Hosea
Mike Hosea 2011년 8월 22일
Although I'm not an expert in the inlining heuristics of the compiler, I'm not aware that inlining has anything to do with the number of outputs. I should think at most it would imply a slight bias. Normally functions get inlined if they are short. You have both general and specific tools for controlling this. The general tool is
>> cfg = coder.config('lib');
>> cfg.InlineThreshold = 0;
>> codegen foo -args {blah1,blah2} -config cfg -report
This is a kind of "nuclear option". You can use a slightly larger InlineThreshold if you do want trivial functions inlined.
The specific method (and what I recommend) is
coder.inline('always')
coder.inline('never')
If you want the compiler to inline things automatically within toolbox functions but not to inline functions that you write, then you can just put coder.inline('never') at the top of each of your functions. -- Mike
  댓글 수: 4
Jim
Jim 2011년 8월 23일
Thanks!
I took a closer look at the coder output. coder.inline('never') did prevent the inline from happening and also successfully convert multiple outputs in Matlab to pass-by-reference inputs for the generated c function. However, it also optimized out two inputs in the original m function that I feed with constants in my testbench. These two inputs are supposed to be mapped to FPGA pins. So here come more questions:
* Would it be possible to write a m function with pass-by-reference inputs so it only returns 1 output? This way the coder wouldn't need to inline the sub c code by default?
* If the answer to the above is no, how can I prevent the coder from optimizing inputs connected to constants when converting m file returning multiple values to c code?
Mike Hosea
Mike Hosea 2011년 8월 26일
The compiler will generate such a function if there is one output and the inputs are, say, arrays, but I don't think you can coax it into generating that for a MATLAB function with multiple outputs.
Constant inputs to a function are normally specialized out by the compiler. I suppose the way around that is not to make them constants as far as the compiler knows. One trick is to have a formal input X to your testbench that you involve in the definition of these parameters. When I don't want the compiler to know something is a constant, I might add X to whatever constant value I wanted to give it. I then invoke the function with X = 0.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Execution Speed에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by