Main Content

coder.CodeConfig

Configuration parameters for C/C++ code generation from MATLAB code

Description

A coder.CodeConfig object contains the configuration parameters that codegen uses for generating a static library, a dynamically linked library, or an executable program. Pass the object to the codegen function by using the -config option.

Creation

Create a coder.CodeConfig object by using the coder.config function.

Once you create a coder.CodeConfig object, you can modify its properties programmatically at the command line or interactively by using the Configuration Parameter Dialog Box. See Specify Code Configuration Parameters Interactively.

Properties

expand all

Compiler optimization or debug settings for toolchain, specified as 'Faster Runs', 'Faster Builds', 'Debug', or 'Specify'. For more information, see Build configuration.

Dynamic array optimization, specified as true or false. For more information, see Cache dynamic array data.

Formatting tool for the generated code, specified as 'Auto', 'Clang-format', or 'MathWorks'. For more information, see Select code format tool to use.

Code replacement library for generated code, specified as a character vector. For more information, see Code replacement library.

Maximum number of function specializations for compile-time recursion, specified as a positive integer. For more information, see Compile-time recursion limit.

Maximum number of instructions that the constant folder executes, specified as a positive integer. For more information, see Constant folding timeout.

Whether to generate C++ code that contains enumeration classes, specified as true or false. For more information, see Generate C++ enum class from MATLAB enumeration.

Name of interface class when you generate C++ code with CppInterfaceStyle set to 'Methods', specified as a character vector. For more information, see C++ interface class name.

Style of interface to the generated C++ code for the MATLAB entry-point functions that you generate code from, specified as 'Functions' or 'Methods'. For more information, see Interface style.

Namespace for the generated C++ code, specified as a character vector. For more information, see C++ namespace.

Namespace for the C++ code generated for MathWorks code, specified as a character vector. For more information, see Namespace for MathWorks code.

Whether to generate C++ classes or C style structures for MATLAB classes, specified as true or false. For more information, see Generate C++ classes from MATLAB classes.

Whether to generate C++ namespaces for the namespaces in your MATLAB code, specified as true or false. For more information, see Generate C++ namespaces from MATLAB namespaces.

Callback class for BLAS library calls in code generated for certain low-level vector and matrix operations in MATLAB code, specified as a character vector. For more information, see Custom BLAS library callback.

Callback class for FFTW library calls in code generated for FFT functions in MATLAB code, specified as a character vector. For more information, see Custom FFT library callback.

Custom code that appears near the top of each C/C++ header file generated from your MATLAB code, except rtwtypes.h and rtwhalf.h, specified as a character vector. For more information, see Header file.

Include folders to add to the include path when compiling the generated code, specified as a string array, cell array of character vectors, or character vector. For more information, see Additional include directories.

Custom code to include in the generated initialize function, specified as a character vector. For more information, see Initialize function.

Callback class for LAPACK library calls in code generated for certain linear algebra functions in MATLAB code, specified as a character vector. For more information, see Custom LAPACK library callback.

Static library files to link with the generated code, specified as a string array, cell array of character vectors, or character vector. For more information, see Additional libraries.

Source files to compile and link with the generated code, specified as a string array, cell array of character vector, or character vector. For more information, see Additional source files.

Specify code to appear near the top of each generated .c or .cpp file (except rtwhalf.c or rtwhalf.cpp), outside of any function, specified as a character vector. For more information, see Source file.

Code that appears in the generated terminate function, specified as a character vector. For more information, see Terminate function.

Custom settings for tools in selected toolchain, specified as a cell array. For more information, see Custom Toolchain Options.

Data type replacement in generated code, specified as 'CBuiltIn' or 'CoderTypeDefs'. For more information, see Data type replacement.

Configuration object for code generation for deep learning networks, specified as specified as one of the objects in this table.

ObjectRequiresDescription
coder.MklDNNConfig

  • Deep Learning Toolbox™

  • MATLAB Coder™ Interface for Deep Learning support package

A coder.MklDNNConfig object contains parameters specific to C++ code generation for deep learning using Intel® MKL-DNN. To create a coder.MklDNNConfig object, use coder.DeepLearningConfig. For example:

cfg = coder.config('mex');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('mkldnn');

See Code Generation for Deep Learning Networks with MKL-DNN.

coder.ARMNEONConfig

  • Deep Learning Toolbox

  • MATLAB Coder Interface for Deep Learning support package

A coder.ARMNEONConfig object contains parameters specific to C++ code generation for deep learning using the ARM® Compute Library. To create a coder.ARMNEONConfig object, use coder.DeepLearningConfig. For example:

