Main Content


Generate code for a deep learning network to target the ARM Mali GPU


cnncodegen(net,'targetlib','arm-compute-mali') generates C++ code for the specified network object by using the ARM® Compute Library for Mali GPUs.

Requires the GPU Coder™ product and the GPU Coder Interface for Deep Learning.


cnncodegen(net,'targetlib','arm-compute-mali',targetparams) generates C++ code for the specified network object by using the ARM Compute Library for Mali GPUs with additional code generation options.


collapse all

Use cnncodegen to generate C++ code for a pretrained network for deployment to an ARM Mali graphics processor.

Get the pretrained GoogLeNet model by using the googlenet (Deep Learning Toolbox) function. This function requires the Deep Learning Toolbox™ Model for GoogLeNet Network. If you have not installed this support package, the function provides a download link. Alternatively, see

net = googlenet;

Generate code by using cnncodegen with 'targetlib' set to 'arm-compute-mali'. By default, the code generator targets version '19.05' of the ARM. To target a different version of the Compute Library, use the 'ArmComputeVersion' parameter.

Compilation suppressed: generating code only.
### Codegen Successfully Generated for arm device

The code generator generates the .cpp and header files in the '/pwd/codegen' folder. The DAG network is generated as a C++ class called CnnMain, containing an array of 87 layer classes. The code generator reduces the number of layers is by layer fusion optimization of convolutional and batch normalization layers. The setup() method of this class sets up handles and allocates resources for each layer object. The predict() method invokes prediction for each of the 87 layers in the network. The cleanup() method releases all the memory and system resources allocated for each layer object. All the binary weights (cnn_**_w) and the bias files (cnn_**_b) for the convolution layers of the network are stored in the codegen folder.

To build the library, move the generated code to the ARM target platform and use the generated makefile

Input Arguments

collapse all

Pretrained SeriesNetwork or DAGNetwork object.


cnncodegen does not support dlnetwork objects.

ARM Compute Library-specific parameters specified as a 1-by-1 structure containing the fields described in these tables.




Version of ARM Compute Library on the target hardware, specified as '19.02' or '19.05'. The default value is '19.05'. If you set ArmComputeVersion to a version later than '19.05', ArmComputeVersion is set to '19.05'.

Version History

Introduced in R2017b

expand all