Use Target Hardware Instruction Set Extensions to Generate SIMD Code for MATLAB System Objects for Intel Platforms
Note
This workflow requires MATLAB® Coder™ license or Embedded Coder® license.
This topic shows how to generate SIMD code for MATLAB System objects for Intel® platforms using the InstructionSetExtensions (Simulink Coder) configuration parameter. For a list of System objects in DSP System Toolbox™ that support this workflow, see System objects in DSP System Toolbox that Support SIMD Code Generation.
To generate SIMD code for MATLAB System objects:
Create a
coder.config(MATLAB Coder) object.Set
ecoder_flagtotrueto create acoder.EmbeddedCodeConfigobject. Setecoder_flagtofalseto create acoder.CodeConfigobject.build_typeis'lib','dll', or'exe'.config_obj = coder.config(build_type,'ecoder',ecoder_flag)Select the hardware device by setting
HardwareImplementation.ProdHWDeviceTypeto one of these options:"AMD->x86-64 (Linux 64)""AMD->x86-64 (Windows64)""Intel->x86-64 (Linux 64)""Intel->x86-64 (Windows64)"
config_obj.HardwareImplementation.ProdHWDeviceType = "Intel->x86-64 (Windows64)"Select the instruction set extensions supported by Intel platforms by setting
InstructionSetExtensionsto one of these options:"SSE2"— If you are using the MATLAB Coder license"SSE","SSE2","SSE4.1","AVX","AVX2","FMA","AVX512F"— If you are using the Embedded Coder license
config_obj.InstructionSetExtensions = "SSE2"Set
OptimizeReductionstotrueto generate SIMD code for reduction operations.config_obj.OptimizeReductions = true
Set
CodeReplacementLibraryto"None".config_obj.CodeReplacementLibrary = "None"In addition, you must satisfy the conditions under which the System objects support SIMD code generation. For more information, see the Extended Capabilities > C/C++ Code Generation section in the respective System object™ reference page.
Generate code using the
codegen(MATLAB Coder) command.codegen MATLABfunctionName -config config_objMATLABfunctionName is the MATLAB function that calls the System object you are trying to generate SIMD code for. For a list of System objects that support SIMD code generation, see System objects in DSP System Toolbox that Support SIMD Code Generation.
The SIMD instructions are the intrinsic functions that start with the identifier
_mm in the generated code. These functions process multiple data
in a single iteration of the loop because the loop increments by four for single data
types and by two for double data types. For models that process more data and are
computationally more intensive, the SIMD instructions can significantly speed up the
code execution time.
See Also
Topics
- System objects in DSP System Toolbox that Support SIMD Code Generation
- Use Intel AVX2 Code Replacement Library to Generate SIMD Code from MATLAB Algorithms
- Use Target Hardware Instruction Set Extensions to Generate SIMD Code from MATLAB System Objects for Apple silicon and ARM Cortex-A Processors
- Use Target Hardware Instruction Set Extensions to Generate SIMD Code from Simulink Blocks for Intel Platforms
- Generate and Deploy SIMD Optimized Code for Interpolated FIR Filter on Intel Desktops
- Generate Code Using Embedded Coder (Embedded Coder)