cfg = coder.config('lib');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('arm-compute');

See Code Generation for Deep Learning Networks with ARM Compute Library.

coder.CuDNNConfig (GPU Coder)

  • Deep Learning Toolbox

  • GPU Coder™

  • GPU Coder Interface for Deep Learning support package

A coder.CuDNNConfig object contains parameters specific to CUDA® code generation for deep learning using the cuDNN library. To create a coder.CuDNNConfig object, use coder.DeepLearningConfig. For example:

cfg = coder.gpuConfig('lib');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('cudnn');

See Code Generation for Deep Learning Networks by Using cuDNN (GPU Coder).

coder.TensorRTConfig (GPU Coder)

  • Deep Learning Toolbox

  • GPU Coder

  • GPU Coder Interface for Deep Learning support package

A coder.TensorRTConfig object contains parameters specific to CUDA code generation for deep learning using the TensorRT library. To create a coder.TensorRTConfig object, use coder.DeepLearningConfig. For example:

cfg = coder.gpuConfig('lib');
cfg.TargetLang = 'C++';
cfg.DeepLearningConfig = coder.DeepLearningConfig('tensorrt');

See Code Generation for Deep Learning Networks by Using TensorRT (GPU Coder).

Dependency: If DeepLearningConfig is set, codegen sets TargetLang to C++.

Object description, specified as a character vector.

Dynamic memory allocation mode, specified as one of the values in this table.

ValueDescription
'Threshold'

This value is the default value.

The code generator allocates memory dynamically on the heap for variable-size arrays whose size (in bytes) is greater than or equal to DynamicMemoryAllocationThreshold.

'AllVariableSizeArrays'The code generator dynamically allocates memory for all variable-size arrays on the heap.
'Off'

The code generator statically allocates memory for variable-size arrays on the stack.

Unbounded variable-size arrays require dynamic memory allocation.

Dependencies:

  • EnableVariableSizing enables this parameter.

  • Setting this DynamicMemoryAllocation to 'Threshold' enables the DynamicMemoryAllocationThreshold parameter.

See Generate Code for Variable-Size Arrays.

Note

The DynamicMemoryAllocation configuration object property will be removed in a future release. To dynamically allocate memory for variable-sized arrays, use the EnableDynamicMemoryAllocation property. Use the DynamicMemoryAllocationThreshold property to set the dynamic memory allocation threshold.

Dynamic memory allocation for fixed-size arrays, specified as false or true. For more information, see Enable dynamic memory allocation for fixed-sized arrays.

Implementation of dynamically allocated array at the interface of the generated C/C++ function, specified as 'Auto', 'C', or 'C++'. For more information, see Dynamic memory allocation interface.

Size threshold for dynamic memory allocation of variable-size arrays, specified as a positive integer. For more information, see Dynamic memory allocation threshold.

Automatic extrinsic function calls, specified as true or false. For more information, see Automatically introduce extrinsic calls.

Automatic parallelization of for loops, specified as false or true. For more information, see Enable automatic parallelization.

Reporting for automatic parallelization of for loops, specified as true or false. For more information, see Enable automatic parallelization reporting.

Dynamic memory allocation for variable-size arrays, specified as true or false. For more information, see Enable dynamic memory allocation.

Implicit expansion capabilities in the generated code, specified as true or false. For more information, see Enable implicit expansion.

memcpy optimization, specified as true or false. For more information, see Use memcpy for vector assignment.

Parallelization of parfor-loops, specified as true or false. For more information, see Enable OpenMP library if possible.

Run-time recursion support, specified as true or false. For more information, see Enable run-time recursion.

Variable-size array support, specified as true or false. For more information, see Enable variable-sizing.

File partitioning mode, specified as 'MapMFileToCFile' 'SingleFile'. For more information, see Generated file partitioning method.

Generation of only source code, specified as true or false. For more information, see Generate code only.

Comments in generated code, specified as true or false. For more information, see Include comments.

Example C/C++ main file generation, specified as 'GenerateCodeOnly', 'DoNotGenerate', or 'GenerateCodeAndCompile'. For more information, see Generate example main.

Makefile generation during the build process, specified true or false. For more information, see Generate makefile.

Generation of support files for nonfinite data, specified true or false. For more information, see Generate nonfinite support files if used.

Code generation report, specified false or true. For more information, see Always create a report.

Configuration object for generating CUDA GPU code using GPU Coder. A GpuCodeConfig object contains parameters specific to CUDA GPU code generation. To create a GpuCodeConfig object, use coder.gpuConfig (GPU Coder). For example:

