coder.MexCodeConfig - Configuration parameters for MEX function generation from MATLAB code - MATLAB (original) (raw)

Configuration parameters for MEX function generation from MATLAB code

Description

A coder.MexCodeConfig object contains the configuration parameters that codegen uses when generating a MEX function. Pass the object to the codegen function by using the-config option.

Properties

expand all

CacheDynamicArrayDataPointer — Dynamic array optimization

true (default) | false

Dynamic array optimization, specified as one of the values in this table.

Value Description
true This value is the default value.The code generator improves the execution time of generated C code by optimizing dynamic array access.
false The code generator does not optimize dynamic array access.

See Optimize Dynamic Array Access.

CodeFormattingTool — Formatting tool for the generated code

'Auto' (default) | 'Clang-format' | 'MathWorks'

Code formatting options for generated code, specified as one of the values in the table.

Value Description
'Clang-format' The code generator formats the generated code according to a clang-format file.
'Auto' Uses an internal heuristic to determine if the generated code is formatted byclang-format or a MathWorks® formatting tool.If the code configuration propertyVerbosity is set to'Verbose', the code generator produces a warning if the heuristic chooses a MathWorks formatting tool.
'MathWorks' Causes the code generator to revert to the MathWorks formatting tool.

clang-format does not have native CUDA® C++ support. When generating CUDA code using GPU Coder™, setting the formatting tool to'Clang-format' might result in build failures during code compilation.

CompileTimeRecursionLimit — Maximum number of function specializations for compile-time recursion

50 (default) | positive integer

Maximum number of function specializations for compile-time recursion, specified as a positive integer. To disallow recursion in the MATLAB® code, set CompileTimeRecursionLimit to 0. The default compile-time recursion limit is large enough for most recursive functions that require this type of recursion. If code generation fails because of the compile-time recursion limit, and you want compile-time recursion, try to increase the limit. Alternatively, change your MATLAB code so that the code generator uses run-time recursion. SeeCompile-Time Recursion Limit Reached.

ConstantFoldingTimeout — Maximum number of instructions to be executed by the constant folder

40000 (default) | positive integer

Maximum number of instructions that the constant folder executes. In some situations, code generation requires specific instructions to be constant. If constant folding stops before these instructions are constant-folded, code generation fails. In this case, increase the value ofConstantFoldingTimeout.

See MATLAB Coder Optimizations in Generated Code.

ConstantInputs — Constant input checking mode

'CheckValues' (default) | 'IgnoreValues' | 'Remove'

Constant input checking mode, specified as one of the values in this table.

Value Description
'CheckValues' This value is the default value.When you call the MEX function, it checks that the value you provide for a constant input argument is the value specified at code generation time.You can call the MEX function and the original MATLAB function with the same arguments. Therefore, you can use the same test file for both functions.Checking the values can slow down execution of the MEX function.
'IgnoreValues' When you call the MEX function, it ignores the value that you provide for a constant input argument. It uses the value specified at code generation time.You can use the same test file without the overhead of checking the constant argument values.
'Remove' The code generator removes constant input arguments from the MEX function signature. When you call the MEX function, you do not provide a value for a constant input argument. This option provides backward compatibility.

See Constant Input Checking in MEX Functions.

CppGenerateEnumClass — Whether to generate C++ enumeration classes for MATLAB enumerations

true (default) | false

Whether to generate C++ code that contains enumeration classes or ordinary C enumerations, specified as one of the values in this table.

Value Description
true This value is the default value.The code generator produces enumeration classes for MATLAB enumerations in the generated C++ code. See Code Generation for Enumerations.
false The code generator produces ordinary C enumerations for MATLAB enumerations in the generated C++ code.

Dependency:

CppNamespace — Namespace name for generated C++ code

'' (default) | character vector

Namespace for the generated C++ code. The code generator does not produce code in a namespace unless you specify a nonempty character vector.

See Organize Generated C++ Code into Namespaces.

Dependency:

CppNamespaceForMathworksCode — Place C++ code generated for MathWorks code in a separate namespace

'coder' (default) | character vector

Namespace for the C++ code generated for MathWorks code. The code generator does not produce such a namespace if you specify this property as an empty character vector.

See Organize Generated C++ Code into Namespaces.

Dependency:

Data Types: char

CppPreserveClasses — Generate C++ classes for MATLAB classes

true (default) | false

Whether to generate C++ classes or C style structures for MATLAB classes, specified as one of the values in this table.

Value Description
true This value is the default value.The code generator produces C++ classes for MATLAB classes. See Generate C++ Classes for MATLAB Classes.
false The code generator produces C style structures for MATLAB classes.

When using GPU Coder, the code generator always disables this parameter.

Dependency:

Data Types: logical

CppPreserveNamespaces — Generate C++ namespaces for MATLAB namespaces

true (default) | false

Whether to generate C++ namespaces for the namespaces in your MATLAB code, specified as one of the values in this table.

Value Description
true This value is the default value.The code generator produces C++ namespaces for the namespaces in your MATLAB code. See Organize Generated C++ Code into Namespaces.
false The code generator does not produce C++ namespaces for the namespaces in your MATLAB code.

