coder.MexCodeConfig
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.
Creation
Create a coder.MexCodeConfig
object by using the coder.config
function.
Once you create a coder.MexCodeConfig
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
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.
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.
Constant input checking mode, specified as
'CheckValues'
or 'IgnoreValues'
.
For more information, see Constant
inputs.
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.
Namespace for the generated C++ code, specified as a character vector. For more information, see C++ namespace.
Place 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.
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.
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.
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 |
| A 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) |
| A 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) |
| A 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
to
C++
.
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 to
|
'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 theDynamicMemoryAllocationThreshold
parameter.
See Generate Code for Variable-Size Arrays.
Note
DynamicMemoryAllocation
configuration option
will be removed in a future release. To dynamically allocation
memory for variable-sized arrays, use the
EnableDynamicMemoryAllocation
option. To set
the threshold, use the
DynamicMemoryAllocationThreshold
option.
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.
Expression echoing, specified as true
or
false
. For more information, see Echo
expressions without terminating semicolons.
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.
C compiler debugging mode, specified as false
or
true
. For more information, see Enable
C/C++ compiler debug mode.
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.
Just-in-time (JIT) compilation mode, specified as false
or true
. For more information, see Use JIT
compilation for build type of MEX.
memcpy
optimization, specified as true
or false
. For more information, see Use
memcpy for vector assignment.
Instrumentation for profiling of generated MEX function, specified as
false
or true
. For more
information, see Enable
execution profiling.
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.
Extrinsic function call support, specified as true
or
false
. For more information, see Keep
extrinsic calls.
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.
Code generation report, specified false
or
true
. For more information, see Always
create a report.
Global data synchronization mode, specified as
'SyncAlways'
,
'SyncAtEntryAndExits'
, or
'NoSync'
. For more information, see Global
data synchronization mode.
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('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).
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).
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.
Memory integrity checking, specified as true
or
false
. For more information, see Check
memory integrity.
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.
Inclusion of MATLAB source code as comments in generated code, specified
true
or false
. For more
information, see MATLAB
source code as comments.
Minimum size for memcpy or memset optimization in bytes, specified as a positive integer. For more information, see Memcpy threshold (bytes).
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.
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.
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.
Responsiveness checks, specified as true
or
false
. For more information, see Enable
responsiveness to CTRL+C and graphics refreshing.
Row-major array layout for the generated code, specified
false
or true
. For more
information, see Array
layout.
Integer overflow support, specified true
or
false
. For more information, see Saturate
on integer overflow.
Level of SIMD intrinsics to use to accelerate vector operations, specified
as 'Portable'
, 'Full'
, or
'None'
. For more information, see Hardware
SIMD acceleration.
Maximum stack usage per application in bytes, specified as a positive integer. For more information, see Stack usage max.
Language to use in generated code, specified as 'C'
or
'C++'
. For more information, see Language.
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 at the MATLAB command line, specified as 'Info'
,
'Silent'
, or 'Verbose'
. For more
information, see Show
verbose compiler output.
Examples
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.
cfg.EnableJIT = 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 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 R2011aNew property UsePrecompiledLibraries
allows you to specify the
extent to which the generated code uses platform-specific precompiled
libraries.
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 the
CustomInclude
, CustomLibrary
, and
CustomSource
code configuration parameters, the code
generator produces an error.
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 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.
Using quotes to specify a single filename or path that contains white spaces (for
example, '"sp ace/fun3.c"'
) for the
CustomInclude
, CustomLibrary
, and
CustomSource
code configuration properties produces a warning
and will be removed in a future release.
In a future release, the DynamicMemoryAllocation
property will
be removed.
To dynamically allocate memory for variable-size arrays, use the
EnableDynamicMemoryAllocation
property. To configure the
dynamic memory allocation threshold, use
DynamicMemoryAllocationThreshold
property.
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
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.
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.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)