Main Content

fxpOptimizationOptions Class

Specify options for data type optimization

Description

The fxpOptimizationOptions object enables you to specify options and constraints to use during the data type optimization process using fxpopt.

Creation

options = fxpOptimizationOptions() creates an fxpOptimizationOptions object with default values.

options = fxpOptimizationOptions('PropertyName',PropertyValue) creates an fxpOptimizationOptions object with specified property name-value pairs.

Properties

expand all

Maximum number of iterations to perform, specified as a nonnegative scalar integer. The optimization process iterates through different solutions until it finds an ideal solution, reaches the maximum number of iterations, or reaches another stopping criteria.

Example: options.MaxIterations = 75;

Example: options = fxpOptimizationOptions('MaxIterations',75);

Data Types: double

Maximum amount of time for the optimization to run, in seconds, specified as a nonnegative scalar. The optimization runs until it reaches the time specified, finds an ideal solution, or reaches another stopping criteria.

Example: options.MaxTime = 1000;

Example: options = fxpOptimizationOptions('MaxTime',1000);

Data Types: double

Maximum number of iterations where no new best solution is found, specified as a scalar integer. The optimization continues as long as the algorithm continues to find new best solutions.

Example: options.Patience = 15;

Example: options = fxpOptimizationOptions('Patience',15);

Data Types: double

The level of information displayed at the command line during the optimization process, specified as one of these values:

  • 'High' — Information is displayed at the command line at each iteration of the optimization process, including whether a new best solution was found and the cost of the solution.

  • 'Moderate' — Information is displayed at each major step of the optimization process, including when the process is in the preprocessing, modeling, and optimization phases.

  • 'Silent' — Nothing is displayed at the command line until the optimization process is finished.

Example: options.Verbosity = 'Moderate';

Example: options = fxpOptimizationOptions('Verbosity','Moderate');

Data Types: char | string

Specify the word lengths that can be used in your optimized system under design. Use this property to target the neighborhood search of the optimization process. The final result of the optimization uses word lengths in the intersection of the AllowableWordLengths and word lengths compatible with hardware constraints specified in the Hardware Implementation pane of your model.

Example: options.AllowableWordLengths = [8:11,16,32];

Data Types: double

Objective function to use during optimization search, specified as one of these values:

  • 'BitWidthSum' — Minimize total bit width sum.

  • 'OperatorCount' — Minimize estimated count of operators in generated C code.

    This option may result in a lower program memory size for C code generated from Simulink® models. The 'OperatorCount' objective function is not suitable for FPGA or ASIC targets.

    Note

    To use 'OperatorCount' as the objective function during optimization, the model must be ready for code generation. For more information about determining code generation readiness, see Check Model and Configuration for Code Generation (Embedded Coder).

Example: options.ObjectiveFunction = 'OperatorCount';

Data Types: char | string

Whether to run iterations of the optimization in parallel, specified as a logical 0 (false) or 1 (true). Running the iterations in parallel requires a Parallel Computing Toolbox™ license. If you do not have a Parallel Computing Toolbox license, or if you specify 0 (false), the iterations run in serial.

Example: options.UseParallel = 1;

Data Types: logical

Additional advanced options for optimization. AdvancedFxpOptimizationOptions is an object containing additional properties that can affect the optimization.

PropertyDescription
PerformNeighborhoodSearch
  • 1 (default) — Perform a neighborhood search for the optimized solution.

  • 0 — Do not perform a neighborhood search. Selecting this option can increase the speed of the optimization process, but also increases the chances of finding a less ideal solution.

EnforceLooseCoupling

Some Simulink blocks have a parameter that forces inputs to share a data type, or forces the output to share the same data type as the input.

  • 1 (default) — Allow the optimizer to relax this restriction on all blocks in the system under design. Relaxing this restriction enables the optimizer to provide better fitting data types.

  • 0 — Do not allow the optimizer to relax this restriction on blocks in the system under design.

UseDerivedRangeAnalysis
  • 0 (default) — The optimizer does not consider ranges derived from design ranges in the model when assessing a solution.

  • 1 — The optimizer considers both observed simulation ranges and ranges derived from design ranges in the model when assessing a solution.

Depending on the model configuration, derived range analysis may take longer than simulation of the model.

SimulationScenariosDefine additional simulation scenarios to consider during optimization using a Simulink.SimulationInput object. For an example, see Optimize Data Types Using Multiple Simulation Scenarios.
SafetyMargin

Enter a safety margin, specified as a nonnegative scalar value indicating the percentage increase in the bounds of the collected range. The safety margin is applied to the union of all collected ranges, including simulation ranges, derived ranges, and design ranges.