Dependency:

Data Types: logical

— Custom code that appears at top of generated C/C++ header files

' ' (default) | character vector

Custom code that appears near the top of each C/C++ header file generated from your MATLAB code, except rtwtypes.h andrtwhalf.h, specified as a character vector.

CustomInclude — Include folders to add to include path for compiling generated code

' ' (default) | string array | cell array of character vectors | character vector

Include folders to add to the include path when compiling the generated code. Specify the list of include folders as a string array, cell array of character vector, or character vector.

To specify a single include folder, you can use a character vector or a string scalar.

To specify multiple folder names, use one of the values in this table.

Value Description
String array A string array inCustomInclude. For example,cfg.CustomInclude = ["C:\Project","C:\Custom Files"];
Cell array of character vectors A cell array of character vectors inCustomInclude. For example,cfg.CustomInclude = {'C:\Project','C:\Custom Files'};

CustomInitializer — Custom code to include in the generated initialize function

' ' (default) | character vector

Custom code to include in the generated initialize function, specified as a character vector.

' ' (default) | string array | cell array of character vectors | character vector

Static library files to link with the generated code, specified as a string array, cell array of character vector, or character vector.

To specify a single static library file, you can use a character vector or a string scalar.

To specify multiple static library file names, use one of the values in this table.

Value Description
String array A string array inCustomLibrary. For example,cfg.CustomLibrary = ["myLib1.lib","myLib2.lib"];
Cell array of character vectors A cell array of character vectors inCustomLibrary. For example,cfg.CustomLibrary = {'myLib1.lib','myLib2.lib'};

' ' (default) | string array | cell array of character vectors | character vector

Source files to compile and link with the generated code, specified as a string array, cell array of character vector, or character vector.

The build process searches for the source files first in the current folder, and then in the include folders that you specify inCustomInclude. If source files with the same name occur in multiple folders on the search path, the build process might use a different file than the file that you specified.

Suppose that you specify foo.cpp as a source file. Iffoo.c and foo.cpp are both on the search path, you cannot be sure whether the build process usesfoo.c or foo.cpp.

To specify a single source file, you can use a character vector or a string scalar.

To specify multiple source file names, use one of the values in this table.

Value Description
String array A string array inCustomSource. For example,cfg.CustomSource = ["mySrc1.c","mySrc2.c"];
Cell array of character vectors A cell array of character vectors inCustomSource. For example,cfg.CustomSource = {'mySrc1.c','mySrc2.c'};

CustomSourceCode — Code to appear near the top of the generated .c or .cpp files

' ' (default) | character vector

Specify code to appear near the top of each generated.c or .cpp file (exceptrtwhalf.c or rtwhalf.cpp), outside of any function. Specify code as a character vector.

Do not specify a C static function definition.

CustomTerminator — Code that appears in the generated terminate function

' ' (default) | character vector

Code that appears in the generated terminate function, specified as a character vector.

DeepLearningConfig — Configuration object for deep learning code generation

coder.MklDNNConfig object | coder.CuDNNConfig object | coder.TensorRTConfig object

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

Object Requires Description
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.CuDNNConfig (GPU Coder) Deep Learning ToolboxGPU CoderGPU 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 acoder.CuDNNConfig object, usecoder.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 ToolboxGPU CoderGPU 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 acoder.TensorRTConfig object, usecoder.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).

Note

MEX code generation is not supported for deep learning using the ARM® Compute Library.

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

DynamicMemoryAllocation — Dynamic memory allocation mode

'Threshold' (default) | 'AllVariableSizeArrays' | 'Off'

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

Value Description
'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 toDynamicMemoryAllocationThreshold.
'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:

See Generate Code for Variable-Size Data.

Note

DynamicMemoryAllocation configuration option will be removed in a future release. To dynamically allocation memory for variable-sized arrays, use theEnableDynamicMemoryAllocation option. To set the threshold, use theDynamicMemoryAllocationThreshold option.

DynamicMemoryAllocationForFixedSizeArrays — Dynamic memory allocation for fixed-size arrays

false (default) | true

Dynamic memory allocation for fixed-size arrays, specified as one of the values in this table.

Value Description
true The code generator allocates memory dynamically on the heap for fixed-size arrays whose size (in bytes) is greater than or equal toDynamicMemoryAllocationThreshold.
false This value is the default value.The code generator statically allocates memory for fixed-size arrays on the stack.

Dependency:

See, Control Dynamic Memory Allocation for Fixed-Size Arrays.

DynamicMemoryAllocationInterface — Dynamically allocated array at generated function interface

'Auto' (default) | 'C' | 'C++'

Implementation of dynamically allocated array at the interface of the generated C/C++ function, specified as one of the values in this table.

When using GPU Coder, the code generator always uses the C style emxArray data structure.

Dependency:

DynamicMemoryAllocationThreshold — Size threshold for dynamic memory allocation of variable-size arrays

65536 (default) | positive integer

