- 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++
3 ビュー (過去 30 日間)
古いコメントを表示
Gustavo Lunardon
2023 年 12 月 11 日
コメント済み: Gustavo Lunardon
2023 年 12 月 15 日
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 件のコメント
採用された回答
Richard McCormack
2023 年 12 月 12 日
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 :)
その他の回答 (1 件)
Infinite_king
2023 年 12 月 13 日
編集済み: Infinite_king
2023 年 12 月 13 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!