fiaccel
Accelerate fixed-point code or convert floating-point MATLAB code to fixed-point MATLAB code
Description
fiaccel
translates the MATLAB® file -options
fcn
fcn
.m
to a MEX function, which
accelerates fixed-point code. To use fiaccel
, your code must meet one
of these requirements:
The top-level function has no inputs or outputs, and the code uses
fi
.The top-level function has an output or a non-constant input, and at least one output or input is a
fi
.The top-level function has at least one input or output containing a built-in integer class (
int8
,uint8
,int16
,uint16
,int32
,uint32
,int64
, oruint64
), and the code usesfi
.
Examples
Accelerate Fixed-Point MATLAB Code
This example shows how to accelerate fixed-point MATLAB code using the fiaccel
function.
Define a function that computes the moving average.
type("moving_average.m")
function [avg,z] = moving_average(x,z) %#codegen if nargin < 2 z = fi(zeros(10,1),1,16,15); end z(2:end) = z(1:end-1); % Update buffer z(1) = x; % Add new value avg = mean(z); % Compute moving average end
Create a test file.
type("test_moving_average.m")
function avg = test_moving_average(x) %#codegen if nargin < 1 x = fi(rand(100,1),1,16,15); end z = fi(zeros(10,1),1,16,15); avg = x; for k = 1:length(x) [avg(k),z] = moving_average(x(k),z); end end
Use the fiaccel
function to create a MEX function and accelerate the MATLAB code.
x = fi(rand(100,1),1,16,15); fiaccel test_moving_average -args {x} -report
Compare the non-accelerated and accelerated code.
tic; avg = test_moving_average(x); toc % Non-compiled version tic; avg = test_moving_average_mex(x); toc % Compiled version
Convert Floating-Point MATLAB Code to Fixed Point
Create a coder.FixptConfig
object, fixptcfg
, with default settings.
fixptcfg = coder.config('fixpt');
Set the test bench name. In this example, the test bench function name is dti_test
.
fixptcfg.TestBenchName = 'dti_test';
Convert a floating-point MATLAB function to fixed-point MATLAB code. In this example, the MATLAB function name is dti
.
fiaccel -float2fixed fixptcfg dti
Input Arguments
fcn
— MATLAB function to generate MEX from
function name
MATLAB function to generate MEX from, specified as a function existing in the current working folder or on the path.
Note
If your top-level file is on a path that contains Unicode characters, code generation might not be able to find the file.
-options
— Compiler options
option value | space delimited list of option values
Compiler options, specified as a space delimited list of option values.
fiaccel
gives precedence to individual command-line options over
options specified using a configuration object. If command-line options conflict, the
right-most option prevails.
Specified as one or more of these values:
-args example_inputs | Define the size, class, and complexity of MATLAB function inputs by providing a cell array of example input values. The position of the example input in the cell array must correspond to the position of the input argument in the MATLAB function definition. To generate a function that has fewer input arguments than the function definition has, omit the example values for the arguments that you do not want. Specify the example inputs immediately after the function to which they apply. Instead of an
example value, you can provide a |
-config config_object | Specify MEX generation parameters, based on
For example: cfg = coder.mexconfig; |
-d out_folder | Store generated files in the absolute or relative path specified by
If you do not
specify the folder location, The function
does not support the following characters in folder names: asterisk
( |
-float2fixed
float2fixed_cfg_name | Generates fixed-point MATLAB code using the settings specified by the floating-point to
fixed-point conversion configuration object named
For this
option, You must set the
For example: fixptcfg.TestBenchName = 'myadd_test'; myadd_test is the test file for the floating-point
to fixed-point configuration object fixptcfg .You cannot use this option with the
|
-g | Compiles the MEX function in debug mode, with optimization turned
off. If not specified, |
-global global_values | Specify initial values for global variables in MATLAB file. Use the values in cell array
The generated MEX code and MATLAB each have their own copies of global data. To ensure consistency, you must synchronize their global data whenever the two interact. If you do not synchronize the data, their global variables might differ. You cannot use this option with the
|
-I include_path | Add
|
-launchreport | Generate and open a code generation report. If you do not specify
this option, |
-nargout | Specify the number of output arguments in the generated entry-point function. The code generator produces the specified number of output arguments in the order in which they occur in the MATLAB function definition. |
-o output_file_name | Generate the MEX function with the base name
If you do not specify an
output file name, the base name is |
-O
optimization_option | Optimize generated MEX code, based on the value of
If not specified, |
-report | Generate a code generation report. If you do not specify this option,
|
-? | Display help for |
Version History
Introduced in R2011aR2023a: Change to default fiaccel
behavior for constant inputs
When the fiaccel
function generates a MEX file, it no longer
automatically removes constants from the call to the MEX file. With this change,
fiaccel
and codegen
MEX generation now have the
same default behavior with respect to constant inputs.
fiaccel myfun -args {x,coder.Constant(c)} myfun_mex(x,c)
To revert to the prior behavior, set the ConstantInputs
property of
the coder.MexConfig
object to 'Remove'
.
cfg = coder.MexConfig; cfg.ConstantInputs = "Remove"; fiaccel myfun -args {x,coder.Constant(c)} -config cfg myfun_mex(x)
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: .
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)