Size threshold for dynamic memory allocation of fixed-size and variable-size arrays, specified as a positive integer. The code generator uses dynamic memory allocation for fixed-size and variable-size arrays whose size (in bytes) is greater than or equal to the threshold.

Dependency:

See Generate Code for Variable-Size Data.

EnableAutoParallelization — Automatic parallelization of for loops

false (default) | true

Automatic parallelization of for loops, specified as one of the values in this table.

Value Description
false This value is the default value.Code generator does not automatically parallelizefor loops.
true The code generator automatically parallelizesfor loops in the generated code. Automatic parallelization can significantly improve the execution speed of the generated code. See Automatically Parallelize for Loops in Generated Code.

When using GPU Coder, the code generator always enables automatic parallelization of for loops.

Data Types: logical

EnableAutoParallelizationReporting — Reporting for automatic parallelization of for loops

true (default) | false

Reporting for automatic parallelization of for loops, specified as one of the values in this table.

Value Description
true This value is the default value.If you set EnableAutoParallelization to true, the code generator produces a code generation report for automatic parallelization of for loops
false The code generator does not produce a code generation report for automatic parallelization offor loops.

EchoExpressions — Expression echoing

true (default) | false

Expression echoing, specified as one of the values in this table.

Value Description
true This value is the default value.The MEX function displays the output of statements that do not end with a semicolon.
false The MEX function does not display the output of statements that do not end with a semicolon.

This property does not apply to common visualization functions, such asdisp, plot, orfigure when they are called as an extrinsic function. MEX functions display the output of those functions regardless of the presence of a semicolon or the value ofEchoExpressions.

EnableAutoExtrinsicCalls — Automatic extrinsic function calls

true (default) | false

Automatic extrinsic function calls, specified as one of the values in this table.

Value Description
true This value is the default value.The code generator treats some common visualization functions as extrinsic functions. You do not have to declare these functions as extrinsic by using coder.extrinsic. This capability reduces the amount of time that you spend making your code suitable for code generation.
false The code generator does not treat common visualization functions as extrinsic functions unless you declare them as extrinsic by using coder.extrinsic.

Some common visualization functions are plot,disp, and figure. See Use MATLAB Engine to Execute a Function Call in Generated Code.

EnableDebugging — C compiler debugging mode

false (default) | true

C compiler debugging mode, specified as one of the values in this table.

Value Description
false This value is the default value.The code generator does not enable the C compiler debugging mode.
true The code generator enables the C compiler debugging mode. When debugging mode is enabled, the C compiler does not optimize the code. The compilation is faster, but the execution is slower.

EnableDynamicMemoryAllocation — Enable dynamic memory allocation for variable-size arrays

true (default) | false

Dynamic memory allocation for variable-size arrays, specified as one of the values in this table.

Value Description
true 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 toDynamicMemoryAllocationThreshold.
false The code generator statically allocates memory for variable-size arrays on the stack.

EnableImplicitExpansion — Implicit expansion capabilities in generated code

true (default) | false

Implicit expansion capabilities in the generated code, specified as one of the values listed in this table.

Value Description
true This value is the default value.The code generator enables implicit expansion in the generated code. The code generator includes modifications in the generated code to apply implicit expansion. See Compatible Array Sizes for Basic Operations.
false The generated code does not follow the rules of implicit expansion.

Data Types: logical

EnableJIT — Just-in-time (JIT) compilation mode

false (default) | true

Just-in-time (JIT) compilation mode, specified as one of the values in this table.

Value Description
false This value is the default value.The code generator creates a C/C++ MEX function by generating and compiling C/C++ code.
true The code generator uses just-in-time (JIT) compilation technology for MEX function generation. The code generator creates a JIT MEX function that contains an abstract representation of the MATLAB code. When you run the JIT MEX function, MATLAB generates the executable code in memory.

To speed up generation of MEX functions, set EnableJIT to true.

JIT compilation is incompatible with certain code generation features and options, such as custom code or use of the OpenMP library. If you specify JIT compilation and the code generator is unable to use it, it generates a C/C++ MEX function with a warning. If EnableJIT andEnableOpenMP are true, and your code uses parfor, the code generator uses JIT compilation and treats the parfor-loops asfor-loops.

See Speed Up MEX Generation by Using JIT Compilation.

EnableMemcpymemcpy optimization

true (default) | false

memcpy optimization, specified as one of the values in this table.

Value Description
true This value is the default value.If possible, the code generator uses thememcpy optimization. To optimize code that copies consecutive array elements, the memcpy optimization replaces the code with a memcpy call. When the number of elements to copy is known at compile time, the code generator uses theMemcpyThreshold property to determine whether to use the optimization. See memcpy Optimization.
false The code generator does not use thememcpy optimization.

When using GPU Coder, the code generator always disables Memcpy optimization.

EnableMexProfiling — Instrumentation for profiling

false (default) | true

Enabling profiling of generated MEX function, specified as one of the values in this table.

