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

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.

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

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. 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 (exceptrtwhalf.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 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 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 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++.

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 Arrays.

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.

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.

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

Instrumentation for profiling of generated MEX function, specified asfalse or true. For more information, see Enable execution profiling.

Extrinsic function call support, specified as true orfalse. For more information, see Keep extrinsic calls.

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

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

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).

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 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**.

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 ortrue. For more information, see Optimize reductions.

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

Generation of code that uses N-dimensional indexing, specifiedfalse 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.

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, specifiedfalse or true. For more information, see Array layout.

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

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 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

New 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 theCustomInclude, CustomLibrary, andCustomSource 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 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.

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.

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.

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.

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.