cfg = coder.gpuConfig('lib');
cfg.GpuConfig

ans =
   GpuCodeConfig with properties:

                    Enabled: 1
                 MallocMode: 'discrete'
           KernelNamePrefix: ''
               EnableCUBLAS: 1
             EnableCUSOLVER: 1
                EnableCUFFT: 1
               Benchmarking: 0
                  SafeBuild: 0
          ComputeCapability: 'Auto'
    CustomComputeCapability: ''
              CompilerFlags: ''
        StackLimitPerThread: 1024
            MallocThreshold: 200
     MaximumBlocksPerKernel: 0
        EnableMemoryManager: 1
           SelectCudaDevice: -1

For more information, see Generate Code Using the Command Line Interface (GPU Coder).

If GpuConfig is set, the code generator uses fixed values for certain properties that are required for GPU code generation. Some properties also have different default values. For more information, see Configure GPU Code Generation (GPU Coder).

Object that specifies a hardware board. To create the coder.Hardware object, use coder.hardware. For example:

cfg = coder.config('lib');
hw = coder.hardware('Raspberry Pi');
cfg.Hardware = hw;

Before you use coder.hardware, you must install the support package for the hardware.

Dependencies:

  • Setting Hardware customizes the hardware implementation object and other configuration parameters for a particular hardware board.

  • If DeepLearningConfig is set to a coder.ARMNEONConfig object and Hardware is empty, then codegen sets the GenCodeOnly property to true.

Note:

  • Suppose that you create a coder.CodeConfig object cfg in a MATLAB session and use it in another MATLAB session. If the MATLAB host computer for the second session does not have the hardware board specified in the cfg.Hardware property installed on it, this parameter reverts to its default value. The default value is []. Setting the Hardware Board option to MATLAB Host Computer in the app is equivalent to using cfg.Hardware and cfg.HardwareImplementation.ProdHWDeviceType with their default value.

Hardware implementation object that specifies hardware-specific configuration parameters for C/C++ code generation. coder.config creates a coder.CodeConfig object with the HardwareImplementation property set to a coder.HardwareImplementation object with default parameter values for the MATLAB host computer.

Style of preprocessor directive in generated code, specified as 'UseIncludeGuard' or 'UsePragmaOnce'. For more information, see Header guard style.

Whether to highlight potential issues resulting from implicit expansion in the code generation report, specified as true or false. For more information, see Highlight potential issues resulting from implicit expansion.

Whether to highlight potential issues resulting from the use of loop control functions in the code generation report, specified as true or false. For more information, see Highlight potential issues in use of coder.loop functions.

Potential row-major layout efficiency issues, specified true or false. For more information, see Highlight potential row-major issues.

Assignment of float and double zero with memset, specified true or false. For more information, see Use memset to initialize floats and doubles to 0.0.

Control inlining between MathWorks functions, specified as 'Speed', 'Always', 'Readability', or 'Never'. For more information, see Inline strategy for MathWorks written MATLAB functions.

Control inlining between user-written functions and MathWorks functions, specified as 'Speed', 'Always', 'Readability', or 'Never'. For more information, see Inline strategy for calls between MathWorks functions and user functions.

Control inlining between user-written functions, specified as 'Speed', 'Always', 'Readability', or 'Never'. For more information, see Inline strategy for user written MATLAB functions.

Instruction sets to generate single instruction, multiple data (SIMD) code for target hardware, specified as 'Auto', 'SSE2', or 'None'. For more information, see Leverage target hardware instruction set extensions.

Annotates the generated C/C++ code to suppress known MISRA™ and AUTOSAR violations, specified false or true. For more information, see Generate justification comments for known MISRA violations.

Whether the code generator embeds large constants for a deep neural network (DNN) in the generated source code or writes these constants to binary data files, specified as 'WriteOnlyDNNConstantsToDataFiles' or 'KeepInSourceFiles'. For more information, see Large constant generation.

Threshold above which the code generator writes DNN constants to binary data files, specified as a positive integer. For more information, see Large constant threshold.

Automatic open of code generation report, specified true or false. For more information, see Automatically launch a report if one is generated.

Threshold on the number of iterations that determines whether to automatically unroll a for-loop or parfor-loop, specified as a positive integer. For more information, see Loop unrolling threshold.

Inclusion of MATLAB source code as comments in generated code, specified true or false. For more information, see MATLAB source code as comments.

Include line numbers of MATLAB source code as comments in the generated code, specified as true or false. For more information, see MATLAB source code comment line numbers.