Value Description
false This value is the default value.The code generator does not include the instrumentation for profiling in the generated MEX function.
true The code generator includes the instrumentation for profiling in the generated MEX function. You can then use the MATLAB Profiler to profile the MEX. See Profile MEX Functions by Using MATLAB Profiler.

EnableOpenMP — Parallelization of parfor-loops

true (default) | false

Parallelization of parfor-loops, specified as one of the values in this table.

Value Description
true This value is the default value.If possible, the code generator uses the OpenMP library to produce loop iterations that run in parallel.
false The code generator treatsparfor-loops asfor-loops.

See parfor.

Use of the OpenMP library is not compatible with just-in-time (JIT) compilation. If EnableJIT andEnableOpenMP are true, the code generator uses JIT compilation and treats parfor-loops asfor-loops.

When using GPU Coder, the code generator always treats parfor-loops asfor-loops.

EnableRuntimeRecursion — Run-time recursion support

true (default) | false

Run-time recursion support, specified as one of the values in this table.

Value Description
true This value is the default value.Recursive functions are allowed in the generated code.
false Recursive functions are not allowed in the generated code.

Some coding standards, such as MISRA™, do not allow recursion. To increase the likelihood of generating code that is compliant with MISRA C™, set EnableRuntimeRecursion tofalse.

If your MATLAB code requires run-time recursion andEnableRuntimeRecursion is false, code generation fails.

See Code Generation for Recursive Functions.

EnableVariableSizing — Variable-size array support

true (default) | false

Variable-size array support, specified as one of the values in this table.

Value Description
true This value is the default value.Variable-size arrays are allowed for code generation.
false Variable-size arrays are not allowed for code generation.

Dependency:

See Code Generation for Variable-Size Arrays.

ExtrinsicCalls — Extrinsic function call support

true (default) | false

Extrinsic function call support, specified as one of the values in this table.

Value Description
true This value is the default value.For an extrinsic function, the code generator produces a call to a MATLAB function. The code generator does not generate the internal code for the function.
false The code generator ignores an extrinsic function. It does not generate code for the call to the MATLAB function. If the extrinsic function affects the output of the MATLAB function, the code generator issues a warning.If you setExtrinsicCalls tofalse, the generated MEX function cannot display run-time messages fromerror orassert statements in your MATLAB code. The MEX function reports that it cannot display the error message. To see the error message, set ExtrinsicCalls totrue and generate the MEX function again.

The value of ExtrinsicCalls affects how a MEX function generates random numbers for rand``, randi, andrandn. If ExtrinsicCalls istrue, the MEX function uses the MATLAB global random number stream to generate random numbers. Otherwise, the MEX function uses a self-contained random number generator.

See Use MATLAB Engine to Execute a Function Call in Generated Code.

FilePartitionMethod — File partitioning mode

'MapMFileToCFile' (default) | 'SingleFile'

File partitioning mode specified as one of the values in this table.

Value Description
'MapMFileToCFile' This value is the default value.The code generator produces separate C/C++ files for each MATLAB language file.
'SingleFile' The code generator produces a single file for C/C++ functions that map to your MATLAB entry-point functions. The code generator produces separate C/C++ files for utility functions.

See How MATLAB Coder Partitions Generated Code.

GenCodeOnly — Generation of only source code

false (default) | true

Generation of only source code, specified as one of the values in this table.

Value Description
false This value is the default value. The code generator produces C/C++ source code and builds object code.
true The code generator produces C/C++ source code, but does not invoke the make command or build object code. When you iterate between modifying MATLAB code and generating C/C++ code, generating only code can save time.

— Comments in generated code

true (default) | false

Comments in generated code, specified as one of the values in this table.

Value Description
true This value is the default value.The code generator places comments in the generated code.
false The code generator does not place comments in the generated code.

If you set GenerateComments to true, the code generator places default comments, such as inferred argument types, in the generated code. The code generator also copies code comments that you make inside your MATLAB functions into the generated code, with some exceptions. For example, the generated code generally does not include code comments from MATLAB functions that are removed due to internal optimizations.

If you generate code for a live function (.mlx file), the code generator does not include the text sections in the generated code, even if GenerateComments is set totrue. To include live function text sections as comments in the generated code, first save the .mlx file as a .m file, which converts the text sections to code comments within the function body. Because the code generator gives precedence to functions in .mlx files over those in.m files, you must rename one of the functions or move one of the files to a different folder. Then, generate code for the function in the .m file. The code generator includes the text sections as comments in the generated code.

GenerateReport — Code generation report

false (default) | true

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

Value Description
false This value is the default value.The code generator produces a report only if error or warning messages occur, or if you set LaunchReport totrue.
true The code generator produces a code generation report.

GlobalDataSyncMethod — Global data synchronization mode

'SyncAlways' (default) | 'SyncAtEntryAndExits' | 'NoSync'

Global data synchronization mode, specified as one of the values in this table.

