Use precompiled libraries
Whether to use precompiled libraries in generated code
Since R2024b
Description
App Configuration Pane: Custom Code
Configuration Objects: coder.MexCodeConfig | coder.CodeConfig | coder.EmbeddedCodeConfig
The Use precompiled libraries parameter specifies the extent to which the generated code uses platform-specific precompiled libraries.
If you want to optimize the performance of the generated code for a specific platform, instruct the code generator to prefer to use precompiled libraries when available.
If you want to create portable applications that can run on many platforms, instruct the code generator to avoid using precompiled libraries if alternative implementations of their algorithms are available.
For certain precompiled libraries (for example, BLAS, LAPACK, and FFTW), there exist individual configuration parameters that allow you to customize their usage. The Use precompiled libraries parameter does not affect the use of these libraries.
Settings
Prefer precompiled libraries when availableThe code generator prefers to use the available platform-specific precompiled libraries. For C/C++ code generation, this is the default value.
Avoid precompiled libraries when possibleThe code generator uses platform-specific precompiled libraries only if no alternative implementations of their algorithms are available. For CUDA® code generation (requires GPU Coder™), this is the default value.
Programmatic Use
Property:
UsePrecompiledLibraries |
Values: 'Prefer' |
'Avoid' |
Default: 'Prefer' |
Examples
Generate Portable Code for Image Filtering Algorithm
This example shows how you can use the
UsePrecompiledLibraries code configuration property to
generate portable code for an image processing function. This example requires the
Image Processing Toolbox™.
Create a MATLAB® entry-point function
libraryUsageTestthat uses theimfilter(Image Processing Toolbox) function to filter an input image.function filteredImage = libraryUsageTest(unfilteredImage) h = [-1 0 1]; filteredImage = imfilter(unfilteredImage,h); end
Generate a static C library for the
libraryUsageTestfunction. Specify a code configuration object with theInstructionSetExtensionsproperty set to'None'. This setting disables the generation of hardware-specific single instruction, multiple data (SIMD) code. Specify the type of the input argument to be an 8-by-8 array of doubles.cfg = coder.config("lib"); cfg.InstructionSetExtensions = "None"; codegen -config cfg libraryUsageTest -args {zeros(8)} -report
Inspect the generated C function
imfilter. This last line of this function contains a call to the precompiled libraryippfilter_real64.void imfilter(const double varargin_1[64], double b[64]) { double aTmp[80]; int i; for (i = 0; i < 8; i++) { aTmp[i] = 0.0; aTmp[i + 72] = 0.0; memcpy(&aTmp[i * 8 + 8], &varargin_1[i * 8], 8U * sizeof(double)); } double kernel[3]; double kernelSizeT[2]; double outSizeT[2]; double padSizeT[2]; outSizeT[0] = 8.0; padSizeT[0] = 8.0; outSizeT[1] = 8.0; padSizeT[1] = 10.0; kernel[0] = -1.0; kernel[1] = 0.0; kernel[2] = 1.0; kernelSizeT[0] = 1.0; kernelSizeT[1] = 3.0; ippfilter_real64(&aTmp[0], &b[0], &outSizeT[0], 2.0, &padSizeT[0], &kernel[0], &kernelSizeT[0], false); }To generate code that contains a portable implementation of the image filtering algorithm as C source code, in the code configuration object
cfg, set theUsePrecompiledLibrariesproperty to"Avoid".cfg.UsePrecompiledLibraries = "Avoid"; codegen -config cfg libraryUsageTest -args {zeros(8)} -report
Inspect the generated C function
imfilter. This function does not contain calls to precompiled libraries.void imfilter(const double varargin_1[64], double b[64]) { double a_padded[80]; int b_i; int i; int jb; for (i = 0; i < 8; i++) { a_padded[i] = 0.0; a_padded[i + 72] = 0.0; memcpy(&a_padded[i * 8 + 8], &varargin_1[i * 8], 8U * sizeof(double)); } memset(&b[0], 0, 64U * sizeof(double)); for (i = 0; i < 8; i++) { int cColOffset; cColOffset = i << 3; for (jb = 0; jb < 3; jb++) { int ia; ia = (i + jb) << 3; for (b_i = 0; b_i < 8; b_i++) { int b_tmp; b_tmp = cColOffset + b_i; b[b_tmp] += (-(2.0 - (double)jb) + 1.0) * a_padded[ia + b_i]; } } } }
Version History
Introduced in R2024b