Maximum number of characters in generated identifiers, specified as a positive integer in the range [31, 2048]. For more information, see Maximum identifier length.

Minimum size for memcpy or memset optimization in bytes, specified as a positive integer. For more information, see Memcpy threshold (bytes).

Multi-instance, reentrant code, specified as true or false. For more information, see Generate re-entrant code.

Object name, specified as a character vector.

Maximum number of CPU threads to run parallel for-loops in the generated C/C++ code, specified as a positive integer. For more information, see Maximum number of CPU threads.

Generate SIMD code for reduction operations and parallelize for-loops performing reduction operations, specified as false or true. For more information, see Optimize reductions.

Output to build from generated C/C++ code, specified as 'LIB', 'DLL', or 'EXE'. For more information, see Build type.

Pass structures by reference to entry-point functions, specified true or false. For more information, see Pass structures by reference to entry-point functions.

Command to customize build processing after MEX function generation with codegen, specified as a character vector. For more information, see Post-code-generation command.

Generation of code that uses N-dimensional indexing, specified false or true. For more information, see Preserve array dimensions.

Since R2024b

Whether to protect entry-point input data from modification when the generated code is called from your custom C/C+ code, specified as false or true. For more information, see Preserve input data for entry-point functions.

Variable names to preserve in the generated code, specified as 'None', 'UserNames', 'All'. For more information, see Preserve variable names.

Name of variable containing code generation report information about code generation, specified as a character vector. For more information, see Export report information to variable.

Potential difference reporting, specified true or false. For more information, see Report differences from MATLAB.

Names that the code generator must not use for functions or variables, specified as a string array, cell array of character vectors, or character vector. For more information, see Reserved names.

Row-major array layout for the generated code, specified false or true. For more information, see Array layout.

Automatically run the initialize function at the beginning of the generated entry-point functions, specified true or false. For more information, see Automatically run the initialize function.

Run-time error detection and reporting in generated code, specified false or true. For more information, see Generate run-time error checks.

Integer overflow support, specified true or false. For more information, see Saturate on integer overflow.

Maximum stack usage per application in bytes, specified as a positive integer. For more information, see Stack usage max.

Support for nonfinite values, specified as true or false. For more information, see Support nonfinite numbers.

Language to use in generated code, specified as 'C' or 'C++'. For more information, see Language.

Language standard to use for the generated code, specified as one of these options:

  • 'Auto'

  • 'C89/C90 (ANSI)'

  • 'C99 (ISO)'

  • 'C++03 (ISO)'

  • 'C++11 (ISO)'

  • 'C++14 (ISO)'

  • 'C++17 (ISO)'

  • 'C++20 (ISO)'

For more information, see Language standard.

Toolchain to use for building a C/C++ library or executable program, specified as a character vector. For more information, see Toolchain.

Generate code that uses the FFTW library shipped with MATLAB for fast Fourier transform (FFT) functions in your MATLAB code, specified false or true. For more information, see Use built-in FFTW library.

Since R2024b

Whether to use precompiled libraries in generated code, specified as 'Prefer' or 'Avoid'. For more information, see Use precompiled libraries.

Code generation progress display, specified as one of the values in this table.

ValueDescription
false

This value is the default value.

The code generator does not display code generation progress.

true

The code generator displays code generation progress, including code generation stages and compiler output.

Note

The Verbose configuration object property will be removed in a future release. To view code generation progress, use the Verbosity property.

Code generation progress display at the MATLAB command line, specified as 'Info', 'Silent', or 'Verbose'. For more information, see Show verbose compiler output.

Examples

collapse all

Write a MATLAB function from which you can generate code. This example uses the function myadd that returns the sum of its inputs.

function c = myadd(a,b)
c = a + b;
end

Create a configuration object for generation of standalone C/C++ code (a static library, a dynamically linked library, or an executable program). For example, create a configuration object for generation of a static library.

cfg = coder.config('lib');

Change the values of the properties for which you do not want to use the default values. For example, enable run-time error detection and reporting in the generated C/C++ code.

cfg.RuntimeChecks = true;

Generate code by using codegen. Pass the configuration object to codegen by using the -config option. Specify that the input arguments are scalar double.

codegen myadd -config cfg -args {1 1} -report

Alternative Functionality

To use default configuration parameters for build types 'LIB', 'DLL', or 'EXE', use the codegen option -config:lib, -config:dll, or -config:exe, respectively. Then, you do not have to create and pass a configuration object to codegen.

Version History

Introduced in R2011a

expand all