Use Intel AVX2 Code Replacement Library to Generate SIMD Code from Simulink Blocks - MATLAB & Simulink (original) (raw)

Main Content

Note

This workflow requires an Embedded Coder® license.

To configure a Simulink® model to generate SIMD code using Intel® AVX2 code replacement library:

Compare the Performance of SIMD Code with Generated Plain C Code

Consider this Simulink model that models a digital communication system. The model contains a root-raised cosine filter on the transmitter and the receiver side, a couple of FIR Interpolation and FIR Decimation blocks to increase and decrease the sample rate of the signal, respectively, and an additive white Gaussian noise (AWGN) communication channel to transmit the signal. The root-raised cosine filters on both sides perform matched filtering. The combined response of the two root-raised cosine filters forms a raised-cosine filter, which helps in minimizing the intersymbol interference (ISI). Due to matched filtering, the signal received at the output has a high signal to noise ratio (SNR) and low probability of error. To confirm, view the output in the constellation diagram that follows.

Open the ex_qam_matchedfilter model.

In the Modeling tab of the model, click Model Settings. In the configuration parameters window that opens, under Code Generation in the Interface pane, set Code replacement libraries to None. Build the model and this setting generates plain C code executable in the current MATLAB directory. However, if you specify a Code generation folder (Simulink) in Simulink preferences, building the model generates plain C code executable in the specified folder. Measure the time it takes to run the executable.

tic; system('ex_qam_matchedfilter'); tplain = toc

Repeat the process by setting the Code replacement libraries to DSP Intel AVX2-FMA (Windows), DSP Intel AVX2-FMA (Linux), or DSP Intel AVX2-FMA (Mac), depending on the platform of the machine you are using. Build the model and measure the time it takes to run the generated AVX2 executable.

tic; system('ex_qam_matchedfilter'); tavx2 = toc

The generated SIMD code is around 4.5x compared to the plain C code on a Windows® 10 machine.

See Also

Topics