Simulink generated code optimization - CPU Load

21 Ansichten (letzte 30 Tage)
Oldrich
Oldrich am 1 Aug. 2024
Kommentiert: Oldrich am 14 Aug. 2024
Hi all,
I'm successfully generating code from the Simulink model. This code substitute manual one with the same function. Code is the integrated with the rest of the manual code, flashed to the HW and running. This substituting of the manual code part with the generated one increses the CPU Load. When I'm checking the Code generation setting, basic targets are RAM minimazing or Execution speed mazimazing. Non of these will directly reduce the CPU Load I suppose.
So I'd like to ask you, do you know what Advanced or Detailed Code generation Optimization setting can reduce the CPU Load? I'm attaching screenshots of the current setting.
And possibly follow up question - is there any metric which can estimate affect on the CPU Load without need of flashing the integrated code to the HW?
Thank you for your help in advance, have a nice day!
Oldrich

Akzeptierte Antwort

Raghava S N
Raghava S N am 2 Aug. 2024
Hi Oldrich,
The increase in CPU load when substituting manual code with generated code from the Simulink model can arise due to the inherent complexity and computational requirements of the generated code. The following steps can be taken to reduce the CPU load:
Simplifying the complex subsystems and removing unnecessary blocks will reduce the overall computational load. This can significantly decrease the CPU usage.
Some code generation settings can be helpful, like “Default parameter behavior”, which when set to “Inlined” can help reduce overhead by embedding parameter values directly in the code. This option can be found in the path: Configuration Parameters > Code Generation > Optimization > Default parameter Behavior. For more details on the “Inlined” parameter, please refer to this link - https://www.mathworks.com/help/rtw/ref/defaultparameterbehavior.html
Another option is to lower the “Loop unrolling threshold”, which can help improve execution speed by reducing the overhead of loop control. This option can be found in the path: Configuration Parameters > Optimization > Loop unrolling threshold. For more details on the “Loop unrolling threshold” parameter, please refer to this link - https://www.mathworks.com/help/rtw/ref/loopunrollingthreshold.html
Also ensure that the “Block reduction” option is checked under Configuration Parameters > Simulation Target > Advanced parameters > Block reduction. This removes redundant blocks during code generation. For more information on the “Block reduction” parameter, please refer to this link - https://www.mathworks.com/help/simulink/gui/blockreduction.html
Please refer to this MATLAB Answer by a staff member regarding handling CPU load for generated code - https://www.mathworks.com/matlabcentral/answers/1984294-how-to-use-more-cpu-in-simulink-for-a-power-system-simulation
Regarding your follow-up question, estimating the CPU load can be done using a software-in-the-loop (SIL), processor-in-the-loop (PIL), or XCP-based external mode simulation that produces execution-time metrics for your generated code. Please refer to this documentation link for a detailed description of the workflow involved in using these methods - https://www.mathworks.com/help/ecoder/ug/view-and-compare-code-execution-times.html
I hope this helps!
Raghava
  1 Kommentar
Oldrich
Oldrich am 14 Aug. 2024
Thank you very much for valuable comments. I'll check your proposals.
Thank you, have a nice day!
Oldrich

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Deployment, Integration, and Supported Hardware finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by