メインコンテンツ

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_flag to true to create a coder.EmbeddedCodeConfig object. Set ecoder_flag to false to create a coder.CodeConfig object. build_type is 'lib', 'dll', or 'exe'.

    config_obj = coder.config(build_type,'ecoder',ecoder_flag)

  • Select the hardware device by setting HardwareImplementation.ProdHWDeviceType to 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 InstructionSetExtensions to 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 OptimizeReductions to true to generate SIMD code for reduction operations.

    config_obj.OptimizeReductions = true

  • Set CodeReplacementLibrary to "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_obj

    MATLABfunctionName 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