Request for Replace Custom Function with Optimized Lookup Table example

조회 수: 10 (최근 30일)
satish guruma
satish guruma 2018년 2월 9일
댓글: Walter Roberson 2018년 2월 9일
Dear All,
I'm trying to implement " Replace Custom Function with Optimized Lookup Table " example.
But I came across the below error message every time.
============= Step3: Generate Fixed Point Code ==============
### Generating Fixed Point MATLAB Code mlhdlc_replacement_exp_fixpt using Proposed Types
### Generating Fixed Point MATLAB Design Wrapper mlhdlc_replacement_exp_wrapper_fixpt
### Generating Mex file for ' mlhdlc_replacement_exp_wrapper_fixpt '
??? Function 'log' is not defined for values of class 'embedded.fi'.
Error in ==> mlhdlc_replacement_exp_fixpt Line: 15 Column: 8
Code generation failed: View Error Report
Build failed.
Use help codegen for more information on using this command.
Function name 'mlhdlc_replacement_exp' specified more than once.
Use help codegen for more information on using this command.
Error using codegen
Actually, I want to make a custom hdl code by using "log" function.
Would you please help me how to to that example ?
Or Would you please give me example code?
I used with the script
clear
clc
clear design_name testbench_name fxpCfg hdlcfg interp_degree
design_name = 'mlhdlc_replacement_exp';
testbench_name = 'mlhdlc_replacement_exp_tb';
interp_degree = 0;
fixed point converter config
fxpCfg = coder.config('fixpt');
fxpCfg.TestBenchName = 'mlhdlc_replacement_exp_tb';
fxpCfg.TestNumerics = true;
% specify this - for optimized HDL
fxpCfg.DefaultWordLength = 40;
fxpCfg.ProposeWordLengthsForDefaultFractionLength = true;
fxpCfg.DefaultFractionLength = 30;
% %% exp - replacement config
% mathFcnGenCfg = coder.approximation('log');
% % generally use to increase accuracy; specify this as power of 2 for optimized HDL
% mathFcnGenCfg.NumberOfPoints = 1024;
% mathFcnGenCfg.InterpolationDegree = interp_degree; % can be 0,1,2, or 3
% fxpCfg.addApproximation(mathFcnGenCfg);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %saturateExp = @(x) 1/(1+exp(-x));
% saturateExp = @(y) log(u)*0.4342944819;
% mathFcnGenCfg = coder.approximation('Function','saturateExp',...
% 'CandidateFunction', saturateExp,...
% 'NumberOfPoints',50,'InputRange',[0,10]);
% fxpCfg.addApproximation(mathFcnGenCfg);
saturateExp = @(x) 1/(1+exp(-x));
custAppx = coder.approximation('Function','saturateExp',...
'CandidateFunction', saturateExp,...
'NumberOfPoints',50,'InputRange',[0,10]);
fxpCfg.addApproximation(custAppx);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
HDL config object
hdlcfg = coder.config('hdl');
hdlcfg.TargetLanguage = 'Verilog';
hdlcfg.DesignFunctionName = design_name;
hdlcfg.TestBenchName = testbench_name;
hdlcfg.GenerateHDLTestBench=true;
hdlcfg.ConstantMultiplierOptimization = 'auto'; %optimize out any multipliers from interpolation
hdlcfg.PipelineVariables = 'y u idx_bot x x_idx';%
hdlcfg.InputPipeline = 2;
hdlcfg.OutputPipeline = 2;
hdlcfg.RegisterInputs = true;
hdlcfg.RegisterOutputs = true;
codegen('-float2fixed',fxpCfg,'-config',hdlcfg,'mlhdlc_replacement_exp')

답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 9일
  댓글 수: 2
satish guruma
satish guruma 2018년 2월 9일
Thanks. But, I came across the below error when I follow your recommends.
Would you please help me what am I supposed to do to resolve this problem?
In fi(var1,var2,...varN) if var1 is not a constant then var2 to varN must be or specify a complete numerictype.
Walter Roberson
Walter Roberson 2018년 2월 9일
I meant more to follow up to the parts about writing replacement functions. You probably do not have a double precision core available for your FPGA, so you are going to have to provide your own log function.

댓글을 달려면 로그인하십시오.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by