Main Content

coder.CMSISNNConfig

R2026b

(To be removed) Parameters to configure deep learning code generation with the CMSIS-NN library for Cortex-M targets

Since R2022a

coder.DeepLearningConfig("cmsis-nn") will be removed in a future release. Instead, create a deep learning configuration object by using the coder.DeepLearningConfig function with the target library set to "none", and set the CodeReplacementLibrary property of the code configuration object to "ARM Cortex-M". For Simulink® workflows, use exportNetworkToSimulink (Deep Learning Toolbox). For information on updating your code, see Version History.

Description

The coder.CMSISNNConfig object contains CMSIS-NN library and associated ARM® Cortex-M target specific parameters that codegen uses for generating C code for deep neural networks.

To use a coder.CMSISNNConfig object for code generation, assign it to the DeepLearningConfig property of a code generation configuration object that you pass to codegen.

Creation

Create a CMSIS-NN configuration object by using the coder.DeepLearningConfig function with target library set as 'cmsis-nn'.

Properties

expand all

Location of the MAT file containing the calibration data. For more information, see Calibration result file path (CMSIS-NN).

Precision of inference computations in supported layers. For more information, see Data type (CMSIS-NN).

Name of target library, specified as a character vector.

Examples

collapse all

Create an entry-point function net_predict that uses the coder.loadDeepLearningNetwork function to load the network object net from the MAT file netFile. The function then performs prediction using this model object.

function out = net_predict(netFile, in)
net = coder.loadDeepLearningNetwork(netFile);
out = predict(net,in);
end

Create a coder.config configuration object for generation of a C static library.

cfg = coder.config('lib');

Create a coder.CMSISNNConfig deep learning configuration object and specify the location of the calibration MAT file. Assign it to the DeepLearningConfig property of the cfg configuration object.

dlcfg = coder.DeepLearningConfig('cmsis-nn');
dlcfg.CalibrationResultFile = 'calibration.mat'; 
cfg.DeepLearningConfig = dlcfg;

Use the -config option of the codegen function to specify the cfg configuration object. The codegen function must determine the size, class, and complexity of MATLAB® function inputs. Use the -args option to specify the size of the input to the entry-point function.

codegen -config cfg net_predict -args {coder.Constant('calibration.mat'), exampleinput}

The codegen command places all the generated files in the codegen folder.

Version History

Introduced in R2022a

collapse all