- EnableAutoParallelization (https://www.mathworks.com/help/coder/ug/automatically-parallelize-for-loops.html)
- InstructionSetExtensions (https://www.mathworks.com/help/rtw/ref/leveragetargethardwareinstructionsetextensions.html)
MATLAB coder: C + JIT or C++
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gustavo Lunardon
am 11 Dez. 2023
Kommentiert: Gustavo Lunardon
am 15 Dez. 2023
Hello,
I have been generating some MEX functions with the sole purpose of using within the MATLAB engine at faster speed.
My questions are:
1 - Normally what is advised to tweak in the options to enforce code run speed (not build time / readability)? Is the default OK for this? I do not intend to use things that imply in loss of functionality (e.g., use integers whenever possible instead of double type). Also, the only coder command I used is coder.inline('always').
2 - Normally what is faster? C and JIT compilation or C++? It seems JIT compilation is not compatible with C++ and the coder issues a warning if tried this setting.
Thanks,
Gustavo
0 Kommentare
Akzeptierte Antwort
Richard McCormack
am 12 Dez. 2023
Hi Gustavo,
1) Yes, I think that in general the default settings are your best bet here. Off the top of my head, there are couple of extra settings you can try adjusting to see if they improve your performance:
2) In general I don't anticipate any performance difference between C and C++ generated code, so I would start with C and JIT.
Hope this helps, and hope you enjoy using MATLAB Coder :)
Weitere Antworten (1)
Infinite_king
am 13 Dez. 2023
Bearbeitet: Infinite_king
am 13 Dez. 2023
Hi Gustavo Lunardona,
I understand you're seeking MATLAB coder settings to enhance the generated Mex speed. While the default settings are generally effective for optimized Mex generation, you can follow these steps to potentially achieve additional speedup,
- Set the below code generation configuration object options to true,
% create a code generation configuration object
cfg = coder.config;
% options
cfg.CacheDynamicArrayDataPointer = true;
cfg.EnableMemcpy = true;
% Note - These options will be 'true' by default, unless you change these
% settings.
- You've already used coder.inline('always'), which can improve performance by allowing the compiler to inline certain functions. However, excessive inlining can lead to larger code size.
- Select suitable data types. Opting for fixed-point or integer types instead of double, where applicable, can enhance performance without compromising accuracy. The effectiveness depends on the specific application.
- Consider memory layout and access patterns for improved cache locality.
- Finally generate code,
% generate code
codegen -config cfg -args {arg1,arg2} function_name
- When it comes to speed, there is no significant difference between C and C++
- Try the suggestions by 'Richard' in the previous answer.
For more information, refer the following MATLAB documentation,
- https://www.mathworks.com/help/coder/ug/matlab-coder-optimizations-in-generated-cc-code.html
- https://www.mathworks.com/help/coder/ref/coder.config.html
- https://www.mathworks.com/help/coder/ug/optimized-dynamic-array-access.html
Hope this is helpful.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!