Making Simulink HDL Coder with Dynamic Input.

2 ビュー (過去 30 日間)
Albin Grip
Albin Grip 2021 年 7 月 8 日
編集済み: Bharath Venkataraman 2021 年 7 月 12 日
Hello.
I'm trying to design an image processing pipeline operating row-by-row to get frame statistics, this is to be deployed through the HDL coder to an MPSoC Ultrascale+. I'm trying to make the MATLAB function blocks that does the processing take the number of rows and number of columns as inputs to use in for loops for pixel-by-pixel operations. For example this is one of the function blocks in the pipeline.
My question is there any way to declare the array_of_col_stats and row stats to be in terms of ncols instead, i.e. zeros(1, ncols) instead of hard coding zeros(1, 3) when dealing with 3x3 frames. Similarily in the for loop for "curr_pix = 1 : 3", is there any way to change this to loop from 1 : ncols for all the pixels in the row, so I don't need to change each function block every time I want to test with a different image size. I've tried implementing these changes, and the errors from the HDL coder are of using variable sized matricies not allowed, and unbounded loops not allowed respectively.
I've attached the simulink model for reference, its the "HDL DUT" I want to run through the HDL coder.
function [row_stats, row_sq_stats, col_stats, col_sq_stats, frame_complete] = array_stats(square_row, row, nrowsint, ncolsint)
%#codegen
nrows = nrowsint;
ncols = ncolsint;
persistent array_of_col_stats; %Intermediate storage arrays until frame is done
if isempty(array_of_col_stats)
array_of_col_stats = uint32(zeros(1, 3)); %Replace with ncols
end
persistent array_of_row_stats;
if isempty(array_of_row_stats)
array_of_row_stats = uint32(zeros(3, 1)); %Replace with nrows
end
persistent array_of_col_sq_stats;
if isempty(array_of_col_sq_stats)
array_of_col_sq_stats = uint32(zeros(1, 3)); %Replace with ncols
end
persistent array_of_row_sq_stats;
if isempty(array_of_row_sq_stats)
array_of_row_sq_stats = uint32(zeros(3, 1)); %Replace with nrows
end
persistent row_ctr; %Used to keep track of when a frame is finished
if isempty(row_ctr)
row_ctr = uint32(2);
end
if row_ctr == 1
array_of_row_stats = uint32(zeros(3, 1)); %Reset to zero at the end of a frame
array_of_row_sq_stats = uint32(zeros(3, 1));
array_of_col_stats = uint32(zeros(1, 3));
array_of_col_sq_stats = uint32(zeros(1, 3));
end
curr_row_sum = uint32(0); %Current row stats
curr_row_sum_sq = uint32(0); %Current row sq stats
for curr_pix = 1 : 3
curr_row_sum = curr_row_sum + row(curr_pix); %Obtain sum for curr row
curr_row_sum_sq = curr_row_sum_sq + square_row(curr_pix); %Obtain sumsq for curr row
array_of_col_stats(curr_pix) = array_of_col_stats(curr_pix) + row(curr_pix); %Add to col statistics array
array_of_col_sq_stats(curr_pix) = array_of_col_sq_stats(curr_pix) + square_row(curr_pix); %Add to colsq statistics array
end
if row_ctr <= nrows
array_of_row_stats(row_ctr) = curr_row_sum; %Append curr row to row stats array
array_of_row_sq_stats(row_ctr) = curr_row_sum_sq; %Append curr row sq to row stats array
end
row_stats = array_of_row_stats; %Output assignments
row_sq_stats = array_of_row_sq_stats;
col_stats = array_of_col_stats;
col_sq_stats = array_of_col_sq_stats;
row_ctr = row_ctr + 1; %Incriment row counter after row processing
if row_ctr == nrows + 1
frame_complete = true; %Use out as a MUX enable for outpuits in Simulink
row_ctr = uint32(1); %Reset row at EOF.
else
frame_complete = false;
end
end
  4 件のコメント
