필터 지우기
필터 지우기

Loop based error while performing HDL conversion using HDL workflow

조회 수: 2 (최근 30일)
Siddarth S
Siddarth S 2024년 3월 9일
편집: Kiran Kintali 2024년 3월 16일
I am trying to find specific rows and columns of an image for image processing based project.I am trying find all the rows/columns which are row of 1.I am able to code it in MATLAB and get the right results but when I try to convert it into HDL format,I am facing this issue all the time and I am unable to proceed further.Although I am able to do it once for a specific row but not in a loop to check for all rows.
The error I am getting is:
My MATLAB code:
%Sample Test bench
x=[1,0,0,1,0;0,0,0,0,1;1,1,1,1,1;0,0,0,0,0;1,1,1,1,1];
[Row]=rowseg1(x);
%Design function
function [x]=rowseg1(image)
[m,~]=size(image);
u=1;
a=repelem(u,m);
x=zeros(1,m);
k=image(3,:);
for i=1:m
if(image(i,:)==a)
x(i)=i;
else
x(i)=0;
end
end
end
  댓글 수: 2
Kiran Kintali
Kiran Kintali 2024년 3월 16일
편집: Kiran Kintali 2024년 3월 16일
This is how you would make the above snippet generate synthesizable code. Notice that you need to run float2fixed conversation if you do not wish to have floating point relational operator in the synthesized hardware. For guidance related to really large image matrices as inputs see the other thread below on this page.
Testbench
x=[1,0,0,1,0;0,0,0,0,1;1,1,1,1,1;0,0,0,0,0;1,1,1,1,1];
[Row]=rowseg1(x);
DUT
%Design function
function [x]=rowseg1(image)
[m,~]=size(image);
u=1;
a=repelem(u,m);
x=zeros(1,m);
k=image(3,:);
for i=1:m
if isequal(image(i,:), a)
x(i)=i;
else
x(i)=0;
end
end
end
Runme
cfg = coder.config('hdl');
cfg.TestBenchName = 'rowseg1_tb';
cfg.DesignFunctionName = 'rowseg1';
cfg.FloatingPointLibrary = 'NativeFloatingPoint';
cfg.AggressiveDataflowConversion = true;
codegen -config cfg

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

답변 (1개)

Kiran Kintali
Kiran Kintali 2024년 3월 10일
편집: Kiran Kintali 2024년 3월 11일
Your MATLAB Coding style is incompatible with MATLAB to HDL workflow. Here are few general pointers while we respond to your specific question. To make the code compatible you have two choices...
  • Option #1: Author the code as sample in and sample out format...
% for sample in and sample out code style follow the example below.
% you can see how the image is serialized in the testbench and the
% serialized image samples are passed into the DUT
>> mlhdlc_demo_setup('heq')
  • Option #2: Author the code with frames and use automatic frame to sample conversion workflow...
% for frame in and frame out code style follow the example below
% you can see how hdl.npufun and hdl.iteratorfun functions are used to
% iterate on the input frame passed into the DUT
>> mlhdlc_demo_setup('fog')
You can see general HDL Coder compatible MATLAB coding style patterns here
  댓글 수: 5
Siddarth S
Siddarth S 2024년 3월 16일
So based on this and some other research,I tried using iteratorfun since it keeps input at a matrix level which will better for this problem.But when try it,I am getting one error which I actually don't understand.
Error:
%Error calling 'test/rowseg'. This call-site passes more inputs to this function than it can accept.
%The error line in the function
outputData = iterFun(I(ii, jj), outputData, idx, varargin{:});
My code:
function y = test(I)
%#codegen
[m,n]=size(I);
y=zeros(1,m);
for i=1:m
out=0;
out=hdl.iteratorfun(@rowseg,I,i,out);
y(i)=out;
end
end
function x=rowseg(I,i)
[m,n]=size(I);
u=1;
a=repelem(u,m);
x=0;
if(I(i,:)==a)
x=i;
end
end
Kiran Kintali
Kiran Kintali 2024년 3월 16일
You are on the right path if you choose frame2sample path (where your DUT receives whole image as input).
However, you need to have a test.m that looks like...
% read an image...
I = imread(<file>);
[height, width] = size(imgOrig);
for height
for width
I_out = dut(I)
end
end
and a dut.m that looks like this...
function I_out = dut(I)
... body that uses I and iterates on it using hdl.npufun and hdl.iteratorfun.
end
You need a runme.m file that looks like this... (see attached fog rectification example with a runme file)
% Runme file for fog rectification example design
% Provide Design Name and Testbench file.
designName = 'mlhdlc_fog_rectification';
designTB = 'mlhdlc_fog_rectification_tb';
% Create HDL config.
cfg = coder.config('hdl');
cfg.TestBenchName = designTB;
% Enable Frame to Sample Conversion
cfg.AggressiveDataflowConversion = true;
cfg.FrameToSampleConversion = true;
cfg.SynthesisTool = 'Xilinx Vivado';
cfg.SynthesizeGeneratedCode = true; % turn this if off if you just want RTL
cfg.SynthesisToolChipFamily = 'Artix7';
cfg.SynthesisToolDeviceName = 'xa7a100t';
cfg.SynthesisToolPackageName = 'csg324';
cfg.SynthesisToolSpeedValue = '-1I';
% Create inputs to provide code generation arguments
I = imread('inputFogRectification.png');
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
% Call codegen with float2fixed and hdl config objects.
codegen('-config', 'cfg', designName, '-launchreport', '-args', {R,G,B});

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

카테고리

Help CenterFile Exchange에서 Code Generation에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by