Generate SIMD Code using Hexagon and HVX Instruction Set for Qualcomm Hexagon Processors
You can generate single instruction multiple data (SIMD) code from certain MATLAB® functions, Simulink® blocks, and DSP System Toolbox™ blocks and System objects using Hexagon® scalar DSP and Hexagon Vector eXtensions set for Qualcomm® Hexagon DSPs.
SIMD is a computing technique in which a single instruction processes multiple data simultaneously. Many modern processors have SIMD instructions that performs several operations such as addition or multiplication at once. For computationally intensive operations on supported functions, SIMD intrinsics can significantly improve the performance of the generated code on Hexagon DSPs.
Generate SIMD Code for MATLAB Functions
You can generate the SIMD code for MATLAB functions using MATLAB Coder app or MATLAB command line.
Using MATLAB Coder App
On the MATLAB toolstrip Apps tab, under Code Generation, click the MATLAB Coder app icon. The app opens the Select Source Files page.
In the Select Source Files page, enter or select the name of the entry-point function An entry-point function is a top-level MATLAB function from which you generate code. The app creates a project with the default name
function_name.prjin the current folder.Click Next to go to the Define Input Types step. To generate code, you must define the input type for every entry-point. To automatically define input types, select a script that uses your entry-points.
Instruct the app to automatically determine input properties by providing a script that calls the entry-point functions with sample inputs or specify the properties in the command window.
Click Settings > Hardware. Set the Hardware board to
Qualcomm Hexagon Android Board,Qualcomm Hexagon Linux Board, orQualcomm Hexagon Simulator.Click Speed > Target Specific Optimization. Set Leverage target hardware instruction set extensions to
HVXfor processors like cDSP orHexagonfor processors like aDSP.Close the settings window.
Click Generate Code.
To generate C code using MATLAB Coder app, see Generate Deployable Standalone Code by Using the MATLAB Coder App.
Using MATLAB Command Line
Create a code generation configuration object.
cfg = coder.config('lib', 'ecoder', true);
Set the hardware board to
Qualcomm Hexagon Android Board,Qualcomm Hexagon Linux Board, orQualcomm Hexagon Simulator.hw = coder.hardware("Qualcomm Hexagon Android Board"); cfg.Hardware = hw;Set the instruction set extension to
HVXorHexagon.cfg.Hardware.ProcessingUnit = 'cdsp'; cfg.InstructionSetExtensions="HVX";
Optionally, set the
OptimizeReductionsproperty to'on'to generate SIMD code for reduction operations such as sum and product functions.cfg.OptimizeReductions=true;
Optionally, set the
FMAproperty to'on'to generate SIMD code for fused multiply-add operations.cfg.InstructionSetExtensionsConfig.FMA = true;
To generate the code, use the
codegenfunction.codegen('-config', cfg, 'function_name');
Generate SIMD Code for Simulink Blocks
You can generate SIMD code for Simulink blocks using the Simulink Coder app.
Open the Simulink Coder app or the Embedded Coder app.
Click Settings > Hardware Implementation.
Set the Hardware Board to
Qualcomm Hexagon Android Board,Qualcomm Hexagon Linux Board, orQualcomm Hexagon Simulator.Click Code Generation > Optimization. Under Target specific optimizations, set Leverage target hardware instruction set extensions to
HVXorHexagon.Optionally, enable the Optimize reductions parameter to generate SIMD code for reduction operations.
Generate code from the model.
To generate c code using the Simulink Coder app, see Generate C Code by Using Simulink Coder Quick Start Tool.