Value Description for Global Data Description for Constant Global Data
'SyncAlways' (default) This value is the default value.Synchronizes global data at MEX function entry and exit and for extrinsic calls for maximum consistency between MATLAB and the generated MEX function. To maximize performance, if the extrinsic calls do not change global data, use this option with the coder.extrinsic -sync:off option to turn off synchronization for these calls. Verifies consistency of constant global data at MEX function entry and after extrinsic calls. If the global data values in the MATLAB global workspace are inconsistent with the compile-time constant global values in the MEX function, the MEX function ends with an error. Use the coder.extrinsic -sync:off option to turn off consistency checks after specific extrinsic calls.
'SyncAtEntryAndExits' Synchronizes global data at MEX function entry and exit only. To maximize performance, if only a few extrinsic calls change global data, use this option with thecoder.extrinsic -sync:on option to turn on synchronization for these calls. Verifies constant global data at MEX function entry only. If the global data values in the MATLAB global workspace are inconsistent with the compile-time constant global values in the MEX function, the MEX function ends with an error. Use the coder.extrinsic -sync:on option to turn on consistency checks after specific extrinsic calls.
'NoSync' Disables synchronization. Before disabling synchronization, verify that your MEX function does not interact with MATLAB global data. Otherwise, inconsistencies between MATLAB and the MEX function can occur. Disables consistency checks.

See Generate Code for Global Data.

GpuConfig — Configuration object for GPU code generation

GpuCodeConfig object

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

cfg = coder.gpuConfig('mex'); 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).

Dependencies: If GpuConfig is set,codegen modifies thecoder.MexCodeConfig properties to values in this table.

HighlightPotentialRowMajorIssues — Potential row-major layout issues

true (default) | false

Display of potential row-major layout efficiency issues, specified as one of the values in this table.

Value Description
true The code generation report displays potential efficiency issues due to row-major layout. (This value is the default value.)
false The code generation report does not display issues related to array layout.

See Code Design for Row-Major Array Layout.

InitFltsAndDblsToZero — Assignment of float and double zero with memset

true (default) | false

Assignment of float and double zero with memset, specified as one of the values in this table.

Value Description
true This value is the default value.If possible, the code generator uses thememset optimization for assignment of floating-point zero to consecutive array elements. To assign consecutive array elements, the memset optimization uses a memset call. When the number of elements to assign is known at compile time, the code generator uses theMemcpyThreshold property to determine whether to use the optimization. See memset Optimization.
false The code generator does not use thememset optimization for assignment of float and double zero to consecutive array elements.

InlineBetweenMathWorksFunctions — Control inlining between MathWorks functions

'Speed' (default) | 'Always' | 'Readability' | 'Never'

Inlining behavior at all call sites where a MathWorks calls another MathWorks function, specified as one of the values in this table.

Value Description
'Speed' This value is the default value.Uses internal heuristics to determine whether to perform inlining at a call site. This setting usually leads to highly optimized code.
'Always' Always performs inlining at a call site.
'Readability' Almost never inlines function calls, except for calls to very small functions. Preserves modularity of code without sacrificing too much speed, whenever possible. Results in highly readable code.
'Never' Never inlines function calls. Results in maximum readability. This setting might significantly reduce the performance of the generated code.

Even if you select the 'Always' or the'Never' option for a setting, in certain cases, the code generator might not strictly follow that instruction. For example, if there is a conflict, the coder.inline('always') orcoder.inline('never') directive placed inside a function body overrides this option. For more information, see Control Inlining to Fine-Tune Performance and Readability of Generated Code.

InlineBetweenUserAndMathWorksFunctions — Control inlining between user-written functions and MathWorks functions

'Speed' (default) | 'Always' | 'Readability' | 'Never'

Inlining behavior at all call sites where a function that you wrote calls a MathWorks function, or a MathWorks function calls a function that you wrote. Specified as one of the values in this table.

Value Description
'Speed' This value is the default value.Uses internal heuristics to determine whether to perform inlining at a call site. This setting usually leads to highly optimized code.
'Always' Always performs inlining at a call site.
'Readability' Almost never inlines function calls, except for calls to very small functions. Preserves modularity of code without sacrificing too much speed, whenever possible. Results in highly readable code.
'Never' Never inlines function calls. Results in maximum readability. This setting might significantly reduce the performance of the generated code.

Even if you select the 'Always' or the'Never' option for a setting, in certain cases, the code generator might not strictly follow that instruction. For example, if there is a conflict, the coder.inline('always') orcoder.inline('never') directive placed inside a function body overrides this option. For more information, see Control Inlining to Fine-Tune Performance and Readability of Generated Code.

InlineBetweenUserFunctions — Control inlining between user-written functions

'Speed' (default) | 'Always' | 'Readability' | 'Never'

Inlining behavior at all call sites where a function that you wrote calls another function that you wrote, specified as one of the values in this table.

Value Description
'Speed' This value is the default value.Uses internal heuristics to determine whether to perform inlining at a call site. This setting usually leads to highly optimized code.
'Always' Always performs inlining at a call site.
'Readability' Almost never inlines function calls, except for calls to very small functions. Preserves modularity of code without sacrificing too much speed, whenever possible. Results in highly readable code.
'Never' Never inlines function calls. Results in maximum readability. This setting might significantly reduce the performance of the generated code.

