Main Content

Acceleration for Simulink Deep Learning Models

You can improve the simulation speed of your Simulink® deep learning models by using the accelerator modes of the Simulink product. Both the accelerator and the rapid accelerator modes are supported. These modes replace the normal interpreted code with compiled target code. Using compiled code speeds up simulation of many models, especially those where run time is long compared to the time associated with compilation and checking to see if the target is up to date. For more information, see What Is Acceleration? (Simulink).

For deep learning, the models are compiled in C++ language taking advantage of the Intel® MKL-DNN library. The accelerator and rapid accelerator modes are supported for Simulink deep learning models implemented by using MATLAB Function blocks or by using blocks from the Deep Neural Networks library. The accelerator mode works with any model, but performance decreases if a model contains blocks that do not support acceleration. The rapid accelerator mode works with only those models containing blocks that support code generation of a standalone executable. To learn about modeling techniques for acceleration, see Design Your Model for Effective Acceleration (Simulink).

Note

Accelerator modes require a compatible C++ compiler. To see a list of supported compilers, open Supported and Compatible Compilers, click the tab that corresponds to your operating system, find the Simulink Product Family table, and go to the For Model Referencing, Accelerator mode, Rapid Accelerator mode, and MATLAB Function blocks column. If you have multiple MATLAB®-supported compilers installed on your system, you can change the default compiler using the mex -setup command. See Change Default Compiler.

Run Acceleration Mode from the User Interface

To accelerate a model, first open it, and then on the Simulation tab, in the Simulate section, select Accelerator or Rapid Accelerator from the drop-down menu. Then start the simulation.

The following example shows how to accelerate the already opened googlenet_classifier model from the Classify Images in Simulink Using GoogLeNet example using the Accelerator mode:

  1. In the Model Configuration Parameters, on the Simulation Target pane, set the Language to C++ and the Target library to MKL-DNN.

  2. On the Simulation tab, in the Simulate section, select Accelerator from the drop-down menu.

    Simulation toolstrip for selecting simulation mode

  3. On the Simulation tab, click Run.

    The Accelerator and Rapid Accelerator modes first check to see if code was previously compiled for your model. If code was created previously, the Accelerator or Rapid Accelerator mode runs the model. If code was not previously built, they first generate and compile the C code, and then run the model.

The Accelerator mode places the generated code in a subfolder of the working folder called slprj/accel/modelname (for example, slprj/accel/googlenet_classifier). If you want to change this path, see Changing the Location of Generated Code (Simulink).

The Rapid Accelerator mode places the generated code in a subfolder of the working folder called slprj/raccel/modelname (for example, slprj/raccel/googlenet_classifier).

Run Acceleration Mode Programmatically

You can set configuration parameters, build an accelerated model, select the simulation mode, and run the simulation from the command prompt or from MATLAB script.

Use set_param to configure the model parameter programmatically in the MATLAB Command Window.

set_param('modelname','SimTargetLang','language')

For example, to specify C++ code generation for simulation targets, you would use:

set_param('googlenet_classifier','SimTargetLang','C++');

You can also control the simulation mode from the command line prompt by using the set_param command:

set_param('modelname','SimulationMode','mode')

The simulation mode can be normal, accelerator, rapid, or external.

For example, to simulate your model with the Accelerator mode, you would use:

set_param('googlenet_classifier','SimulationMode','accelerator')

Then, use the sim (Simulink) command to start the simulation:

sim(googlenet_classifier);

However, a preferable method is to specify the simulation mode within the sim command:

simOut = sim('googlenet_classifier', 'SimulationMode', 'accelerator');

See Also

Functions

Blocks

Related Topics