coder.CodeConfig - Configuration parameters for C/C++ code generation from MATLAB code - MATLAB (original) (raw)

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

Description

Acoder.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 thecodegen function by using the -config option.

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.

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.

Name of interface class when you generate C++ code withCppInterfaceStyle 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.

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

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

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.

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

Object description, specified as a character vector.

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

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

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.

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.

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, specifiedtrue or false. For more information, see Generate makefile.

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('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:

Note:

Hardware implementation object that specifies hardware-specific configuration parameters for C/C++ code generation. coder.config creates acoder.CodeConfig object with theHardwareImplementation 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 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**.

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

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

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.

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

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.

Since R2024b

Whether to protect entry-point input data from modification when the generated code is called from your custom C/C+ code, specified asfalse 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.

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.

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.

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

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

Value Description
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 thecodegen option -config:lib,-config:dll, or -config:exe, respectively. Then, you do not have to create and pass a configuration object tocodegen.

Version History

Introduced in R2011a

expand all

The default setting for theInlineBetweenUserAndMathWorksFunctions code configuration option is now 'Readability'.

In addition to C++03 (ISO) and C++11 (ISO), the code generator can generate C++ code compatible with C++14 (ISO), C++17 (ISO), and C++20 (ISO).

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

New property PreserveInputData allows you to generate code that protects entry-point input data from modification when the generated code is called from your custom C/C++ code.

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.

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

To configure the code generation progress display, use theVerbosity property.