Unnecessary copies in code when using nested non-virtual buses with atomic subsystems

22 vues (au cours des 30 derniers jours)
Ali
Ali le 22 Sep 2025
Commenté : Ali le 29 Sep 2025
I'm using Matlab/Simulink r2017B with Embedded Coder, to generate C code of my model. In my model, I have nested atomic subsystems, packaged as 'Reusable Function', which emits nonvirtual bus signals. Going deep to surface, those nonvirtual bus signals at the same level, combined into another nonvirtual bus signal.
The problem is, when I look to the generated code, in each subsystem function that have nonvirtual bus output with nested buses, there are unnecessary copies occured. For example:
void subsys_inner(uint32 rtu_in1, uint32 rtu_in2, Out_Bus* rty_out, /* some other args like block struct and DWorks */)
{
uint32 rtb_outsig1;
uint32 rtb_outsig2;
rtb_outsig1 = rtu_in1 + 1;
rtb_outsig2 = rtu_in2 + 1;
/* It uses local signal copies and assigns to output instead of using rty_out
inside code directly
*/
rty_out->outsig1 = rtb_outsig1;
rty_out->outsig2 = rtb_outsig2;
}
void subsys_outer(Outer_Bus* rty_out, /* some other args like block struct and DWorks */)
{
/* It creates a local copy of the nested bus */
Out_Bus rtb_Out_Bus_signal;
subsys_inner(1, 2, &rtb_Out_Bus_signal ...);
/* Again it made a deep copy instead of using rty_out->outbus directly in the above call */
rty_out->outbus = rtb_Out_Bus_signal;
}
That code is something I've made up right now to express the thing briefly, not a direct output of Embedded Coder.
I tried a lot of configuration options in Model Configuration pane but could not succeed to eliminate those copies. Is there any way to eliminate those copies?
Thanks in advance.

Réponses (1)

Mark McBroom
Mark McBroom le 29 Sep 2025
Each release of Embedded Coder incluces improved optimization, and removing data copies is one of the most common improvements. Do you have access to a newer MATLAB release?
Thanks.
Mark.
  1 commentaire
Ali
Ali le 29 Sep 2025

Unfortunately I don’t have.

Due to my observations, ExpressionFolding optimization eliminates the deep copies on local scope, so it solves the deep copy problem presented in “subsys_inner” function, but it does not help when crossing atomic boundary.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by