Even if you select the 'Always' or the'Never' option for a setting, in certain cases, the code generator might not strictly follow that instruction. For example, if there is a conflict, the coder.inline('always') orcoder.inline('never') directive placed inside a function body overrides this option. For more information, see Control Inlining to Fine-Tune Performance and Readability of Generated Code.

IntegrityChecks — Memory integrity checking

true (default) | false

Memory integrity checking, specified as one of the values in this table.

Value Description
true This value is the default value.The generated code detects memory integrity violations and stops execution with a diagnostic message.
false The generated code does not detect memory integrity violations. SettingIntegrityChecks tofalse can improve performance. However, without memory integrity checks, violations result in unpredictable behavior. SetIntegrityChecks tofalse only if you have verified that array bounds checking and dimension checking are unnecessary. SettingIntegrityChecks tofalse also disables the run-time stack.

See Control Run-Time Checks.

LargeConstantGeneration — Whether to write large deep learning constants to binary data files

'WriteOnlyDNNConstantsToDataFiles' (default) | 'KeepInSourceFiles'

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 one of the values in the following table. To specify the threshold (in bytes) above which the DNN constants are written to binary data files, set the LargeConstantThreshold property. The default value of this property is131072.

This property is applicable only if you generate code that does not depend on third-party deep learning libraries.

Value Description
'WriteOnlyDNNConstantsToDataFiles' This value is the default value.The code generator writes large constants for a deep neural network (DNN) in binary data files.
'KeepInSourceFiles' The code generator embeds large constants for a deep neural network (DNN) in the generated source code.

The generated binary data files are located in the code generation folder and are loaded by the generated code at run time. If you relocate these files, set the environment variable CODER_DATA_PATH to this new location before running the generated code.

The code generator always embeds the non-DNN constants in the generated source code, irrespective of the sizes of these constants.

Dependency:

LargeConstantThreshold — Threshold above which the code generator writes DNN constants to binary data files

131072 (default) | integer

The LargeConstantThreshold property specifies the threshold (in bytes) above which the constants for a deep neural network (DNN) are written to binary data files. The code generator by default sets this threshold to 131072 bytes. Depending on your application, you can set this threshold to a different integer value.

This property is applicable only if you generate code that does not depend on third-party deep learning libraries.

Dependencies: To enable this property, perform both these actions.

LaunchReport — Automatic open of code generation report

false (default) | true

Automatic open of code generation report, specified as one of the values in this table.

Value Description
false This value is the default value.If errors or warnings occur, or ifGenerateReport istrue, the code generator produces a report, but does not open the report.
true The code generator produces and opens a code generation report.

— Inclusion of MATLAB source code as comments in generated code

false (default) | true

Inclusion of MATLAB source code as comments in generated code, specified as one of the values in this table.

Value Description
false This value is the default value.The code generator does not insert MATLAB source code as comments in the generated code. The code generator does not include the MATLAB function signature in the function banner.
true The code generator inserts MATLAB source code as comments in the generated code. A traceability tag immediately precedes each line of source code. The traceability tag helps you to locate the corresponding MATLAB source code. See Tracing Generated C/C++ Code to MATLAB Source Code.The code generator also includes the MATLAB function signature in the function banner.

Dependency:

See Tracing Generated C/C++ Code to MATLAB Source Code.

MemcpyThreshold — Minimum size for memcpy or memset optimization

64 (default) | positive integer

Minimum size, in bytes, for memcpy or memset optimization, specified as a positive integer.

To optimize generated code that copies consecutive array elements, the code generator tries to replace the code with a memcpy call. To optimize generated code that assigns a literal constant to consecutive array elements, the code generator tries to replace the code with a memset call.

The number of bytes is the number of array elements to copy or assign multiplied by the number of bytes required for the C/C++ data type.

If the number of elements to copy or assign is variable (not known at compile time), the code generator ignores theMemcpyThreshold property.

See memcpy Optimization and memset Optimization.

Name — Object name

'MexCodeConfig' (default) | character vector

Object name, specified as a character vector.

OptimizeReductions — Generate SIMD code for reduction operations | Parallelize for-loops performing reduction operations

'false' (default) | 'true'

To generate SIMD code for reduction operations, use one of the values as specified in this table.

Value Description
false This value is the default value.Code generator does not generate SIMD code for reduction operations.
true To use this parameter, you must select an instruction set for theInstructionSetExtensions parameter. The code generator uses the specified instruction set to generate SIMD code for reduction operations.

See Generate SIMD Code from MATLAB Functions for Intel Platforms.

To generate parallel for-loops performing reduction operations, use one of the values as specified in this table.

Value Description
false This value is the default value.Code generator does not automatically parallelizefor-loops performing reduction operations.
true The code generator automatically parallelizesfor-loops performing reduction operations in the generated code, only if you setEnableAutoParallelization totrue.

See Reduction Operations Supported for Automatic Parallelization of for-loops.

PostCodeGenCommand — Command to customize build processing

'' (default) | character vector

