필터 지우기
필터 지우기

MATLAB coder: C + JIT or C++

조회 수: 12 (최근 30일)
Gustavo Lunardon
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

채택된 답변

Richard McCormack
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
Gustavo Lunardon
Gustavo Lunardon 2023년 12월 15일
Thank you for answering my question!

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

추가 답변 (1개)

Infinite_king
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,
  1. https://www.mathworks.com/help/coder/ug/matlab-coder-optimizations-in-generated-cc-code.html
  2. https://www.mathworks.com/help/coder/ref/coder.config.html
  3. https://www.mathworks.com/help/coder/ug/optimized-dynamic-array-access.html
Hope this is helpful.
  댓글 수: 1
Gustavo Lunardon
Gustavo Lunardon 2023년 12월 15일
Thank you for answering my question and complementing the previous answer!

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

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by