Main Content

coder.DeepLearningCodeConfig

R2026b

Parameters to configure deep learning code generation that does not depend on third-party libraries

Description

The coder.DeepLearningCodeConfig object contains the parameters that the codegen function uses to generate generic C or C++ code for deep neural networks.

Creation

Create an DeepLearningCodeConfig configuration object by using the coder.DeepLearningConfig function with target library set to "none".

Properties

expand all

Since R2026a

Computation precision, specified as "FP32" or "FP16". When performing computation in 32-bit floats, use "FP32". For half-precision, use "FP16". Default value is "FP32".

To perform half-precision computations, use "FP16". You can only use "FP16"for generating CUDA code. "FP16" precision requires a GPU with minimum compute capability of 7.5 or higher.

Compression type, specified as "none" or "bfloat16". To enable learnables compression, use "bfloat16". For more information, see Learnables compression.

This property is read-only.

Name of the target deep learning library, returned as "none". This property indicates that the generated code does not depend on any third-party deep learning library. The value is set when you create the configuration object by calling coder.DeepLearningConfig with the TargetLibrary argument set to "none".

Examples

collapse all

Create an entry-point function resnet50 that uses the imagePretrainedNetwork function to load the dlnetwork object that contains the ResNet-50 network. For more information, see Code Generation for dlarray.

function out = resnet_predict(in)

dlIn = dlarray(in, "SSCB");
persistent dlnet;
if isempty(dlnet)
    dlnet = imagePretrainedNetwork("resnet50");
end

dlOut = predict(dlnet, dlIn);
out = extractdata(dlOut);

Create a coder.config configuration object for MEX code generation.

cfg = coder.config("mex");

Set the target language to C++.

cfg.TargetLang = "C++";

Create a coder.DeepLearningCodeConfig deep learning configuration object. Assign it to the DeepLearningConfig property of the cfg configuration object.

dlcfg = coder.DeepLearningConfig(TargetLibrary="none");
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 -args {ones(224,224,3,"single")} -config cfg resnet_predict

The codegen command places the generated files in the codegen folder. This folder contains the C++ code for the entry-point function resnet_predict.cpp, the header, and the source files that contain the C++ class definitions for the neural network, weight, and bias files.

Version History

Introduced in R2021a

expand all