Use Target Hardware Instruction Set Extensions to Generate SIMD Code from MATLAB System Objects for Apple silicon and ARM Cortex-A Processors
Note
This workflow requires Embedded Coder® license.
This topic shows how to generate SIMD code from MATLAB® System objects for Apple silicon and ARM® Cortex®-A processors 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 from MATLAB System objects:
Create a
coder.config(MATLAB Coder) object.Set
ecoder_flagtotrueto create acoder.EmbeddedCodeConfigobject.build_typeis'lib','dll', or'exe'.config_obj = coder.config(build_type,'ecoder',true)Select the hardware device by setting
HardwareImplementation.ProdHWDeviceTypeto one of these options:"Apple->ARM64""ARM Compatible->ARM Cortex-A (32-bit)""ARM Compatible->ARM Cortex-A (64-bit)"
config_obj.HardwareImplementation.ProdHWDeviceType = "Apple->ARM64"Select the instruction set extensions by setting
InstructionSetExtensionstoNeon v7.config_obj.InstructionSetExtensions = "Neon v7"Set
OptimizeReductionstotrueto generate SIMD code for reduction operations.config_obj.OptimizeReductions = true
Set
InstructionSetExtensionsConfig.FMAtotrueto generate SIMD code for fused multiply-add operations.config_obj.InstructionSetExtensionsConfig.FMA = 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 from. 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
v 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 for MATLAB System Objects for Intel Platforms
- Use Target Hardware Instruction Set Extensions to Generate SIMD Code from Simulink Blocks for Apple silicon
- Use Target Hardware Instruction Set Extensions to Generate SIMD Code from Simulink Blocks for ARM Cortex-A Processors
- Generate Code Using Embedded Coder (Embedded Coder)