Command to customize build processing after MEX function generation withcodegen, specified as a character vector.

See Build Process Customization.

PreserveArrayDimensions — N-dimensional indexing

false (default) | true

Generation of code that uses N-dimensional indexing, specified as one of the values in this table.

Value Description
false Generate code that uses one-dimensional indexing. (This value is the default value.)
true Generate code that uses N-dimensional indexing.

See Generate Code That Uses N-Dimensional Indexing.

PreserveVariableNames — Variable names to preserve in the generated code

'None' (default) | 'UserNames' | 'All'

Variable names to preserve in the generated code, specified as one of the values in this table.

Value Description
'None' This value is the default value.The code generator does not have to preserve any variable names. It can reuse any variables that meet the requirements for variable reuse.If your code uses large structures or arrays, settingPreserveVariableNames to'None' can reduce memory usage or improve execution speed.
'UserNames' The code generator preserves names that correspond to variables that you define in the MATLAB code. It does not replace your variable name with another name and does not use your name for another variable. To improve readability, setPreserveVariableNames to'UserNames'. Then, you can more easily trace the variables in the generated code back to the variables in your MATLAB code.SettingPreserveVariableNames to'UserNames' does not prevent an optimization from removing your variables from the generated code or prevent the C/C++ compiler from reusing the variables in the generated binary code.
'All' Preserve all variable names. This parameter value disables variable reuse. Use it only for testing or debugging, not for production code.

See Preserve Variable Names in Generated Code.

ReportInfoVarName — Name of variable containing code generation report information

'' (default) | character vector

Name of variable to which you export information about code generation, specified as a character vector. The code generator creates this variable in the base MATLAB workspace. This variable contains information about code generation settings, input files, generated files, and code generation messages.

See Access Code Generation Report Information Programmatically andcoder.ReportInfo Properties.

ReportPotentialDifferences — Potential differences reporting

true (default) | false

Potential difference reporting, specified as one of the values in this table:

Value Description
true The code generator reports potential behavior differences between generated code and MATLAB code. The potential differences are listed on a tab of the code generation report. A potential difference is a difference that occurs at run time only under certain conditions.
false The code generator does not report potential differences.

See Potential Differences Reporting.

ReservedNameArray — Names that the code generator cannot use for functions or variables

'' (default) | string array | cell array of character vectors | character vector

List of names that the code generator must not use for functions or variables, specified as a string arrays, cell array of character vectors, or character vector.

Multiple reserved names, specified as one of the values in this table.

Value Description
String arrays A string array inReservedNameArray. For example,cfg.ReservedNameArray = ["reserve1","reserve2","reserve3"].
Cell array of character vectors A cell array of character vectors inReservedNameArray. For example,cfg.ReservedNameArray = {'reserve1','reserve2','reserve3'}.
Character vectors A semicolon-separated list of reserved names inReservedNameArray. For example,cfg.ReservedNameArray = 'reserve1;reserve2;reserve3'.NoteSpecifying multiple entries in code configuration objects by using character vectors will be removed in a future release. Use string array and cell array of character vector instead. For more information, see Compatibility Considerations.

ResponsivenessChecks — Responsiveness checks

true (default) | false

Responsiveness checks, specified as one of the values in this table.

Value Description
true This value is the default value.You can useCtrl+C to stop execution of a generated MEX function.
false To end a long-running MEX function, you might have to terminate MATLAB.

When using GPU Coder, the code generator always disables this parameter.

See Control Run-Time Checks.

RowMajor — Row-major array layout

false (default) | true

Generation of code that uses row-major array layout, specified as one of the values in this table.

Value Description
false Generate code that uses column-major array layout. (This value is the default value.)
true Generate code that uses row-major array layout.

See Generate Code That Uses Row-Major Array Layout.

SaturateOnIntegerOverflow — Integer overflow support

true (default) | false

Integer overflow support, specified as one of the values in this table.

Value Description
true This value is the default value.The code generator produces code to handle integer overflow. Overflows saturate to either the minimum or maximum value that the data type can represent.
false The code generator does not produce code to handle integer overflow. Do not setSaturateOnIntegerOverflow tofalse unless you are sure that your code does not depend on integer overflow support. If you disable integer overflow support and integrity checks are enabled, the generated code produces an error for overflows. If you disable integer overflow support and you disable integrity checks, the overflow behavior depends on your target C compiler. In the C standard, the behavior for integer overflow is undefined. However, most C compilers wrap on overflow.

This parameter applies only to MATLAB built-in integer types. It does not apply to doubles, singles, or fixed-point data types.

See Disable Support for Integer Overflow or Nonfinites.

SIMDAcceleration — Level of SIMD intrinsics

'Portable' (default) | 'Full' | 'None'

Level of SIMD intrinsics to use to accelerate vector operations. MATLAB Coder checks your specified hardware and compiler and uses the compatible intrinsics up to the level that you specify according to this table.

Value Instruction Sets
'Full' AVX2
'Portable' SSE2
'None' No instructions sets are used.

You can generate SIMD code for Intel and AMD platforms. If you generate code for a different platform, the code does not contain SIMD intrinsics.