DataTypeOverride

Override data types specified in the model when simulating during the range collection phase of optimization.

  • 'Off' (default) — Do not override data types.

  • 'Single' — Override data types with singles.

  • 'Double' — Override data types with doubles.

  • 'ScaledDouble' — Override data types with scaled doubles.

HandleUnsupported

Some blocks are not supported for fixed-point conversion. Specify how the optimizer handles unsupported blocks.

  • 'Isolate' (default) — Isolate unsupported blocks with Data Type Conversion blocks. Isolated blocks are ignored by the optimizer.

  • 'Error' — Stop optimization and report an error when the system contains blocks that are not supported for fixed-point conversion.

  • 'Warn' — Warn when the system contains blocks that are not supported for fixed-point conversion. Ignore unsupported blocks and continue optimization. This option allows you to manually replace unsupported constructs with other solutions, such as lookup tables, after optimization is complete.

  • In R2024b: 'ReplaceLUT' — Automatically replace unsupported blocks with an optimized lookup table approximation. You must specify design minimum and maximum values upstream of the unsupported block.

For more information, see Blocks That Do Not Support Fixed-Point Data Types.

PerformSlopeBiasCancellation
  • 0 (default) — Do not propagate slope-bias data types.

  • 1 — Propagate slope-bias data types from outside the system under design. Slopes and biases are chosen to reduce the complexity of generated code.

InstrumentationContext[model '/Subsystem'] — Restrict instrumentation for minimum, maximum, and overflow logging for the range collection step of optimization to a subsystem. The subsystem must be under the top-level model and contain the system under design.

Example: options.AdvancedOptions.PerformNeighborhoodSearch = 0;

Methods

expand all

Examples

collapse all

Create an fxpOptimizationObject with default property values.

options = fxpOptimizationOptions();

Edit the properties after creation using dot syntax.

options.Patience = 15;
options.AllowableWordLengths = [8,16,32];
options.AdvancedOptions.UseDerivedRangeAnalysis = true
options = 
  fxpOptimizationOptions with properties:

           MaxIterations: 50
                 MaxTime: 600
                Patience: 15
               Verbosity: High
    AllowableWordLengths: [8 16 32]
       ObjectiveFunction: BitWidthSum
             UseParallel: 0

   Advanced Options
         AdvancedOptions: [1x1 DataTypeOptimization.AdvancedFxpOptimizationOptions]

Use property name-value pairs to set properties at object creation.

options = fxpOptimizationOptions('Patience',15,'AllowableWordLengths',[8,16,32])
options = 
  fxpOptimizationOptions with properties:

           MaxIterations: 50
                 MaxTime: 600
                Patience: 15
               Verbosity: High
    AllowableWordLengths: [8 16 32]
       ObjectiveFunction: BitWidthSum
             UseParallel: 0

   Advanced Options
         AdvancedOptions: [1x1 DataTypeOptimization.AdvancedFxpOptimizationOptions]

Specify advanced options.

options.AdvancedOptions.UseDerivedRangeAnalysis = 1
options = 
  fxpOptimizationOptions with properties:

           MaxIterations: 50
                 MaxTime: 600
                Patience: 15
               Verbosity: High
    AllowableWordLengths: [8 16 32]
       ObjectiveFunction: BitWidthSum
             UseParallel: 0

   Advanced Options
         AdvancedOptions: [1x1 DataTypeOptimization.AdvancedFxpOptimizationOptions]

You can import an fxpOptimizationOptions object into the Fixed-Point Tool to perform data type optimization in the app. By importing an fxpOptimizationOptions object rather than specifying settings manually in the app, you can easily save and restore your settings.

Open the model.

model = 'ex_controllerHarness';
open_system(model);

To specify options for the optimization, such as the allowable word length and number of iterations, use the fxpOptimizationOptions object.

options = fxpOptimizationOptions('AllowableWordLengths',[2:32],...
    'MaxIterations',3e2,...
    'Patience',50);

Open the Fixed-Point Tool with the Controller subsystem selected.

fxptdlg('ex_controllerHarness/Controller')

In the Fixed-Point Tool, select New > Optimized Fixed-Point Conversion to start the data type optimization workflow.

In the Setup pane, under Advanced Options, select the optimization options object to import from the dropdown menu. Click Import.

FPT_advancedOptionsOptimization4.png

Expand the Settings menu in the toolstrip to confirm that the optimization options were applied.

FPT_modifiedSettingsOptimization.png

Version History

Introduced in R2018a

expand all