Bharath Venkataraman
Bharath Venkataraman 2021 年 7 月 12 日
The issue with row-by-row is that the number of data points is variable, where as with pixel by pixel (or even multiple pixels at a time), depending on where in time the start and end line signals show up, the line/row length can be varied.
One other thing you can do is to have a max row size (for loop goes from1:maxRowSize), and a current row size value, so while you process the max row size, you can disregard any result after the current row size has been reached.
One question I have is if you are trying to change the number of pixels per row in real-time, or if you are merely trying to change the parameter once at the start of the simulation.
If it helps, there are two examples of external memory with Vision HDL Toolbox in this page: Vertical video flipping, and CLAHE.

サインインしてコメントする。

回答 (1 件)

Kiran Kintali
Kiran Kintali 2021 年 7 月 8 日
What version of MATLAB are you using?
I am able to generate code for the 'masters_v5/DUT/HDL DUT' subsystem
>> makehdl(gcb)
### Applying HDL optimizations on the model 'masters_v5'...
### Begin model generation.
### Model generation complete.
### Begin VHDL Code Generation for 'masters_v5'.
### Working on masters_v5/DUT/HDL DUT/Regular Processing Pipeline/Array Stats as masterv4\hdlsrc\masters_v5\Array_Stats.vhd.
### Working on masters_v5/DUT/HDL DUT/Regular Processing Pipeline/SSSQ Algorithm as masterv4\hdlsrc\masters_v5\SSSQ_Algorithm.vhd.
### Working on masters_v5/DUT/HDL DUT/Regular Processing Pipeline/Square Row as masterv4\hdlsrc\masters_v5\Square_Row.vhd.
### Working on masters_v5/DUT/HDL DUT/Regular Processing Pipeline as masterv4\hdlsrc\masters_v5\Regular_Processing_Pipeline.vhd.
### Working on masters_v5/DUT/HDL DUT/FIFO Ring Buffer as masterv4\hdlsrc\masters_v5\FIFO_Ring_Buffer.vhd.
### Working on masters_v5/DUT/HDL DUT as masterv4\hdlsrc\masters_v5\HDL_DUT.vhd.
### Generating package file masterv4\hdlsrc\masters_v5\HDL_DUT_pkg.vhd.
### Code Generation for 'masters_v5' completed.
### Creating HDL Code Generation Check Report HDL_DUT_report.html
### HDL check for 'masters_v5' complete with 0 errors, 1 warnings, and 0 messages.
### HDL code generation complete.
>> makehdltb(gcb)
### Begin TestBench generation.
### Generating HDL TestBench for 'masters_v5/DUT/HDL DUT'.
### Begin compilation of the model 'masters_v5'...
### Collecting data...
### Generating test bench data file: masterv4\hdlsrc\masters_v5\row_dat.dat.
### Generating test bench data file: masterv4\hdlsrc\masters_v5\sum_frame_expected.dat.
### Generating test bench data file: masterv4\hdlsrc\masters_v5\sssq_frame_expected.dat.
### Generating test bench data file: masterv4\hdlsrc\masters_v5\n_expected.dat.
### Generating test bench data file: masterv4\hdlsrc\masters_v5\row_stats_frame_expected.dat.
### Generating test bench data file: masterv4\hdlsrc\masters_v5\row_stats_sq_frame_expected.dat.
### Generating test bench data file: masterv4\hdlsrc\masters_v5\col_stats_frame_expected.dat.
### Generating test bench data file: masterv4\hdlsrc\masters_v5\col_stats_sq_frame_expected.dat.
### Working on HDL_DUT_tb as masterv4\hdlsrc\masters_v5\HDL_DUT_tb.vhd.
### Generating package file masterv4\hdlsrc\masters_v5\HDL_DUT_tb_pkg.vhd.
### HDL TestBench generation complete.
>>
  1 件のコメント
Albin Grip
Albin Grip 2021 年 7 月 9 日
The version I uploaded is with everything hard coded, if I try to make it dynamic these errors come up. I've attached this version here to show the problems with the code generation.

サインインしてコメントする。

カテゴリ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by