StackUsageMax — Maximum stack usage per application

200000 (default) | positive integer

Maximum stack usage per application, in bytes, specified as a positive integer. Set a limit that is lower than the available stack size. Otherwise, a run-time stack overflow might occur. The C compiler detects and reports stack overflows.

See Control Stack Space Usage.

TargetLang — Language to use in generated code

'C' (default) | 'C++'

Language to use in generated code, specified as 'C' or'C++'.

When using GPU Coder, the code generator sets TargetLang toC++.

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

UsePrecompiledLibraries — Whether to use precompiled libraries in generated code

'Prefer' | 'Avoid'

Since R2024b

Extent to which the generated code uses platform-specific precompiled libraries, specified as one of the values in this table.

Value Instruction Sets
'Prefer' For C/C++ code generation, this value is the default value.The code generator prefers to use the available platform-specific precompiled libraries.This setting is an appropriate choice when you want to optimize the performance of the generated code for specific platforms.
'Avoid' For CUDA code generation (requires GPU Coder), this value is the default value.The code generator uses platform-specific precompiled libraries only if no alternative implementations of their algorithms are available.This setting is useful when you want to emulate the run-time behavior of portable standalone generated code inside the MATLAB environment.

Verbosity — Code generation progress display

'Info' (default) | 'Silent' | 'Verbose'

Whether to display the status of the code generation progress at the MATLAB command line, specified as one of the values in this table.

Value Description
'Silent' If code generation succeeds without warning, all messages are suppressed, including when you generate a report.Warning and error messages are displayed.
'Info' This value is the default value.Compared to the'Silent' mode, if code generation succeeds, these additional messages are displayed:Code generation successfulLink to the generated report, if one has been generated
'Verbose' In addition to the messages shown in the'Info' mode, code generation status and target build log messages are displayed.

Examples

collapse all

Specify Configuration Parameters for MEX Function Generation

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 MEX function generation.

cfg = coder.config('mex');

Change the values of the properties for which you do not want to use the default values. For example, enable just-in-time (JIT) compilation.

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 parameter values for MEX function generation, instead of creating a configuration object, you can call codegen without specifying a configuration object or with the -config:mex option.

Version History

Introduced in R2011a

expand all

R2024b: UsePrecompiledLibraries Property Added

New property UsePrecompiledLibraries allows you to specify the extent to which the generated code uses platform-specific precompiled libraries.

R2024a: Using Quotes to Specify a Single Filename or Path That Contains White Spaces has been Removed

If you try to use quotes to specify a single filename or path that contains white space (for example, '"folder1\folder2\sp ace\fun3.c"') for theCustomInclude, CustomLibrary, andCustomSource code configuration parameters, the code generator produces an error.

R2023b: Specifying Multiple Entries in Code Configuration Objects by Using Character Vector Errors

Specifying multiple file names, paths, or reserved names in code configuration objects by using character vectors or string scalars that have delimiters produces an error. Use string arrays and a cell array of character vector instead. For example, to include multiple folder names, you can use either a string array inCustomInclude as cfg.CustomInclude = ["C:\Project","C:\Custom Files"]; or a cell array of character vectors as cfg.CustomInclude = {'C:\Project','C:\Custom Files'}; to include the path for compiling the generated code.

R2023b: Using Quotes to Specify Single Filename or Path That Contains White Spaces Warns

Using quotes to specify a single filename or path that contains white spaces (for example, '"sp ace/fun3.c"') for theCustomInclude, CustomLibrary, andCustomSource code configuration properties produces a warning and will be removed in a future release.

R2023a: DynamicMemoryAllocation Property To Be Removed

In a future release, the DynamicMemoryAllocation property will be removed.

To dynamically allocate memory for variable-size arrays, use theEnableDynamicMemoryAllocation property. To configure the dynamic memory allocation threshold, useDynamicMemoryAllocationThreshold property.

R2022b: Capability to Specify Multiple Entries in Code Configuration Objects by Using Character Vector Warns

Specifying multiple file names, paths, or reserved names in code configuration objects by using character vectors or string scalars that have delimiters produces a warning and will be removed in a future release. Use string arrays and a cell array of character vector instead. For example, to include multiple folder names, you can use either a string array in CustomInclude ascfg.CustomInclude = ["C:\Project","C:\Custom Files"]; or a cell array of character vectors as cfg.CustomInclude = {'C:\Project','C:\Custom Files'}; to include the path for compiling the generated code.

R2021a: Capability to Specify Multiple Entries in Code Configuration Objects by Using Character Vector Will Be Removed

In a future release, specifying multiple file names, paths, or reserved names in code configuration objects by using character vectors or string scalars that have delimiters will be removed. Use string arrays and a cell array of character vector instead. For example, to include multiple folder names, you can use either a string array in CustomInclude as cfg.CustomInclude = ["C:\Project","C:\Custom Files"]; or a cell array of character vectors as cfg.CustomInclude = {'C:\Project','C:\Custom Files'}; to include the path for compiling the generated code.